target_if_spectral.c 84 KB

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