target_if_spectral.c 71 KB

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