target_if_spectral.c 79 KB

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