target_if_spectral.c 84 KB

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