target_if_spectral.c 79 KB

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