target_if_spectral.c 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847
  1. /*
  2. * Copyright (c) 2011,2017-2018 The Linux Foundation. All rights reserved.
  3. *
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include <wlan_tgt_def_config.h>
  20. #include <hif.h>
  21. #include <target_type.h>
  22. #include <hif_hw_version.h>
  23. #include <wmi_unified_api.h>
  24. #include <target_if_spectral.h>
  25. #include <wlan_lmac_if_def.h>
  26. #include <wlan_osif_priv.h>
  27. #include <init_deinit_ucfg.h>
  28. #include <reg_services_public_struct.h>
  29. #ifdef CONFIG_WIN
  30. #include <wlan_mlme_dispatcher.h>
  31. #endif /*CONFIG_WIN*/
  32. #include <reg_services_public_struct.h>
  33. #include <target_if_spectral_sim.h>
  34. #include <target_if.h>
  35. /**
  36. * @spectral_ops - Spectral function table, holds the Spectral functions that
  37. * depend on whether the architecture is Direct Attach or Offload. This is used
  38. * to populate the actual Spectral function table present in the Spectral
  39. * module.
  40. */
  41. struct target_if_spectral_ops spectral_ops;
  42. int spectral_debug_level = DEBUG_SPECTRAL;
  43. struct wlan_objmgr_vdev *
  44. target_if_spectral_get_vdev(struct target_if_spectral *spectral)
  45. {
  46. struct wlan_objmgr_pdev *pdev = NULL;
  47. struct wlan_objmgr_vdev *vdev = NULL;
  48. qdf_assert_always(spectral);
  49. pdev = spectral->pdev_obj;
  50. qdf_assert_always(pdev);
  51. if (wlan_objmgr_pdev_try_get_ref(pdev, WLAN_SPECTRAL_ID) !=
  52. QDF_STATUS_SUCCESS) {
  53. spectral_err("Unable to get pdev reference.");
  54. return NULL;
  55. }
  56. vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, 0, WLAN_SPECTRAL_ID);
  57. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  58. if (!vdev) {
  59. spectral_warn("Unable to get first vdev of pdev.");
  60. return NULL;
  61. }
  62. return vdev;
  63. }
  64. /**
  65. * target_if_send_vdev_spectral_configure_cmd() - Send WMI command to configure
  66. * spectral parameters
  67. * @spectral: Pointer to Spectral target_if internal private data
  68. * @param: Pointer to spectral_config giving the Spectral configuration
  69. *
  70. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  71. */
  72. static int
  73. target_if_send_vdev_spectral_configure_cmd(struct target_if_spectral *spectral,
  74. struct spectral_config *param)
  75. {
  76. struct vdev_spectral_configure_params sparam;
  77. struct wlan_objmgr_pdev *pdev = NULL;
  78. struct wlan_objmgr_vdev *vdev = NULL;
  79. qdf_assert_always(spectral && param);
  80. pdev = spectral->pdev_obj;
  81. qdf_assert_always(pdev);
  82. vdev = target_if_spectral_get_vdev(spectral);
  83. if (!vdev)
  84. return QDF_STATUS_E_NOENT;
  85. qdf_mem_set(&sparam, sizeof(sparam), 0);
  86. sparam.vdev_id = wlan_vdev_get_id(vdev);
  87. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  88. sparam.count = param->ss_count;
  89. sparam.period = param->ss_period;
  90. sparam.spectral_pri = param->ss_spectral_pri;
  91. sparam.fft_size = param->ss_fft_size;
  92. sparam.gc_enable = param->ss_gc_ena;
  93. sparam.restart_enable = param->ss_restart_ena;
  94. sparam.noise_floor_ref = param->ss_noise_floor_ref;
  95. sparam.init_delay = param->ss_init_delay;
  96. sparam.nb_tone_thr = param->ss_nb_tone_thr;
  97. sparam.str_bin_thr = param->ss_str_bin_thr;
  98. sparam.wb_rpt_mode = param->ss_wb_rpt_mode;
  99. sparam.rssi_rpt_mode = param->ss_rssi_rpt_mode;
  100. sparam.rssi_thr = param->ss_rssi_thr;
  101. sparam.pwr_format = param->ss_pwr_format;
  102. sparam.rpt_mode = param->ss_rpt_mode;
  103. sparam.bin_scale = param->ss_bin_scale;
  104. sparam.dbm_adj = param->ss_dbm_adj;
  105. sparam.chn_mask = param->ss_chn_mask;
  106. return spectral->param_wmi_cmd_ops.wmi_spectral_configure_cmd_send(
  107. GET_WMI_HDL_FROM_PDEV(pdev), &sparam);
  108. }
  109. /**
  110. * target_if_send_vdev_spectral_enable_cmd() - Send WMI command to
  111. * enable/disable Spectral
  112. * @spectral: Pointer to Spectral target_if internal private data
  113. * @is_spectral_active_valid: Flag to indicate if spectral activate (trigger) is
  114. * valid
  115. * @is_spectral_active: Value of spectral activate
  116. * @is_spectral_enabled_valid: Flag to indicate if spectral enable is valid
  117. * @is_spectral_enabled: Value of spectral enable
  118. *
  119. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  120. */
  121. static int
  122. target_if_send_vdev_spectral_enable_cmd(struct target_if_spectral *spectral,
  123. uint8_t is_spectral_active_valid,
  124. uint8_t is_spectral_active,
  125. uint8_t is_spectral_enabled_valid,
  126. uint8_t is_spectral_enabled)
  127. {
  128. struct vdev_spectral_enable_params param;
  129. struct wlan_objmgr_pdev *pdev = NULL;
  130. struct wlan_objmgr_vdev *vdev = NULL;
  131. qdf_assert_always(spectral);
  132. pdev = spectral->pdev_obj;
  133. qdf_assert_always(pdev);
  134. vdev = target_if_spectral_get_vdev(spectral);
  135. if (!vdev)
  136. return QDF_STATUS_E_NOENT;
  137. qdf_mem_set(&param, sizeof(param), 0);
  138. param.vdev_id = wlan_vdev_get_id(vdev);
  139. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  140. param.active_valid = is_spectral_active_valid;
  141. param.enabled_valid = is_spectral_enabled_valid;
  142. param.active = is_spectral_active;
  143. param.enabled = is_spectral_enabled;
  144. return spectral->param_wmi_cmd_ops.wmi_spectral_enable_cmd_send(
  145. GET_WMI_HDL_FROM_PDEV(pdev), &param);
  146. }
  147. /**
  148. * target_if_spectral_info_init_defaults() - Helper function to load defaults
  149. * for Spectral information (parameters and state) into cache.
  150. * @spectral: Pointer to Spectral target_if internal private data
  151. *
  152. * It is assumed that the caller has obtained the requisite lock if applicable.
  153. * Note that this is currently treated as a temporary function. Ideally, we
  154. * would like to get defaults from the firmware.
  155. *
  156. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  157. */
  158. static int
  159. target_if_spectral_info_init_defaults(struct target_if_spectral *spectral)
  160. {
  161. struct target_if_spectral_param_state_info *info =
  162. &spectral->param_info;
  163. struct wlan_objmgr_vdev *vdev = NULL;
  164. /* State */
  165. info->osps_cache.osc_spectral_active = SPECTRAL_SCAN_ACTIVE_DEFAULT;
  166. info->osps_cache.osc_spectral_enabled = SPECTRAL_SCAN_ENABLE_DEFAULT;
  167. /* Parameters */
  168. info->osps_cache.osc_params.ss_count = SPECTRAL_SCAN_COUNT_DEFAULT;
  169. info->osps_cache.osc_params.ss_period = SPECTRAL_SCAN_PERIOD_DEFAULT;
  170. info->osps_cache.osc_params.ss_spectral_pri =
  171. SPECTRAL_SCAN_PRIORITY_DEFAULT;
  172. info->osps_cache.osc_params.ss_fft_size =
  173. SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  174. info->osps_cache.osc_params.ss_gc_ena = SPECTRAL_SCAN_GC_ENA_DEFAULT;
  175. info->osps_cache.osc_params.ss_restart_ena =
  176. SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  177. info->osps_cache.osc_params.ss_noise_floor_ref =
  178. SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  179. info->osps_cache.osc_params.ss_init_delay =
  180. SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  181. info->osps_cache.osc_params.ss_nb_tone_thr =
  182. SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  183. info->osps_cache.osc_params.ss_str_bin_thr =
  184. SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  185. info->osps_cache.osc_params.ss_wb_rpt_mode =
  186. SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  187. info->osps_cache.osc_params.ss_rssi_rpt_mode =
  188. SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  189. info->osps_cache.osc_params.ss_rssi_thr =
  190. SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  191. info->osps_cache.osc_params.ss_pwr_format =
  192. SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  193. info->osps_cache.osc_params.ss_rpt_mode =
  194. SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  195. info->osps_cache.osc_params.ss_bin_scale =
  196. SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  197. info->osps_cache.osc_params.ss_dbm_adj = SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  198. vdev = target_if_spectral_get_vdev(spectral);
  199. if (!vdev)
  200. return QDF_STATUS_E_NOENT;
  201. info->osps_cache.osc_params.ss_chn_mask =
  202. wlan_vdev_mlme_get_rxchainmask(vdev);
  203. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  204. /* The cache is now valid */
  205. info->osps_cache.osc_is_valid = 1;
  206. return QDF_STATUS_SUCCESS;
  207. }
  208. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  209. /**
  210. * target_if_log_read_spectral_active() - Helper function to log whether
  211. * spectral is active after reading cache
  212. * @function_name: Function name
  213. * @output: whether spectral is active or not
  214. *
  215. * Helper function to log whether spectral is active after reading cache
  216. *
  217. * Return: none
  218. */
  219. static void
  220. target_if_log_read_spectral_active(
  221. const char *function_name,
  222. unsigned char output)
  223. {
  224. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE. Returning val=%u",
  225. function_name, output);
  226. }
  227. /**
  228. * target_if_log_read_spectral_enabled() - Helper function to log whether
  229. * spectral is enabled after reading cache
  230. * @function_name: Function name
  231. * @output: whether spectral is enabled or not
  232. *
  233. * Helper function to log whether spectral is enabled after reading cache
  234. *
  235. * Return: none
  236. */
  237. static void
  238. target_if_log_read_spectral_enabled(
  239. const char *function_name,
  240. unsigned char output)
  241. {
  242. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED. Returning val=%u",
  243. function_name, output);
  244. }
  245. /**
  246. * target_if_log_read_spectral_enabled() - Helper function to log spectral
  247. * parameters after reading cache
  248. * @function_name: Function name
  249. * @pparam: Spectral parameters
  250. *
  251. * Helper function to log spectral parameters after reading cache
  252. *
  253. * Return: none
  254. */
  255. static void
  256. target_if_log_read_spectral_params(
  257. const char *function_name,
  258. struct spectral_config *pparam)
  259. {
  260. 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",
  261. function_name,
  262. pparam->ss_count,
  263. pparam->ss_period,
  264. pparam->ss_spectral_pri,
  265. pparam->ss_fft_size,
  266. pparam->ss_gc_ena,
  267. pparam->ss_restart_ena,
  268. (int8_t)pparam->ss_noise_floor_ref,
  269. pparam->ss_init_delay,
  270. pparam->ss_nb_tone_thr,
  271. pparam->ss_str_bin_thr,
  272. pparam->ss_wb_rpt_mode,
  273. pparam->ss_rssi_rpt_mode,
  274. (int8_t)pparam->ss_rssi_thr,
  275. pparam->ss_pwr_format,
  276. pparam->ss_rpt_mode,
  277. pparam->ss_bin_scale,
  278. pparam->ss_dbm_adj,
  279. pparam->ss_chn_mask);
  280. }
  281. /**
  282. * target_if_log_read_spectral_active_catch_validate() - Helper function to
  283. * log whether spectral is active after intializing the cache
  284. * @function_name: Function name
  285. * @output: whether spectral is active or not
  286. *
  287. * Helper function to log whether spectral is active after intializing cache
  288. *
  289. * Return: none
  290. */
  291. static void
  292. target_if_log_read_spectral_active_catch_validate(
  293. const char *function_name,
  294. unsigned char output)
  295. {
  296. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE on initial cache validation\nReturning val=%u",
  297. function_name, output);
  298. }
  299. /**
  300. * target_if_log_read_spectral_enabled_catch_validate() - Helper function to
  301. * log whether spectral is enabled after intializing the cache
  302. * @function_name: Function name
  303. * @output: whether spectral is enabled or not
  304. *
  305. * Helper function to log whether spectral is enabled after intializing cache
  306. *
  307. * Return: none
  308. */
  309. static void
  310. target_if_log_read_spectral_enabled_catch_validate(
  311. const char *function_name,
  312. unsigned char output)
  313. {
  314. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED on initial cache validation\nReturning val=%u\n",
  315. function_name, output);
  316. }
  317. /**
  318. * target_if_log_read_spectral_params_catch_validate() - Helper function to
  319. * log spectral parameters after intializing the cache
  320. * @function_name: Function name
  321. * @pparam: Spectral parameters
  322. *
  323. * Helper function to log spectral parameters after intializing the cache
  324. *
  325. * Return: none
  326. */
  327. static void
  328. target_if_log_read_spectral_params_catch_validate(
  329. const char *function_name,
  330. struct spectral_config *pparam)
  331. {
  332. 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",
  333. function_name,
  334. pparam->ss_count,
  335. pparam->ss_period,
  336. pparam->ss_spectral_pri,
  337. pparam->ss_fft_size,
  338. pparam->ss_gc_ena,
  339. pparam->ss_restart_ena,
  340. (int8_t)pparam->ss_noise_floor_ref,
  341. pparam->ss_init_delay,
  342. pparam->ss_nb_tone_thr,
  343. pparam->ss_str_bin_thr,
  344. pparam->ss_wb_rpt_mode,
  345. pparam->ss_rssi_rpt_mode,
  346. (int8_t)pparam->ss_rssi_thr,
  347. pparam->ss_pwr_format,
  348. pparam->ss_rpt_mode,
  349. pparam->ss_bin_scale,
  350. pparam->ss_dbm_adj, pparam->ss_chn_mask);
  351. }
  352. #else
  353. static void
  354. target_if_log_read_spectral_active(
  355. const char *function_name,
  356. unsigned char output)
  357. {
  358. }
  359. static void
  360. target_if_log_read_spectral_enabled(
  361. const char *function_name,
  362. unsigned char output)
  363. {
  364. }
  365. static void
  366. target_if_log_read_spectral_params(
  367. const char *function_name,
  368. struct spectral_config *pparam)
  369. {
  370. }
  371. static void
  372. target_if_log_read_spectral_active_catch_validate(
  373. const char *function_name,
  374. unsigned char output)
  375. {
  376. }
  377. static void
  378. target_if_log_read_spectral_enabled_catch_validate(
  379. const char *function_name,
  380. unsigned char output)
  381. {
  382. }
  383. static void
  384. target_if_log_read_spectral_params_catch_validate(
  385. const char *function_name,
  386. struct spectral_config *pparam)
  387. {
  388. }
  389. #endif
  390. /**
  391. * target_if_spectral_info_read() - Read spectral information from the cache.
  392. * @spectral: Pointer to Spectral target_if internal private data
  393. * @specifier: target_if_spectral_info enumeration specifying which
  394. * information is required
  395. * @output: Void output pointer into which the information will be read
  396. * @output_len: size of object pointed to by output pointer
  397. *
  398. * Read spectral parameters or the desired state information from the cache.
  399. *
  400. * Return: 0 on success, negative error code on failure
  401. */
  402. static int
  403. target_if_spectral_info_read(
  404. struct target_if_spectral *spectral,
  405. enum target_if_spectral_info specifier,
  406. void *output, int output_len)
  407. {
  408. /*
  409. * Note: This function is designed to be able to accommodate
  410. * WMI reads for defaults, non-cacheable information, etc
  411. * if required.
  412. */
  413. struct target_if_spectral_param_state_info *info =
  414. &spectral->param_info;
  415. int is_cacheable = 0;
  416. int init_def_retval = 0;
  417. if (!output)
  418. return -EINVAL;
  419. switch (specifier) {
  420. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  421. if (output_len != sizeof(info->osps_cache.osc_spectral_active))
  422. return -EINVAL;
  423. is_cacheable = 1;
  424. break;
  425. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  426. if (output_len != sizeof(info->osps_cache.osc_spectral_enabled))
  427. return -EINVAL;
  428. is_cacheable = 1;
  429. break;
  430. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  431. if (output_len != sizeof(info->osps_cache.osc_params))
  432. return -EINVAL;
  433. is_cacheable = 1;
  434. break;
  435. default:
  436. spectral_err("Unknown target_if_spectral_info specifier");
  437. return -EINVAL;
  438. }
  439. qdf_spin_lock(&info->osps_lock);
  440. if (is_cacheable) {
  441. if (info->osps_cache.osc_is_valid) {
  442. switch (specifier) {
  443. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  444. qdf_mem_copy(
  445. output,
  446. &info->osps_cache.osc_spectral_active,
  447. sizeof(info->osps_cache.osc_spectral_active));
  448. target_if_log_read_spectral_active(
  449. __func__,
  450. *((unsigned char *)output));
  451. break;
  452. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  453. qdf_mem_copy(
  454. output,
  455. &info->osps_cache.osc_spectral_enabled,
  456. sizeof(
  457. info->osps_cache.osc_spectral_enabled));
  458. target_if_log_read_spectral_enabled(
  459. __func__,
  460. *((unsigned char *)output));
  461. break;
  462. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  463. qdf_mem_copy(
  464. output,
  465. &info->osps_cache.osc_params,
  466. sizeof(info->osps_cache.osc_params));
  467. target_if_log_read_spectral_params(
  468. __func__,
  469. (struct spectral_config *)output);
  470. break;
  471. default:
  472. /* We can't reach this point */
  473. break;
  474. }
  475. qdf_spin_unlock(&info->osps_lock);
  476. return 0;
  477. }
  478. }
  479. /* Cache is invalid */
  480. /*
  481. * If WMI Reads are implemented to fetch defaults/non-cacheable info,
  482. * then the below implementation will change
  483. */
  484. init_def_retval = target_if_spectral_info_init_defaults(spectral);
  485. if (init_def_retval != QDF_STATUS_SUCCESS) {
  486. qdf_spin_unlock(&info->osps_lock);
  487. if (init_def_retval == QDF_STATUS_E_NOENT)
  488. return -ENOENT;
  489. else
  490. return -EINVAL;
  491. }
  492. /* target_if_spectral_info_init_defaults() has set cache to valid */
  493. switch (specifier) {
  494. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  495. qdf_mem_copy(output,
  496. &info->osps_cache.osc_spectral_active,
  497. sizeof(info->osps_cache.osc_spectral_active));
  498. target_if_log_read_spectral_active_catch_validate(
  499. __func__,
  500. *((unsigned char *)output));
  501. break;
  502. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  503. qdf_mem_copy(output,
  504. &info->osps_cache.osc_spectral_enabled,
  505. sizeof(info->osps_cache.osc_spectral_enabled));
  506. target_if_log_read_spectral_enabled_catch_validate(
  507. __func__,
  508. *((unsigned char *)output));
  509. break;
  510. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  511. qdf_mem_copy(output,
  512. &info->osps_cache.osc_params,
  513. sizeof(info->osps_cache.osc_params));
  514. target_if_log_read_spectral_params_catch_validate(
  515. __func__,
  516. (struct spectral_config *)output);
  517. break;
  518. default:
  519. /* We can't reach this point */
  520. break;
  521. }
  522. qdf_spin_unlock(&info->osps_lock);
  523. return 0;
  524. }
  525. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  526. /**
  527. * target_if_log_write_spectral_active() - Helper function to log inputs and
  528. * return value of call to configure the Spectral 'active' configuration,
  529. * TARGET_IF_SPECTRAL_INFO_ACTIVE into firmware
  530. * @function_name: Function name in which this is called
  531. * @pval: whether spectral is active or not
  532. * @ret: return value of the firmware write function
  533. *
  534. * Return: none
  535. */
  536. static void
  537. target_if_log_write_spectral_active(
  538. const char *function_name,
  539. uint8_t pval,
  540. int ret)
  541. {
  542. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE with val=%u status=%d",
  543. function_name, pval, ret);
  544. }
  545. /**
  546. * target_if_log_write_spectral_enabled() - Helper function to log inputs and
  547. * return value of call to configure the Spectral 'enabled' configuration,
  548. * TARGET_IF_SPECTRAL_INFO_ENABLED into firmware
  549. * @function_name: Function name in which this is called
  550. * @pval: whether spectral is enabled or not
  551. * @ret: return value of the firmware write function
  552. *
  553. * Return: none
  554. */
  555. static void
  556. target_if_log_write_spectral_enabled(
  557. const char *function_name,
  558. uint8_t pval,
  559. int ret)
  560. {
  561. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED with val=%u status=%d",
  562. function_name, pval, ret);
  563. }
  564. /**
  565. * target_if_log_write_spectral_params() - Helper function to log inputs and
  566. * return value of call to configure Spectral parameters,
  567. * TARGET_IF_SPECTRAL_INFO_PARAMS into firmware
  568. * @param: Spectral parameters
  569. * @function_name: Function name in which this is called
  570. * @ret: return value of the firmware write function
  571. *
  572. * Return: none
  573. */
  574. static void
  575. target_if_log_write_spectral_params(
  576. struct spectral_config *param,
  577. const char *function_name,
  578. int ret)
  579. {
  580. 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",
  581. function_name,
  582. param->ss_count,
  583. param->ss_period,
  584. param->ss_spectral_pri,
  585. param->ss_fft_size,
  586. param->ss_gc_ena,
  587. param->ss_restart_ena,
  588. (int8_t)param->ss_noise_floor_ref,
  589. param->ss_init_delay,
  590. param->ss_nb_tone_thr,
  591. param->ss_str_bin_thr,
  592. param->ss_wb_rpt_mode,
  593. param->ss_rssi_rpt_mode,
  594. (int8_t)param->ss_rssi_thr,
  595. param->ss_pwr_format,
  596. param->ss_rpt_mode,
  597. param->ss_bin_scale,
  598. param->ss_dbm_adj, param->ss_chn_mask, ret);
  599. }
  600. #else
  601. static void
  602. target_if_log_write_spectral_active(
  603. const char *function_name,
  604. uint8_t pval,
  605. int ret)
  606. {
  607. }
  608. static void
  609. target_if_log_write_spectral_enabled(
  610. const char *function_name,
  611. uint8_t pval,
  612. int ret)
  613. {
  614. }
  615. static void
  616. target_if_log_write_spectral_params(
  617. struct spectral_config *param,
  618. const char *function_name,
  619. int ret)
  620. {
  621. }
  622. #endif
  623. /**
  624. * target_if_spectral_info_write() - Write Spectral information to the
  625. * firmware, and update cache
  626. * @spectral: Pointer to Spectral target_if internal private data
  627. * @specifier: target_if_spectral_info enumeration specifying which
  628. * information is involved
  629. * @input: void input pointer containing the information to be written
  630. * @input_len: size of object pointed to by input pointer
  631. *
  632. * Write Spectral parameters or the desired state information to
  633. * the firmware, and update cache
  634. *
  635. * Return: 0 on success, negative error code on failure
  636. */
  637. static int
  638. target_if_spectral_info_write(
  639. struct target_if_spectral *spectral,
  640. enum target_if_spectral_info specifier,
  641. void *input, int input_len)
  642. {
  643. struct target_if_spectral_param_state_info *info =
  644. &spectral->param_info;
  645. int ret;
  646. uint8_t *pval = NULL;
  647. struct spectral_config *param = NULL;
  648. if (!input)
  649. return -EINVAL;
  650. switch (specifier) {
  651. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  652. if (input_len != sizeof(info->osps_cache.osc_spectral_active))
  653. return -EINVAL;
  654. pval = (uint8_t *)input;
  655. qdf_spin_lock(&info->osps_lock);
  656. ret = target_if_send_vdev_spectral_enable_cmd(spectral,
  657. 1, *pval, 0, 0);
  658. target_if_log_write_spectral_active(
  659. __func__,
  660. *pval,
  661. ret);
  662. if (ret < 0) {
  663. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  664. ret);
  665. qdf_spin_unlock(&info->osps_lock);
  666. return ret;
  667. }
  668. info->osps_cache.osc_spectral_active = *pval;
  669. qdf_spin_unlock(&info->osps_lock);
  670. break;
  671. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  672. if (input_len != sizeof(info->osps_cache.osc_spectral_enabled))
  673. return -EINVAL;
  674. pval = (uint8_t *)input;
  675. qdf_spin_lock(&info->osps_lock);
  676. ret = target_if_send_vdev_spectral_enable_cmd(spectral,
  677. 0, 0, 1, *pval);
  678. target_if_log_write_spectral_enabled(
  679. __func__,
  680. *pval,
  681. ret);
  682. if (ret < 0) {
  683. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  684. ret);
  685. qdf_spin_unlock(&info->osps_lock);
  686. return ret;
  687. }
  688. info->osps_cache.osc_spectral_enabled = *pval;
  689. qdf_spin_unlock(&info->osps_lock);
  690. break;
  691. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  692. if (input_len != sizeof(info->osps_cache.osc_params))
  693. return -EINVAL;
  694. param = (struct spectral_config *)input;
  695. qdf_spin_lock(&info->osps_lock);
  696. ret = target_if_send_vdev_spectral_configure_cmd(spectral,
  697. param);
  698. target_if_log_write_spectral_params(
  699. param,
  700. __func__,
  701. ret);
  702. if (ret < 0) {
  703. spectral_err("target_if_send_vdev_spectral_configure_cmd failed with error=%d",
  704. ret);
  705. qdf_spin_unlock(&info->osps_lock);
  706. return ret;
  707. }
  708. qdf_mem_copy(&info->osps_cache.osc_params,
  709. param, sizeof(info->osps_cache.osc_params));
  710. qdf_spin_unlock(&info->osps_lock);
  711. break;
  712. default:
  713. spectral_err("Unknown target_if_spectral_info specifier");
  714. return -EINVAL;
  715. }
  716. return 0;
  717. }
  718. /**
  719. * target_if_spectral_get_tsf64() - Function to get the TSF value
  720. * @arg: Pointer to handle for Spectral target_if internal private data
  721. *
  722. * Get the last TSF received in WMI buffer
  723. *
  724. * Return: TSF value
  725. */
  726. static uint64_t
  727. target_if_spectral_get_tsf64(void *arg)
  728. {
  729. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  730. return spectral->tsf64;
  731. }
  732. /**
  733. * target_if_spectral_get_capability() - Function to get whether a
  734. * given Spectral hardware capability is available
  735. * @arg: Pointer to handle for Spectral target_if internal private data
  736. * @type: Spectral hardware capability type
  737. *
  738. * Get whether a given Spectral hardware capability is available
  739. *
  740. * Return: True if the capability is available, false if the capability is not
  741. * available
  742. */
  743. uint32_t
  744. target_if_spectral_get_capability(void *arg, enum spectral_capability_type type)
  745. {
  746. int status = STATUS_FAIL;
  747. switch (type) {
  748. case SPECTRAL_CAP_PHYDIAG:
  749. case SPECTRAL_CAP_RADAR:
  750. case SPECTRAL_CAP_SPECTRAL_SCAN:
  751. case SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN:
  752. status = STATUS_PASS;
  753. break;
  754. default:
  755. status = STATUS_FAIL;
  756. }
  757. return status;
  758. }
  759. /**
  760. * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
  761. * @arg: Pointer to handle for Spectral target_if internal private data
  762. * @rxfilter: Rx filter to be used
  763. *
  764. * Note: This is only a placeholder function. It is not currently required since
  765. * FW should be taking care of setting the required filters.
  766. *
  767. * Return: 0
  768. */
  769. uint32_t
  770. target_if_spectral_set_rxfilter(void *arg, int rxfilter)
  771. {
  772. /*
  773. * Will not be required since enabling of spectral in firmware
  774. * will take care of this
  775. */
  776. return 0;
  777. }
  778. /**
  779. * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
  780. * @arg: Pointer to handle for Spectral target_if internal private data
  781. *
  782. * Note: This is only a placeholder function. It is not currently required since
  783. * FW should be taking care of setting the required filters.
  784. *
  785. * Return: 0
  786. */
  787. uint32_t
  788. target_if_spectral_get_rxfilter(void *arg)
  789. {
  790. /*
  791. * Will not be required since enabling of spectral in firmware
  792. * will take care of this
  793. */
  794. return 0;
  795. }
  796. /**
  797. * target_if_sops_is_spectral_active() - Get whether Spectral is active
  798. * @arg: Pointer to handle for Spectral target_if internal private data
  799. *
  800. * Function to check whether Spectral is active
  801. *
  802. * Return: True if Spectral is active, false if Spectral is not active
  803. */
  804. uint32_t
  805. target_if_sops_is_spectral_active(void *arg)
  806. {
  807. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  808. uint8_t val = 0;
  809. int ret;
  810. ret = target_if_spectral_info_read(
  811. spectral,
  812. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  813. &val, sizeof(val));
  814. if (ret != 0) {
  815. /*
  816. * Could not determine if Spectral is active.
  817. * Return false as a safe value.
  818. * XXX: Consider changing the function prototype
  819. * to be able to indicate failure to fetch value.
  820. */
  821. return 0;
  822. }
  823. return val;
  824. }
  825. /**
  826. * target_if_sops_is_spectral_enabled() - Get whether Spectral is enabled
  827. * @arg: Pointer to handle for Spectral target_if internal private data
  828. *
  829. * Function to check whether Spectral is enabled
  830. *
  831. * Return: True if Spectral is enabled, false if Spectral is not enabled
  832. */
  833. uint32_t
  834. target_if_sops_is_spectral_enabled(void *arg)
  835. {
  836. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  837. uint8_t val = 0;
  838. int ret;
  839. ret = target_if_spectral_info_read(
  840. spectral,
  841. TARGET_IF_SPECTRAL_INFO_ENABLED,
  842. &val, sizeof(val));
  843. if (ret != 0) {
  844. /*
  845. * Could not determine if Spectral is enabled.
  846. * Return false as a safe value.
  847. * XXX: Consider changing the function prototype
  848. * to be able to indicate failure to fetch value.
  849. */
  850. return 0;
  851. }
  852. return val;
  853. }
  854. /**
  855. * target_if_sops_start_spectral_scan() - Start Spectral scan
  856. * @arg: Pointer to handle for Spectral target_if internal private data
  857. *
  858. * Function to start spectral scan
  859. *
  860. * Return: 0 on success else failure
  861. */
  862. uint32_t
  863. target_if_sops_start_spectral_scan(void *arg)
  864. {
  865. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  866. uint8_t val = 1;
  867. uint8_t enabled = 0;
  868. int ret;
  869. ret = target_if_spectral_info_read(
  870. spectral,
  871. TARGET_IF_SPECTRAL_INFO_ENABLED,
  872. &enabled, sizeof(enabled));
  873. if (ret != 0) {
  874. /*
  875. * Could not determine if Spectral is enabled. Assume we need
  876. * to enable it
  877. */
  878. enabled = 0;
  879. }
  880. if (!enabled) {
  881. ret = target_if_spectral_info_write(
  882. spectral,
  883. TARGET_IF_SPECTRAL_INFO_ENABLED,
  884. &val, sizeof(val));
  885. if (ret != 0)
  886. return ret;
  887. }
  888. ret = target_if_spectral_info_write(
  889. spectral,
  890. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  891. &val, sizeof(val));
  892. if (ret != 0)
  893. return ret;
  894. return 0;
  895. }
  896. /**
  897. * target_if_sops_stop_spectral_scan() - Stop Spectral scan
  898. * @arg: Pointer to handle for Spectral target_if internal private data
  899. *
  900. * Function to stop spectral scan
  901. *
  902. * Return: 0 on success else failure
  903. */
  904. uint32_t
  905. target_if_sops_stop_spectral_scan(void *arg)
  906. {
  907. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  908. uint8_t val = 0;
  909. int tempret, ret = 0;
  910. tempret = target_if_spectral_info_write(
  911. spectral,
  912. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  913. &val, sizeof(val));
  914. if (tempret != 0)
  915. ret = tempret;
  916. tempret = target_if_spectral_info_write(
  917. spectral,
  918. TARGET_IF_SPECTRAL_INFO_ENABLED,
  919. &val, sizeof(val));
  920. if (tempret != 0)
  921. ret = tempret;
  922. return ret;
  923. }
  924. /**
  925. * target_if_spectral_get_extension_channel() - Get the Extension channel
  926. * @arg: Pointer to handle for Spectral target_if internal private data
  927. *
  928. * Function to get the current Extension channel (in MHz)
  929. *
  930. * Return: Current Extension channel (in MHz) on success, 0 on failure or if
  931. * extension channel is not present.
  932. */
  933. uint32_t
  934. target_if_spectral_get_extension_channel(void *arg)
  935. {
  936. /*
  937. * XXX: Once we expand to use cases where Spectral could be activated
  938. * without a channel being set to VDEV, we need to consider returning a
  939. * negative value in case of failure and having all callers handle this.
  940. */
  941. struct target_if_spectral *spectral = NULL;
  942. struct wlan_objmgr_vdev *vdev = NULL;
  943. uint16_t sec20chan_freq = 0;
  944. qdf_assert_always(arg);
  945. spectral = (struct target_if_spectral *)arg;
  946. vdev = target_if_spectral_get_vdev(spectral);
  947. if (!vdev)
  948. return 0;
  949. if (target_if_vdev_get_sec20chan_freq_mhz(vdev, &sec20chan_freq) < 0) {
  950. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  951. return 0;
  952. }
  953. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  954. return sec20chan_freq;
  955. }
  956. /**
  957. * target_if_spectral_get_current_channel() - Get the current channel
  958. * @arg: Pointer to handle for Spectral target_if internal private data
  959. *
  960. * Function to get the current channel (in MHz)
  961. *
  962. * Return: Current channel (in MHz) on success, 0 on failure
  963. */
  964. uint32_t
  965. target_if_spectral_get_current_channel(void *arg)
  966. {
  967. /*
  968. * XXX: Once we expand to use cases where Spectral could be activated
  969. * without a channel being set to VDEV, we need to consider returning a
  970. * negative value in case of failure and having all callers handle this.
  971. */
  972. struct target_if_spectral *spectral = NULL;
  973. int16_t chan_freq = 0;
  974. struct wlan_objmgr_vdev *vdev = NULL;
  975. qdf_assert_always(arg);
  976. spectral = (struct target_if_spectral *)arg;
  977. vdev = target_if_spectral_get_vdev(spectral);
  978. if (!vdev)
  979. return 0;
  980. chan_freq = target_if_vdev_get_chan_freq(vdev);
  981. if (chan_freq < 0) {
  982. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  983. return 0;
  984. }
  985. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  986. return chan_freq;
  987. }
  988. /**
  989. * target_if_spectral_reset_hw() - Reset the hardware
  990. * @arg: Pointer to handle for Spectral target_if internal private data
  991. *
  992. * This is only a placeholder since it is not currently required in the offload
  993. * case.
  994. *
  995. * Return: 0
  996. */
  997. uint32_t
  998. target_if_spectral_reset_hw(void *arg)
  999. {
  1000. not_yet_implemented();
  1001. return 0;
  1002. }
  1003. /**
  1004. * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
  1005. * Noisefloor history buffer
  1006. * @arg: Pointer to handle for Spectral target_if internal private data
  1007. * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
  1008. *
  1009. * This is only a placeholder since it is not currently required in the offload
  1010. * case.
  1011. *
  1012. * Return: 0
  1013. */
  1014. uint32_t
  1015. target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1016. {
  1017. not_yet_implemented();
  1018. return 0;
  1019. }
  1020. /**
  1021. * target_if_spectral_get_ext_noisefloor() - Get the extension channel
  1022. * noisefloor
  1023. * @arg: Pointer to handle for Spectral target_if internal private data
  1024. *
  1025. * This is only a placeholder since it is not currently required in the offload
  1026. * case.
  1027. *
  1028. * Return: 0
  1029. */
  1030. int8_t
  1031. target_if_spectral_get_ext_noisefloor(void *arg)
  1032. {
  1033. not_yet_implemented();
  1034. return 0;
  1035. }
  1036. /**
  1037. * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
  1038. * @arg: Pointer to handle for Spectral target_if internal private data
  1039. *
  1040. * This is only a placeholder since it is not currently required in the offload
  1041. * case.
  1042. *
  1043. * Return: 0
  1044. */
  1045. int8_t
  1046. target_if_spectral_get_ctl_noisefloor(void *arg)
  1047. {
  1048. not_yet_implemented();
  1049. return 0;
  1050. }
  1051. /**
  1052. * target_if_spectral_sops_configure_params() - Configure user supplied Spectral
  1053. * parameters
  1054. * @arg: Pointer to handle for Spectral target_if internal private data
  1055. * @params: Spectral parameters
  1056. *
  1057. * Function to configure spectral parameters
  1058. *
  1059. * Return: 0 on success else failure
  1060. */
  1061. uint32_t
  1062. target_if_spectral_sops_configure_params(
  1063. void *arg, struct spectral_config *params)
  1064. {
  1065. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1066. return target_if_spectral_info_write(
  1067. spectral,
  1068. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1069. params, sizeof(*params));
  1070. }
  1071. /**
  1072. * target_if_spectral_sops_get_params() - Get user configured Spectral
  1073. * parameters
  1074. * @arg: Pointer to handle for Spectral target_if internal private data
  1075. * @params: Pointer to buffer into which Spectral parameters should be copied
  1076. *
  1077. * Function to get the configured spectral parameters
  1078. *
  1079. * Return: 0 on success else failure
  1080. */
  1081. uint32_t
  1082. target_if_spectral_sops_get_params(void *arg, struct spectral_config *params)
  1083. {
  1084. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1085. return target_if_spectral_info_read(
  1086. spectral,
  1087. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1088. params, sizeof(*params));
  1089. }
  1090. /**
  1091. * target_if_spectral_get_ent_mask() - Get enterprise mask
  1092. * @arg: Pointer to handle for Spectral target_if internal private data
  1093. *
  1094. * This is only a placeholder since it is not currently required in the offload
  1095. * case.
  1096. *
  1097. * Return: 0
  1098. */
  1099. static uint32_t
  1100. target_if_spectral_get_ent_mask(void *arg)
  1101. {
  1102. not_yet_implemented();
  1103. return 0;
  1104. }
  1105. /**
  1106. * target_if_spectral_get_macaddr() - Get radio MAC address
  1107. * @arg: Pointer to handle for Spectral target_if internal private data
  1108. * @addr: Pointer to buffer into which MAC address should be copied
  1109. *
  1110. * Function to get the MAC address of the pdev
  1111. *
  1112. * Return: 0 on success, -1 on failure
  1113. */
  1114. static uint32_t
  1115. target_if_spectral_get_macaddr(void *arg, char *addr)
  1116. {
  1117. uint8_t *myaddr = NULL;
  1118. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1119. struct wlan_objmgr_pdev *pdev = NULL;
  1120. pdev = spectral->pdev_obj;
  1121. wlan_pdev_obj_lock(pdev);
  1122. myaddr = wlan_pdev_get_hw_macaddr(pdev);
  1123. wlan_pdev_obj_unlock(pdev);
  1124. qdf_mem_copy(addr, myaddr, IEEE80211_ADDR_LEN);
  1125. return 0;
  1126. }
  1127. /**
  1128. * target_if_init_spectral_capability() - Initialize Spectral capability
  1129. * @spectral: Pointer to Spectral target_if internal private data
  1130. *
  1131. * This is a workaround.
  1132. *
  1133. * Return: None
  1134. */
  1135. void
  1136. target_if_init_spectral_capability(struct target_if_spectral *spectral)
  1137. {
  1138. struct spectral_caps *pcap = &spectral->capability;
  1139. /* XXX : Workaround: Set Spectral capability */
  1140. pcap = &spectral->capability;
  1141. pcap->phydiag_cap = 1;
  1142. pcap->radar_cap = 1;
  1143. pcap->spectral_cap = 1;
  1144. pcap->advncd_spectral_cap = 1;
  1145. }
  1146. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1147. /**
  1148. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1149. * internal operations with functions related to spectral simulation
  1150. * @p_sops: spectral low level ops table
  1151. *
  1152. * Initialize spectral target_if internal operations with functions
  1153. * related to spectral simulation
  1154. *
  1155. * Return: None
  1156. */
  1157. static void
  1158. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1159. {
  1160. /*
  1161. * Spectral simulation is currently intended for platform transitions
  1162. * where underlying HW support may not be available for some time.
  1163. * Hence, we do not currently provide a runtime switch to turn the
  1164. * simulation on or off.
  1165. * In case of future requirements where runtime switches are required,
  1166. * this can be added. But it is suggested to use application layer
  1167. * simulation as far as possible in such cases, since the main
  1168. * use of record and replay of samples would concern higher
  1169. * level sample processing rather than lower level delivery.
  1170. */
  1171. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  1172. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  1173. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  1174. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  1175. p_sops->configure_spectral =
  1176. target_if_spectral_sops_sim_configure_params;
  1177. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  1178. }
  1179. #else
  1180. /**
  1181. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1182. * internal operations
  1183. * @p_sops: spectral low level ops table
  1184. *
  1185. * Return: None
  1186. */
  1187. static void
  1188. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1189. {
  1190. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  1191. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  1192. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  1193. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  1194. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  1195. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  1196. }
  1197. #endif
  1198. /**
  1199. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  1200. * operations common to all Spectral chipset generations
  1201. *
  1202. * Initializes target_if_spectral_ops common to all chipset generations
  1203. *
  1204. * Return: None
  1205. */
  1206. static void
  1207. target_if_init_spectral_ops_common(void)
  1208. {
  1209. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1210. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  1211. p_sops->get_capability = target_if_spectral_get_capability;
  1212. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  1213. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  1214. target_if_init_spectral_simulation_ops(p_sops);
  1215. p_sops->get_extension_channel =
  1216. target_if_spectral_get_extension_channel;
  1217. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  1218. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  1219. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  1220. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  1221. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  1222. p_sops->reset_hw = target_if_spectral_reset_hw;
  1223. p_sops->get_chain_noise_floor =
  1224. target_if_spectral_get_chain_noise_floor;
  1225. }
  1226. /**
  1227. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  1228. * operations specific to Spectral chipset generation 2.
  1229. *
  1230. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  1231. *
  1232. * Return: None
  1233. */
  1234. static void
  1235. target_if_init_spectral_ops_gen2(void)
  1236. {
  1237. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1238. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  1239. }
  1240. /**
  1241. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  1242. * operations specific to Spectral chipset generation 3.
  1243. *
  1244. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  1245. *
  1246. * Return: None
  1247. */
  1248. static void
  1249. target_if_init_spectral_ops_gen3(void)
  1250. {
  1251. /* Placeholder */
  1252. spectral_debug("Placeholder for gen3 spectral ops registration");
  1253. return;
  1254. }
  1255. /**
  1256. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  1257. * operations.
  1258. * @spectral: Pointer to Spectral target_if internal private data
  1259. *
  1260. * Initializes all function pointers in target_if_spectral_ops for
  1261. * all generations
  1262. *
  1263. * Return: None
  1264. */
  1265. static void
  1266. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  1267. {
  1268. target_if_init_spectral_ops_common();
  1269. if (spectral->spectral_gen == SPECTRAL_GEN2)
  1270. target_if_init_spectral_ops_gen2();
  1271. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  1272. target_if_init_spectral_ops_gen3();
  1273. else
  1274. spectral_err("Invalid Spectral generation");
  1275. }
  1276. /*
  1277. * Dummy Functions:
  1278. * These functions are initially registered to avoid any crashes due to
  1279. * invocation of spectral functions before they are registered.
  1280. */
  1281. static uint64_t
  1282. null_get_tsf64(void *arg)
  1283. {
  1284. spectral_ops_not_registered("get_tsf64");
  1285. return 0;
  1286. }
  1287. static uint32_t
  1288. null_get_capability(void *arg, enum spectral_capability_type type)
  1289. {
  1290. /*
  1291. * TODO : We should have conditional compilation to get the capability
  1292. * : We have not yet attahced ATH layer here, so there is no
  1293. * : way to check the HAL capbalities
  1294. */
  1295. spectral_ops_not_registered("get_capability");
  1296. /* TODO : For the time being, we are returning TRUE */
  1297. return true;
  1298. }
  1299. static uint32_t
  1300. null_set_rxfilter(void *arg, int rxfilter)
  1301. {
  1302. spectral_ops_not_registered("set_rxfilter");
  1303. return 1;
  1304. }
  1305. static uint32_t
  1306. null_get_rxfilter(void *arg)
  1307. {
  1308. spectral_ops_not_registered("get_rxfilter");
  1309. return 0;
  1310. }
  1311. static uint32_t
  1312. null_is_spectral_active(void *arg)
  1313. {
  1314. spectral_ops_not_registered("is_spectral_active");
  1315. return 1;
  1316. }
  1317. static uint32_t
  1318. null_is_spectral_enabled(void *arg)
  1319. {
  1320. spectral_ops_not_registered("is_spectral_enabled");
  1321. return 1;
  1322. }
  1323. static uint32_t
  1324. null_start_spectral_scan(void *arg)
  1325. {
  1326. spectral_ops_not_registered("start_spectral_scan");
  1327. return 1;
  1328. }
  1329. static uint32_t
  1330. null_stop_spectral_scan(void *arg)
  1331. {
  1332. spectral_ops_not_registered("stop_spectral_scan");
  1333. return 1;
  1334. }
  1335. static uint32_t
  1336. null_get_extension_channel(void *arg)
  1337. {
  1338. spectral_ops_not_registered("get_extension_channel");
  1339. return 1;
  1340. }
  1341. static int8_t
  1342. null_get_ctl_noisefloor(void *arg)
  1343. {
  1344. spectral_ops_not_registered("get_ctl_noisefloor");
  1345. return 1;
  1346. }
  1347. static int8_t
  1348. null_get_ext_noisefloor(void *arg)
  1349. {
  1350. spectral_ops_not_registered("get_ext_noisefloor");
  1351. return 0;
  1352. }
  1353. static uint32_t
  1354. null_configure_spectral(void *arg, struct spectral_config *params)
  1355. {
  1356. spectral_ops_not_registered("configure_spectral");
  1357. return 0;
  1358. }
  1359. static uint32_t
  1360. null_get_spectral_config(void *arg, struct spectral_config *params)
  1361. {
  1362. spectral_ops_not_registered("get_spectral_config");
  1363. return 0;
  1364. }
  1365. static uint32_t
  1366. null_get_ent_spectral_mask(void *arg)
  1367. {
  1368. spectral_ops_not_registered("get_ent_spectral_mask");
  1369. return 0;
  1370. }
  1371. static uint32_t
  1372. null_get_mac_address(void *arg, char *addr)
  1373. {
  1374. spectral_ops_not_registered("get_mac_address");
  1375. return 0;
  1376. }
  1377. static uint32_t
  1378. null_get_current_channel(void *arg)
  1379. {
  1380. spectral_ops_not_registered("get_current_channel");
  1381. return 0;
  1382. }
  1383. static uint32_t
  1384. null_reset_hw(void *arg)
  1385. {
  1386. spectral_ops_not_registered("get_current_channel");
  1387. return 0;
  1388. }
  1389. static uint32_t
  1390. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1391. {
  1392. spectral_ops_not_registered("get_chain_noise_floor");
  1393. return 0;
  1394. }
  1395. static int
  1396. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  1397. uint8_t *data,
  1398. uint32_t datalen,
  1399. struct target_if_spectral_rfqual_info *p_rfqual,
  1400. struct target_if_spectral_chan_info *p_chaninfo,
  1401. uint64_t tsf64,
  1402. struct target_if_spectral_acs_stats *acs_stats)
  1403. {
  1404. spectral_ops_not_registered("spectral_process_phyerr");
  1405. return 0;
  1406. }
  1407. /**
  1408. * target_if_spectral_init_dummy_function_table() -
  1409. * Initialize target_if internal
  1410. * Spectral operations to dummy functions
  1411. * @ps: Pointer to Spectral target_if internal private data
  1412. *
  1413. * Initialize all the function pointers in target_if_spectral_ops with
  1414. * dummy functions.
  1415. *
  1416. * Return: None
  1417. */
  1418. static void
  1419. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  1420. {
  1421. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  1422. p_sops->get_tsf64 = null_get_tsf64;
  1423. p_sops->get_capability = null_get_capability;
  1424. p_sops->set_rxfilter = null_set_rxfilter;
  1425. p_sops->get_rxfilter = null_get_rxfilter;
  1426. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  1427. p_sops->is_spectral_active = null_is_spectral_active;
  1428. p_sops->start_spectral_scan = null_start_spectral_scan;
  1429. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  1430. p_sops->get_extension_channel = null_get_extension_channel;
  1431. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  1432. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  1433. p_sops->configure_spectral = null_configure_spectral;
  1434. p_sops->get_spectral_config = null_get_spectral_config;
  1435. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  1436. p_sops->get_mac_address = null_get_mac_address;
  1437. p_sops->get_current_channel = null_get_current_channel;
  1438. p_sops->reset_hw = null_reset_hw;
  1439. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  1440. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  1441. }
  1442. /**
  1443. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  1444. * operations
  1445. * @spectral: Pointer to Spectral target_if internal private data
  1446. * @p: Pointer to Spectral function table
  1447. *
  1448. * Return: None
  1449. */
  1450. static void
  1451. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  1452. struct target_if_spectral_ops *p)
  1453. {
  1454. struct target_if_spectral_ops *p_sops =
  1455. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1456. p_sops->get_tsf64 = p->get_tsf64;
  1457. p_sops->get_capability = p->get_capability;
  1458. p_sops->set_rxfilter = p->set_rxfilter;
  1459. p_sops->get_rxfilter = p->get_rxfilter;
  1460. p_sops->is_spectral_enabled = p->is_spectral_enabled;
  1461. p_sops->is_spectral_active = p->is_spectral_active;
  1462. p_sops->start_spectral_scan = p->start_spectral_scan;
  1463. p_sops->stop_spectral_scan = p->stop_spectral_scan;
  1464. p_sops->get_extension_channel = p->get_extension_channel;
  1465. p_sops->get_ctl_noisefloor = p->get_ctl_noisefloor;
  1466. p_sops->get_ext_noisefloor = p->get_ext_noisefloor;
  1467. p_sops->configure_spectral = p->configure_spectral;
  1468. p_sops->get_spectral_config = p->get_spectral_config;
  1469. p_sops->get_ent_spectral_mask = p->get_ent_spectral_mask;
  1470. p_sops->get_mac_address = p->get_mac_address;
  1471. p_sops->get_current_channel = p->get_current_channel;
  1472. p_sops->reset_hw = p->reset_hw;
  1473. p_sops->get_chain_noise_floor = p->get_chain_noise_floor;
  1474. p_sops->spectral_process_phyerr = p->spectral_process_phyerr;
  1475. }
  1476. /**
  1477. * target_if_spectral_clear_stats() - Clear Spectral stats
  1478. * @spectral: Pointer to Spectral target_if internal private data
  1479. *
  1480. * Function to clear spectral stats
  1481. *
  1482. * Return: None
  1483. */
  1484. static void
  1485. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  1486. {
  1487. struct target_if_spectral_ops *p_sops =
  1488. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1489. qdf_mem_zero(&spectral->spectral_stats,
  1490. sizeof(struct target_if_spectral_stats));
  1491. spectral->spectral_stats.last_reset_tstamp =
  1492. p_sops->get_tsf64(spectral);
  1493. }
  1494. /**
  1495. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  1496. * @spectral: Pointer to Spectral target_if internal private data
  1497. *
  1498. * Function to check whether hardware supports spectral
  1499. *
  1500. * Return: True if HW supports Spectral, false if HW does not support Spectral
  1501. */
  1502. static int
  1503. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  1504. {
  1505. struct target_if_spectral_ops *p_sops = NULL;
  1506. struct spectral_caps *pcap = NULL;
  1507. int is_spectral_supported = true;
  1508. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1509. pcap = &spectral->capability;
  1510. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  1511. is_spectral_supported = false;
  1512. spectral_info("SPECTRAL : No PHYDIAG support");
  1513. return is_spectral_supported;
  1514. }
  1515. pcap->phydiag_cap = 1;
  1516. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  1517. is_spectral_supported = false;
  1518. spectral_info("SPECTRAL : No RADAR support");
  1519. return is_spectral_supported;
  1520. }
  1521. pcap->radar_cap = 1;
  1522. if (p_sops->get_capability(spectral,
  1523. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  1524. is_spectral_supported = false;
  1525. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  1526. return is_spectral_supported;
  1527. }
  1528. pcap->spectral_cap = 1;
  1529. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  1530. == false) {
  1531. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  1532. } else {
  1533. pcap->advncd_spectral_cap = 1;
  1534. }
  1535. return is_spectral_supported;
  1536. }
  1537. /**
  1538. * target_if_spectral_init_param_defaults() - Initialize Spectral
  1539. * parameter defaults
  1540. * @spectral: Pointer to Spectral target_if internal private data
  1541. *
  1542. * It is the caller's responsibility to ensure that the Spectral parameters
  1543. * structure passed as part of Spectral target_if internal private data is
  1544. * valid.
  1545. *
  1546. * Return: None
  1547. */
  1548. static void
  1549. target_if_spectral_init_param_defaults(struct target_if_spectral *spectral)
  1550. {
  1551. struct spectral_config *params = &spectral->params;
  1552. params->ss_count = SPECTRAL_SCAN_COUNT_DEFAULT;
  1553. params->ss_period = SPECTRAL_SCAN_PERIOD_DEFAULT;
  1554. params->ss_spectral_pri = SPECTRAL_SCAN_PRIORITY_DEFAULT;
  1555. params->ss_fft_size = SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  1556. params->ss_gc_ena = SPECTRAL_SCAN_GC_ENA_DEFAULT;
  1557. params->ss_restart_ena = SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  1558. params->ss_noise_floor_ref = SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  1559. params->ss_init_delay = SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  1560. params->ss_nb_tone_thr = SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  1561. params->ss_str_bin_thr = SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  1562. params->ss_wb_rpt_mode = SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  1563. params->ss_rssi_rpt_mode = SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  1564. params->ss_rssi_thr = SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  1565. params->ss_pwr_format = SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  1566. params->ss_rpt_mode = SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  1567. params->ss_bin_scale = SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  1568. params->ss_dbm_adj = SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  1569. /*
  1570. * XXX
  1571. * SPECTRAL_SCAN_CHN_MASK_DEFAULT (0x1) specifies that chain 0 is to be
  1572. * used
  1573. * for Spectral. This is expected to be an optimal configuration for
  1574. * most chipsets considering aspects like power save. But this can later
  1575. * optionally be changed to be set to the default system Rx chainmask
  1576. * advertised by FW (if required for some purpose), once the Convergence
  1577. * framework supports such retrieval at pdev attach time.
  1578. */
  1579. params->ss_chn_mask = SPECTRAL_SCAN_CHN_MASK_DEFAULT;
  1580. params->ss_short_report = SPECTRAL_SCAN_SHORT_REPORT_DEFAULT;
  1581. params->ss_fft_period = SPECTRAL_SCAN_FFT_PERIOD_DEFAULT;
  1582. }
  1583. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1584. /**
  1585. * target_if_spectral_detach_simulation() - De-initialize Spectral
  1586. * Simulation functionality
  1587. * @spectral: Pointer to Spectral target_if internal private data
  1588. *
  1589. * Function to de-initialize Spectral Simulation functionality
  1590. *
  1591. * Return: None
  1592. */
  1593. static void
  1594. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1595. {
  1596. target_if_spectral_sim_detach(spectral);
  1597. }
  1598. #else
  1599. static void
  1600. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1601. {
  1602. }
  1603. #endif
  1604. /**
  1605. * target_if_spectral_detach() - De-initialize target_if Spectral
  1606. * @pdev: Pointer to pdev object
  1607. *
  1608. * Function to detach target_if spectral
  1609. *
  1610. * Return: None
  1611. */
  1612. static void
  1613. target_if_spectral_detach(struct target_if_spectral *spectral)
  1614. {
  1615. spectral_info("spectral detach");
  1616. if (spectral) {
  1617. qdf_spinlock_destroy(&spectral->param_info.osps_lock);
  1618. target_if_spectral_detach_simulation(spectral);
  1619. spectral->nl_cb.destroy_netlink(spectral->pdev_obj);
  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. void
  2460. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  2461. {
  2462. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  2463. target_if_pdev_spectral_init;
  2464. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  2465. target_if_pdev_spectral_deinit;
  2466. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  2467. target_if_set_spectral_config;
  2468. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  2469. target_if_get_spectral_config;
  2470. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  2471. target_if_start_spectral_scan;
  2472. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  2473. target_if_stop_spectral_scan;
  2474. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  2475. target_if_is_spectral_active;
  2476. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  2477. target_if_is_spectral_enabled;
  2478. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  2479. target_if_set_debug_level;
  2480. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  2481. target_if_get_debug_level;
  2482. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  2483. target_if_get_spectral_capinfo;
  2484. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  2485. target_if_get_spectral_diagstats;
  2486. tx_ops->sptrl_tx_ops.sptrlto_register_wmi_spectral_cmd_ops =
  2487. target_if_register_wmi_spectral_cmd_ops;
  2488. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  2489. target_if_register_netlink_cb;
  2490. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  2491. target_if_use_nl_bcast;
  2492. }
  2493. EXPORT_SYMBOL(target_if_sptrl_register_tx_ops);
  2494. void
  2495. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  2496. uint16_t cw_int, uint32_t dcs_enabled)
  2497. {
  2498. struct spectral_samp_msg *msg = NULL;
  2499. struct target_if_spectral_ops *p_sops = NULL;
  2500. struct target_if_spectral *spectral = NULL;
  2501. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2502. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_nbuff(
  2503. spectral->pdev_obj);
  2504. if (msg) {
  2505. msg->int_type = cw_int ?
  2506. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  2507. msg->dcs_enabled = dcs_enabled;
  2508. msg->signature = SPECTRAL_SIGNATURE;
  2509. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2510. p_sops->get_mac_address(spectral, msg->macaddr);
  2511. if (spectral->send_phy_data(pdev) == 0)
  2512. spectral->spectral_sent_msg++;
  2513. }
  2514. }
  2515. EXPORT_SYMBOL(target_if_spectral_send_intf_found_msg);