target_if_spectral.c 80 KB

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