target_if_spectral.c 78 KB

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