target_if_spectral.c 79 KB

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