target_if_spectral.c 81 KB

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