target_if_spectral.c 78 KB

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