target_if_spectral.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512
  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 <wlan_tgt_def_config.h>
  20. #include <hif.h>
  21. #include <target_type.h>
  22. #include <hif_hw_version.h>
  23. #include <wmi_unified_api.h>
  24. #include <target_if_spectral.h>
  25. #include <wlan_lmac_if_def.h>
  26. #include <wlan_osif_priv.h>
  27. #include <reg_services_public_struct.h>
  28. #ifdef CONFIG_WIN
  29. #include <wlan_mlme_dispatcher.h>
  30. #endif /*CONFIG_WIN*/
  31. #include <reg_services_public_struct.h>
  32. #include <target_if_spectral_sim.h>
  33. /**
  34. * @spectral_ops - Spectral function table, holds the Spectral functions that
  35. * depend on whether the architecture is Direct Attach or Offload. This is used
  36. * to populate the actual Spectral function table present in the Spectral
  37. * module.
  38. */
  39. struct target_if_spectral_ops spectral_ops;
  40. int spectral_debug_level = ATH_DEBUG_SPECTRAL;
  41. /**
  42. * target_if_spectral_get_vdev() - Get pointer to vdev to be used for Spectral
  43. * operations
  44. * @spectral: Pointer to Spectral target_if internal private data
  45. *
  46. * Spectral operates on pdev. However, in order to retrieve some WLAN
  47. * properties, a vdev is required. To facilitate this, the function returns the
  48. * first vdev in our pdev. The caller should release the reference to the vdev
  49. * once it is done using it.
  50. * TODO: If the framework later provides an API to obtain the first active
  51. * vdev, then it would be preferable to use this API.
  52. *
  53. * Return: Pointer to vdev on success, NULL on failure
  54. */
  55. struct wlan_objmgr_vdev *
  56. target_if_spectral_get_vdev(struct target_if_spectral *spectral)
  57. {
  58. struct wlan_objmgr_pdev *pdev = NULL;
  59. struct wlan_objmgr_vdev *vdev = NULL;
  60. qdf_assert_always(spectral);
  61. pdev = spectral->pdev_obj;
  62. qdf_assert_always(pdev);
  63. if (wlan_objmgr_pdev_try_get_ref(pdev, WLAN_SPECTRAL_ID) !=
  64. QDF_STATUS_SUCCESS) {
  65. qdf_print("%s: Unable to get pdev reference.\n", __func__);
  66. return NULL;
  67. }
  68. vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, 0, WLAN_SPECTRAL_ID);
  69. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  70. if (!vdev) {
  71. qdf_print("%s: Unable to get first vdev of pdev.\n", __func__);
  72. return NULL;
  73. }
  74. return vdev;
  75. }
  76. /**
  77. * target_if_send_vdev_spectral_configure_cmd() - Send WMI command to configure
  78. * Spectral parameters
  79. * @spectral: Pointer to Spectral target_if internal private data
  80. * @param: Pointer to spectral_config giving the Spectral configuration
  81. *
  82. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  83. */
  84. static int target_if_send_vdev_spectral_configure_cmd(
  85. struct target_if_spectral *spectral,
  86. struct spectral_config *param)
  87. {
  88. struct vdev_spectral_configure_params sparam;
  89. struct wlan_objmgr_pdev *pdev = NULL;
  90. struct wlan_objmgr_vdev *vdev = NULL;
  91. qdf_assert_always(spectral && param);
  92. pdev = spectral->pdev_obj;
  93. qdf_assert_always(pdev);
  94. vdev = target_if_spectral_get_vdev(spectral);
  95. if (!vdev)
  96. return QDF_STATUS_E_NOENT;
  97. qdf_mem_set(&sparam, sizeof(sparam), 0);
  98. sparam.vdev_id = wlan_vdev_get_id(vdev);
  99. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  100. sparam.count = param->ss_count;
  101. sparam.period = param->ss_period;
  102. sparam.spectral_pri = param->ss_spectral_pri;
  103. sparam.fft_size = param->ss_fft_size;
  104. sparam.gc_enable = param->ss_gc_ena;
  105. sparam.restart_enable = param->ss_restart_ena;
  106. sparam.noise_floor_ref = param->ss_noise_floor_ref;
  107. sparam.init_delay = param->ss_init_delay;
  108. sparam.nb_tone_thr = param->ss_nb_tone_thr;
  109. sparam.str_bin_thr = param->ss_str_bin_thr;
  110. sparam.wb_rpt_mode = param->ss_wb_rpt_mode;
  111. sparam.rssi_rpt_mode = param->ss_rssi_rpt_mode;
  112. sparam.rssi_thr = param->ss_rssi_thr;
  113. sparam.pwr_format = param->ss_pwr_format;
  114. sparam.rpt_mode = param->ss_rpt_mode;
  115. sparam.bin_scale = param->ss_bin_scale;
  116. sparam.dBm_adj = param->ss_dbm_adj;
  117. sparam.chn_mask = param->ss_chn_mask;
  118. return spectral->param_wmi_cmd_ops.wmi_spectral_configure_cmd_send(
  119. (wmi_unified_t)pdev->tgt_if_handle, &sparam);
  120. }
  121. /**
  122. * target_if_send_vdev_spectral_enable_cmd() - Send WMI command to
  123. * enable/disable Spectral
  124. * @spectral: Pointer to Spectral target_if internal private data
  125. * @is_spectral_active_valid: Flag to indicate if spectral activate (trigger) is
  126. * valid
  127. * @is_spectral_active: Value of spectral activate
  128. * @is_spectral_enabled_valid: Flag to indicate if spectral enable is valid
  129. * @is_spectral_enabled: Value of spectral enable
  130. *
  131. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  132. */
  133. static int target_if_send_vdev_spectral_enable_cmd(
  134. struct target_if_spectral *spectral,
  135. u_int8_t is_spectral_active_valid,
  136. u_int8_t is_spectral_active,
  137. u_int8_t is_spectral_enabled_valid,
  138. u_int8_t is_spectral_enabled)
  139. {
  140. struct vdev_spectral_enable_params param;
  141. struct wlan_objmgr_pdev *pdev = NULL;
  142. struct wlan_objmgr_vdev *vdev = NULL;
  143. qdf_assert_always(spectral);
  144. pdev = spectral->pdev_obj;
  145. qdf_assert_always(pdev);
  146. vdev = target_if_spectral_get_vdev(spectral);
  147. if (!vdev)
  148. return QDF_STATUS_E_NOENT;
  149. qdf_mem_set(&param, sizeof(param), 0);
  150. param.vdev_id = wlan_vdev_get_id(vdev);
  151. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  152. param.active_valid = is_spectral_active_valid;
  153. param.enabled_valid = is_spectral_enabled_valid;
  154. param.active = is_spectral_active;
  155. param.enabled = is_spectral_enabled;
  156. return spectral->param_wmi_cmd_ops.wmi_spectral_enable_cmd_send(
  157. (wmi_unified_t)pdev->tgt_if_handle, &param);
  158. }
  159. /**
  160. * target_if_spectral_info_init_defaults() - Helper function to load defaults
  161. * for Spectral information (parameters and state) into cache.
  162. * @spectral: Pointer to Spectral target_if internal private data
  163. *
  164. * It is assumed that the caller has obtained the requisite lock if applicable.
  165. * Note that this is currently treated as a temporary function. Ideally, we
  166. * would like to get defaults from the firmware.
  167. *
  168. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  169. */
  170. static int target_if_spectral_info_init_defaults(struct target_if_spectral *spectral)
  171. {
  172. struct target_if_spectral_param_state_info *info = &spectral->ol_info;
  173. struct wlan_objmgr_vdev *vdev = NULL;
  174. /* State */
  175. info->osps_cache.osc_spectral_active =
  176. SPECTRAL_SCAN_ACTIVE_DEFAULT;
  177. info->osps_cache.osc_spectral_enabled =
  178. SPECTRAL_SCAN_ENABLE_DEFAULT;
  179. /* Parameters */
  180. info->osps_cache.osc_params.ss_count =
  181. SPECTRAL_SCAN_COUNT_DEFAULT;
  182. info->osps_cache.osc_params.ss_period =
  183. SPECTRAL_SCAN_PERIOD_DEFAULT;
  184. info->osps_cache.osc_params.ss_spectral_pri =
  185. SPECTRAL_SCAN_PRIORITY_DEFAULT;
  186. info->osps_cache.osc_params.ss_fft_size =
  187. SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  188. info->osps_cache.osc_params.ss_gc_ena =
  189. SPECTRAL_SCAN_GC_ENA_DEFAULT;
  190. info->osps_cache.osc_params.ss_restart_ena =
  191. SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  192. info->osps_cache.osc_params.ss_noise_floor_ref =
  193. SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  194. info->osps_cache.osc_params.ss_init_delay =
  195. SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  196. info->osps_cache.osc_params.ss_nb_tone_thr =
  197. SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  198. info->osps_cache.osc_params.ss_str_bin_thr =
  199. SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  200. info->osps_cache.osc_params.ss_wb_rpt_mode =
  201. SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  202. info->osps_cache.osc_params.ss_rssi_rpt_mode =
  203. SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  204. info->osps_cache.osc_params.ss_rssi_thr =
  205. SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  206. info->osps_cache.osc_params.ss_pwr_format =
  207. SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  208. info->osps_cache.osc_params.ss_rpt_mode =
  209. SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  210. info->osps_cache.osc_params.ss_bin_scale =
  211. SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  212. info->osps_cache.osc_params.ss_dbm_adj =
  213. SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  214. vdev = target_if_spectral_get_vdev(spectral);
  215. if (!vdev)
  216. return QDF_STATUS_E_NOENT;
  217. info->osps_cache.osc_params.ss_chn_mask =
  218. wlan_vdev_mlme_get_rxchainmask(vdev);
  219. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  220. /* The cache is now valid */
  221. info->osps_cache.osc_is_valid = 1;
  222. return QDF_STATUS_SUCCESS;
  223. }
  224. /**
  225. * ol_spectral_info_read() - Read Spectral parameters or the desired state
  226. * information from the cache.
  227. * @spectral: Pointer to Spectral target_if internal private data
  228. * @specifier: ol_spectral_info_spec enumeration specifying which information is
  229. * required
  230. * @output: Void output pointer into which the information will be read
  231. * @output_len: size of object pointed to by output pointer
  232. *
  233. * Return: 0 on success, negative error code on failure
  234. */
  235. static int ol_spectral_info_read(struct target_if_spectral *spectral,
  236. enum ol_spectral_info_spec specifier,
  237. void *output,
  238. int output_len)
  239. {
  240. /* Note: This function is designed to be able to accommodate
  241. * WMI reads for defaults, non-cacheable information, etc
  242. * if required.
  243. */
  244. struct target_if_spectral_param_state_info *info = &spectral->ol_info;
  245. int is_cacheable = 0;
  246. int init_def_retval = 0;
  247. if (!output)
  248. return -EINVAL;
  249. switch (specifier) {
  250. case OL_SPECTRAL_INFO_SPEC_ACTIVE:
  251. if (output_len !=
  252. sizeof(info->osps_cache.osc_spectral_active))
  253. return -EINVAL;
  254. is_cacheable = 1;
  255. break;
  256. case OL_SPECTRAL_INFO_SPEC_ENABLED:
  257. if (output_len !=
  258. sizeof(info->osps_cache.osc_spectral_enabled))
  259. return -EINVAL;
  260. is_cacheable = 1;
  261. break;
  262. case OL_SPECTRAL_INFO_SPEC_PARAMS:
  263. if (output_len != sizeof(info->osps_cache.osc_params))
  264. return -EINVAL;
  265. is_cacheable = 1;
  266. break;
  267. default:
  268. qdf_print("%s: Unknown ol_spectral_info_spec specifier\n",
  269. __func__);
  270. return -EINVAL;
  271. }
  272. qdf_spin_lock(&info->osps_lock);
  273. if (is_cacheable) {
  274. if (info->osps_cache.osc_is_valid) {
  275. switch (specifier) {
  276. case OL_SPECTRAL_INFO_SPEC_ACTIVE:
  277. qdf_mem_copy(
  278. output,
  279. &info->osps_cache.osc_spectral_active,
  280. sizeof(info->osps_cache.osc_spectral_active));
  281. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  282. qdf_print("%s: OL_SPECTRAL_INFO_SPEC_ACTIVE. "
  283. "Returning val=%u\n",
  284. __func__,
  285. *((unsigned char *)output));
  286. #endif /* OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS */
  287. break;
  288. case OL_SPECTRAL_INFO_SPEC_ENABLED:
  289. qdf_mem_copy(
  290. output,
  291. &info->osps_cache.osc_spectral_enabled,
  292. sizeof(info->osps_cache.osc_spectral_enabled));
  293. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  294. qdf_print("%s: OL_SPECTRAL_INFO_SPEC_ENABLED. "
  295. "Returning val=%u\n",
  296. __func__,
  297. *((unsigned char *)output));
  298. #endif /* OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS */
  299. break;
  300. case OL_SPECTRAL_INFO_SPEC_PARAMS:
  301. qdf_mem_copy(
  302. output,
  303. &info->osps_cache.osc_params,
  304. sizeof(info->osps_cache.osc_params));
  305. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  306. {
  307. struct spectral_config *pparam =
  308. (struct spectral_config *)output;
  309. qdf_print("%s: OL_SPECTRAL_INFO_SPEC_PARAMS. "
  310. "Returning following params:\n"
  311. "ss_count = %u\n"
  312. "ss_period = %u\n"
  313. "ss_spectral_pri = %u\n"
  314. "ss_fft_size = %u\n"
  315. "ss_gc_ena = %u\n"
  316. "ss_restart_ena = %u\n"
  317. "ss_noise_floor_ref = %d\n"
  318. "ss_init_delay = %u\n"
  319. "ss_nb_tone_thr = %u\n"
  320. "ss_str_bin_thr = %u\n"
  321. "ss_wb_rpt_mode = %u\n"
  322. "ss_rssi_rpt_mode = %u\n"
  323. "ss_rssi_thr = %d\n"
  324. "ss_pwr_format = %u\n"
  325. "ss_rpt_mode = %u\n"
  326. "ss_bin_scale = %u\n"
  327. "ss_dbm_adj = %u\n"
  328. "ss_chn_mask = %u\n\n",
  329. __func__,
  330. pparam->ss_count,
  331. pparam->ss_period,
  332. pparam->ss_spectral_pri,
  333. pparam->ss_fft_size,
  334. pparam->ss_gc_ena,
  335. pparam->ss_restart_ena,
  336. (int8_t)pparam->ss_noise_floor_ref,
  337. pparam->ss_init_delay,
  338. pparam->ss_nb_tone_thr,
  339. pparam->ss_str_bin_thr,
  340. pparam->ss_wb_rpt_mode,
  341. pparam->ss_rssi_rpt_mode,
  342. (int8_t)pparam->ss_rssi_thr,
  343. pparam->ss_pwr_format,
  344. pparam->ss_rpt_mode,
  345. pparam->ss_bin_scale,
  346. pparam->ss_dbm_adj,
  347. pparam->ss_chn_mask);
  348. }
  349. #endif /* OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS */
  350. break;
  351. default:
  352. /* We can't reach this point */
  353. break;
  354. }
  355. qdf_spin_unlock(&info->osps_lock);
  356. return 0;
  357. }
  358. }
  359. /* Cache is invalid */
  360. /* If WMI Reads are implemented to fetch defaults/non-cacheable info,
  361. * then the below implementation will change
  362. */
  363. init_def_retval = target_if_spectral_info_init_defaults(spectral);
  364. if (init_def_retval != QDF_STATUS_SUCCESS) {
  365. if (init_def_retval == QDF_STATUS_E_NOENT)
  366. return -ENOENT;
  367. else
  368. return -EINVAL;
  369. }
  370. /* target_if_spectral_info_init_defaults() has set cache to valid */
  371. switch (specifier) {
  372. case OL_SPECTRAL_INFO_SPEC_ACTIVE:
  373. qdf_mem_copy(output,
  374. &info->osps_cache.osc_spectral_active,
  375. sizeof(info->osps_cache.osc_spectral_active));
  376. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  377. qdf_print("%s: OL_SPECTRAL_INFO_SPEC_ACTIVE on "
  378. "initial cache validation\n"
  379. "Returning val=%u\n",
  380. __func__,
  381. *((unsigned char *)output));
  382. #endif /* OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS */
  383. break;
  384. case OL_SPECTRAL_INFO_SPEC_ENABLED:
  385. qdf_mem_copy(output,
  386. &info->osps_cache.osc_spectral_enabled,
  387. sizeof(info->osps_cache.osc_spectral_enabled));
  388. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  389. qdf_print("%s: OL_SPECTRAL_INFO_SPEC_ENABLED on "
  390. "initial cache validation\n"
  391. "Returning val=%u\n",
  392. __func__,
  393. *((unsigned char *)output));
  394. #endif /* OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS */
  395. break;
  396. case OL_SPECTRAL_INFO_SPEC_PARAMS:
  397. qdf_mem_copy(output,
  398. &info->osps_cache.osc_params,
  399. sizeof(info->osps_cache.osc_params));
  400. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  401. {
  402. struct spectral_config *pparam =
  403. (struct spectral_config *)output;
  404. qdf_print("%s: OL_SPECTRAL_INFO_SPEC_PARAMS on "
  405. "initial cache validation\n"
  406. "Returning following params:\n"
  407. "ss_count = %u\n"
  408. "ss_period = %u\n"
  409. "ss_spectral_pri = %u\n"
  410. "ss_fft_size = %u\n"
  411. "ss_gc_ena = %u\n"
  412. "ss_restart_ena = %u\n"
  413. "ss_noise_floor_ref = %d\n"
  414. "ss_init_delay = %u\n"
  415. "ss_nb_tone_thr = %u\n"
  416. "ss_str_bin_thr = %u\n"
  417. "ss_wb_rpt_mode = %u\n"
  418. "ss_rssi_rpt_mode = %u\n"
  419. "ss_rssi_thr = %d\n"
  420. "ss_pwr_format = %u\n"
  421. "ss_rpt_mode = %u\n"
  422. "ss_bin_scale = %u\n"
  423. "ss_dbm_adj = %u\n"
  424. "ss_chn_mask = %u\n\n",
  425. __func__,
  426. pparam->ss_count,
  427. pparam->ss_period,
  428. pparam->ss_spectral_pri,
  429. pparam->ss_fft_size,
  430. pparam->ss_gc_ena,
  431. pparam->ss_restart_ena,
  432. (int8_t)pparam->ss_noise_floor_ref,
  433. pparam->ss_init_delay,
  434. pparam->ss_nb_tone_thr,
  435. pparam->ss_str_bin_thr,
  436. pparam->ss_wb_rpt_mode,
  437. pparam->ss_rssi_rpt_mode,
  438. (int8_t)pparam->ss_rssi_thr,
  439. pparam->ss_pwr_format,
  440. pparam->ss_rpt_mode,
  441. pparam->ss_bin_scale,
  442. pparam->ss_dbm_adj,
  443. pparam->ss_chn_mask);
  444. }
  445. #endif /* OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS */
  446. break;
  447. default:
  448. /* We can't reach this point */
  449. break;
  450. }
  451. qdf_spin_unlock(&info->osps_lock);
  452. return 0;
  453. }
  454. /**
  455. * ol_spectral_info_write() - Write Spectral parameters or the desired state
  456. * information to the firmware, and update cache
  457. * @spectral: Pointer to Spectral target_if internal private data
  458. * @specifier: ol_spectral_info_spec enumeration specifying which information is
  459. * involved
  460. * @input: void input pointer containing the information to be written
  461. * @input_len: size of object pointed to by input pointer
  462. *
  463. * Return: 0 on success, negative error code on failure
  464. */
  465. static int ol_spectral_info_write(struct target_if_spectral *spectral,
  466. enum ol_spectral_info_spec specifier,
  467. void *input,
  468. int input_len)
  469. {
  470. struct target_if_spectral_param_state_info *info = &spectral->ol_info;
  471. int ret;
  472. u_int8_t *pval = NULL;
  473. struct spectral_config *param = NULL;
  474. if (!input)
  475. return -EINVAL;
  476. switch (specifier) {
  477. case OL_SPECTRAL_INFO_SPEC_ACTIVE:
  478. if (input_len !=
  479. sizeof(info->osps_cache.osc_spectral_active))
  480. return -EINVAL;
  481. pval = (u_int8_t *)input;
  482. qdf_spin_lock(&info->osps_lock);
  483. ret = target_if_send_vdev_spectral_enable_cmd(
  484. spectral,
  485. 1,
  486. *pval,
  487. 0,
  488. 0);
  489. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  490. qdf_print("%s: OL_SPECTRAL_INFO_SPEC_ACTIVE with "
  491. "val=%u status=%d\n",
  492. __func__,
  493. *pval,
  494. ret);
  495. #endif /* OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS */
  496. if (ret < 0) {
  497. qdf_print(
  498. "%s: target_if_send_vdev_spectral_enable_cmd "
  499. "failed with error=%d\n",
  500. __func__,
  501. ret);
  502. qdf_spin_unlock(&info->osps_lock);
  503. return ret;
  504. }
  505. info->osps_cache.osc_spectral_active = *pval;
  506. qdf_spin_unlock(&info->osps_lock);
  507. break;
  508. case OL_SPECTRAL_INFO_SPEC_ENABLED:
  509. if (input_len !=
  510. sizeof(info->osps_cache.osc_spectral_enabled))
  511. return -EINVAL;
  512. pval = (u_int8_t *)input;
  513. qdf_spin_lock(&info->osps_lock);
  514. ret = target_if_send_vdev_spectral_enable_cmd(
  515. spectral,
  516. 0,
  517. 0,
  518. 1,
  519. *pval);
  520. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  521. qdf_print("%s: OL_SPECTRAL_INFO_SPEC_ENABLED with "
  522. "val=%u status=%d\n",
  523. __func__,
  524. *pval,
  525. ret);
  526. #endif /* OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS */
  527. if (ret < 0) {
  528. qdf_print(
  529. "%s: target_if_send_vdev_spectral_enable_cmd "
  530. "failed with error=%d\n",
  531. __func__,
  532. ret);
  533. qdf_spin_unlock(&info->osps_lock);
  534. return ret;
  535. }
  536. info->osps_cache.osc_spectral_enabled = *pval;
  537. qdf_spin_unlock(&info->osps_lock);
  538. break;
  539. case OL_SPECTRAL_INFO_SPEC_PARAMS:
  540. if (input_len != sizeof(info->osps_cache.osc_params))
  541. return -EINVAL;
  542. param = (struct spectral_config *)input;
  543. qdf_spin_lock(&info->osps_lock);
  544. ret = target_if_send_vdev_spectral_configure_cmd(
  545. spectral,
  546. param);
  547. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  548. qdf_print("%s: OL_SPECTRAL_INFO_SPEC_PARAMS. "
  549. "Params:\n"
  550. "ss_count = %u\n"
  551. "ss_period = %u\n"
  552. "ss_spectral_pri = %u\n"
  553. "ss_fft_size = %u\n"
  554. "ss_gc_ena = %u\n"
  555. "ss_restart_ena = %u\n"
  556. "ss_noise_floor_ref = %d\n"
  557. "ss_init_delay = %u\n"
  558. "ss_nb_tone_thr = %u\n"
  559. "ss_str_bin_thr = %u\n"
  560. "ss_wb_rpt_mode = %u\n"
  561. "ss_rssi_rpt_mode = %u\n"
  562. "ss_rssi_thr = %d\n"
  563. "ss_pwr_format = %u\n"
  564. "ss_rpt_mode = %u\n"
  565. "ss_bin_scale = %u\n"
  566. "ss_dbm_adj = %u\n"
  567. "ss_chn_mask = %u\n"
  568. "status = %d\n\n",
  569. __func__,
  570. param->ss_count,
  571. param->ss_period,
  572. param->ss_spectral_pri,
  573. param->ss_fft_size,
  574. param->ss_gc_ena,
  575. param->ss_restart_ena,
  576. (int8_t)param->ss_noise_floor_ref,
  577. param->ss_init_delay,
  578. param->ss_nb_tone_thr,
  579. param->ss_str_bin_thr,
  580. param->ss_wb_rpt_mode,
  581. param->ss_rssi_rpt_mode,
  582. (int8_t)param->ss_rssi_thr,
  583. param->ss_pwr_format,
  584. param->ss_rpt_mode,
  585. param->ss_bin_scale,
  586. param->ss_dbm_adj,
  587. param->ss_chn_mask,
  588. ret);
  589. #endif /* OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS */
  590. if (ret < 0) {
  591. qdf_print(
  592. "%s: "
  593. "target_if_send_vdev_spectral_configure_cmd "
  594. "failed with error=%d\n",
  595. __func__,
  596. ret);
  597. qdf_spin_unlock(&info->osps_lock);
  598. return ret;
  599. }
  600. qdf_mem_copy(&info->osps_cache.osc_params,
  601. param,
  602. sizeof(info->osps_cache.osc_params));
  603. qdf_spin_unlock(&info->osps_lock);
  604. break;
  605. default:
  606. qdf_print("%s: Unknown OL_SPECTRAL_INFO_SPEC_T "
  607. "specifier\n",
  608. __func__);
  609. return -EINVAL;
  610. }
  611. return 0;
  612. }
  613. /**
  614. * target_if_spectral_get_tsf64() - Get the last TSF received in WMI buffer
  615. * @arg: Pointer to handle for Spectral target_if internal private data
  616. *
  617. * Return: TSF value
  618. */
  619. static u_int64_t target_if_spectral_get_tsf64(void *arg)
  620. {
  621. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  622. return spectral->tsf64;
  623. }
  624. /**
  625. * target_if_spectral_get_capability() - Get whether a given Spectral hardware
  626. * capability is available
  627. * @arg: Pointer to handle for Spectral target_if internal private data
  628. * @type: Spectral hardware capability type
  629. *
  630. * Return: True if the capability is available, false if the capability is not
  631. * available
  632. */
  633. u_int32_t target_if_spectral_get_capability(
  634. void *arg,
  635. SPECTRAL_CAPABILITY_TYPE type)
  636. {
  637. int status = STATUS_FAIL;
  638. switch (type) {
  639. case SPECTRAL_CAP_PHYDIAG:
  640. case SPECTRAL_CAP_RADAR:
  641. case SPECTRAL_CAP_SPECTRAL_SCAN:
  642. case SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN:
  643. status = STATUS_PASS;
  644. break;
  645. default:
  646. status = STATUS_FAIL;
  647. }
  648. return status;
  649. }
  650. /**
  651. * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
  652. * @arg: Pointer to handle for Spectral target_if internal private data
  653. * @rxfilter: Rx filter to be used
  654. *
  655. * Note: This is only a placeholder function. It is not currently required since
  656. * FW should be taking care of setting the required filters.
  657. *
  658. * Return: 0
  659. */
  660. u_int32_t target_if_spectral_set_rxfilter(void *arg, int rxfilter)
  661. {
  662. /* Will not be required since enabling of spectral in firmware
  663. * will take care of this
  664. */
  665. return 0;
  666. }
  667. /**
  668. * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
  669. * @arg: Pointer to handle for Spectral target_if internal private data
  670. *
  671. * Note: This is only a placeholder function. It is not currently required since
  672. * FW should be taking care of setting the required filters.
  673. *
  674. * Return: 0
  675. */
  676. u_int32_t target_if_spectral_get_rxfilter(void *arg)
  677. {
  678. /* Will not be required since enabling of spectral in firmware
  679. * will take care of this
  680. */
  681. return 0;
  682. }
  683. /**
  684. * tgt_if_is_spectral_active() - Get whether Spectral is active
  685. * @arg: Pointer to handle for Spectral target_if internal private data
  686. *
  687. * Return: True if Spectral is active, false if Spectral is not active
  688. */
  689. u_int32_t tgt_if_is_spectral_active(void *arg)
  690. {
  691. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  692. u_int8_t val = 0;
  693. int ret;
  694. ret = ol_spectral_info_read(spectral,
  695. OL_SPECTRAL_INFO_SPEC_ACTIVE,
  696. &val,
  697. sizeof(val));
  698. if (ret != 0) {
  699. /* Could not determine if Spectral is active.
  700. * Return false as a safe value.
  701. * XXX: Consider changing the function prototype
  702. * to be able to indicate failure to fetch value.
  703. */
  704. return 0;
  705. }
  706. return val;
  707. }
  708. /**
  709. * tgt_if_is_spectral_enabled() - Get whether Spectral is enabled
  710. * @arg: Pointer to handle for Spectral target_if internal private data
  711. *
  712. * Return: True if Spectral is enabled, false if Spectral is not enabled
  713. */
  714. u_int32_t tgt_if_is_spectral_enabled(void *arg)
  715. {
  716. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  717. u_int8_t val = 0;
  718. int ret;
  719. ret = ol_spectral_info_read(spectral,
  720. OL_SPECTRAL_INFO_SPEC_ENABLED,
  721. &val,
  722. sizeof(val));
  723. if (ret != 0) {
  724. /* Could not determine if Spectral is enabled.
  725. * Return false as a safe value.
  726. * XXX: Consider changing the function prototype
  727. * to be able to indicate failure to fetch value.
  728. */
  729. return 0;
  730. }
  731. return val;
  732. }
  733. /**
  734. * tgt_if_start_spectral_scan() - Start Spectral scan
  735. * @arg: Pointer to handle for Spectral target_if internal private data
  736. *
  737. * Return: 1 on success, 0 on failure
  738. */
  739. u_int32_t tgt_if_start_spectral_scan(void *arg)
  740. {
  741. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  742. u_int8_t val = 1;
  743. u_int8_t enabled = 0;
  744. int ret;
  745. ret = ol_spectral_info_read(spectral,
  746. OL_SPECTRAL_INFO_SPEC_ENABLED,
  747. &enabled,
  748. sizeof(enabled));
  749. if (ret != 0) {
  750. /* Could not determine if Spectral is enabled. Assume we need
  751. * to enable it
  752. */
  753. enabled = 0;
  754. }
  755. if (!enabled) {
  756. ret = ol_spectral_info_write(spectral,
  757. OL_SPECTRAL_INFO_SPEC_ENABLED,
  758. &val,
  759. sizeof(val));
  760. if (ret != 0)
  761. return 0;
  762. }
  763. ret = ol_spectral_info_write(spectral,
  764. OL_SPECTRAL_INFO_SPEC_ACTIVE,
  765. &val,
  766. sizeof(val));
  767. if (ret != 0)
  768. return 0;
  769. return 1;
  770. }
  771. /**
  772. * tgt_if_stop_spectral_scan() - Stop Spectral scan
  773. * @arg: Pointer to handle for Spectral target_if internal private data
  774. *
  775. * Return: 1 on success, 0 on failure
  776. */
  777. u_int32_t tgt_if_stop_spectral_scan(void *arg)
  778. {
  779. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  780. u_int8_t val = 0;
  781. int tempret, ret = 1;
  782. tempret = ol_spectral_info_write(spectral,
  783. OL_SPECTRAL_INFO_SPEC_ACTIVE,
  784. &val,
  785. sizeof(val));
  786. if (tempret != 0)
  787. ret = 0;
  788. tempret = ol_spectral_info_write(spectral,
  789. OL_SPECTRAL_INFO_SPEC_ENABLED,
  790. &val,
  791. sizeof(val));
  792. if (tempret != 0)
  793. ret = 0;
  794. return ret;
  795. }
  796. /**
  797. * target_if_spectral_get_extension_channel() - Get the current Extension
  798. * channel (in MHz)
  799. * @arg: Pointer to handle for Spectral target_if internal private data
  800. *
  801. * Return: Current Extension channel (in MHz) on success, 0 on failure or if
  802. * extension channel is not present.
  803. */
  804. u_int32_t target_if_spectral_get_extension_channel(void *arg)
  805. {
  806. /* XXX: Once we expand to use cases where Spectral could be activated
  807. * without a channel being set to VDEV, we need to consider returning a
  808. * negative value in case of failure and having all callers handle this.
  809. */
  810. struct target_if_spectral *spectral = NULL;
  811. struct wlan_objmgr_vdev *vdev = NULL;
  812. u_int16_t sec20chan_freq = 0;
  813. qdf_assert_always(arg);
  814. spectral = (struct target_if_spectral *)arg;
  815. vdev = target_if_spectral_get_vdev(spectral);
  816. if (!vdev)
  817. return 0;
  818. if (target_if_vdev_get_sec20chan_freq_mhz(vdev, &sec20chan_freq) < 0) {
  819. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  820. return 0;
  821. }
  822. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  823. return sec20chan_freq;
  824. }
  825. /**
  826. * target_if_spectral_get_current_channel() - Get the current channel (in MHz)
  827. * @arg: Pointer to handle for Spectral target_if internal private data
  828. *
  829. * Return: Current channel (in MHz) on success, 0 on failure
  830. */
  831. u_int32_t target_if_spectral_get_current_channel(void *arg)
  832. {
  833. /* XXX: Once we expand to use cases where Spectral could be activated
  834. * without a channel being set to VDEV, we need to consider returning a
  835. * negative value in case of failure and having all callers handle this.
  836. */
  837. struct target_if_spectral *spectral = NULL;
  838. int16_t chan_freq = 0;
  839. struct wlan_objmgr_vdev *vdev = NULL;
  840. qdf_assert_always(arg);
  841. spectral = (struct target_if_spectral *)arg;
  842. vdev = target_if_spectral_get_vdev(spectral);
  843. if (!vdev)
  844. return 0;
  845. chan_freq = target_if_vdev_get_chan_freq(vdev);
  846. if (chan_freq < 0) {
  847. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  848. return 0;
  849. }
  850. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  851. return chan_freq;
  852. }
  853. /**
  854. * target_if_spectral_reset_hw() - Reset the hardware
  855. * @arg: Pointer to handle for Spectral target_if internal private data
  856. *
  857. * This is only a placeholder since it is not currently required in the offload
  858. * case.
  859. *
  860. * Return: 0
  861. */
  862. u_int32_t target_if_spectral_reset_hw(void *arg)
  863. {
  864. not_yet_implemented();
  865. return 0;
  866. }
  867. /**
  868. * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
  869. * Noisefloor history buffer
  870. * @arg: Pointer to handle for Spectral target_if internal private data
  871. * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
  872. *
  873. * This is only a placeholder since it is not currently required in the offload
  874. * case.
  875. *
  876. * Return: 0
  877. */
  878. u_int32_t target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  879. {
  880. not_yet_implemented();
  881. return 0;
  882. }
  883. /**
  884. * target_if_spectral_get_ext_noisefloor() - Get the extension channel
  885. * noisefloor
  886. * @arg: Pointer to handle for Spectral target_if internal private data
  887. *
  888. * This is only a placeholder since it is not currently required in the offload
  889. * case.
  890. *
  891. * Return: 0
  892. */
  893. int8_t target_if_spectral_get_ext_noisefloor(void *arg)
  894. {
  895. not_yet_implemented();
  896. return 0;
  897. }
  898. /**
  899. * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
  900. * @arg: Pointer to handle for Spectral target_if internal private data
  901. *
  902. * This is only a placeholder since it is not currently required in the offload
  903. * case.
  904. *
  905. * Return: 0
  906. */
  907. int8_t target_if_spectral_get_ctl_noisefloor(void *arg)
  908. {
  909. not_yet_implemented();
  910. return 0;
  911. }
  912. /**
  913. * target_if_spectral_configure_params() - Configure user supplied Spectral
  914. * parameters
  915. * @arg: Pointer to handle for Spectral target_if internal private data
  916. * @params: Spectral parameters
  917. *
  918. * Return: 1 on success, 0 on failure.
  919. */
  920. u_int32_t target_if_spectral_configure_params(
  921. void *arg,
  922. struct spectral_config *params)
  923. {
  924. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  925. int ret;
  926. ret = ol_spectral_info_write(spectral,
  927. OL_SPECTRAL_INFO_SPEC_PARAMS,
  928. params,
  929. sizeof(*params));
  930. if (ret != 0)
  931. return 0;
  932. return 1;
  933. }
  934. /**
  935. * target_if_spectral_get_params() - Get user configured Spectral parameters
  936. * @arg: Pointer to handle for Spectral target_if internal private data
  937. * @params: Pointer to buffer into which Spectral parameters should be copied
  938. *
  939. * Return: 1 on success, 0 on failure.
  940. */
  941. u_int32_t target_if_spectral_get_params(
  942. void *arg,
  943. struct spectral_config *params)
  944. {
  945. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  946. int ret;
  947. ret = ol_spectral_info_read(spectral,
  948. OL_SPECTRAL_INFO_SPEC_PARAMS,
  949. params,
  950. sizeof(*params));
  951. if (ret != 0)
  952. return 0;
  953. return 1;
  954. }
  955. /**
  956. * target_if_spectral_get_ent_mask() - Get enterprise mask
  957. * @arg: Pointer to handle for Spectral target_if internal private data
  958. *
  959. * This is only a placeholder since it is not currently required in the offload
  960. * case.
  961. *
  962. * Return: 0
  963. */
  964. static u_int32_t target_if_spectral_get_ent_mask(void *arg)
  965. {
  966. not_yet_implemented();
  967. return 0;
  968. }
  969. /**
  970. * target_if_spectral_get_macaddr() - Get radio MAC address
  971. * @arg: Pointer to handle for Spectral target_if internal private data
  972. * @addr: Pointer to buffer into which MAC address should be copied
  973. *
  974. * Return: 0 on success, -1 on failure
  975. */
  976. static u_int32_t target_if_spectral_get_macaddr(void *arg, char *addr)
  977. {
  978. uint8_t *myaddr = NULL;
  979. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  980. struct wlan_objmgr_pdev *pdev = NULL;
  981. pdev = spectral->pdev_obj;
  982. wlan_pdev_obj_lock(pdev);
  983. myaddr = wlan_pdev_get_hw_macaddr(pdev);
  984. wlan_pdev_obj_unlock(pdev);
  985. qdf_mem_copy(addr, myaddr, IEEE80211_ADDR_LEN);
  986. return 0;
  987. }
  988. /**
  989. * init_spectral_capability() - Initialize Spectral capability
  990. * @spectral: Pointer to Spectral target_if internal private data
  991. *
  992. * This is a workaround.
  993. *
  994. * Return: None
  995. */
  996. void init_spectral_capability(struct target_if_spectral *spectral)
  997. {
  998. struct spectral_caps *pcap = &spectral->capability;
  999. /* XXX : Workaround: Set Spectral capability */
  1000. pcap = &spectral->capability;
  1001. pcap->phydiag_cap = 1;
  1002. pcap->radar_cap = 1;
  1003. pcap->spectral_cap = 1;
  1004. pcap->advncd_spectral_cap = 1;
  1005. }
  1006. /**
  1007. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  1008. * operations common to all Spectral chipset generations
  1009. *
  1010. * Return: None
  1011. */
  1012. static void target_if_init_spectral_ops_common(void)
  1013. {
  1014. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1015. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  1016. p_sops->get_capability = target_if_spectral_get_capability;
  1017. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  1018. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  1019. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1020. /* Spectral simulation is currently intended for platform transitions
  1021. * where underlying HW support may not be available for some time.
  1022. * Hence, we do not currently provide a runtime switch to turn the
  1023. * simulation on or off.
  1024. * In case of future requirements where runtime switches are required,
  1025. * this can be added. But it is suggested to use application layer
  1026. * simulation as far as possible in such cases, since the main
  1027. * use of record and replay of samples would concern higher
  1028. * level sample processing rather than lower level delivery.
  1029. */
  1030. p_sops->is_spectral_enabled = tif_spectral_sim_is_spectral_enabled;
  1031. p_sops->is_spectral_active = tif_spectral_sim_is_spectral_active;
  1032. p_sops->start_spectral_scan = tif_spectral_sim_start_spectral_scan;
  1033. p_sops->stop_spectral_scan = tif_spectral_sim_stop_spectral_scan;
  1034. p_sops->configure_spectral = tif_spectral_sim_configure_params;
  1035. p_sops->get_spectral_config = tif_spectral_sim_get_params;
  1036. #else
  1037. p_sops->is_spectral_enabled = tgt_if_is_spectral_enabled;
  1038. p_sops->is_spectral_active = tgt_if_is_spectral_active;
  1039. p_sops->start_spectral_scan = tgt_if_start_spectral_scan;
  1040. p_sops->stop_spectral_scan = tgt_if_stop_spectral_scan;
  1041. p_sops->configure_spectral = target_if_spectral_configure_params;
  1042. p_sops->get_spectral_config = target_if_spectral_get_params;
  1043. #endif /* QCA_SUPPORT_SPECTRAL_SIMULATION */
  1044. p_sops->get_extension_channel =
  1045. target_if_spectral_get_extension_channel;
  1046. p_sops->get_ctl_noisefloor =
  1047. target_if_spectral_get_ctl_noisefloor;
  1048. p_sops->get_ext_noisefloor =
  1049. target_if_spectral_get_ext_noisefloor;
  1050. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  1051. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  1052. p_sops->get_current_channel =
  1053. target_if_spectral_get_current_channel;
  1054. p_sops->reset_hw = target_if_spectral_reset_hw;
  1055. p_sops->get_chain_noise_floor =
  1056. target_if_spectral_get_chain_noise_floor;
  1057. }
  1058. /**
  1059. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  1060. * operations specific to Spectral chipset generation 2.
  1061. *
  1062. * Return: None
  1063. */
  1064. static void target_if_init_spectral_ops_gen2(void)
  1065. {
  1066. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1067. p_sops->spectral_process_phyerr = spectral_process_phyerr_gen2;
  1068. }
  1069. /**
  1070. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  1071. * operations specific to Spectral chipset generation 3.
  1072. *
  1073. * Return: None
  1074. */
  1075. static void target_if_init_spectral_ops_gen3(void)
  1076. {
  1077. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1078. p_sops->spectral_process_phyerr = spectral_process_phyerr_gen3;
  1079. }
  1080. /**
  1081. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  1082. * operations.
  1083. * @spectral: Pointer to Spectral target_if internal private data
  1084. *
  1085. * Return: None
  1086. */
  1087. static void target_if_init_spectral_ops(struct target_if_spectral *spectral)
  1088. {
  1089. target_if_init_spectral_ops_common();
  1090. if (spectral->spectral_gen == SPECTRAL_GEN2)
  1091. target_if_init_spectral_ops_gen2();
  1092. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  1093. target_if_init_spectral_ops_gen3();
  1094. else
  1095. qdf_print("Invalid spetral generation\n");
  1096. }
  1097. /*
  1098. * Dummy Functions:
  1099. * These functions are initially registered to avoid any crashes due to
  1100. * invocation of spectral functions before they are registered.
  1101. */
  1102. static u_int64_t null_get_tsf64(void *arg)
  1103. {
  1104. spectral_ops_not_registered("get_tsf64");
  1105. return 0;
  1106. }
  1107. static u_int32_t null_get_capability(void *arg, SPECTRAL_CAPABILITY_TYPE type)
  1108. {
  1109. /*
  1110. * TODO : We should have conditional compilation to get the capability
  1111. * : We have not yet attahced ATH layer here, so there is no
  1112. * : way to check the HAL capbalities
  1113. */
  1114. spectral_ops_not_registered("get_capability");
  1115. /* TODO : For the time being, we are returning TRUE */
  1116. return true;
  1117. }
  1118. static u_int32_t null_set_rxfilter(void *arg, int rxfilter)
  1119. {
  1120. spectral_ops_not_registered("set_rxfilter");
  1121. return 1;
  1122. }
  1123. static u_int32_t null_get_rxfilter(void *arg)
  1124. {
  1125. spectral_ops_not_registered("get_rxfilter");
  1126. return 0;
  1127. }
  1128. static u_int32_t null_is_spectral_active(void *arg)
  1129. {
  1130. spectral_ops_not_registered("is_spectral_active");
  1131. return 1;
  1132. }
  1133. static u_int32_t null_is_spectral_enabled(void *arg)
  1134. {
  1135. spectral_ops_not_registered("is_spectral_enabled");
  1136. return 1;
  1137. }
  1138. static u_int32_t null_start_spectral_scan(void *arg)
  1139. {
  1140. spectral_ops_not_registered("start_spectral_scan");
  1141. return 1;
  1142. }
  1143. static u_int32_t null_stop_spectral_scan(void *arg)
  1144. {
  1145. spectral_ops_not_registered("stop_spectral_scan");
  1146. return 1;
  1147. }
  1148. static u_int32_t null_get_extension_channel(void *arg)
  1149. {
  1150. spectral_ops_not_registered("get_extension_channel");
  1151. return 1;
  1152. }
  1153. static int8_t null_get_ctl_noisefloor(void *arg)
  1154. {
  1155. spectral_ops_not_registered("get_ctl_noisefloor");
  1156. return 1;
  1157. }
  1158. static int8_t null_get_ext_noisefloor(void *arg)
  1159. {
  1160. spectral_ops_not_registered("get_ext_noisefloor");
  1161. return 0;
  1162. }
  1163. static u_int32_t null_configure_spectral(
  1164. void *arg,
  1165. struct spectral_config *params)
  1166. {
  1167. spectral_ops_not_registered("configure_spectral");
  1168. return 0;
  1169. }
  1170. static u_int32_t null_get_spectral_config(
  1171. void *arg,
  1172. struct spectral_config *params)
  1173. {
  1174. spectral_ops_not_registered("get_spectral_config");
  1175. return 0;
  1176. }
  1177. static u_int32_t null_get_ent_spectral_mask(void *arg)
  1178. {
  1179. spectral_ops_not_registered("get_ent_spectral_mask");
  1180. return 0;
  1181. }
  1182. static u_int32_t null_get_mac_address(void *arg, char *addr)
  1183. {
  1184. spectral_ops_not_registered("get_mac_address");
  1185. return 0;
  1186. }
  1187. static u_int32_t null_get_current_channel(void *arg)
  1188. {
  1189. spectral_ops_not_registered("get_current_channel");
  1190. return 0;
  1191. }
  1192. static u_int32_t null_reset_hw(void *arg)
  1193. {
  1194. spectral_ops_not_registered("get_current_channel");
  1195. return 0;
  1196. }
  1197. static u_int32_t null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1198. {
  1199. spectral_ops_not_registered("get_chain_noise_floor");
  1200. return 0;
  1201. }
  1202. static int null_spectral_process_phyerr(
  1203. struct target_if_spectral *spectral,
  1204. u_int8_t *data,
  1205. u_int32_t datalen,
  1206. struct target_if_spectral_rfqual_info *p_rfqual,
  1207. struct target_if_spectral_chan_info *p_chaninfo,
  1208. u_int64_t tsf64,
  1209. struct target_if_spectral_acs_stats *acs_stats)
  1210. {
  1211. spectral_ops_not_registered("spectral_process_phyerr");
  1212. return 0;
  1213. }
  1214. /**
  1215. * target_if_spectral_init_dummy_function_table() -
  1216. * Initialize target_if internal
  1217. * Spectral operations to dummy functions
  1218. * @ps: Pointer to Spectral target_if internal private data
  1219. *
  1220. * Return: None
  1221. */
  1222. static void target_if_spectral_init_dummy_function_table(
  1223. struct target_if_spectral *ps)
  1224. {
  1225. struct target_if_spectral_ops *p_sops = GET_TIF_SPECTRAL_OPS(ps);
  1226. p_sops->get_tsf64 = null_get_tsf64;
  1227. p_sops->get_capability = null_get_capability;
  1228. p_sops->set_rxfilter = null_set_rxfilter;
  1229. p_sops->get_rxfilter = null_get_rxfilter;
  1230. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  1231. p_sops->is_spectral_active = null_is_spectral_active;
  1232. p_sops->start_spectral_scan = null_start_spectral_scan;
  1233. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  1234. p_sops->get_extension_channel = null_get_extension_channel;
  1235. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  1236. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  1237. p_sops->configure_spectral = null_configure_spectral;
  1238. p_sops->get_spectral_config = null_get_spectral_config;
  1239. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  1240. p_sops->get_mac_address = null_get_mac_address;
  1241. p_sops->get_current_channel = null_get_current_channel;
  1242. p_sops->reset_hw = null_reset_hw;
  1243. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  1244. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  1245. }
  1246. /**
  1247. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  1248. * operations
  1249. * @spectral: Pointer to Spectral target_if internal private data
  1250. * @p: Pointer to Spectral function table
  1251. *
  1252. * Return: None
  1253. */
  1254. static void target_if_spectral_register_funcs(
  1255. struct target_if_spectral *spectral,
  1256. struct target_if_spectral_ops *p)
  1257. {
  1258. struct target_if_spectral_ops *p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  1259. p_sops->get_tsf64 = p->get_tsf64;
  1260. p_sops->get_capability = p->get_capability;
  1261. p_sops->set_rxfilter = p->set_rxfilter;
  1262. p_sops->get_rxfilter = p->get_rxfilter;
  1263. p_sops->is_spectral_enabled = p->is_spectral_enabled;
  1264. p_sops->is_spectral_active = p->is_spectral_active;
  1265. p_sops->start_spectral_scan = p->start_spectral_scan;
  1266. p_sops->stop_spectral_scan = p->stop_spectral_scan;
  1267. p_sops->get_extension_channel = p->get_extension_channel;
  1268. p_sops->get_ctl_noisefloor = p->get_ctl_noisefloor;
  1269. p_sops->get_ext_noisefloor = p->get_ext_noisefloor;
  1270. p_sops->configure_spectral = p->configure_spectral;
  1271. p_sops->get_spectral_config = p->get_spectral_config;
  1272. p_sops->get_ent_spectral_mask = p->get_ent_spectral_mask;
  1273. p_sops->get_mac_address = p->get_mac_address;
  1274. p_sops->get_current_channel = p->get_current_channel;
  1275. p_sops->reset_hw = p->reset_hw;
  1276. p_sops->get_chain_noise_floor = p->get_chain_noise_floor;
  1277. p_sops->spectral_process_phyerr = p->spectral_process_phyerr;
  1278. }
  1279. /**
  1280. * target_if_spectral_clear_stats() - Clear Spectral stats
  1281. * @spectral: Pointer to Spectral target_if internal private data
  1282. *
  1283. * Return: None
  1284. */
  1285. static void target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  1286. {
  1287. struct target_if_spectral_ops *p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  1288. qdf_mem_zero(
  1289. &spectral->ath_spectral_stats,
  1290. sizeof(struct target_if_spectral_stats));
  1291. spectral->ath_spectral_stats.last_reset_tstamp =
  1292. p_sops->get_tsf64(spectral);
  1293. }
  1294. /**
  1295. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  1296. * @spectral: Pointer to Spectral target_if internal private data
  1297. *
  1298. * Return: True if HW supports Spectral, false if HW does not support Spectral
  1299. */
  1300. static int target_if_spectral_check_hw_capability(
  1301. struct target_if_spectral *spectral)
  1302. {
  1303. struct target_if_spectral_ops *p_sops = NULL;
  1304. struct spectral_caps *pcap = NULL;
  1305. int is_spectral_supported = true;
  1306. p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  1307. pcap = &spectral->capability;
  1308. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  1309. is_spectral_supported = false;
  1310. qdf_print("SPECTRAL : No PHYDIAG support\n");
  1311. return is_spectral_supported;
  1312. }
  1313. pcap->phydiag_cap = 1;
  1314. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  1315. is_spectral_supported = false;
  1316. qdf_print("SPECTRAL : No RADAR support\n");
  1317. return is_spectral_supported;
  1318. }
  1319. pcap->radar_cap = 1;
  1320. if (
  1321. p_sops->get_capability(spectral,
  1322. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  1323. is_spectral_supported = false;
  1324. qdf_print("SPECTRAL : No SPECTRAL SUPPORT\n");
  1325. return is_spectral_supported;
  1326. }
  1327. pcap->spectral_cap = 1;
  1328. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  1329. == false) {
  1330. qdf_print("SPECTRAL : No ADVANCED SPECTRAL SUPPORT\n");
  1331. } else {
  1332. pcap->advncd_spectral_cap = 1;
  1333. }
  1334. return is_spectral_supported;
  1335. }
  1336. /**
  1337. * target_if_spectral_init_param_defaults() - Initialize Spectral
  1338. * parameter defaults
  1339. * @spectral: Pointer to Spectral target_if internal private data
  1340. *
  1341. * It is the caller's responsibility to ensure that the Spectral parameters
  1342. * structure passed as part of Spectral target_if internal private data is
  1343. * valid.
  1344. *
  1345. * Return: None
  1346. */
  1347. static void target_if_spectral_init_param_defaults(
  1348. struct target_if_spectral *spectral)
  1349. {
  1350. struct spectral_config *params = &spectral->params;
  1351. params->ss_count = SPECTRAL_SCAN_COUNT_DEFAULT;
  1352. params->ss_period = SPECTRAL_SCAN_PERIOD_DEFAULT;
  1353. params->ss_spectral_pri = SPECTRAL_SCAN_PRIORITY_DEFAULT;
  1354. params->ss_fft_size = SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  1355. params->ss_gc_ena = SPECTRAL_SCAN_GC_ENA_DEFAULT;
  1356. params->ss_restart_ena = SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  1357. params->ss_noise_floor_ref = SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  1358. params->ss_init_delay = SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  1359. params->ss_nb_tone_thr = SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  1360. params->ss_str_bin_thr = SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  1361. params->ss_wb_rpt_mode = SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  1362. params->ss_rssi_rpt_mode = SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  1363. params->ss_rssi_thr = SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  1364. params->ss_pwr_format = SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  1365. params->ss_rpt_mode = SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  1366. params->ss_bin_scale = SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  1367. params->ss_dbm_adj = SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  1368. /*
  1369. * XXX
  1370. * SPECTRAL_SCAN_CHN_MASK_DEFAULT (0x1) specifies that chain 0 is to be
  1371. * used
  1372. * for Spectral. This is expected to be an optimal configuration for
  1373. * most chipsets considering aspects like power save. But this can later
  1374. * optionally be changed to be set to the default system Rx chainmask
  1375. * advertised by FW (if required for some purpose), once the Convergence
  1376. * framework supports such retrieval at pdev attach time.
  1377. */
  1378. params->ss_chn_mask = SPECTRAL_SCAN_CHN_MASK_DEFAULT;
  1379. params->ss_short_report = SPECTRAL_SCAN_SHORT_REPORT_DEFAULT;
  1380. params->ss_fft_period = SPECTRAL_SCAN_FFT_PERIOD_DEFAULT;
  1381. }
  1382. /**
  1383. * target_if_spectral_detach() - De-initialize target_if Spectral
  1384. * @pdev: Pointer to pdev object
  1385. *
  1386. * Return: None
  1387. */
  1388. static void target_if_spectral_detach(struct target_if_spectral *spectral)
  1389. {
  1390. qdf_print("spectral detach\n");
  1391. qdf_spinlock_destroy(&spectral->ol_info.osps_lock);
  1392. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1393. target_if_spectral_sim_detach(spectral);
  1394. #endif /* QCA_SUPPORT_SPECTRAL_SIMULATION */
  1395. #ifdef SPECTRAL_USE_NETLINK_SOCKETS
  1396. target_if_spectral_destroy_netlink(spectral);
  1397. #endif
  1398. qdf_spinlock_destroy(&spectral->ath_spectral_lock);
  1399. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  1400. if (spectral) {
  1401. qdf_mem_free(spectral);
  1402. spectral = NULL;
  1403. }
  1404. }
  1405. /**
  1406. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  1407. * functionality for the given pdev
  1408. * @pdev: Pointer to pdev object
  1409. *
  1410. * Return: On success, pointer to Spectral target_if internal private data, on
  1411. * failure, NULL
  1412. */
  1413. void *target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  1414. {
  1415. struct target_if_spectral_ops *p_sops = NULL;
  1416. struct target_if_spectral *spectral = NULL;
  1417. #ifdef CONFIG_WIN
  1418. struct ol_ath_softc_net80211 *scn = NULL;
  1419. #endif
  1420. struct pdev_osif_priv *osif_priv = NULL;
  1421. osif_priv = wlan_pdev_get_ospriv(pdev);
  1422. #ifdef CONFIG_WIN
  1423. scn = (struct ol_ath_softc_net80211 *)osif_priv->legacy_osif_priv;
  1424. if (!scn) {
  1425. qdf_print("%s: scn is NULL!\n", __func__);
  1426. return NULL;
  1427. }
  1428. #endif
  1429. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  1430. sizeof(struct target_if_spectral));
  1431. if (!spectral) {
  1432. qdf_print("SPECTRAL : Memory allocation failed\n");
  1433. return spectral;
  1434. }
  1435. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  1436. /* Store pdev in Spectral */
  1437. spectral->pdev_obj = pdev;
  1438. /* init the function ptr table */
  1439. target_if_spectral_init_dummy_function_table(spectral);
  1440. /* get spectral function table */
  1441. p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  1442. /* TODO : Should this be called here of after ath_attach ? */
  1443. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  1444. qdf_print(KERN_INFO "HAL_CAP_PHYDIAG : Capable\n");
  1445. SPECTRAL_TODO("Need to fix the capablity check for RADAR");
  1446. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  1447. qdf_print(KERN_INFO "HAL_CAP_RADAR : Capable\n");
  1448. SPECTRAL_TODO("Need to fix the capablity check for SPECTRAL\n");
  1449. /* TODO : Should this be called here of after ath_attach ? */
  1450. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  1451. qdf_print(KERN_INFO "HAL_CAP_SPECTRAL_SCAN : Capable\n");
  1452. qdf_spinlock_create(&spectral->ath_spectral_lock);
  1453. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  1454. target_if_spectral_clear_stats(spectral);
  1455. qdf_spinlock_create(&spectral->spectral_skbqlock);
  1456. STAILQ_INIT(&spectral->spectral_skbq);
  1457. #ifdef SPECTRAL_USE_NETLINK_SOCKETS
  1458. target_if_spectral_init_netlink(spectral);
  1459. #endif
  1460. /* Set the default values for spectral parameters */
  1461. target_if_spectral_init_param_defaults(spectral);
  1462. #ifdef CONFIG_WIN
  1463. if ((scn->soc->target_type == TARGET_TYPE_QCA8074) || (
  1464. scn->soc->target_type == TARGET_TYPE_QCA6290)) {
  1465. spectral->spectral_gen = SPECTRAL_GEN3;
  1466. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  1467. spectral->tag_sscan_summary_exp =
  1468. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  1469. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  1470. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  1471. } else {
  1472. spectral->spectral_gen = SPECTRAL_GEN2;
  1473. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  1474. spectral->tag_sscan_summary_exp =
  1475. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  1476. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  1477. spectral->tlvhdr_size = sizeof(SPECTRAL_PHYERR_TLV_GEN2);
  1478. }
  1479. #else
  1480. spectral->spectral_gen = SPECTRAL_GEN3;
  1481. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  1482. spectral->tag_sscan_summary_exp =
  1483. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  1484. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  1485. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  1486. #endif
  1487. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1488. if (target_if_spectral_sim_attach(spectral)) {
  1489. qdf_mem_free(spectral);
  1490. return NULL;
  1491. }
  1492. #endif /* QCA_SUPPORT_SPECTRAL_SIMULATION */
  1493. target_if_init_spectral_ops(spectral);
  1494. qdf_spinlock_create(&spectral->ol_info.osps_lock);
  1495. spectral->ol_info.osps_cache.osc_is_valid = 0;
  1496. target_if_spectral_register_funcs(spectral, &spectral_ops);
  1497. if (target_if_spectral_check_hw_capability(spectral) == false) {
  1498. target_if_spectral_detach(spectral);
  1499. spectral = NULL;
  1500. } else {
  1501. /* TODO: Once the driver architecture transitions to chipset
  1502. * versioning based checks, reflect this here.
  1503. */
  1504. spectral->is_160_format = false;
  1505. spectral->is_lb_edge_extrabins_format = false;
  1506. spectral->is_rb_edge_extrabins_format = false;
  1507. #ifdef CONFIG_WIN
  1508. if (scn->soc->target_type == TARGET_TYPE_QCA9984 ||
  1509. scn->soc->target_type == TARGET_TYPE_QCA9888) {
  1510. spectral->is_160_format = true;
  1511. spectral->is_lb_edge_extrabins_format = true;
  1512. spectral->is_rb_edge_extrabins_format = true;
  1513. } else if ((scn->soc->target_type == TARGET_TYPE_AR900B) &&
  1514. (scn->soc->target_revision == AR900B_REV_2)) {
  1515. spectral->is_rb_edge_extrabins_format = true;
  1516. }
  1517. if (scn->soc->target_type == TARGET_TYPE_QCA9984 ||
  1518. scn->soc->target_type == TARGET_TYPE_QCA9888)
  1519. spectral->is_sec80_rssi_war_required = true;
  1520. #else
  1521. spectral->is_160_format = true;
  1522. spectral->is_lb_edge_extrabins_format = true;
  1523. spectral->is_rb_edge_extrabins_format = true;
  1524. #endif
  1525. }
  1526. return spectral;
  1527. }
  1528. /**
  1529. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  1530. * functionality for the given pdev
  1531. * @pdev: Pointer to pdev object
  1532. *
  1533. * Return: None
  1534. */
  1535. void target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  1536. {
  1537. struct target_if_spectral *spectral = NULL;
  1538. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1539. if (!spectral) {
  1540. qdf_print("SPECTRAL : Module doesn't exist\n");
  1541. return;
  1542. }
  1543. target_if_spectral_detach(spectral);
  1544. return;
  1545. }
  1546. /**
  1547. * target_if_set_spectral_config() - Set spectral config
  1548. * @pdev: Pointer to pdev object
  1549. * @threshtype: config type
  1550. * @value: config value
  1551. *
  1552. * API to set spectral configurations
  1553. *
  1554. * Return: 1 on success, 0 on failure
  1555. */
  1556. int target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  1557. const u_int32_t threshtype,
  1558. const u_int32_t value)
  1559. {
  1560. struct spectral_config params;
  1561. struct target_if_spectral_ops *p_sops = NULL;
  1562. struct target_if_spectral *spectral = NULL;
  1563. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1564. p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  1565. if (!spectral) {
  1566. qdf_print("%s: spectral object is NULL\n", __func__);
  1567. return 0;
  1568. }
  1569. switch (threshtype) {
  1570. case SPECTRAL_PARAM_FFT_PERIOD:
  1571. spectral->params.ss_fft_period = value;
  1572. break;
  1573. case SPECTRAL_PARAM_SCAN_PERIOD:
  1574. spectral->params.ss_period = value;
  1575. break;
  1576. case SPECTRAL_PARAM_SCAN_COUNT:
  1577. spectral->params.ss_count = value;
  1578. break;
  1579. case SPECTRAL_PARAM_SHORT_REPORT:
  1580. spectral->params.ss_short_report = (!!value) ? true : false;
  1581. break;
  1582. case SPECTRAL_PARAM_SPECT_PRI:
  1583. spectral->params.ss_spectral_pri = (!!value) ? true : false;
  1584. break;
  1585. case SPECTRAL_PARAM_FFT_SIZE:
  1586. spectral->params.ss_fft_size = value;
  1587. break;
  1588. case SPECTRAL_PARAM_GC_ENA:
  1589. spectral->params.ss_gc_ena = !!value;
  1590. break;
  1591. case SPECTRAL_PARAM_RESTART_ENA:
  1592. spectral->params.ss_restart_ena = !!value;
  1593. break;
  1594. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  1595. spectral->params.ss_noise_floor_ref = value;
  1596. break;
  1597. case SPECTRAL_PARAM_INIT_DELAY:
  1598. spectral->params.ss_init_delay = value;
  1599. break;
  1600. case SPECTRAL_PARAM_NB_TONE_THR:
  1601. spectral->params.ss_nb_tone_thr = value;
  1602. break;
  1603. case SPECTRAL_PARAM_STR_BIN_THR:
  1604. spectral->params.ss_str_bin_thr = value;
  1605. break;
  1606. case SPECTRAL_PARAM_WB_RPT_MODE:
  1607. spectral->params.ss_wb_rpt_mode = !!value;
  1608. break;
  1609. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  1610. spectral->params.ss_rssi_rpt_mode = !!value;
  1611. break;
  1612. case SPECTRAL_PARAM_RSSI_THR:
  1613. spectral->params.ss_rssi_thr = value;
  1614. break;
  1615. case SPECTRAL_PARAM_PWR_FORMAT:
  1616. spectral->params.ss_pwr_format = !!value;
  1617. break;
  1618. case SPECTRAL_PARAM_RPT_MODE:
  1619. spectral->params.ss_rpt_mode = value;
  1620. break;
  1621. case SPECTRAL_PARAM_BIN_SCALE:
  1622. spectral->params.ss_bin_scale = value;
  1623. break;
  1624. case SPECTRAL_PARAM_DBM_ADJ:
  1625. spectral->params.ss_dbm_adj = !!value;
  1626. break;
  1627. case SPECTRAL_PARAM_CHN_MASK:
  1628. spectral->params.ss_chn_mask = value;
  1629. break;
  1630. }
  1631. p_sops->configure_spectral(spectral, &spectral->params);
  1632. /* only to validate the writes */
  1633. p_sops->get_spectral_config(spectral, &params);
  1634. /* print_spectral_params(&spectral->params); */
  1635. return 1;
  1636. }
  1637. static int get_fft_bin_count(int fft_len)
  1638. {
  1639. int bin_count = 0;
  1640. switch (fft_len) {
  1641. case 5:
  1642. bin_count = 16;
  1643. break;
  1644. case 6:
  1645. bin_count = 32;
  1646. break;
  1647. case 7:
  1648. bin_count = 64;
  1649. break;
  1650. case 8:
  1651. bin_count = 128;
  1652. break;
  1653. case 9:
  1654. bin_count = 256;
  1655. break;
  1656. default:
  1657. break;
  1658. }
  1659. return bin_count;
  1660. }
  1661. static void init_upper_lower_flags(struct target_if_spectral *spectral)
  1662. {
  1663. int current_channel = 0;
  1664. int ext_channel = 0;
  1665. struct target_if_spectral_ops *p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  1666. current_channel = p_sops->get_current_channel(spectral);
  1667. ext_channel = p_sops->get_extension_channel(spectral);
  1668. if ((current_channel == 0) || (ext_channel == 0))
  1669. return;
  1670. if (spectral->sc_spectral_20_40_mode) {
  1671. /* HT40 mode */
  1672. if (ext_channel < current_channel) {
  1673. spectral->lower_is_extension = 1;
  1674. spectral->upper_is_control = 1;
  1675. spectral->lower_is_control = 0;
  1676. spectral->upper_is_extension = 0;
  1677. } else {
  1678. spectral->lower_is_extension = 0;
  1679. spectral->upper_is_control = 0;
  1680. spectral->lower_is_control = 1;
  1681. spectral->upper_is_extension = 1;
  1682. }
  1683. } else {
  1684. /* HT20 mode, lower is always control */
  1685. spectral->lower_is_extension = 0;
  1686. spectral->upper_is_control = 0;
  1687. spectral->lower_is_control = 1;
  1688. spectral->upper_is_extension = 0;
  1689. }
  1690. }
  1691. /**
  1692. * target_if_get_spectral_config() - Get spectral configuration
  1693. * @pdev: Pointer to pdev object
  1694. * @param: Pointer to spectral_config structure in which the configuration
  1695. * should be returned
  1696. *
  1697. * API to get the current spectral configuration
  1698. *
  1699. * Return: 1 on success, 0 on failure.
  1700. */
  1701. void target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  1702. struct spectral_config *param)
  1703. {
  1704. struct target_if_spectral_ops *p_sops = NULL;
  1705. struct target_if_spectral *spectral = NULL;
  1706. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1707. p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  1708. qdf_mem_zero(param, sizeof(struct spectral_config));
  1709. p_sops->get_spectral_config(spectral, param);
  1710. }
  1711. /**
  1712. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  1713. * parameters
  1714. * @spectral: Pointer to Spectral target_if internal private data
  1715. * @spectral_params: Pointer to Spectral parameters
  1716. *
  1717. * Enable use of desired Spectral parameters by configuring them into HW, and
  1718. * starting Spectral scan
  1719. *
  1720. * Return: 0 on success, 1 on failure
  1721. */
  1722. int target_if_spectral_scan_enable_params(
  1723. struct target_if_spectral *spectral,
  1724. struct spectral_config *spectral_params)
  1725. {
  1726. int extension_channel = 0;
  1727. int current_channel = 0;
  1728. struct target_if_spectral_ops *p_sops = NULL;
  1729. struct wlan_objmgr_vdev *vdev = NULL;
  1730. if (!spectral) {
  1731. qdf_print("SPECTRAL : Spectral is NULL\n");
  1732. return 1;
  1733. }
  1734. p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  1735. if (!p_sops) {
  1736. qdf_print("SPECTRAL : p_sops is NULL\n");
  1737. return 1;
  1738. }
  1739. spectral->sc_spectral_noise_pwr_cal =
  1740. spectral_params->ss_spectral_pri ? 1 : 0;
  1741. /* check if extension channel is present */
  1742. extension_channel = p_sops->get_extension_channel(spectral);
  1743. current_channel = p_sops->get_current_channel(spectral);
  1744. vdev = target_if_spectral_get_vdev(spectral);
  1745. if (!vdev)
  1746. return 1;
  1747. spectral->ch_width = target_if_vdev_get_ch_width(vdev);
  1748. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1749. if (spectral->ch_width == CH_WIDTH_INVALID)
  1750. return 1;
  1751. if (spectral->capability.advncd_spectral_cap) {
  1752. spectral->lb_edge_extrabins = 0;
  1753. spectral->rb_edge_extrabins = 0;
  1754. if (spectral->is_lb_edge_extrabins_format &&
  1755. spectral->params.ss_rpt_mode == 2) {
  1756. spectral->lb_edge_extrabins = 4;
  1757. }
  1758. if (spectral->is_rb_edge_extrabins_format &&
  1759. spectral->params.ss_rpt_mode == 2) {
  1760. spectral->rb_edge_extrabins = 4;
  1761. }
  1762. if (spectral->ch_width == CH_WIDTH_20MHZ) {
  1763. /* qdf_print("SPECTRAL : (11AC) 20MHz Channel Width
  1764. * (Channel = %d)\n", current_channel);
  1765. */
  1766. spectral->sc_spectral_20_40_mode = 0;
  1767. spectral->spectral_numbins =
  1768. get_fft_bin_count(spectral->params.ss_fft_size);
  1769. spectral->spectral_fft_len =
  1770. get_fft_bin_count(spectral->params.ss_fft_size);
  1771. spectral->spectral_data_len =
  1772. get_fft_bin_count(spectral->params.ss_fft_size);
  1773. /* Initialize classifier params to be sent to user
  1774. * space classifier
  1775. */
  1776. spectral->classifier_params.lower_chan_in_mhz =
  1777. current_channel;
  1778. spectral->classifier_params.upper_chan_in_mhz = 0;
  1779. } else if (spectral->ch_width == CH_WIDTH_40MHZ) {
  1780. /* qdf_print("SPECTRAL : (11AC) 40MHz Channel Width
  1781. * (Channel = %d)\n", current_channel);
  1782. */
  1783. spectral->sc_spectral_20_40_mode =
  1784. 1; /* TODO : Remove this variable */
  1785. spectral->spectral_numbins =
  1786. get_fft_bin_count(spectral->params.ss_fft_size);
  1787. spectral->spectral_fft_len =
  1788. get_fft_bin_count(spectral->params.ss_fft_size);
  1789. spectral->spectral_data_len =
  1790. get_fft_bin_count(spectral->params.ss_fft_size);
  1791. /* Initialize classifier params to be sent to user
  1792. * space classifier
  1793. */
  1794. if (extension_channel < current_channel) {
  1795. spectral->classifier_params.lower_chan_in_mhz =
  1796. extension_channel;
  1797. spectral->classifier_params.upper_chan_in_mhz =
  1798. current_channel;
  1799. } else {
  1800. spectral->classifier_params.lower_chan_in_mhz =
  1801. current_channel;
  1802. spectral->classifier_params.upper_chan_in_mhz =
  1803. extension_channel;
  1804. }
  1805. } else if (spectral->ch_width == CH_WIDTH_80MHZ) {
  1806. /* qdf_print("SPECTRAL : (11AC) 80MHz Channel Width
  1807. * (Channel = %d)\n", current_channel);
  1808. */
  1809. /* Set the FFT Size */
  1810. spectral->sc_spectral_20_40_mode =
  1811. 0; /* TODO : Remove this variable */
  1812. spectral->spectral_numbins =
  1813. get_fft_bin_count(spectral->params.ss_fft_size);
  1814. spectral->spectral_fft_len =
  1815. get_fft_bin_count(spectral->params.ss_fft_size);
  1816. spectral->spectral_data_len =
  1817. get_fft_bin_count(spectral->params.ss_fft_size);
  1818. /* Initialize classifier params to be sent to user
  1819. * space classifier
  1820. */
  1821. spectral->classifier_params.lower_chan_in_mhz =
  1822. current_channel;
  1823. spectral->classifier_params.upper_chan_in_mhz = 0;
  1824. /* Initialize classifier params to be sent to user
  1825. * space classifier
  1826. */
  1827. if (extension_channel < current_channel) {
  1828. spectral->classifier_params.lower_chan_in_mhz =
  1829. extension_channel;
  1830. spectral->classifier_params.upper_chan_in_mhz =
  1831. current_channel;
  1832. } else {
  1833. spectral->classifier_params.lower_chan_in_mhz =
  1834. current_channel;
  1835. spectral->classifier_params.upper_chan_in_mhz =
  1836. extension_channel;
  1837. }
  1838. } else if (spectral->ch_width == CH_WIDTH_160MHZ) {
  1839. /* qdf_print("SPECTRAL : (11AC) 160MHz Channel Width
  1840. * (Channel = %d)\n", current_channel);
  1841. */
  1842. /* Set the FFT Size */
  1843. /* The below applies to both 160 and 80+80 cases */
  1844. spectral->sc_spectral_20_40_mode =
  1845. 0; /* TODO : Remove this variable */
  1846. spectral->spectral_numbins =
  1847. get_fft_bin_count(spectral->params.ss_fft_size);
  1848. spectral->spectral_fft_len =
  1849. get_fft_bin_count(spectral->params.ss_fft_size);
  1850. spectral->spectral_data_len =
  1851. get_fft_bin_count(spectral->params.ss_fft_size);
  1852. /* Initialize classifier params to be sent to user
  1853. * space classifier
  1854. */
  1855. spectral->classifier_params.lower_chan_in_mhz =
  1856. current_channel;
  1857. spectral->classifier_params.upper_chan_in_mhz = 0;
  1858. /* Initialize classifier params to be sent to user
  1859. * space classifier
  1860. */
  1861. if (extension_channel < current_channel) {
  1862. spectral->classifier_params.lower_chan_in_mhz =
  1863. extension_channel;
  1864. spectral->classifier_params.upper_chan_in_mhz =
  1865. current_channel;
  1866. } else {
  1867. spectral->classifier_params.lower_chan_in_mhz =
  1868. current_channel;
  1869. spectral->classifier_params.upper_chan_in_mhz =
  1870. extension_channel;
  1871. }
  1872. }
  1873. if (spectral->spectral_numbins) {
  1874. spectral->spectral_numbins +=
  1875. spectral->lb_edge_extrabins;
  1876. spectral->spectral_numbins +=
  1877. spectral->rb_edge_extrabins;
  1878. }
  1879. if (spectral->spectral_fft_len) {
  1880. spectral->spectral_fft_len +=
  1881. spectral->lb_edge_extrabins;
  1882. spectral->spectral_fft_len +=
  1883. spectral->rb_edge_extrabins;
  1884. }
  1885. if (spectral->spectral_data_len) {
  1886. spectral->spectral_data_len +=
  1887. spectral->lb_edge_extrabins;
  1888. spectral->spectral_data_len +=
  1889. spectral->rb_edge_extrabins;
  1890. }
  1891. } else {
  1892. /* qdf_print("SPECTRAL : Legacy (Non-11AC)\n"); */
  1893. /*
  1894. * The decision to find 20/40 mode is found based on the
  1895. * presence of extension channel
  1896. * instead of channel width, as the channel width can
  1897. * dynamically change
  1898. */
  1899. if (extension_channel == 0) {
  1900. /* qdf_print("SPECTRAL : (Legacy) 20MHz Channel Width
  1901. * (Channel = %d)\n", current_channel);
  1902. */
  1903. spectral->spectral_numbins =
  1904. SPECTRAL_HT20_NUM_BINS;
  1905. spectral->spectral_dc_index =
  1906. SPECTRAL_HT20_DC_INDEX;
  1907. spectral->spectral_fft_len =
  1908. SPECTRAL_HT20_FFT_LEN;
  1909. spectral->spectral_data_len =
  1910. SPECTRAL_HT20_TOTAL_DATA_LEN;
  1911. spectral->spectral_lower_max_index_offset =
  1912. -1; /* only valid in 20-40 mode */
  1913. spectral->spectral_upper_max_index_offset =
  1914. -1; /* only valid in 20-40 mode */
  1915. spectral->spectral_max_index_offset =
  1916. spectral->spectral_fft_len + 2;
  1917. spectral->sc_spectral_20_40_mode = 0;
  1918. /* Initialize classifier params to be sent to user
  1919. * space classifier
  1920. */
  1921. spectral->classifier_params.lower_chan_in_mhz =
  1922. current_channel;
  1923. spectral->classifier_params.upper_chan_in_mhz = 0;
  1924. } else {
  1925. /* qdf_print("SPECTRAL : (Legacy) 40MHz Channel Width
  1926. * (Channel = %d)\n", current_channel);
  1927. */
  1928. spectral->spectral_numbins =
  1929. SPECTRAL_HT40_TOTAL_NUM_BINS;
  1930. spectral->spectral_fft_len =
  1931. SPECTRAL_HT40_FFT_LEN;
  1932. spectral->spectral_data_len =
  1933. SPECTRAL_HT40_TOTAL_DATA_LEN;
  1934. spectral->spectral_dc_index =
  1935. SPECTRAL_HT40_DC_INDEX;
  1936. spectral->spectral_max_index_offset =
  1937. -1; /* only valid in 20 mode */
  1938. spectral->spectral_lower_max_index_offset =
  1939. spectral->spectral_fft_len + 2;
  1940. spectral->spectral_upper_max_index_offset =
  1941. spectral->spectral_fft_len + 5;
  1942. spectral->sc_spectral_20_40_mode = 1;
  1943. /* Initialize classifier params to be sent to user
  1944. * space classifier
  1945. */
  1946. if (extension_channel < current_channel) {
  1947. spectral->classifier_params.lower_chan_in_mhz =
  1948. extension_channel;
  1949. spectral->classifier_params.upper_chan_in_mhz =
  1950. current_channel;
  1951. } else {
  1952. spectral->classifier_params.lower_chan_in_mhz =
  1953. current_channel;
  1954. spectral->classifier_params.upper_chan_in_mhz =
  1955. extension_channel;
  1956. }
  1957. }
  1958. }
  1959. spectral->send_single_packet = 0;
  1960. spectral->classifier_params.spectral_20_40_mode =
  1961. spectral->sc_spectral_20_40_mode;
  1962. spectral->classifier_params.spectral_dc_index =
  1963. spectral->spectral_dc_index;
  1964. spectral->spectral_sent_msg = 0;
  1965. spectral->classify_scan = 0;
  1966. spectral->num_spectral_data = 0;
  1967. if (!p_sops->is_spectral_active(spectral)) {
  1968. p_sops->configure_spectral(spectral, spectral_params);
  1969. p_sops->start_spectral_scan(spectral);
  1970. /* qdf_print("Enabled spectral scan on channel %d\n",
  1971. * p_sops->get_current_channel(spectral));
  1972. */
  1973. } else {
  1974. /* qdf_print("Spectral scan is already ACTIVE on channel %d\n",
  1975. * p_sops->get_current_channel(spectral));
  1976. */
  1977. }
  1978. /* get current spectral configuration */
  1979. p_sops->get_spectral_config(spectral, &spectral->params);
  1980. init_upper_lower_flags(spectral);
  1981. #ifdef SPECTRAL_CLASSIFIER_IN_KERNEL
  1982. init_classifier(sc);
  1983. #endif
  1984. return 0;
  1985. }
  1986. /**
  1987. * target_if_start_spectral_scan() - Start spectral scan
  1988. * @pdev: Pointer to pdev object
  1989. *
  1990. * API to start spectral scan
  1991. *
  1992. * Return: 0 in case of success, -1 on failure
  1993. */
  1994. int target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev)
  1995. {
  1996. struct target_if_spectral_ops *p_sops = NULL;
  1997. struct target_if_spectral *spectral = NULL;
  1998. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1999. if (!spectral) {
  2000. qdf_print("SPECTRAL : Spectral LMAC object is NUll (%s)\n",
  2001. __func__);
  2002. return -EPERM;
  2003. }
  2004. p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  2005. qdf_spin_lock(&spectral->ath_spectral_lock);
  2006. target_if_spectral_scan_enable_params(spectral, &spectral->params);
  2007. qdf_spin_unlock(&spectral->ath_spectral_lock);
  2008. return 0;
  2009. }
  2010. /**
  2011. * target_if_stop_spectral_scan() - Stop spectral scan
  2012. * @pdev: Pointer to pdev object
  2013. *
  2014. * API to stop the current on-going spectral scan
  2015. *
  2016. * Return: None
  2017. */
  2018. void target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev)
  2019. {
  2020. struct target_if_spectral_ops *p_sops = NULL;
  2021. struct target_if_spectral *spectral = NULL;
  2022. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2023. if (!spectral) {
  2024. qdf_print("SPECTRAL : Spectral LMAC object is NUll (%s)\n",
  2025. __func__);
  2026. return;
  2027. }
  2028. p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  2029. qdf_spin_lock(&spectral->ath_spectral_lock);
  2030. p_sops->stop_spectral_scan(spectral);
  2031. if (spectral->classify_scan) {
  2032. SPECTRAL_TODO("Check if this logic is necessary");
  2033. spectral->detects_control_channel = 0;
  2034. spectral->detects_extension_channel = 0;
  2035. spectral->detects_above_dc = 0;
  2036. spectral->detects_below_dc = 0;
  2037. spectral->classify_scan = 0;
  2038. }
  2039. spectral->send_single_packet = 0;
  2040. spectral->sc_spectral_scan = 0;
  2041. spectral->sc_spectral_noise_pwr_cal = 0;
  2042. /*
  2043. * Reset the priority because it stops WLAN rx.
  2044. * If it is needed to set, user has to set it explicitly
  2045. *
  2046. */
  2047. /* Reset Priority */
  2048. spectral->params.ss_spectral_pri = 0;
  2049. qdf_spin_unlock(&spectral->ath_spectral_lock);
  2050. }
  2051. /**
  2052. * target_if_is_spectral_active() - Get whether Spectral is active
  2053. * @pdev: Pointer to pdev object
  2054. *
  2055. * Return: True if Spectral is active, false if Spectral is not active
  2056. */
  2057. bool target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev)
  2058. {
  2059. struct target_if_spectral *spectral = NULL;
  2060. struct target_if_spectral_ops *p_sops = NULL;
  2061. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2062. p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  2063. return p_sops->is_spectral_active(spectral);
  2064. }
  2065. /**
  2066. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  2067. * @pdev: Pointer to pdev object
  2068. *
  2069. * Return: True if Spectral is enabled, false if Spectral is not enabled
  2070. */
  2071. bool target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev)
  2072. {
  2073. struct target_if_spectral *spectral = NULL;
  2074. struct target_if_spectral_ops *p_sops = NULL;
  2075. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2076. p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  2077. return p_sops->is_spectral_enabled(spectral);
  2078. }
  2079. /**
  2080. * target_if_set_debug_level() - Set debug level for Spectral
  2081. * @pdev: Pointer to pdev object
  2082. * @debug_level: Debug level
  2083. *
  2084. * Return: 0 in case of success
  2085. */
  2086. int target_if_set_debug_level(struct wlan_objmgr_pdev *pdev,
  2087. u_int32_t debug_level)
  2088. {
  2089. spectral_debug_level = (ATH_DEBUG_SPECTRAL << debug_level);
  2090. return 0;
  2091. }
  2092. /**
  2093. * target_if_get_debug_level() - Get debug level for Spectral
  2094. * @pdev: Pointer to pdev object
  2095. *
  2096. * Return: Current debug level
  2097. */
  2098. u_int32_t target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  2099. {
  2100. return spectral_debug_level;
  2101. }
  2102. /**
  2103. * target_if_get_spectral_capinfo() - Get Spectral capability information
  2104. * @pdev: Pointer to pdev object
  2105. * @outdata: Buffer into which data should be copied
  2106. *
  2107. * Return: void
  2108. */
  2109. void target_if_get_spectral_capinfo(
  2110. struct wlan_objmgr_pdev *pdev,
  2111. void *outdata)
  2112. {
  2113. struct target_if_spectral *spectral = NULL;
  2114. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2115. qdf_mem_copy(outdata, &spectral->capability,
  2116. sizeof(struct spectral_caps));
  2117. }
  2118. /**
  2119. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  2120. * @pdev: Pointer to pdev object
  2121. * @outdata: Buffer into which data should be copied
  2122. *
  2123. * Return: void
  2124. */
  2125. void target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  2126. void *outdata)
  2127. {
  2128. struct target_if_spectral *spectral = NULL;
  2129. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2130. qdf_mem_copy(outdata, &spectral->diag_stats,
  2131. sizeof(struct spectral_diag_stats));
  2132. }
  2133. void target_if_register_wmi_spectral_cmd_ops(
  2134. struct wlan_objmgr_pdev *pdev,
  2135. struct wmi_spectral_cmd_ops *cmd_ops)
  2136. {
  2137. struct target_if_spectral *spectral = NULL;
  2138. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2139. spectral->param_wmi_cmd_ops.wmi_spectral_configure_cmd_send =
  2140. cmd_ops->wmi_spectral_configure_cmd_send;
  2141. spectral->param_wmi_cmd_ops.wmi_spectral_enable_cmd_send =
  2142. cmd_ops->wmi_spectral_enable_cmd_send;
  2143. }
  2144. /**
  2145. * target_if_sptrl_register_tx_ops() - Register Spectral target_if Tx Ops
  2146. * @tx_ops: Tx Ops
  2147. *
  2148. * Return: void
  2149. */
  2150. void target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  2151. {
  2152. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  2153. target_if_pdev_spectral_init;
  2154. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  2155. target_if_pdev_spectral_deinit;
  2156. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  2157. target_if_set_spectral_config;
  2158. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  2159. target_if_get_spectral_config;
  2160. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  2161. target_if_start_spectral_scan;
  2162. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  2163. target_if_stop_spectral_scan;
  2164. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  2165. target_if_is_spectral_active;
  2166. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  2167. target_if_is_spectral_enabled;
  2168. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  2169. target_if_set_debug_level;
  2170. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  2171. target_if_get_debug_level;
  2172. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  2173. target_if_get_spectral_capinfo;
  2174. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  2175. target_if_get_spectral_diagstats;
  2176. tx_ops->sptrl_tx_ops.sptrlto_register_wmi_spectral_cmd_ops =
  2177. target_if_register_wmi_spectral_cmd_ops;
  2178. }
  2179. EXPORT_SYMBOL(target_if_sptrl_register_tx_ops);
  2180. /**
  2181. * target_if_spectral_send_intf_found_msg() - Send message to application layer
  2182. * indicating that interference has been found
  2183. * @pdev: Pointer to pdev
  2184. * @cw_int: 1 if CW interference is found, 0 if WLAN interference is found
  2185. * @dcs_enabled: 1 if DCS is enabled, 0 if DCS is disabled
  2186. *
  2187. * Return: None
  2188. */
  2189. void target_if_spectral_send_intf_found_msg(
  2190. struct wlan_objmgr_pdev *pdev,
  2191. u_int16_t cw_int, u_int32_t dcs_enabled)
  2192. {
  2193. #ifdef SPECTRAL_USE_NETLINK_SOCKETS
  2194. SPECTRAL_SAMP_MSG *msg = NULL;
  2195. struct target_if_spectral_ops *p_sops = NULL;
  2196. struct target_if_spectral *spectral = NULL;
  2197. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2198. p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  2199. target_if_spectral_prep_skb(spectral);
  2200. if (spectral->spectral_skb) {
  2201. spectral->spectral_nlh =
  2202. (struct nlmsghdr *)spectral->spectral_skb->data;
  2203. msg = (SPECTRAL_SAMP_MSG *)NLMSG_DATA(spectral->spectral_nlh);
  2204. msg->int_type = cw_int ?
  2205. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  2206. msg->dcs_enabled = dcs_enabled;
  2207. msg->signature = SPECTRAL_SIGNATURE;
  2208. p_sops->get_mac_address(spectral, msg->macaddr);
  2209. target_if_spectral_bcast_msg(spectral);
  2210. }
  2211. #endif
  2212. }
  2213. EXPORT_SYMBOL(target_if_spectral_send_intf_found_msg);