target_if_spectral.c 80 KB

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