target_if_spectral.c 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165
  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_param_properties() - Initialize Spectral parameter
  1149. * properties
  1150. * @spectral: Pointer to Spectral target_if internal private data
  1151. *
  1152. * Initialize Spectral parameter properties
  1153. *
  1154. * Return: QDF_STATUS
  1155. */
  1156. static QDF_STATUS
  1157. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1158. {
  1159. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1160. int param;
  1161. /* Initialize default values for properties.
  1162. * Default values are supported for all the parameters for all modes
  1163. * and allows different values for each mode for all the parameters .
  1164. */
  1165. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1166. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1167. spectral->properties[smode][param].supported = true;
  1168. spectral->properties[smode][param].common_all_modes =
  1169. false;
  1170. }
  1171. }
  1172. return QDF_STATUS_SUCCESS;
  1173. }
  1174. /**
  1175. * target_if_init_spectral_capability() - Initialize Spectral capability
  1176. * @spectral: Pointer to Spectral target_if internal private data
  1177. *
  1178. * This is a workaround.
  1179. *
  1180. * Return: QDF_STATUS
  1181. */
  1182. QDF_STATUS
  1183. target_if_init_spectral_capability(struct target_if_spectral *spectral)
  1184. {
  1185. struct wlan_objmgr_psoc *psoc;
  1186. struct wlan_objmgr_pdev *pdev;
  1187. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  1188. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  1189. struct target_psoc_info *tgt_psoc_info;
  1190. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  1191. struct spectral_caps *pcap = &spectral->capability;
  1192. pdev = spectral->pdev_obj;
  1193. psoc = wlan_pdev_get_psoc(pdev);
  1194. if (!psoc) {
  1195. spectral_err("psoc is null");
  1196. return QDF_STATUS_E_FAILURE;
  1197. }
  1198. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  1199. if (!tgt_psoc_info) {
  1200. spectral_err("target_psoc_info is null");
  1201. return QDF_STATUS_E_FAILURE;
  1202. }
  1203. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  1204. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  1205. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  1206. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  1207. /* XXX : Workaround: Set Spectral capability */
  1208. pcap = &spectral->capability;
  1209. pcap->phydiag_cap = 1;
  1210. pcap->radar_cap = 1;
  1211. pcap->spectral_cap = 1;
  1212. pcap->advncd_spectral_cap = 1;
  1213. pcap->hw_gen = spectral->spectral_gen;
  1214. for (param_idx = 0; param_idx < num_bin_scaling_params; param_idx++) {
  1215. if (scaling_params[param_idx].pdev_id == pdev_id) {
  1216. pcap->is_scaling_params_populated = true;
  1217. pcap->formula_id = scaling_params[param_idx].formula_id;
  1218. pcap->low_level_offset =
  1219. scaling_params[param_idx].low_level_offset;
  1220. pcap->high_level_offset =
  1221. scaling_params[param_idx].high_level_offset;
  1222. pcap->rssi_thr = scaling_params[param_idx].rssi_thr;
  1223. pcap->default_agc_max_gain =
  1224. scaling_params[param_idx].default_agc_max_gain;
  1225. break;
  1226. }
  1227. }
  1228. return QDF_STATUS_SUCCESS;
  1229. }
  1230. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1231. /**
  1232. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1233. * internal operations with functions related to spectral simulation
  1234. * @p_sops: spectral low level ops table
  1235. *
  1236. * Initialize spectral target_if internal operations with functions
  1237. * related to spectral simulation
  1238. *
  1239. * Return: None
  1240. */
  1241. static void
  1242. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1243. {
  1244. /*
  1245. * Spectral simulation is currently intended for platform transitions
  1246. * where underlying HW support may not be available for some time.
  1247. * Hence, we do not currently provide a runtime switch to turn the
  1248. * simulation on or off.
  1249. * In case of future requirements where runtime switches are required,
  1250. * this can be added. But it is suggested to use application layer
  1251. * simulation as far as possible in such cases, since the main
  1252. * use of record and replay of samples would concern higher
  1253. * level sample processing rather than lower level delivery.
  1254. */
  1255. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  1256. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  1257. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  1258. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  1259. p_sops->configure_spectral =
  1260. target_if_spectral_sops_sim_configure_params;
  1261. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  1262. }
  1263. #else
  1264. /**
  1265. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1266. * internal operations
  1267. * @p_sops: spectral low level ops table
  1268. *
  1269. * Return: None
  1270. */
  1271. static void
  1272. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1273. {
  1274. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  1275. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  1276. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  1277. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  1278. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  1279. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  1280. }
  1281. #endif
  1282. /**
  1283. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  1284. * operations common to all Spectral chipset generations
  1285. *
  1286. * Initializes target_if_spectral_ops common to all chipset generations
  1287. *
  1288. * Return: None
  1289. */
  1290. static void
  1291. target_if_init_spectral_ops_common(void)
  1292. {
  1293. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1294. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  1295. p_sops->get_capability = target_if_spectral_get_capability;
  1296. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  1297. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  1298. target_if_init_spectral_simulation_ops(p_sops);
  1299. p_sops->get_extension_channel =
  1300. target_if_spectral_get_extension_channel;
  1301. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  1302. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  1303. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  1304. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  1305. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  1306. p_sops->reset_hw = target_if_spectral_reset_hw;
  1307. p_sops->get_chain_noise_floor =
  1308. target_if_spectral_get_chain_noise_floor;
  1309. }
  1310. /**
  1311. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  1312. * operations specific to Spectral chipset generation 2.
  1313. *
  1314. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  1315. *
  1316. * Return: None
  1317. */
  1318. static void
  1319. target_if_init_spectral_ops_gen2(void)
  1320. {
  1321. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1322. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  1323. }
  1324. /**
  1325. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  1326. * operations specific to Spectral chipset generation 3.
  1327. *
  1328. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  1329. *
  1330. * Return: None
  1331. */
  1332. static void
  1333. target_if_init_spectral_ops_gen3(void)
  1334. {
  1335. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1336. p_sops->process_spectral_report =
  1337. target_if_spectral_process_report_gen3;
  1338. return;
  1339. }
  1340. /**
  1341. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  1342. * operations.
  1343. * @spectral: Pointer to Spectral target_if internal private data
  1344. *
  1345. * Initializes all function pointers in target_if_spectral_ops for
  1346. * all generations
  1347. *
  1348. * Return: None
  1349. */
  1350. static void
  1351. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  1352. {
  1353. target_if_init_spectral_ops_common();
  1354. if (spectral->spectral_gen == SPECTRAL_GEN2)
  1355. target_if_init_spectral_ops_gen2();
  1356. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  1357. target_if_init_spectral_ops_gen3();
  1358. else
  1359. spectral_err("Invalid Spectral generation");
  1360. }
  1361. /*
  1362. * Dummy Functions:
  1363. * These functions are initially registered to avoid any crashes due to
  1364. * invocation of spectral functions before they are registered.
  1365. */
  1366. static uint64_t
  1367. null_get_tsf64(void *arg)
  1368. {
  1369. spectral_ops_not_registered("get_tsf64");
  1370. return 0;
  1371. }
  1372. static uint32_t
  1373. null_get_capability(void *arg, enum spectral_capability_type type)
  1374. {
  1375. /*
  1376. * TODO : We should have conditional compilation to get the capability
  1377. * : We have not yet attahced ATH layer here, so there is no
  1378. * : way to check the HAL capbalities
  1379. */
  1380. spectral_ops_not_registered("get_capability");
  1381. /* TODO : For the time being, we are returning TRUE */
  1382. return true;
  1383. }
  1384. static uint32_t
  1385. null_set_rxfilter(void *arg, int rxfilter)
  1386. {
  1387. spectral_ops_not_registered("set_rxfilter");
  1388. return 1;
  1389. }
  1390. static uint32_t
  1391. null_get_rxfilter(void *arg)
  1392. {
  1393. spectral_ops_not_registered("get_rxfilter");
  1394. return 0;
  1395. }
  1396. static uint32_t
  1397. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  1398. {
  1399. spectral_ops_not_registered("is_spectral_active");
  1400. return 1;
  1401. }
  1402. static uint32_t
  1403. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  1404. {
  1405. spectral_ops_not_registered("is_spectral_enabled");
  1406. return 1;
  1407. }
  1408. static uint32_t
  1409. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  1410. enum spectral_cp_error_code *err)
  1411. {
  1412. spectral_ops_not_registered("start_spectral_scan");
  1413. return 1;
  1414. }
  1415. static uint32_t
  1416. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  1417. {
  1418. spectral_ops_not_registered("stop_spectral_scan");
  1419. return 1;
  1420. }
  1421. static uint32_t
  1422. null_get_extension_channel(void *arg)
  1423. {
  1424. spectral_ops_not_registered("get_extension_channel");
  1425. return 1;
  1426. }
  1427. static int8_t
  1428. null_get_ctl_noisefloor(void *arg)
  1429. {
  1430. spectral_ops_not_registered("get_ctl_noisefloor");
  1431. return 1;
  1432. }
  1433. static int8_t
  1434. null_get_ext_noisefloor(void *arg)
  1435. {
  1436. spectral_ops_not_registered("get_ext_noisefloor");
  1437. return 0;
  1438. }
  1439. static uint32_t
  1440. null_configure_spectral(void *arg, struct spectral_config *params,
  1441. enum spectral_scan_mode smode)
  1442. {
  1443. spectral_ops_not_registered("configure_spectral");
  1444. return 0;
  1445. }
  1446. static uint32_t
  1447. null_get_spectral_config(void *arg, struct spectral_config *params,
  1448. enum spectral_scan_mode smode)
  1449. {
  1450. spectral_ops_not_registered("get_spectral_config");
  1451. return 0;
  1452. }
  1453. static uint32_t
  1454. null_get_ent_spectral_mask(void *arg)
  1455. {
  1456. spectral_ops_not_registered("get_ent_spectral_mask");
  1457. return 0;
  1458. }
  1459. static uint32_t
  1460. null_get_mac_address(void *arg, char *addr)
  1461. {
  1462. spectral_ops_not_registered("get_mac_address");
  1463. return 0;
  1464. }
  1465. static uint32_t
  1466. null_get_current_channel(void *arg)
  1467. {
  1468. spectral_ops_not_registered("get_current_channel");
  1469. return 0;
  1470. }
  1471. static uint32_t
  1472. null_reset_hw(void *arg)
  1473. {
  1474. spectral_ops_not_registered("get_current_channel");
  1475. return 0;
  1476. }
  1477. static uint32_t
  1478. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1479. {
  1480. spectral_ops_not_registered("get_chain_noise_floor");
  1481. return 0;
  1482. }
  1483. static int
  1484. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  1485. uint8_t *data,
  1486. uint32_t datalen,
  1487. struct target_if_spectral_rfqual_info *p_rfqual,
  1488. struct target_if_spectral_chan_info *p_chaninfo,
  1489. uint64_t tsf64,
  1490. struct target_if_spectral_acs_stats *acs_stats)
  1491. {
  1492. spectral_ops_not_registered("spectral_process_phyerr");
  1493. return 0;
  1494. }
  1495. static int
  1496. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  1497. void *payload)
  1498. {
  1499. spectral_ops_not_registered("process_spectral_report");
  1500. return 0;
  1501. }
  1502. /**
  1503. * target_if_spectral_init_dummy_function_table() -
  1504. * Initialize target_if internal
  1505. * Spectral operations to dummy functions
  1506. * @ps: Pointer to Spectral target_if internal private data
  1507. *
  1508. * Initialize all the function pointers in target_if_spectral_ops with
  1509. * dummy functions.
  1510. *
  1511. * Return: None
  1512. */
  1513. static void
  1514. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  1515. {
  1516. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  1517. p_sops->get_tsf64 = null_get_tsf64;
  1518. p_sops->get_capability = null_get_capability;
  1519. p_sops->set_rxfilter = null_set_rxfilter;
  1520. p_sops->get_rxfilter = null_get_rxfilter;
  1521. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  1522. p_sops->is_spectral_active = null_is_spectral_active;
  1523. p_sops->start_spectral_scan = null_start_spectral_scan;
  1524. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  1525. p_sops->get_extension_channel = null_get_extension_channel;
  1526. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  1527. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  1528. p_sops->configure_spectral = null_configure_spectral;
  1529. p_sops->get_spectral_config = null_get_spectral_config;
  1530. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  1531. p_sops->get_mac_address = null_get_mac_address;
  1532. p_sops->get_current_channel = null_get_current_channel;
  1533. p_sops->reset_hw = null_reset_hw;
  1534. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  1535. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  1536. p_sops->process_spectral_report = null_process_spectral_report;
  1537. }
  1538. /**
  1539. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  1540. * operations
  1541. * @spectral: Pointer to Spectral target_if internal private data
  1542. * @p: Pointer to Spectral function table
  1543. *
  1544. * Return: None
  1545. */
  1546. static void
  1547. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  1548. struct target_if_spectral_ops *p)
  1549. {
  1550. struct target_if_spectral_ops *p_sops =
  1551. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1552. p_sops->get_tsf64 = p->get_tsf64;
  1553. p_sops->get_capability = p->get_capability;
  1554. p_sops->set_rxfilter = p->set_rxfilter;
  1555. p_sops->get_rxfilter = p->get_rxfilter;
  1556. p_sops->is_spectral_enabled = p->is_spectral_enabled;
  1557. p_sops->is_spectral_active = p->is_spectral_active;
  1558. p_sops->start_spectral_scan = p->start_spectral_scan;
  1559. p_sops->stop_spectral_scan = p->stop_spectral_scan;
  1560. p_sops->get_extension_channel = p->get_extension_channel;
  1561. p_sops->get_ctl_noisefloor = p->get_ctl_noisefloor;
  1562. p_sops->get_ext_noisefloor = p->get_ext_noisefloor;
  1563. p_sops->configure_spectral = p->configure_spectral;
  1564. p_sops->get_spectral_config = p->get_spectral_config;
  1565. p_sops->get_ent_spectral_mask = p->get_ent_spectral_mask;
  1566. p_sops->get_mac_address = p->get_mac_address;
  1567. p_sops->get_current_channel = p->get_current_channel;
  1568. p_sops->reset_hw = p->reset_hw;
  1569. p_sops->get_chain_noise_floor = p->get_chain_noise_floor;
  1570. p_sops->spectral_process_phyerr = p->spectral_process_phyerr;
  1571. p_sops->process_spectral_report = p->process_spectral_report;
  1572. }
  1573. /**
  1574. * target_if_spectral_clear_stats() - Clear Spectral stats
  1575. * @spectral: Pointer to Spectral target_if internal private data
  1576. *
  1577. * Function to clear spectral stats
  1578. *
  1579. * Return: None
  1580. */
  1581. static void
  1582. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  1583. {
  1584. struct target_if_spectral_ops *p_sops =
  1585. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1586. qdf_mem_zero(&spectral->spectral_stats,
  1587. sizeof(struct target_if_spectral_stats));
  1588. spectral->spectral_stats.last_reset_tstamp =
  1589. p_sops->get_tsf64(spectral);
  1590. }
  1591. /**
  1592. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  1593. * @spectral: Pointer to Spectral target_if internal private data
  1594. *
  1595. * Function to check whether hardware supports spectral
  1596. *
  1597. * Return: True if HW supports Spectral, false if HW does not support Spectral
  1598. */
  1599. static int
  1600. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  1601. {
  1602. struct target_if_spectral_ops *p_sops = NULL;
  1603. struct spectral_caps *pcap = NULL;
  1604. int is_spectral_supported = true;
  1605. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1606. pcap = &spectral->capability;
  1607. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  1608. is_spectral_supported = false;
  1609. spectral_info("SPECTRAL : No PHYDIAG support");
  1610. return is_spectral_supported;
  1611. }
  1612. pcap->phydiag_cap = 1;
  1613. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  1614. is_spectral_supported = false;
  1615. spectral_info("SPECTRAL : No RADAR support");
  1616. return is_spectral_supported;
  1617. }
  1618. pcap->radar_cap = 1;
  1619. if (p_sops->get_capability(spectral,
  1620. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  1621. is_spectral_supported = false;
  1622. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  1623. return is_spectral_supported;
  1624. }
  1625. pcap->spectral_cap = 1;
  1626. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  1627. == false) {
  1628. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  1629. } else {
  1630. pcap->advncd_spectral_cap = 1;
  1631. }
  1632. return is_spectral_supported;
  1633. }
  1634. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1635. /**
  1636. * target_if_spectral_detach_simulation() - De-initialize Spectral
  1637. * Simulation functionality
  1638. * @spectral: Pointer to Spectral target_if internal private data
  1639. *
  1640. * Function to de-initialize Spectral Simulation functionality
  1641. *
  1642. * Return: None
  1643. */
  1644. static void
  1645. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1646. {
  1647. target_if_spectral_sim_detach(spectral);
  1648. }
  1649. #else
  1650. static void
  1651. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1652. {
  1653. }
  1654. #endif
  1655. /**
  1656. * target_if_spectral_detach() - De-initialize target_if Spectral
  1657. * @pdev: Pointer to pdev object
  1658. *
  1659. * Function to detach target_if spectral
  1660. *
  1661. * Return: None
  1662. */
  1663. static void
  1664. target_if_spectral_detach(struct target_if_spectral *spectral)
  1665. {
  1666. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1667. spectral_info("spectral detach");
  1668. if (spectral) {
  1669. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1670. qdf_spinlock_destroy
  1671. (&spectral->param_info[smode].osps_lock);
  1672. target_if_spectral_detach_simulation(spectral);
  1673. qdf_spinlock_destroy(&spectral->spectral_lock);
  1674. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  1675. qdf_mem_free(spectral);
  1676. spectral = NULL;
  1677. }
  1678. }
  1679. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1680. /**
  1681. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  1682. * functionality
  1683. * @spectral: Pointer to Spectral target_if internal private data
  1684. *
  1685. * Function to initialize spectral simulation functionality
  1686. *
  1687. * Return: 0 on success, negative error code on failure
  1688. */
  1689. static int
  1690. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1691. {
  1692. if (target_if_spectral_sim_attach(spectral)) {
  1693. qdf_mem_free(spectral);
  1694. return -EPERM;
  1695. }
  1696. return 0;
  1697. }
  1698. #else
  1699. static int
  1700. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1701. {
  1702. return 0;
  1703. }
  1704. #endif
  1705. /**
  1706. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  1707. * functionality for the given pdev
  1708. * @pdev: Pointer to pdev object
  1709. *
  1710. * Function to initialize pointer to spectral target_if internal private data
  1711. *
  1712. * Return: On success, pointer to Spectral target_if internal private data, on
  1713. * failure, NULL
  1714. */
  1715. void *
  1716. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  1717. {
  1718. struct target_if_spectral_ops *p_sops = NULL;
  1719. struct target_if_spectral *spectral = NULL;
  1720. uint32_t target_type;
  1721. uint32_t target_revision;
  1722. struct wlan_objmgr_psoc *psoc;
  1723. struct wlan_lmac_if_target_tx_ops *tx_ops;
  1724. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1725. if (!pdev) {
  1726. spectral_err("SPECTRAL: pdev is NULL!");
  1727. return NULL;
  1728. }
  1729. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  1730. sizeof(struct target_if_spectral));
  1731. if (!spectral)
  1732. return spectral;
  1733. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  1734. /* Store pdev in Spectral */
  1735. spectral->pdev_obj = pdev;
  1736. psoc = wlan_pdev_get_psoc(pdev);
  1737. tx_ops = &psoc->soc_cb.tx_ops.target_tx_ops;
  1738. if (tx_ops->tgt_get_tgt_type) {
  1739. target_type = tx_ops->tgt_get_tgt_type(psoc);
  1740. } else {
  1741. qdf_mem_free(spectral);
  1742. return NULL;
  1743. }
  1744. if (tx_ops->tgt_get_tgt_revision) {
  1745. target_revision = tx_ops->tgt_get_tgt_revision(psoc);
  1746. } else {
  1747. qdf_mem_free(spectral);
  1748. return NULL;
  1749. }
  1750. /* init the function ptr table */
  1751. target_if_spectral_init_dummy_function_table(spectral);
  1752. /* get spectral function table */
  1753. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1754. /* TODO : Should this be called here of after ath_attach ? */
  1755. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  1756. spectral_info("HAL_CAP_PHYDIAG : Capable");
  1757. /* TODO: Need to fix the capablity check for RADAR */
  1758. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  1759. spectral_info("HAL_CAP_RADAR : Capable");
  1760. /* TODO : Need to fix the capablity check for SPECTRAL */
  1761. /* TODO : Should this be called here of after ath_attach ? */
  1762. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  1763. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  1764. qdf_spinlock_create(&spectral->spectral_lock);
  1765. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  1766. target_if_spectral_clear_stats(spectral);
  1767. if (target_type == TARGET_TYPE_QCA8074V2)
  1768. spectral->fftbin_size_war =
  1769. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  1770. else if (target_type == TARGET_TYPE_QCA8074 ||
  1771. target_type == TARGET_TYPE_QCA6018)
  1772. spectral->fftbin_size_war =
  1773. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  1774. else
  1775. spectral->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  1776. if (target_type == TARGET_TYPE_QCA8074 ||
  1777. target_type == TARGET_TYPE_QCA8074V2 ||
  1778. target_type == TARGET_TYPE_QCA6018) {
  1779. spectral->inband_fftbin_size_adj = 1;
  1780. spectral->null_fftbin_adj = 1;
  1781. } else {
  1782. spectral->inband_fftbin_size_adj = 0;
  1783. spectral->null_fftbin_adj = 0;
  1784. }
  1785. if ((target_type == TARGET_TYPE_QCA8074) ||
  1786. (target_type == TARGET_TYPE_QCA8074V2) ||
  1787. (target_type == TARGET_TYPE_QCA6018) ||
  1788. (target_type == TARGET_TYPE_QCN9000) ||
  1789. (target_type == TARGET_TYPE_QCA6290)) {
  1790. spectral->spectral_gen = SPECTRAL_GEN3;
  1791. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  1792. spectral->tag_sscan_summary_exp =
  1793. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  1794. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  1795. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  1796. spectral->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3;
  1797. spectral->fft_size_max = SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3;
  1798. } else {
  1799. spectral->spectral_gen = SPECTRAL_GEN2;
  1800. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  1801. spectral->tag_sscan_summary_exp =
  1802. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  1803. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  1804. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  1805. spectral->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1806. spectral->fft_size_max = SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1807. }
  1808. target_if_init_spectral_param_properties(spectral);
  1809. /* Init spectral capability */
  1810. if (target_if_init_spectral_capability(spectral) !=
  1811. QDF_STATUS_SUCCESS) {
  1812. qdf_mem_free(spectral);
  1813. return NULL;
  1814. }
  1815. if (target_if_spectral_attach_simulation(spectral) < 0)
  1816. return NULL;
  1817. target_if_init_spectral_ops(spectral);
  1818. /* Spectral mode specific init */
  1819. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1820. spectral->last_fft_timestamp[smode] = 0;
  1821. spectral->timestamp_war_offset[smode] = 0;
  1822. spectral->params_valid[smode] = false;
  1823. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  1824. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  1825. }
  1826. target_if_spectral_register_funcs(spectral, &spectral_ops);
  1827. if (target_if_spectral_check_hw_capability(spectral) == false) {
  1828. target_if_spectral_detach(spectral);
  1829. spectral = NULL;
  1830. } else {
  1831. /*
  1832. * TODO: Once the driver architecture transitions to chipset
  1833. * versioning based checks, reflect this here.
  1834. */
  1835. spectral->is_160_format = false;
  1836. spectral->is_lb_edge_extrabins_format = false;
  1837. spectral->is_rb_edge_extrabins_format = false;
  1838. if (target_type == TARGET_TYPE_QCA9984 ||
  1839. target_type == TARGET_TYPE_QCA9888) {
  1840. spectral->is_160_format = true;
  1841. spectral->is_lb_edge_extrabins_format = true;
  1842. spectral->is_rb_edge_extrabins_format = true;
  1843. } else if ((target_type == TARGET_TYPE_AR900B) &&
  1844. (target_revision == AR900B_REV_2)) {
  1845. spectral->is_rb_edge_extrabins_format = true;
  1846. }
  1847. if (target_type == TARGET_TYPE_QCA9984 ||
  1848. target_type == TARGET_TYPE_QCA9888)
  1849. spectral->is_sec80_rssi_war_required = true;
  1850. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  1851. if (spectral->spectral_gen == SPECTRAL_GEN3)
  1852. init_160mhz_delivery_state_machine(spectral);
  1853. }
  1854. return spectral;
  1855. }
  1856. /**
  1857. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  1858. * functionality for the given pdev
  1859. * @pdev: Pointer to pdev object
  1860. *
  1861. * Function to de-initialize pointer to spectral target_if internal private data
  1862. *
  1863. * Return: None
  1864. */
  1865. void
  1866. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  1867. {
  1868. struct target_if_spectral *spectral = NULL;
  1869. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1870. if (!spectral) {
  1871. spectral_err("SPECTRAL : Module doesn't exist");
  1872. return;
  1873. }
  1874. target_if_spectral_detach(spectral);
  1875. return;
  1876. }
  1877. /**
  1878. * _target_if_set_spectral_config() - Set spectral config
  1879. * @spectral: Pointer to spectral object
  1880. * @threshtype: config type
  1881. * @value: config value
  1882. * @smode: Spectral scan mode
  1883. * @err: Spectral error code
  1884. *
  1885. * API to set spectral configurations
  1886. *
  1887. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  1888. */
  1889. static QDF_STATUS
  1890. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  1891. const uint32_t threshtype, const uint32_t value,
  1892. const enum spectral_scan_mode smode,
  1893. enum spectral_cp_error_code *err)
  1894. {
  1895. struct spectral_config params;
  1896. struct target_if_spectral_ops *p_sops;
  1897. struct spectral_config *sparams;
  1898. if (!err) {
  1899. spectral_err("Error code argument is null");
  1900. QDF_ASSERT(0);
  1901. }
  1902. *err = SPECTRAL_SCAN_ERR_INVALID;
  1903. if (!spectral) {
  1904. spectral_err("spectral object is NULL");
  1905. return QDF_STATUS_E_FAILURE;
  1906. }
  1907. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1908. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1909. spectral_err("Invalid Spectral mode %u", smode);
  1910. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  1911. return QDF_STATUS_E_FAILURE;
  1912. }
  1913. sparams = &spectral->params[smode];
  1914. if (!spectral->params_valid[smode]) {
  1915. target_if_spectral_info_read(spectral,
  1916. smode,
  1917. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1918. &spectral->params[smode],
  1919. sizeof(spectral->params[smode]));
  1920. spectral->params_valid[smode] = true;
  1921. }
  1922. switch (threshtype) {
  1923. case SPECTRAL_PARAM_FFT_PERIOD:
  1924. sparams->ss_fft_period = value;
  1925. break;
  1926. case SPECTRAL_PARAM_SCAN_PERIOD:
  1927. sparams->ss_period = value;
  1928. break;
  1929. case SPECTRAL_PARAM_SCAN_COUNT:
  1930. sparams->ss_count = value;
  1931. break;
  1932. case SPECTRAL_PARAM_SHORT_REPORT:
  1933. sparams->ss_short_report = (!!value) ? true : false;
  1934. break;
  1935. case SPECTRAL_PARAM_SPECT_PRI:
  1936. sparams->ss_spectral_pri = (!!value) ? true : false;
  1937. break;
  1938. case SPECTRAL_PARAM_FFT_SIZE:
  1939. if ((value < spectral->fft_size_min) ||
  1940. (value > spectral->fft_size_max)) {
  1941. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  1942. return QDF_STATUS_E_FAILURE;
  1943. }
  1944. sparams->ss_fft_size = value;
  1945. break;
  1946. case SPECTRAL_PARAM_GC_ENA:
  1947. sparams->ss_gc_ena = !!value;
  1948. break;
  1949. case SPECTRAL_PARAM_RESTART_ENA:
  1950. sparams->ss_restart_ena = !!value;
  1951. break;
  1952. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  1953. sparams->ss_noise_floor_ref = value;
  1954. break;
  1955. case SPECTRAL_PARAM_INIT_DELAY:
  1956. sparams->ss_init_delay = value;
  1957. break;
  1958. case SPECTRAL_PARAM_NB_TONE_THR:
  1959. sparams->ss_nb_tone_thr = value;
  1960. break;
  1961. case SPECTRAL_PARAM_STR_BIN_THR:
  1962. sparams->ss_str_bin_thr = value;
  1963. break;
  1964. case SPECTRAL_PARAM_WB_RPT_MODE:
  1965. sparams->ss_wb_rpt_mode = !!value;
  1966. break;
  1967. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  1968. sparams->ss_rssi_rpt_mode = !!value;
  1969. break;
  1970. case SPECTRAL_PARAM_RSSI_THR:
  1971. sparams->ss_rssi_thr = value;
  1972. break;
  1973. case SPECTRAL_PARAM_PWR_FORMAT:
  1974. sparams->ss_pwr_format = !!value;
  1975. break;
  1976. case SPECTRAL_PARAM_RPT_MODE:
  1977. if ((value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  1978. (value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  1979. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  1980. return QDF_STATUS_E_FAILURE;
  1981. }
  1982. sparams->ss_rpt_mode = value;
  1983. break;
  1984. case SPECTRAL_PARAM_BIN_SCALE:
  1985. sparams->ss_bin_scale = value;
  1986. break;
  1987. case SPECTRAL_PARAM_DBM_ADJ:
  1988. sparams->ss_dbm_adj = !!value;
  1989. break;
  1990. case SPECTRAL_PARAM_CHN_MASK:
  1991. sparams->ss_chn_mask = value;
  1992. break;
  1993. case SPECTRAL_PARAM_FREQUENCY:
  1994. sparams->ss_frequency = value;
  1995. break;
  1996. }
  1997. p_sops->configure_spectral(spectral, sparams, smode);
  1998. /* only to validate the writes */
  1999. p_sops->get_spectral_config(spectral, &params, smode);
  2000. return QDF_STATUS_SUCCESS;
  2001. }
  2002. QDF_STATUS
  2003. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  2004. const uint32_t threshtype, const uint32_t value,
  2005. const enum spectral_scan_mode smode,
  2006. enum spectral_cp_error_code *err)
  2007. {
  2008. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  2009. struct target_if_spectral *spectral;
  2010. QDF_STATUS status;
  2011. if (!err) {
  2012. spectral_err("Error code argument is null");
  2013. QDF_ASSERT(0);
  2014. }
  2015. *err = SPECTRAL_SCAN_ERR_INVALID;
  2016. if (!pdev) {
  2017. spectral_err("pdev object is NULL");
  2018. return QDF_STATUS_E_FAILURE;
  2019. }
  2020. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2021. if (!spectral) {
  2022. spectral_err("spectral object is NULL");
  2023. return QDF_STATUS_E_FAILURE;
  2024. }
  2025. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2026. spectral_err("Invalid Spectral mode %u", smode);
  2027. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2028. return QDF_STATUS_E_FAILURE;
  2029. }
  2030. if (!spectral->properties[smode][threshtype].supported) {
  2031. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  2032. threshtype, smode);
  2033. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  2034. return QDF_STATUS_E_FAILURE;
  2035. }
  2036. if (spectral->properties[smode][threshtype].common_all_modes) {
  2037. spectral_warn("Setting Spectral parameter %u for all modes",
  2038. threshtype);
  2039. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  2040. status = _target_if_set_spectral_config
  2041. (spectral, threshtype, value,
  2042. mode, err);
  2043. if (QDF_IS_STATUS_ERROR(status))
  2044. return QDF_STATUS_E_FAILURE;
  2045. }
  2046. return QDF_STATUS_SUCCESS;
  2047. }
  2048. return _target_if_set_spectral_config(spectral, threshtype,
  2049. value, smode, err);
  2050. }
  2051. /**
  2052. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  2053. * @fft_len: FFT length
  2054. * @pdev: Pointer to pdev object
  2055. *
  2056. * API to get fft bin count for a given fft length
  2057. *
  2058. * Return: FFt bin count
  2059. */
  2060. static int
  2061. target_if_get_fft_bin_count(int fft_len)
  2062. {
  2063. int bin_count = 0;
  2064. switch (fft_len) {
  2065. case 5:
  2066. bin_count = 16;
  2067. break;
  2068. case 6:
  2069. bin_count = 32;
  2070. break;
  2071. case 7:
  2072. bin_count = 64;
  2073. break;
  2074. case 8:
  2075. bin_count = 128;
  2076. break;
  2077. case 9:
  2078. bin_count = 256;
  2079. break;
  2080. default:
  2081. break;
  2082. }
  2083. return bin_count;
  2084. }
  2085. /**
  2086. * target_if_init_upper_lower_flags() - Initializes control and extension
  2087. * segment flags
  2088. * @fft_len: FFT length
  2089. * @pdev: Pointer to pdev object
  2090. *
  2091. * API to initialize the control and extension flags with the lower/upper
  2092. * segment based on the HT mode
  2093. *
  2094. * Return: FFt bin count
  2095. */
  2096. static void
  2097. target_if_init_upper_lower_flags(struct target_if_spectral *spectral)
  2098. {
  2099. int current_channel = 0;
  2100. int ext_channel = 0;
  2101. struct target_if_spectral_ops *p_sops =
  2102. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2103. current_channel = p_sops->get_current_channel(spectral);
  2104. ext_channel = p_sops->get_extension_channel(spectral);
  2105. if ((current_channel == 0) || (ext_channel == 0))
  2106. return;
  2107. if (spectral->sc_spectral_20_40_mode) {
  2108. /* HT40 mode */
  2109. if (ext_channel < current_channel) {
  2110. spectral->lower_is_extension = 1;
  2111. spectral->upper_is_control = 1;
  2112. spectral->lower_is_control = 0;
  2113. spectral->upper_is_extension = 0;
  2114. } else {
  2115. spectral->lower_is_extension = 0;
  2116. spectral->upper_is_control = 0;
  2117. spectral->lower_is_control = 1;
  2118. spectral->upper_is_extension = 1;
  2119. }
  2120. } else {
  2121. /* HT20 mode, lower is always control */
  2122. spectral->lower_is_extension = 0;
  2123. spectral->upper_is_control = 0;
  2124. spectral->lower_is_control = 1;
  2125. spectral->upper_is_extension = 0;
  2126. }
  2127. }
  2128. /**
  2129. * target_if_get_spectral_config() - Get spectral configuration
  2130. * @pdev: Pointer to pdev object
  2131. * @param: Pointer to spectral_config structure in which the configuration
  2132. * should be returned
  2133. * @smode: Spectral scan mode
  2134. *
  2135. * API to get the current spectral configuration
  2136. *
  2137. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2138. */
  2139. QDF_STATUS
  2140. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  2141. struct spectral_config *param,
  2142. enum spectral_scan_mode smode)
  2143. {
  2144. struct target_if_spectral_ops *p_sops = NULL;
  2145. struct target_if_spectral *spectral = NULL;
  2146. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2147. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2148. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2149. spectral_err("Invalid Spectral mode %u", smode);
  2150. return QDF_STATUS_E_FAILURE;
  2151. }
  2152. qdf_mem_zero(param, sizeof(struct spectral_config));
  2153. p_sops->get_spectral_config(spectral, param, smode);
  2154. return QDF_STATUS_SUCCESS;
  2155. }
  2156. /**
  2157. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  2158. * parameters
  2159. * @spectral: Pointer to Spectral target_if internal private data
  2160. * @spectral_params: Pointer to Spectral parameters
  2161. * @smode: Spectral scan mode
  2162. * @err: Spectral error code
  2163. *
  2164. * Enable use of desired Spectral parameters by configuring them into HW, and
  2165. * starting Spectral scan
  2166. *
  2167. * Return: 0 on success, 1 on failure
  2168. */
  2169. int
  2170. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  2171. struct spectral_config *spectral_params,
  2172. enum spectral_scan_mode smode,
  2173. enum spectral_cp_error_code *err)
  2174. {
  2175. int extension_channel = 0;
  2176. int current_channel = 0;
  2177. struct target_if_spectral_ops *p_sops = NULL;
  2178. struct wlan_objmgr_vdev *vdev = NULL;
  2179. if (!spectral) {
  2180. spectral_err("Spectral LMAC object is NULL");
  2181. return 1;
  2182. }
  2183. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2184. spectral_err("Invalid Spectral mode %u", smode);
  2185. return 1;
  2186. }
  2187. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2188. if (!p_sops) {
  2189. spectral_err("p_sops is NULL");
  2190. return 1;
  2191. }
  2192. spectral->sc_spectral_noise_pwr_cal =
  2193. spectral_params->ss_spectral_pri ? 1 : 0;
  2194. /* check if extension channel is present */
  2195. extension_channel = p_sops->get_extension_channel(spectral);
  2196. current_channel = p_sops->get_current_channel(spectral);
  2197. vdev = target_if_spectral_get_vdev(spectral);
  2198. if (!vdev)
  2199. return 1;
  2200. spectral->ch_width = target_if_vdev_get_ch_width(vdev);
  2201. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2202. if (spectral->ch_width == CH_WIDTH_INVALID)
  2203. return 1;
  2204. if (spectral->capability.advncd_spectral_cap) {
  2205. spectral->lb_edge_extrabins = 0;
  2206. spectral->rb_edge_extrabins = 0;
  2207. if (spectral->is_lb_edge_extrabins_format &&
  2208. spectral->params[smode].ss_rpt_mode == 2) {
  2209. spectral->lb_edge_extrabins = 4;
  2210. }
  2211. if (spectral->is_rb_edge_extrabins_format &&
  2212. spectral->params[smode].ss_rpt_mode == 2) {
  2213. spectral->rb_edge_extrabins = 4;
  2214. }
  2215. if (spectral->ch_width == CH_WIDTH_20MHZ) {
  2216. spectral->sc_spectral_20_40_mode = 0;
  2217. spectral->spectral_numbins =
  2218. target_if_get_fft_bin_count(
  2219. spectral->params[smode].ss_fft_size);
  2220. spectral->spectral_fft_len =
  2221. target_if_get_fft_bin_count(
  2222. spectral->params[smode].ss_fft_size);
  2223. spectral->spectral_data_len =
  2224. target_if_get_fft_bin_count(
  2225. spectral->params[smode].ss_fft_size);
  2226. /*
  2227. * Initialize classifier params to be sent to user
  2228. * space classifier
  2229. */
  2230. spectral->classifier_params.lower_chan_in_mhz =
  2231. current_channel;
  2232. spectral->classifier_params.upper_chan_in_mhz = 0;
  2233. } else if (spectral->ch_width == CH_WIDTH_40MHZ) {
  2234. /* TODO : Remove this variable */
  2235. spectral->sc_spectral_20_40_mode = 1;
  2236. spectral->spectral_numbins =
  2237. target_if_get_fft_bin_count(
  2238. spectral->params[smode].ss_fft_size);
  2239. spectral->spectral_fft_len =
  2240. target_if_get_fft_bin_count(
  2241. spectral->params[smode].ss_fft_size);
  2242. spectral->spectral_data_len =
  2243. target_if_get_fft_bin_count(
  2244. spectral->params[smode].ss_fft_size);
  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. } else if (spectral->ch_width == CH_WIDTH_80MHZ) {
  2261. /* Set the FFT Size */
  2262. /* TODO : Remove this variable */
  2263. spectral->sc_spectral_20_40_mode = 0;
  2264. spectral->spectral_numbins =
  2265. target_if_get_fft_bin_count(
  2266. spectral->params[smode].ss_fft_size);
  2267. spectral->spectral_fft_len =
  2268. target_if_get_fft_bin_count(
  2269. spectral->params[smode].ss_fft_size);
  2270. spectral->spectral_data_len =
  2271. target_if_get_fft_bin_count(
  2272. spectral->params[smode].ss_fft_size);
  2273. /*
  2274. * Initialize classifier params to be sent to user
  2275. * space classifier
  2276. */
  2277. spectral->classifier_params.lower_chan_in_mhz =
  2278. current_channel;
  2279. spectral->classifier_params.upper_chan_in_mhz = 0;
  2280. /*
  2281. * Initialize classifier params to be sent to user
  2282. * space classifier
  2283. */
  2284. if (extension_channel < current_channel) {
  2285. spectral->classifier_params.lower_chan_in_mhz =
  2286. extension_channel;
  2287. spectral->classifier_params.upper_chan_in_mhz =
  2288. current_channel;
  2289. } else {
  2290. spectral->classifier_params.lower_chan_in_mhz =
  2291. current_channel;
  2292. spectral->classifier_params.upper_chan_in_mhz =
  2293. extension_channel;
  2294. }
  2295. } else if (spectral->ch_width == CH_WIDTH_160MHZ) {
  2296. /* Set the FFT Size */
  2297. /* The below applies to both 160 and 80+80 cases */
  2298. /* TODO : Remove this variable */
  2299. spectral->sc_spectral_20_40_mode = 0;
  2300. spectral->spectral_numbins =
  2301. target_if_get_fft_bin_count(
  2302. spectral->params[smode].ss_fft_size);
  2303. spectral->spectral_fft_len =
  2304. target_if_get_fft_bin_count(
  2305. spectral->params[smode].ss_fft_size);
  2306. spectral->spectral_data_len =
  2307. target_if_get_fft_bin_count(
  2308. spectral->params[smode].ss_fft_size);
  2309. /*
  2310. * Initialize classifier params to be sent to user
  2311. * space classifier
  2312. */
  2313. spectral->classifier_params.lower_chan_in_mhz =
  2314. current_channel;
  2315. spectral->classifier_params.upper_chan_in_mhz = 0;
  2316. /*
  2317. * Initialize classifier params to be sent to user
  2318. * space classifier
  2319. */
  2320. if (extension_channel < current_channel) {
  2321. spectral->classifier_params.lower_chan_in_mhz =
  2322. extension_channel;
  2323. spectral->classifier_params.upper_chan_in_mhz =
  2324. current_channel;
  2325. } else {
  2326. spectral->classifier_params.lower_chan_in_mhz =
  2327. current_channel;
  2328. spectral->classifier_params.upper_chan_in_mhz =
  2329. extension_channel;
  2330. }
  2331. }
  2332. if (spectral->spectral_numbins) {
  2333. spectral->spectral_numbins +=
  2334. spectral->lb_edge_extrabins;
  2335. spectral->spectral_numbins +=
  2336. spectral->rb_edge_extrabins;
  2337. }
  2338. if (spectral->spectral_fft_len) {
  2339. spectral->spectral_fft_len +=
  2340. spectral->lb_edge_extrabins;
  2341. spectral->spectral_fft_len +=
  2342. spectral->rb_edge_extrabins;
  2343. }
  2344. if (spectral->spectral_data_len) {
  2345. spectral->spectral_data_len +=
  2346. spectral->lb_edge_extrabins;
  2347. spectral->spectral_data_len +=
  2348. spectral->rb_edge_extrabins;
  2349. }
  2350. } else {
  2351. /*
  2352. * The decision to find 20/40 mode is found based on the
  2353. * presence of extension channel
  2354. * instead of channel width, as the channel width can
  2355. * dynamically change
  2356. */
  2357. if (extension_channel == 0) {
  2358. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  2359. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  2360. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  2361. spectral->spectral_data_len =
  2362. SPECTRAL_HT20_TOTAL_DATA_LEN;
  2363. /* only valid in 20-40 mode */
  2364. spectral->spectral_lower_max_index_offset = -1;
  2365. /* only valid in 20-40 mode */
  2366. spectral->spectral_upper_max_index_offset = -1;
  2367. spectral->spectral_max_index_offset =
  2368. spectral->spectral_fft_len + 2;
  2369. spectral->sc_spectral_20_40_mode = 0;
  2370. /*
  2371. * Initialize classifier params to be sent to user
  2372. * space classifier
  2373. */
  2374. spectral->classifier_params.lower_chan_in_mhz =
  2375. current_channel;
  2376. spectral->classifier_params.upper_chan_in_mhz = 0;
  2377. } else {
  2378. spectral->spectral_numbins =
  2379. SPECTRAL_HT40_TOTAL_NUM_BINS;
  2380. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  2381. spectral->spectral_data_len =
  2382. SPECTRAL_HT40_TOTAL_DATA_LEN;
  2383. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  2384. /* only valid in 20 mode */
  2385. spectral->spectral_max_index_offset = -1;
  2386. spectral->spectral_lower_max_index_offset =
  2387. spectral->spectral_fft_len + 2;
  2388. spectral->spectral_upper_max_index_offset =
  2389. spectral->spectral_fft_len + 5;
  2390. spectral->sc_spectral_20_40_mode = 1;
  2391. /*
  2392. * Initialize classifier params to be sent to user
  2393. * space classifier
  2394. */
  2395. if (extension_channel < current_channel) {
  2396. spectral->classifier_params.lower_chan_in_mhz =
  2397. extension_channel;
  2398. spectral->classifier_params.upper_chan_in_mhz =
  2399. current_channel;
  2400. } else {
  2401. spectral->classifier_params.lower_chan_in_mhz =
  2402. current_channel;
  2403. spectral->classifier_params.upper_chan_in_mhz =
  2404. extension_channel;
  2405. }
  2406. }
  2407. }
  2408. spectral->send_single_packet = 0;
  2409. spectral->classifier_params.spectral_20_40_mode =
  2410. spectral->sc_spectral_20_40_mode;
  2411. spectral->classifier_params.spectral_dc_index =
  2412. spectral->spectral_dc_index;
  2413. spectral->spectral_sent_msg = 0;
  2414. spectral->classify_scan = 0;
  2415. spectral->num_spectral_data = 0;
  2416. if (!p_sops->is_spectral_active(spectral, smode)) {
  2417. p_sops->configure_spectral(spectral, spectral_params, smode);
  2418. p_sops->start_spectral_scan(spectral, smode, err);
  2419. spectral->timestamp_war_offset[smode] = 0;
  2420. spectral->last_fft_timestamp[smode] = 0;
  2421. }
  2422. /* get current spectral configuration */
  2423. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  2424. target_if_init_upper_lower_flags(spectral);
  2425. return 0;
  2426. }
  2427. QDF_STATUS
  2428. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  2429. const enum spectral_scan_mode smode,
  2430. enum spectral_cp_error_code *err)
  2431. {
  2432. struct target_if_spectral_ops *p_sops;
  2433. struct target_if_spectral *spectral;
  2434. if (!err) {
  2435. spectral_err("Error code argument is null");
  2436. QDF_ASSERT(0);
  2437. }
  2438. *err = SPECTRAL_SCAN_ERR_INVALID;
  2439. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2440. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2441. spectral_err("Invalid Spectral mode %u", smode);
  2442. return QDF_STATUS_E_FAILURE;
  2443. }
  2444. if (!pdev) {
  2445. spectral_err("pdev object is NUll");
  2446. return QDF_STATUS_E_FAILURE;
  2447. }
  2448. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2449. if (!spectral) {
  2450. spectral_err("Spectral LMAC object is NUll");
  2451. return QDF_STATUS_E_FAILURE;
  2452. }
  2453. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2454. if (!spectral->params_valid[smode]) {
  2455. target_if_spectral_info_read(spectral,
  2456. smode,
  2457. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2458. &spectral->params[smode],
  2459. sizeof(spectral->params[smode]));
  2460. spectral->params_valid[smode] = true;
  2461. }
  2462. qdf_spin_lock(&spectral->spectral_lock);
  2463. if (smode == SPECTRAL_SCAN_MODE_AGILE &&
  2464. !spectral->params[smode].ss_frequency) {
  2465. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  2466. qdf_spin_unlock(&spectral->spectral_lock);
  2467. return QDF_STATUS_E_FAILURE;
  2468. }
  2469. target_if_spectral_scan_enable_params(spectral,
  2470. &spectral->params[smode], smode,
  2471. err);
  2472. qdf_spin_unlock(&spectral->spectral_lock);
  2473. return QDF_STATUS_SUCCESS;
  2474. }
  2475. QDF_STATUS
  2476. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  2477. const enum spectral_scan_mode smode,
  2478. enum spectral_cp_error_code *err)
  2479. {
  2480. struct target_if_spectral_ops *p_sops;
  2481. struct target_if_spectral *spectral;
  2482. if (!err) {
  2483. spectral_err("Error code argument is null");
  2484. QDF_ASSERT(0);
  2485. }
  2486. *err = SPECTRAL_SCAN_ERR_INVALID;
  2487. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2488. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2489. spectral_err("Invalid Spectral mode %u", smode);
  2490. return QDF_STATUS_E_FAILURE;
  2491. }
  2492. if (!pdev) {
  2493. spectral_err("pdev object is NUll ");
  2494. return QDF_STATUS_E_FAILURE;
  2495. }
  2496. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2497. if (!spectral) {
  2498. spectral_err("Spectral LMAC object is NUll ");
  2499. return QDF_STATUS_E_FAILURE;
  2500. }
  2501. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2502. qdf_spin_lock(&spectral->spectral_lock);
  2503. p_sops->stop_spectral_scan(spectral, smode);
  2504. if (spectral->classify_scan) {
  2505. /* TODO : Check if this logic is necessary */
  2506. spectral->detects_control_channel = 0;
  2507. spectral->detects_extension_channel = 0;
  2508. spectral->detects_above_dc = 0;
  2509. spectral->detects_below_dc = 0;
  2510. spectral->classify_scan = 0;
  2511. }
  2512. spectral->send_single_packet = 0;
  2513. spectral->sc_spectral_scan = 0;
  2514. qdf_spin_unlock(&spectral->spectral_lock);
  2515. return QDF_STATUS_SUCCESS;
  2516. }
  2517. /**
  2518. * target_if_is_spectral_active() - Get whether Spectral is active
  2519. * @pdev: Pointer to pdev object
  2520. * @smode: Spectral scan mode
  2521. *
  2522. * API to get whether Spectral is active
  2523. *
  2524. * Return: True if Spectral is active, false if Spectral is not active
  2525. */
  2526. bool
  2527. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  2528. const enum spectral_scan_mode smode)
  2529. {
  2530. struct target_if_spectral *spectral = NULL;
  2531. struct target_if_spectral_ops *p_sops = NULL;
  2532. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2533. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2534. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2535. spectral_err("Invalid Spectral mode %u", smode);
  2536. return QDF_STATUS_E_FAILURE;
  2537. }
  2538. return p_sops->is_spectral_active(spectral, smode);
  2539. }
  2540. /**
  2541. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  2542. * @pdev: Pointer to pdev object
  2543. * @smode: Spectral scan mode
  2544. *
  2545. * API to get whether Spectral is enabled
  2546. *
  2547. * Return: True if Spectral is enabled, false if Spectral is not enabled
  2548. */
  2549. bool
  2550. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  2551. enum spectral_scan_mode smode)
  2552. {
  2553. struct target_if_spectral *spectral = NULL;
  2554. struct target_if_spectral_ops *p_sops = NULL;
  2555. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2556. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2557. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2558. spectral_err("Invalid Spectral mode %u", smode);
  2559. return QDF_STATUS_E_FAILURE;
  2560. }
  2561. return p_sops->is_spectral_enabled(spectral, smode);
  2562. }
  2563. /**
  2564. * target_if_set_debug_level() - Set debug level for Spectral
  2565. * @pdev: Pointer to pdev object
  2566. * @debug_level: Debug level
  2567. *
  2568. * API to set the debug level for Spectral
  2569. *
  2570. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2571. */
  2572. QDF_STATUS
  2573. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  2574. {
  2575. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  2576. return QDF_STATUS_SUCCESS;
  2577. }
  2578. /**
  2579. * target_if_get_debug_level() - Get debug level for Spectral
  2580. * @pdev: Pointer to pdev object
  2581. *
  2582. * API to get the debug level for Spectral
  2583. *
  2584. * Return: Current debug level
  2585. */
  2586. uint32_t
  2587. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  2588. {
  2589. return spectral_debug_level;
  2590. }
  2591. /**
  2592. * target_if_get_spectral_capinfo() - Get Spectral capability information
  2593. * @pdev: Pointer to pdev object
  2594. * @scaps: Buffer into which data should be copied
  2595. *
  2596. * API to get the spectral capability information
  2597. *
  2598. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2599. */
  2600. QDF_STATUS
  2601. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  2602. struct spectral_caps *scaps)
  2603. {
  2604. struct target_if_spectral *spectral = NULL;
  2605. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2606. qdf_mem_copy(scaps, &spectral->capability,
  2607. sizeof(struct spectral_caps));
  2608. return QDF_STATUS_SUCCESS;
  2609. }
  2610. /**
  2611. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  2612. * @pdev: Pointer to pdev object
  2613. * @stats: Buffer into which data should be copied
  2614. *
  2615. * API to get the spectral diagnostic statistics
  2616. *
  2617. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2618. */
  2619. QDF_STATUS
  2620. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  2621. struct spectral_diag_stats *stats)
  2622. {
  2623. struct target_if_spectral *spectral = NULL;
  2624. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2625. qdf_mem_copy(stats, &spectral->diag_stats,
  2626. sizeof(struct spectral_diag_stats));
  2627. return QDF_STATUS_SUCCESS;
  2628. }
  2629. /**
  2630. * target_if_register_wmi_spectral_cmd_ops() - Register wmi_spectral_cmd_ops
  2631. * @cmd_ops: Pointer to the structure having wmi_spectral_cmd function pointers
  2632. * @pdev: Pointer to pdev object
  2633. *
  2634. * API for register wmi_spectral_cmd_ops in spectral internal data structure
  2635. *
  2636. * Return: void
  2637. */
  2638. void
  2639. target_if_register_wmi_spectral_cmd_ops(struct wlan_objmgr_pdev *pdev,
  2640. struct wmi_spectral_cmd_ops *cmd_ops)
  2641. {
  2642. struct target_if_spectral *spectral =
  2643. get_target_if_spectral_handle_from_pdev(pdev);
  2644. if (!spectral) {
  2645. spectral_err("Spectral LMAC object is null");
  2646. return;
  2647. }
  2648. spectral->param_wmi_cmd_ops = *cmd_ops;
  2649. }
  2650. /**
  2651. * target_if_register_netlink_cb() - Register Netlink callbacks
  2652. * @pdev: Pointer to pdev object
  2653. * @nl_cb: Netlink callbacks to register
  2654. *
  2655. * Return: void
  2656. */
  2657. static void
  2658. target_if_register_netlink_cb(
  2659. struct wlan_objmgr_pdev *pdev,
  2660. struct spectral_nl_cb *nl_cb)
  2661. {
  2662. struct target_if_spectral *spectral = NULL;
  2663. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2664. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  2665. if (spectral->use_nl_bcast)
  2666. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  2667. else
  2668. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  2669. }
  2670. /**
  2671. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  2672. * Netlink messages to the application layer
  2673. * @pdev: Pointer to pdev object
  2674. *
  2675. * Return: true for broadcast, false for unicast
  2676. */
  2677. static bool
  2678. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  2679. {
  2680. struct target_if_spectral *spectral = NULL;
  2681. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2682. return spectral->use_nl_bcast;
  2683. }
  2684. /**
  2685. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  2686. * @pdev: Pointer to pdev object
  2687. *
  2688. * Return: void
  2689. */
  2690. static void
  2691. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  2692. {
  2693. struct target_if_spectral *spectral = NULL;
  2694. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2695. if (!spectral) {
  2696. spectral_err("SPECTRAL : Module doesn't exist");
  2697. return;
  2698. }
  2699. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  2700. }
  2701. static int
  2702. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  2703. void *payload)
  2704. {
  2705. struct target_if_spectral *spectral = NULL;
  2706. struct target_if_spectral_ops *p_sops = NULL;
  2707. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2708. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2709. return p_sops->process_spectral_report(pdev, payload);
  2710. }
  2711. void
  2712. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  2713. {
  2714. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  2715. target_if_pdev_spectral_init;
  2716. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  2717. target_if_pdev_spectral_deinit;
  2718. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  2719. target_if_set_spectral_config;
  2720. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  2721. target_if_get_spectral_config;
  2722. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  2723. target_if_start_spectral_scan;
  2724. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  2725. target_if_stop_spectral_scan;
  2726. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  2727. target_if_is_spectral_active;
  2728. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  2729. target_if_is_spectral_enabled;
  2730. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  2731. target_if_set_debug_level;
  2732. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  2733. target_if_get_debug_level;
  2734. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  2735. target_if_get_spectral_capinfo;
  2736. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  2737. target_if_get_spectral_diagstats;
  2738. tx_ops->sptrl_tx_ops.sptrlto_register_wmi_spectral_cmd_ops =
  2739. target_if_register_wmi_spectral_cmd_ops;
  2740. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  2741. target_if_register_netlink_cb;
  2742. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  2743. target_if_use_nl_bcast;
  2744. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  2745. target_if_deregister_netlink_cb;
  2746. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  2747. target_if_process_spectral_report;
  2748. }
  2749. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  2750. void
  2751. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  2752. uint16_t cw_int, uint32_t dcs_enabled)
  2753. {
  2754. struct spectral_samp_msg *msg = NULL;
  2755. struct target_if_spectral_ops *p_sops = NULL;
  2756. struct target_if_spectral *spectral = NULL;
  2757. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2758. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  2759. spectral->pdev_obj,
  2760. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  2761. SPECTRAL_MSG_BUF_NEW);
  2762. if (msg) {
  2763. msg->int_type = cw_int ?
  2764. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  2765. msg->dcs_enabled = dcs_enabled;
  2766. msg->signature = SPECTRAL_SIGNATURE;
  2767. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2768. p_sops->get_mac_address(spectral, msg->macaddr);
  2769. if (spectral->send_phy_data
  2770. (pdev,
  2771. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  2772. spectral->spectral_sent_msg++;
  2773. }
  2774. }
  2775. qdf_export_symbol(target_if_spectral_send_intf_found_msg);