target_if_spectral.c 81 KB

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