target_if_spectral.c 80 KB

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