target_if_spectral.c 85 KB

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