target_if_spectral.c 79 KB

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