target_if_spectral.c 80 KB

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