target_if_spectral.c 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771
  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 <target_if_spectral_sim.h>
  30. #include <target_if.h>
  31. #include <qdf_module.h>
  32. #include <wlan_reg_services_api.h>
  33. #include <wlan_dfs_ucfg_api.h>
  34. /**
  35. * @spectral_ops - Spectral function table, holds the Spectral functions that
  36. * depend on whether the architecture is Direct Attach or Offload. This is used
  37. * to populate the actual Spectral function table present in the Spectral
  38. * module.
  39. */
  40. struct target_if_spectral_ops spectral_ops;
  41. int spectral_debug_level = DEBUG_SPECTRAL;
  42. static void target_if_spectral_get_firstvdev_pdev(struct wlan_objmgr_pdev *pdev,
  43. void *obj, void *arg)
  44. {
  45. struct wlan_objmgr_vdev *vdev = obj;
  46. struct wlan_objmgr_vdev **first_vdev = arg;
  47. if (!(*first_vdev))
  48. *first_vdev = vdev;
  49. }
  50. struct wlan_objmgr_vdev *
  51. target_if_spectral_get_vdev(struct target_if_spectral *spectral)
  52. {
  53. struct wlan_objmgr_pdev *pdev = NULL;
  54. struct wlan_objmgr_vdev *first_vdev = NULL;
  55. qdf_assert_always(spectral);
  56. pdev = spectral->pdev_obj;
  57. qdf_assert_always(pdev);
  58. if (wlan_objmgr_pdev_try_get_ref(pdev, WLAN_SPECTRAL_ID) !=
  59. QDF_STATUS_SUCCESS) {
  60. spectral_err("Unable to get pdev reference.");
  61. return NULL;
  62. }
  63. wlan_objmgr_pdev_iterate_obj_list(pdev, WLAN_VDEV_OP,
  64. target_if_spectral_get_firstvdev_pdev,
  65. &first_vdev, 0, WLAN_SPECTRAL_ID);
  66. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  67. if (!first_vdev)
  68. return NULL;
  69. if (wlan_objmgr_vdev_try_get_ref(first_vdev, WLAN_SPECTRAL_ID) !=
  70. QDF_STATUS_SUCCESS)
  71. first_vdev = NULL;
  72. return first_vdev;
  73. }
  74. /**
  75. * target_if_send_vdev_spectral_configure_cmd() - Send WMI command to configure
  76. * spectral parameters
  77. * @spectral: Pointer to Spectral target_if internal private data
  78. * @param: Pointer to spectral_config giving the Spectral configuration
  79. *
  80. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  81. */
  82. static int
  83. target_if_send_vdev_spectral_configure_cmd(struct target_if_spectral *spectral,
  84. struct spectral_config *param)
  85. {
  86. struct vdev_spectral_configure_params sparam;
  87. struct wlan_objmgr_pdev *pdev = NULL;
  88. struct wlan_objmgr_vdev *vdev = NULL;
  89. qdf_assert_always(spectral && param);
  90. pdev = spectral->pdev_obj;
  91. qdf_assert_always(pdev);
  92. vdev = target_if_spectral_get_vdev(spectral);
  93. if (!vdev)
  94. return QDF_STATUS_E_NOENT;
  95. qdf_mem_zero(&sparam, sizeof(sparam));
  96. sparam.vdev_id = wlan_vdev_get_id(vdev);
  97. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  98. sparam.count = param->ss_count;
  99. sparam.period = param->ss_period;
  100. sparam.spectral_pri = param->ss_spectral_pri;
  101. sparam.fft_size = param->ss_fft_size;
  102. sparam.gc_enable = param->ss_gc_ena;
  103. sparam.restart_enable = param->ss_restart_ena;
  104. sparam.noise_floor_ref = param->ss_noise_floor_ref;
  105. sparam.init_delay = param->ss_init_delay;
  106. sparam.nb_tone_thr = param->ss_nb_tone_thr;
  107. sparam.str_bin_thr = param->ss_str_bin_thr;
  108. sparam.wb_rpt_mode = param->ss_wb_rpt_mode;
  109. sparam.rssi_rpt_mode = param->ss_rssi_rpt_mode;
  110. sparam.rssi_thr = param->ss_rssi_thr;
  111. sparam.pwr_format = param->ss_pwr_format;
  112. sparam.rpt_mode = param->ss_rpt_mode;
  113. sparam.bin_scale = param->ss_bin_scale;
  114. sparam.dbm_adj = param->ss_dbm_adj;
  115. sparam.chn_mask = param->ss_chn_mask;
  116. return spectral->param_wmi_cmd_ops.wmi_spectral_configure_cmd_send(
  117. GET_WMI_HDL_FROM_PDEV(pdev), &sparam);
  118. }
  119. /**
  120. * target_if_send_vdev_spectral_enable_cmd() - Send WMI command to
  121. * enable/disable Spectral
  122. * @spectral: Pointer to Spectral target_if internal private data
  123. * @is_spectral_active_valid: Flag to indicate if spectral activate (trigger) is
  124. * valid
  125. * @is_spectral_active: Value of spectral activate
  126. * @is_spectral_enabled_valid: Flag to indicate if spectral enable is valid
  127. * @is_spectral_enabled: Value of spectral enable
  128. *
  129. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  130. */
  131. static int
  132. target_if_send_vdev_spectral_enable_cmd(struct target_if_spectral *spectral,
  133. uint8_t is_spectral_active_valid,
  134. uint8_t is_spectral_active,
  135. uint8_t is_spectral_enabled_valid,
  136. uint8_t is_spectral_enabled)
  137. {
  138. struct vdev_spectral_enable_params param;
  139. struct wlan_objmgr_pdev *pdev = NULL;
  140. struct wlan_objmgr_vdev *vdev = NULL;
  141. qdf_assert_always(spectral);
  142. pdev = spectral->pdev_obj;
  143. qdf_assert_always(pdev);
  144. vdev = target_if_spectral_get_vdev(spectral);
  145. if (!vdev)
  146. return QDF_STATUS_E_NOENT;
  147. qdf_mem_zero(&param, sizeof(param));
  148. param.vdev_id = wlan_vdev_get_id(vdev);
  149. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  150. param.active_valid = is_spectral_active_valid;
  151. param.enabled_valid = is_spectral_enabled_valid;
  152. param.active = is_spectral_active;
  153. param.enabled = is_spectral_enabled;
  154. return spectral->param_wmi_cmd_ops.wmi_spectral_enable_cmd_send(
  155. GET_WMI_HDL_FROM_PDEV(pdev), &param);
  156. }
  157. /**
  158. * target_if_spectral_info_init_defaults() - Helper function to load defaults
  159. * for Spectral information (parameters and state) into cache.
  160. * @spectral: Pointer to Spectral target_if internal private data
  161. * @smode: Spectral scan mode
  162. *
  163. * It is assumed that the caller has obtained the requisite lock if applicable.
  164. * Note that this is currently treated as a temporary function. Ideally, we
  165. * would like to get defaults from the firmware.
  166. *
  167. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  168. */
  169. static QDF_STATUS
  170. target_if_spectral_info_init_defaults(struct target_if_spectral *spectral,
  171. enum spectral_scan_mode smode)
  172. {
  173. struct target_if_spectral_param_state_info *info;
  174. struct wlan_objmgr_vdev *vdev = NULL;
  175. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  176. spectral_err("Invalid Spectral mode %u", smode);
  177. return QDF_STATUS_E_FAILURE;
  178. }
  179. info = &spectral->param_info[smode];
  180. /* State */
  181. info->osps_cache.osc_spectral_active = SPECTRAL_SCAN_ACTIVE_DEFAULT;
  182. info->osps_cache.osc_spectral_enabled = SPECTRAL_SCAN_ENABLE_DEFAULT;
  183. /* Parameters */
  184. info->osps_cache.osc_params.ss_count = SPECTRAL_SCAN_COUNT_DEFAULT;
  185. if (spectral->spectral_gen == SPECTRAL_GEN3)
  186. info->osps_cache.osc_params.ss_period =
  187. SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT;
  188. else
  189. info->osps_cache.osc_params.ss_period =
  190. SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT;
  191. info->osps_cache.osc_params.ss_spectral_pri =
  192. SPECTRAL_SCAN_PRIORITY_DEFAULT;
  193. info->osps_cache.osc_params.ss_fft_size =
  194. SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  195. info->osps_cache.osc_params.ss_gc_ena = SPECTRAL_SCAN_GC_ENA_DEFAULT;
  196. info->osps_cache.osc_params.ss_restart_ena =
  197. SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  198. info->osps_cache.osc_params.ss_noise_floor_ref =
  199. SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  200. info->osps_cache.osc_params.ss_init_delay =
  201. SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  202. info->osps_cache.osc_params.ss_nb_tone_thr =
  203. SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  204. info->osps_cache.osc_params.ss_str_bin_thr =
  205. SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  206. info->osps_cache.osc_params.ss_wb_rpt_mode =
  207. SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  208. info->osps_cache.osc_params.ss_rssi_rpt_mode =
  209. SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  210. info->osps_cache.osc_params.ss_rssi_thr =
  211. SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  212. info->osps_cache.osc_params.ss_pwr_format =
  213. SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  214. info->osps_cache.osc_params.ss_rpt_mode =
  215. SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  216. info->osps_cache.osc_params.ss_bin_scale =
  217. SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  218. info->osps_cache.osc_params.ss_dbm_adj = SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  219. vdev = target_if_spectral_get_vdev(spectral);
  220. if (!vdev)
  221. return QDF_STATUS_E_NOENT;
  222. info->osps_cache.osc_params.ss_chn_mask =
  223. wlan_vdev_mlme_get_rxchainmask(vdev);
  224. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  225. info->osps_cache.osc_params.ss_short_report =
  226. SPECTRAL_SCAN_SHORT_REPORT_DEFAULT;
  227. info->osps_cache.osc_params.ss_fft_period =
  228. SPECTRAL_SCAN_FFT_PERIOD_DEFAULT;
  229. info->osps_cache.osc_params.ss_frequency =
  230. SPECTRAL_SCAN_FREQUENCY_DEFAULT;
  231. /* The cache is now valid */
  232. info->osps_cache.osc_is_valid = 1;
  233. return QDF_STATUS_SUCCESS;
  234. }
  235. /**
  236. * target_if_log_read_spectral_active() - Helper function to log whether
  237. * spectral is active after reading cache
  238. * @function_name: Function name
  239. * @output: whether spectral is active or not
  240. *
  241. * Helper function to log whether spectral is active after reading cache
  242. *
  243. * Return: none
  244. */
  245. static void
  246. target_if_log_read_spectral_active(
  247. const char *function_name,
  248. unsigned char output)
  249. {
  250. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE. Returning val=%u",
  251. function_name, output);
  252. }
  253. /**
  254. * target_if_log_read_spectral_enabled() - Helper function to log whether
  255. * spectral is enabled after reading cache
  256. * @function_name: Function name
  257. * @output: whether spectral is enabled or not
  258. *
  259. * Helper function to log whether spectral is enabled after reading cache
  260. *
  261. * Return: none
  262. */
  263. static void
  264. target_if_log_read_spectral_enabled(
  265. const char *function_name,
  266. unsigned char output)
  267. {
  268. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED. Returning val=%u",
  269. function_name, output);
  270. }
  271. /**
  272. * target_if_log_read_spectral_enabled() - Helper function to log spectral
  273. * parameters after reading cache
  274. * @function_name: Function name
  275. * @pparam: Spectral parameters
  276. *
  277. * Helper function to log spectral parameters after reading cache
  278. *
  279. * Return: none
  280. */
  281. static void
  282. target_if_log_read_spectral_params(
  283. const char *function_name,
  284. struct spectral_config *pparam)
  285. {
  286. 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",
  287. function_name,
  288. pparam->ss_count,
  289. pparam->ss_period,
  290. pparam->ss_spectral_pri,
  291. pparam->ss_fft_size,
  292. pparam->ss_gc_ena,
  293. pparam->ss_restart_ena,
  294. (int8_t)pparam->ss_noise_floor_ref,
  295. pparam->ss_init_delay,
  296. pparam->ss_nb_tone_thr,
  297. pparam->ss_str_bin_thr,
  298. pparam->ss_wb_rpt_mode,
  299. pparam->ss_rssi_rpt_mode,
  300. (int8_t)pparam->ss_rssi_thr,
  301. pparam->ss_pwr_format,
  302. pparam->ss_rpt_mode,
  303. pparam->ss_bin_scale,
  304. pparam->ss_dbm_adj,
  305. pparam->ss_chn_mask,
  306. pparam->ss_frequency);
  307. }
  308. /**
  309. * target_if_log_read_spectral_active_catch_validate() - Helper function to
  310. * log whether spectral is active after intializing the cache
  311. * @function_name: Function name
  312. * @output: whether spectral is active or not
  313. *
  314. * Helper function to log whether spectral is active after intializing cache
  315. *
  316. * Return: none
  317. */
  318. static void
  319. target_if_log_read_spectral_active_catch_validate(
  320. const char *function_name,
  321. unsigned char output)
  322. {
  323. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE on initial cache validation\nReturning val=%u",
  324. function_name, output);
  325. }
  326. /**
  327. * target_if_log_read_spectral_enabled_catch_validate() - Helper function to
  328. * log whether spectral is enabled after intializing the cache
  329. * @function_name: Function name
  330. * @output: whether spectral is enabled or not
  331. *
  332. * Helper function to log whether spectral is enabled after intializing cache
  333. *
  334. * Return: none
  335. */
  336. static void
  337. target_if_log_read_spectral_enabled_catch_validate(
  338. const char *function_name,
  339. unsigned char output)
  340. {
  341. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED on initial cache validation\nReturning val=%u\n",
  342. function_name, output);
  343. }
  344. /**
  345. * target_if_log_read_spectral_params_catch_validate() - Helper function to
  346. * log spectral parameters after intializing the cache
  347. * @function_name: Function name
  348. * @pparam: Spectral parameters
  349. *
  350. * Helper function to log spectral parameters after intializing the cache
  351. *
  352. * Return: none
  353. */
  354. static void
  355. target_if_log_read_spectral_params_catch_validate(
  356. const char *function_name,
  357. struct spectral_config *pparam)
  358. {
  359. 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",
  360. function_name,
  361. pparam->ss_count,
  362. pparam->ss_period,
  363. pparam->ss_spectral_pri,
  364. pparam->ss_fft_size,
  365. pparam->ss_gc_ena,
  366. pparam->ss_restart_ena,
  367. (int8_t)pparam->ss_noise_floor_ref,
  368. pparam->ss_init_delay,
  369. pparam->ss_nb_tone_thr,
  370. pparam->ss_str_bin_thr,
  371. pparam->ss_wb_rpt_mode,
  372. pparam->ss_rssi_rpt_mode,
  373. (int8_t)pparam->ss_rssi_thr,
  374. pparam->ss_pwr_format,
  375. pparam->ss_rpt_mode,
  376. pparam->ss_bin_scale,
  377. pparam->ss_dbm_adj, pparam->ss_chn_mask);
  378. }
  379. /**
  380. * target_if_spectral_info_read() - Read spectral information from the cache.
  381. * @spectral: Pointer to Spectral target_if internal private data
  382. * @smode: Spectral scan mode
  383. * @specifier: target_if_spectral_info enumeration specifying which
  384. * information is required
  385. * @output: Void output pointer into which the information will be read
  386. * @output_len: size of object pointed to by output pointer
  387. *
  388. * Read spectral parameters or the desired state information from the cache.
  389. *
  390. * Return: 0 on success, negative error code on failure
  391. */
  392. static int
  393. target_if_spectral_info_read(
  394. struct target_if_spectral *spectral,
  395. enum spectral_scan_mode smode,
  396. enum target_if_spectral_info specifier,
  397. void *output, int output_len)
  398. {
  399. /*
  400. * Note: This function is designed to be able to accommodate
  401. * WMI reads for defaults, non-cacheable information, etc
  402. * if required.
  403. */
  404. struct target_if_spectral_param_state_info *info;
  405. int is_cacheable = 0;
  406. int init_def_retval = 0;
  407. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  408. spectral_err("Invalid Spectral mode %u", smode);
  409. return -EINVAL;
  410. }
  411. info = &spectral->param_info[smode];
  412. if (!output)
  413. return -EINVAL;
  414. switch (specifier) {
  415. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  416. if (output_len != sizeof(info->osps_cache.osc_spectral_active))
  417. return -EINVAL;
  418. is_cacheable = 1;
  419. break;
  420. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  421. if (output_len != sizeof(info->osps_cache.osc_spectral_enabled))
  422. return -EINVAL;
  423. is_cacheable = 1;
  424. break;
  425. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  426. if (output_len != sizeof(info->osps_cache.osc_params))
  427. return -EINVAL;
  428. is_cacheable = 1;
  429. break;
  430. default:
  431. spectral_err("Unknown target_if_spectral_info specifier");
  432. return -EINVAL;
  433. }
  434. qdf_spin_lock(&info->osps_lock);
  435. if (is_cacheable) {
  436. if (info->osps_cache.osc_is_valid) {
  437. switch (specifier) {
  438. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  439. qdf_mem_copy(
  440. output,
  441. &info->osps_cache.osc_spectral_active,
  442. sizeof(info->osps_cache.osc_spectral_active));
  443. target_if_log_read_spectral_active(
  444. __func__,
  445. *((unsigned char *)output));
  446. break;
  447. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  448. qdf_mem_copy(
  449. output,
  450. &info->osps_cache.osc_spectral_enabled,
  451. sizeof(
  452. info->osps_cache.osc_spectral_enabled));
  453. target_if_log_read_spectral_enabled(
  454. __func__,
  455. *((unsigned char *)output));
  456. break;
  457. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  458. qdf_mem_copy(
  459. output,
  460. &info->osps_cache.osc_params,
  461. sizeof(info->osps_cache.osc_params));
  462. target_if_log_read_spectral_params(
  463. __func__,
  464. (struct spectral_config *)output);
  465. break;
  466. default:
  467. /* We can't reach this point */
  468. break;
  469. }
  470. qdf_spin_unlock(&info->osps_lock);
  471. return 0;
  472. }
  473. }
  474. /* Cache is invalid */
  475. /*
  476. * If WMI Reads are implemented to fetch defaults/non-cacheable info,
  477. * then the below implementation will change
  478. */
  479. init_def_retval =
  480. target_if_spectral_info_init_defaults(spectral, smode);
  481. if (init_def_retval != QDF_STATUS_SUCCESS) {
  482. qdf_spin_unlock(&info->osps_lock);
  483. if (init_def_retval == QDF_STATUS_E_NOENT)
  484. return -ENOENT;
  485. else
  486. return -EINVAL;
  487. }
  488. /* target_if_spectral_info_init_defaults() has set cache to valid */
  489. switch (specifier) {
  490. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  491. qdf_mem_copy(output,
  492. &info->osps_cache.osc_spectral_active,
  493. sizeof(info->osps_cache.osc_spectral_active));
  494. target_if_log_read_spectral_active_catch_validate(
  495. __func__,
  496. *((unsigned char *)output));
  497. break;
  498. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  499. qdf_mem_copy(output,
  500. &info->osps_cache.osc_spectral_enabled,
  501. sizeof(info->osps_cache.osc_spectral_enabled));
  502. target_if_log_read_spectral_enabled_catch_validate(
  503. __func__,
  504. *((unsigned char *)output));
  505. break;
  506. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  507. qdf_mem_copy(output,
  508. &info->osps_cache.osc_params,
  509. sizeof(info->osps_cache.osc_params));
  510. target_if_log_read_spectral_params_catch_validate(
  511. __func__,
  512. (struct spectral_config *)output);
  513. break;
  514. default:
  515. /* We can't reach this point */
  516. break;
  517. }
  518. qdf_spin_unlock(&info->osps_lock);
  519. return 0;
  520. }
  521. /**
  522. * target_if_log_write_spectral_active() - Helper function to log inputs and
  523. * return value of call to configure the Spectral 'active' configuration,
  524. * TARGET_IF_SPECTRAL_INFO_ACTIVE into firmware
  525. * @function_name: Function name in which this is called
  526. * @pval: whether spectral is active or not
  527. * @ret: return value of the firmware write function
  528. *
  529. * Return: none
  530. */
  531. static void
  532. target_if_log_write_spectral_active(
  533. const char *function_name,
  534. uint8_t pval,
  535. int ret)
  536. {
  537. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE with val=%u status=%d",
  538. function_name, pval, ret);
  539. }
  540. /**
  541. * target_if_log_write_spectral_enabled() - Helper function to log inputs and
  542. * return value of call to configure the Spectral 'enabled' configuration,
  543. * TARGET_IF_SPECTRAL_INFO_ENABLED into firmware
  544. * @function_name: Function name in which this is called
  545. * @pval: whether spectral is enabled or not
  546. * @ret: return value of the firmware write function
  547. *
  548. * Return: none
  549. */
  550. static void
  551. target_if_log_write_spectral_enabled(
  552. const char *function_name,
  553. uint8_t pval,
  554. int ret)
  555. {
  556. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED with val=%u status=%d",
  557. function_name, pval, ret);
  558. }
  559. /**
  560. * target_if_log_write_spectral_params() - Helper function to log inputs and
  561. * return value of call to configure Spectral parameters,
  562. * TARGET_IF_SPECTRAL_INFO_PARAMS into firmware
  563. * @param: Spectral parameters
  564. * @function_name: Function name in which this is called
  565. * @ret: return value of the firmware write function
  566. *
  567. * Return: none
  568. */
  569. static void
  570. target_if_log_write_spectral_params(
  571. struct spectral_config *param,
  572. const char *function_name,
  573. int ret)
  574. {
  575. 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",
  576. function_name,
  577. param->ss_count,
  578. param->ss_period,
  579. param->ss_spectral_pri,
  580. param->ss_fft_size,
  581. param->ss_gc_ena,
  582. param->ss_restart_ena,
  583. (int8_t)param->ss_noise_floor_ref,
  584. param->ss_init_delay,
  585. param->ss_nb_tone_thr,
  586. param->ss_str_bin_thr,
  587. param->ss_wb_rpt_mode,
  588. param->ss_rssi_rpt_mode,
  589. (int8_t)param->ss_rssi_thr,
  590. param->ss_pwr_format,
  591. param->ss_rpt_mode,
  592. param->ss_bin_scale,
  593. param->ss_dbm_adj,
  594. param->ss_chn_mask,
  595. param->ss_frequency,
  596. ret);
  597. }
  598. /**
  599. * target_if_spectral_info_write() - Write Spectral information to the
  600. * firmware, and update cache
  601. * @spectral: Pointer to Spectral target_if internal private data
  602. * @smode: Spectral scan mode
  603. * @specifier: target_if_spectral_info enumeration specifying which
  604. * information is involved
  605. * @input: void input pointer containing the information to be written
  606. * @input_len: size of object pointed to by input pointer
  607. *
  608. * Write Spectral parameters or the desired state information to
  609. * the firmware, and update cache
  610. *
  611. * Return: 0 on success, negative error code on failure
  612. */
  613. static int
  614. target_if_spectral_info_write(
  615. struct target_if_spectral *spectral,
  616. enum spectral_scan_mode smode,
  617. enum target_if_spectral_info specifier,
  618. void *input, int input_len)
  619. {
  620. struct target_if_spectral_param_state_info *info;
  621. int ret;
  622. uint8_t *pval = NULL;
  623. struct spectral_config *param = NULL;
  624. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  625. spectral_err("Invalid Spectral mode %u", smode);
  626. return -EINVAL;
  627. }
  628. info = &spectral->param_info[smode];
  629. if (!input)
  630. return -EINVAL;
  631. switch (specifier) {
  632. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  633. if (input_len != sizeof(info->osps_cache.osc_spectral_active))
  634. return -EINVAL;
  635. pval = (uint8_t *)input;
  636. qdf_spin_lock(&info->osps_lock);
  637. ret = target_if_send_vdev_spectral_enable_cmd(spectral,
  638. 1, *pval, 0, 0);
  639. target_if_log_write_spectral_active(
  640. __func__,
  641. *pval,
  642. ret);
  643. if (ret < 0) {
  644. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  645. ret);
  646. qdf_spin_unlock(&info->osps_lock);
  647. return ret;
  648. }
  649. info->osps_cache.osc_spectral_active = *pval;
  650. /* The cache is now valid */
  651. info->osps_cache.osc_is_valid = 1;
  652. qdf_spin_unlock(&info->osps_lock);
  653. break;
  654. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  655. if (input_len != sizeof(info->osps_cache.osc_spectral_enabled))
  656. return -EINVAL;
  657. pval = (uint8_t *)input;
  658. qdf_spin_lock(&info->osps_lock);
  659. ret = target_if_send_vdev_spectral_enable_cmd(spectral,
  660. 0, 0, 1, *pval);
  661. target_if_log_write_spectral_enabled(
  662. __func__,
  663. *pval,
  664. ret);
  665. if (ret < 0) {
  666. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  667. ret);
  668. qdf_spin_unlock(&info->osps_lock);
  669. return ret;
  670. }
  671. info->osps_cache.osc_spectral_enabled = *pval;
  672. /* The cache is now valid */
  673. info->osps_cache.osc_is_valid = 1;
  674. qdf_spin_unlock(&info->osps_lock);
  675. break;
  676. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  677. if (input_len != sizeof(info->osps_cache.osc_params))
  678. return -EINVAL;
  679. param = (struct spectral_config *)input;
  680. qdf_spin_lock(&info->osps_lock);
  681. ret = target_if_send_vdev_spectral_configure_cmd(spectral,
  682. param);
  683. target_if_log_write_spectral_params(
  684. param,
  685. __func__,
  686. ret);
  687. if (ret < 0) {
  688. spectral_err("target_if_send_vdev_spectral_configure_cmd failed with error=%d",
  689. ret);
  690. qdf_spin_unlock(&info->osps_lock);
  691. return ret;
  692. }
  693. qdf_mem_copy(&info->osps_cache.osc_params,
  694. param, sizeof(info->osps_cache.osc_params));
  695. /* The cache is now valid */
  696. info->osps_cache.osc_is_valid = 1;
  697. qdf_spin_unlock(&info->osps_lock);
  698. break;
  699. default:
  700. spectral_err("Unknown target_if_spectral_info specifier");
  701. return -EINVAL;
  702. }
  703. return 0;
  704. }
  705. /**
  706. * target_if_spectral_get_tsf64() - Function to get the TSF value
  707. * @arg: Pointer to handle for Spectral target_if internal private data
  708. *
  709. * Get the last TSF received in WMI buffer
  710. *
  711. * Return: TSF value
  712. */
  713. static uint64_t
  714. target_if_spectral_get_tsf64(void *arg)
  715. {
  716. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  717. return spectral->tsf64;
  718. }
  719. /**
  720. * target_if_spectral_get_capability() - Function to get whether a
  721. * given Spectral hardware capability is available
  722. * @arg: Pointer to handle for Spectral target_if internal private data
  723. * @type: Spectral hardware capability type
  724. *
  725. * Get whether a given Spectral hardware capability is available
  726. *
  727. * Return: True if the capability is available, false if the capability is not
  728. * available
  729. */
  730. uint32_t
  731. target_if_spectral_get_capability(void *arg, enum spectral_capability_type type)
  732. {
  733. int status = STATUS_FAIL;
  734. switch (type) {
  735. case SPECTRAL_CAP_PHYDIAG:
  736. case SPECTRAL_CAP_RADAR:
  737. case SPECTRAL_CAP_SPECTRAL_SCAN:
  738. case SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN:
  739. status = STATUS_PASS;
  740. break;
  741. default:
  742. status = STATUS_FAIL;
  743. }
  744. return status;
  745. }
  746. /**
  747. * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
  748. * @arg: Pointer to handle for Spectral target_if internal private data
  749. * @rxfilter: Rx filter to be used
  750. *
  751. * Note: This is only a placeholder function. It is not currently required since
  752. * FW should be taking care of setting the required filters.
  753. *
  754. * Return: 0
  755. */
  756. uint32_t
  757. target_if_spectral_set_rxfilter(void *arg, int rxfilter)
  758. {
  759. /*
  760. * Will not be required since enabling of spectral in firmware
  761. * will take care of this
  762. */
  763. return 0;
  764. }
  765. /**
  766. * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
  767. * @arg: Pointer to handle for Spectral target_if internal private data
  768. *
  769. * Note: This is only a placeholder function. It is not currently required since
  770. * FW should be taking care of setting the required filters.
  771. *
  772. * Return: 0
  773. */
  774. uint32_t
  775. target_if_spectral_get_rxfilter(void *arg)
  776. {
  777. /*
  778. * Will not be required since enabling of spectral in firmware
  779. * will take care of this
  780. */
  781. return 0;
  782. }
  783. /**
  784. * target_if_sops_is_spectral_active() - Get whether Spectral is active
  785. * @arg: Pointer to handle for Spectral target_if internal private data
  786. * @smode: Spectral scan mode
  787. *
  788. * Function to check whether Spectral is active
  789. *
  790. * Return: True if Spectral is active, false if Spectral is not active
  791. */
  792. uint32_t
  793. target_if_sops_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  794. {
  795. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  796. uint8_t val = 0;
  797. int ret;
  798. ret = target_if_spectral_info_read(
  799. spectral,
  800. smode,
  801. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  802. &val, sizeof(val));
  803. if (ret != 0) {
  804. /*
  805. * Could not determine if Spectral is active.
  806. * Return false as a safe value.
  807. * XXX: Consider changing the function prototype
  808. * to be able to indicate failure to fetch value.
  809. */
  810. return 0;
  811. }
  812. return val;
  813. }
  814. /**
  815. * target_if_sops_is_spectral_enabled() - Get whether Spectral is enabled
  816. * @arg: Pointer to handle for Spectral target_if internal private data
  817. * @smode: Spectral scan mode
  818. *
  819. * Function to check whether Spectral is enabled
  820. *
  821. * Return: True if Spectral is enabled, false if Spectral is not enabled
  822. */
  823. uint32_t
  824. target_if_sops_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  825. {
  826. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  827. uint8_t val = 0;
  828. int ret;
  829. ret = target_if_spectral_info_read(
  830. spectral,
  831. smode,
  832. TARGET_IF_SPECTRAL_INFO_ENABLED,
  833. &val, sizeof(val));
  834. if (ret != 0) {
  835. /*
  836. * Could not determine if Spectral is enabled.
  837. * Return false as a safe value.
  838. * XXX: Consider changing the function prototype
  839. * to be able to indicate failure to fetch value.
  840. */
  841. return 0;
  842. }
  843. return val;
  844. }
  845. /**
  846. * target_if_sops_start_spectral_scan() - Start Spectral scan
  847. * @arg: Pointer to handle for Spectral target_if internal private data
  848. * @smode: Spectral scan mode
  849. * @err: Spectral error code
  850. *
  851. * Function to start spectral scan
  852. *
  853. * Return: 0 on success else failure
  854. */
  855. uint32_t
  856. target_if_sops_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  857. enum spectral_cp_error_code *err)
  858. {
  859. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  860. uint8_t val = 1;
  861. uint8_t enabled = 0;
  862. int ret;
  863. ret = target_if_spectral_info_read(
  864. spectral,
  865. smode,
  866. TARGET_IF_SPECTRAL_INFO_ENABLED,
  867. &enabled, sizeof(enabled));
  868. if (ret != 0) {
  869. /*
  870. * Could not determine if Spectral is enabled. Assume we need
  871. * to enable it
  872. */
  873. enabled = 0;
  874. }
  875. if (!enabled) {
  876. ret = target_if_spectral_info_write(
  877. spectral,
  878. smode,
  879. TARGET_IF_SPECTRAL_INFO_ENABLED,
  880. &val, sizeof(val));
  881. if (ret != 0)
  882. return ret;
  883. }
  884. ret = target_if_spectral_info_write(
  885. spectral,
  886. smode,
  887. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  888. &val, sizeof(val));
  889. if (ret != 0)
  890. return ret;
  891. return 0;
  892. }
  893. /**
  894. * target_if_sops_stop_spectral_scan() - Stop Spectral scan
  895. * @arg: Pointer to handle for Spectral target_if internal private data
  896. * @smode: Spectral scan mode
  897. *
  898. * Function to stop spectral scan
  899. *
  900. * Return: 0 on success else failure
  901. */
  902. uint32_t
  903. target_if_sops_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  904. {
  905. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  906. uint8_t val = 0;
  907. int tempret, ret = 0;
  908. uint8_t enabled = 0;
  909. tempret = target_if_spectral_info_read(
  910. spectral,
  911. smode,
  912. TARGET_IF_SPECTRAL_INFO_ENABLED,
  913. &enabled, sizeof(enabled));
  914. if (tempret)
  915. /*
  916. * Could not determine if Spectral is enabled. Assume scan is
  917. * not in progress
  918. */
  919. enabled = 0;
  920. /* if scan is not enabled, no need to send stop to FW */
  921. if (!enabled)
  922. return -EPERM;
  923. tempret = target_if_spectral_info_write(
  924. spectral,
  925. smode,
  926. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  927. &val, sizeof(val));
  928. if (tempret != 0)
  929. ret = tempret;
  930. tempret = target_if_spectral_info_write(
  931. spectral,
  932. smode,
  933. TARGET_IF_SPECTRAL_INFO_ENABLED,
  934. &val, sizeof(val));
  935. if (tempret != 0)
  936. ret = tempret;
  937. return ret;
  938. }
  939. /**
  940. * target_if_spectral_get_extension_channel() - Get the Extension channel
  941. * @arg: Pointer to handle for Spectral target_if internal private data
  942. *
  943. * Function to get the current Extension channel (in MHz)
  944. *
  945. * Return: Current Extension channel (in MHz) on success, 0 on failure or if
  946. * extension channel is not present.
  947. */
  948. uint32_t
  949. target_if_spectral_get_extension_channel(void *arg)
  950. {
  951. /*
  952. * XXX: Once we expand to use cases where Spectral could be activated
  953. * without a channel being set to VDEV, we need to consider returning a
  954. * negative value in case of failure and having all callers handle this.
  955. */
  956. struct target_if_spectral *spectral = NULL;
  957. struct wlan_objmgr_vdev *vdev = NULL;
  958. uint16_t sec20chan_freq = 0;
  959. qdf_assert_always(arg);
  960. spectral = (struct target_if_spectral *)arg;
  961. vdev = target_if_spectral_get_vdev(spectral);
  962. if (!vdev)
  963. return 0;
  964. if (target_if_vdev_get_sec20chan_freq_mhz(vdev, &sec20chan_freq) < 0) {
  965. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  966. return 0;
  967. }
  968. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  969. return sec20chan_freq;
  970. }
  971. /**
  972. * target_if_spectral_get_current_channel() - Get the current channel
  973. * @arg: Pointer to handle for Spectral target_if internal private data
  974. *
  975. * Function to get the current channel (in MHz)
  976. *
  977. * Return: Current channel (in MHz) on success, 0 on failure
  978. */
  979. uint32_t
  980. target_if_spectral_get_current_channel(void *arg)
  981. {
  982. /*
  983. * XXX: Once we expand to use cases where Spectral could be activated
  984. * without a channel being set to VDEV, we need to consider returning a
  985. * negative value in case of failure and having all callers handle this.
  986. */
  987. struct target_if_spectral *spectral = NULL;
  988. int16_t chan_freq = 0;
  989. struct wlan_objmgr_vdev *vdev = NULL;
  990. qdf_assert_always(arg);
  991. spectral = (struct target_if_spectral *)arg;
  992. vdev = target_if_spectral_get_vdev(spectral);
  993. if (!vdev)
  994. return 0;
  995. chan_freq = target_if_vdev_get_chan_freq(vdev);
  996. if (chan_freq < 0) {
  997. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  998. return 0;
  999. }
  1000. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1001. return chan_freq;
  1002. }
  1003. /**
  1004. * target_if_spectral_reset_hw() - Reset the hardware
  1005. * @arg: Pointer to handle for Spectral target_if internal private data
  1006. *
  1007. * This is only a placeholder since it is not currently required in the offload
  1008. * case.
  1009. *
  1010. * Return: 0
  1011. */
  1012. uint32_t
  1013. target_if_spectral_reset_hw(void *arg)
  1014. {
  1015. not_yet_implemented();
  1016. return 0;
  1017. }
  1018. /**
  1019. * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
  1020. * Noisefloor history buffer
  1021. * @arg: Pointer to handle for Spectral target_if internal private data
  1022. * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
  1023. *
  1024. * This is only a placeholder since it is not currently required in the offload
  1025. * case.
  1026. *
  1027. * Return: 0
  1028. */
  1029. uint32_t
  1030. target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1031. {
  1032. not_yet_implemented();
  1033. return 0;
  1034. }
  1035. /**
  1036. * target_if_spectral_get_ext_noisefloor() - Get the extension channel
  1037. * noisefloor
  1038. * @arg: Pointer to handle for Spectral target_if internal private data
  1039. *
  1040. * This is only a placeholder since it is not currently required in the offload
  1041. * case.
  1042. *
  1043. * Return: 0
  1044. */
  1045. int8_t
  1046. target_if_spectral_get_ext_noisefloor(void *arg)
  1047. {
  1048. not_yet_implemented();
  1049. return 0;
  1050. }
  1051. /**
  1052. * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
  1053. * @arg: Pointer to handle for Spectral target_if internal private data
  1054. *
  1055. * This is only a placeholder since it is not currently required in the offload
  1056. * case.
  1057. *
  1058. * Return: 0
  1059. */
  1060. int8_t
  1061. target_if_spectral_get_ctl_noisefloor(void *arg)
  1062. {
  1063. not_yet_implemented();
  1064. return 0;
  1065. }
  1066. /**
  1067. * target_if_spectral_sops_configure_params() - Configure user supplied Spectral
  1068. * parameters
  1069. * @arg: Pointer to handle for Spectral target_if internal private data
  1070. * @params: Spectral parameters
  1071. * @smode: Spectral scan mode
  1072. *
  1073. * Function to configure spectral parameters
  1074. *
  1075. * Return: 0 on success else failure
  1076. */
  1077. uint32_t
  1078. target_if_spectral_sops_configure_params(
  1079. void *arg, struct spectral_config *params,
  1080. enum spectral_scan_mode smode)
  1081. {
  1082. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1083. return target_if_spectral_info_write(
  1084. spectral,
  1085. smode,
  1086. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1087. params, sizeof(*params));
  1088. }
  1089. /**
  1090. * target_if_spectral_sops_get_params() - Get user configured Spectral
  1091. * parameters
  1092. * @arg: Pointer to handle for Spectral target_if internal private data
  1093. * @params: Pointer to buffer into which Spectral parameters should be copied
  1094. * @smode: Spectral scan mode
  1095. *
  1096. * Function to get the configured spectral parameters
  1097. *
  1098. * Return: 0 on success else failure
  1099. */
  1100. uint32_t
  1101. target_if_spectral_sops_get_params(void *arg, struct spectral_config *params,
  1102. enum spectral_scan_mode smode)
  1103. {
  1104. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1105. return target_if_spectral_info_read(
  1106. spectral,
  1107. smode,
  1108. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1109. params, sizeof(*params));
  1110. }
  1111. /**
  1112. * target_if_spectral_get_ent_mask() - Get enterprise mask
  1113. * @arg: Pointer to handle for Spectral target_if internal private data
  1114. *
  1115. * This is only a placeholder since it is not currently required in the offload
  1116. * case.
  1117. *
  1118. * Return: 0
  1119. */
  1120. static uint32_t
  1121. target_if_spectral_get_ent_mask(void *arg)
  1122. {
  1123. not_yet_implemented();
  1124. return 0;
  1125. }
  1126. /**
  1127. * target_if_spectral_get_macaddr() - Get radio MAC address
  1128. * @arg: Pointer to handle for Spectral target_if internal private data
  1129. * @addr: Pointer to buffer into which MAC address should be copied
  1130. *
  1131. * Function to get the MAC address of the pdev
  1132. *
  1133. * Return: 0 on success, -1 on failure
  1134. */
  1135. static uint32_t
  1136. target_if_spectral_get_macaddr(void *arg, char *addr)
  1137. {
  1138. uint8_t *myaddr = NULL;
  1139. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1140. struct wlan_objmgr_pdev *pdev = NULL;
  1141. pdev = spectral->pdev_obj;
  1142. wlan_pdev_obj_lock(pdev);
  1143. myaddr = wlan_pdev_get_hw_macaddr(pdev);
  1144. wlan_pdev_obj_unlock(pdev);
  1145. qdf_mem_copy(addr, myaddr, QDF_MAC_ADDR_SIZE);
  1146. return 0;
  1147. }
  1148. /**
  1149. * target_if_init_spectral_param_properties() - Initialize Spectral parameter
  1150. * properties
  1151. * @spectral: Pointer to Spectral target_if internal private data
  1152. *
  1153. * Initialize Spectral parameter properties
  1154. *
  1155. * Return: QDF_STATUS
  1156. */
  1157. static QDF_STATUS
  1158. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1159. {
  1160. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1161. int param;
  1162. /* Initialize default values for properties.
  1163. * Default values are supported for all the parameters for all modes
  1164. * and allows different values for each mode for all the parameters .
  1165. */
  1166. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1167. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1168. spectral->properties[smode][param].supported = true;
  1169. spectral->properties[smode][param].common_all_modes =
  1170. false;
  1171. }
  1172. }
  1173. return QDF_STATUS_SUCCESS;
  1174. }
  1175. /**
  1176. * target_if_init_spectral_capability() - Initialize Spectral capability
  1177. * @spectral: Pointer to Spectral target_if internal private data
  1178. *
  1179. * This is a workaround.
  1180. *
  1181. * Return: QDF_STATUS
  1182. */
  1183. QDF_STATUS
  1184. target_if_init_spectral_capability(struct target_if_spectral *spectral)
  1185. {
  1186. struct wlan_objmgr_psoc *psoc;
  1187. struct wlan_objmgr_pdev *pdev;
  1188. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  1189. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  1190. struct target_psoc_info *tgt_psoc_info;
  1191. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  1192. struct spectral_caps *pcap = &spectral->capability;
  1193. pdev = spectral->pdev_obj;
  1194. psoc = wlan_pdev_get_psoc(pdev);
  1195. if (!psoc) {
  1196. spectral_err("psoc is null");
  1197. return QDF_STATUS_E_FAILURE;
  1198. }
  1199. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  1200. if (!tgt_psoc_info) {
  1201. spectral_err("target_psoc_info is null");
  1202. return QDF_STATUS_E_FAILURE;
  1203. }
  1204. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  1205. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  1206. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  1207. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  1208. /* XXX : Workaround: Set Spectral capability */
  1209. pcap = &spectral->capability;
  1210. pcap->phydiag_cap = 1;
  1211. pcap->radar_cap = 1;
  1212. pcap->spectral_cap = 1;
  1213. pcap->advncd_spectral_cap = 1;
  1214. pcap->hw_gen = spectral->spectral_gen;
  1215. for (param_idx = 0; param_idx < num_bin_scaling_params; param_idx++) {
  1216. if (scaling_params[param_idx].pdev_id == pdev_id) {
  1217. pcap->is_scaling_params_populated = true;
  1218. pcap->formula_id = scaling_params[param_idx].formula_id;
  1219. pcap->low_level_offset =
  1220. scaling_params[param_idx].low_level_offset;
  1221. pcap->high_level_offset =
  1222. scaling_params[param_idx].high_level_offset;
  1223. pcap->rssi_thr = scaling_params[param_idx].rssi_thr;
  1224. pcap->default_agc_max_gain =
  1225. scaling_params[param_idx].default_agc_max_gain;
  1226. break;
  1227. }
  1228. }
  1229. return QDF_STATUS_SUCCESS;
  1230. }
  1231. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1232. /**
  1233. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1234. * internal operations with functions related to spectral simulation
  1235. * @p_sops: spectral low level ops table
  1236. *
  1237. * Initialize spectral target_if internal operations with functions
  1238. * related to spectral simulation
  1239. *
  1240. * Return: None
  1241. */
  1242. static void
  1243. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1244. {
  1245. /*
  1246. * Spectral simulation is currently intended for platform transitions
  1247. * where underlying HW support may not be available for some time.
  1248. * Hence, we do not currently provide a runtime switch to turn the
  1249. * simulation on or off.
  1250. * In case of future requirements where runtime switches are required,
  1251. * this can be added. But it is suggested to use application layer
  1252. * simulation as far as possible in such cases, since the main
  1253. * use of record and replay of samples would concern higher
  1254. * level sample processing rather than lower level delivery.
  1255. */
  1256. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  1257. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  1258. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  1259. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  1260. p_sops->configure_spectral =
  1261. target_if_spectral_sops_sim_configure_params;
  1262. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  1263. }
  1264. #else
  1265. /**
  1266. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1267. * internal operations
  1268. * @p_sops: spectral low level ops table
  1269. *
  1270. * Return: None
  1271. */
  1272. static void
  1273. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1274. {
  1275. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  1276. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  1277. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  1278. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  1279. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  1280. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  1281. }
  1282. #endif
  1283. /**
  1284. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  1285. * operations common to all Spectral chipset generations
  1286. *
  1287. * Initializes target_if_spectral_ops common to all chipset generations
  1288. *
  1289. * Return: None
  1290. */
  1291. static void
  1292. target_if_init_spectral_ops_common(void)
  1293. {
  1294. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1295. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  1296. p_sops->get_capability = target_if_spectral_get_capability;
  1297. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  1298. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  1299. target_if_init_spectral_simulation_ops(p_sops);
  1300. p_sops->get_extension_channel =
  1301. target_if_spectral_get_extension_channel;
  1302. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  1303. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  1304. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  1305. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  1306. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  1307. p_sops->reset_hw = target_if_spectral_reset_hw;
  1308. p_sops->get_chain_noise_floor =
  1309. target_if_spectral_get_chain_noise_floor;
  1310. }
  1311. /**
  1312. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  1313. * operations specific to Spectral chipset generation 2.
  1314. *
  1315. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  1316. *
  1317. * Return: None
  1318. */
  1319. static void
  1320. target_if_init_spectral_ops_gen2(void)
  1321. {
  1322. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1323. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  1324. }
  1325. /**
  1326. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  1327. * operations specific to Spectral chipset generation 3.
  1328. *
  1329. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  1330. *
  1331. * Return: None
  1332. */
  1333. static void
  1334. target_if_init_spectral_ops_gen3(void)
  1335. {
  1336. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1337. p_sops->process_spectral_report =
  1338. target_if_spectral_process_report_gen3;
  1339. return;
  1340. }
  1341. /**
  1342. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  1343. * operations.
  1344. * @spectral: Pointer to Spectral target_if internal private data
  1345. *
  1346. * Initializes all function pointers in target_if_spectral_ops for
  1347. * all generations
  1348. *
  1349. * Return: None
  1350. */
  1351. static void
  1352. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  1353. {
  1354. target_if_init_spectral_ops_common();
  1355. if (spectral->spectral_gen == SPECTRAL_GEN2)
  1356. target_if_init_spectral_ops_gen2();
  1357. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  1358. target_if_init_spectral_ops_gen3();
  1359. else
  1360. spectral_err("Invalid Spectral generation");
  1361. }
  1362. /*
  1363. * Dummy Functions:
  1364. * These functions are initially registered to avoid any crashes due to
  1365. * invocation of spectral functions before they are registered.
  1366. */
  1367. static uint64_t
  1368. null_get_tsf64(void *arg)
  1369. {
  1370. spectral_ops_not_registered("get_tsf64");
  1371. return 0;
  1372. }
  1373. static uint32_t
  1374. null_get_capability(void *arg, enum spectral_capability_type type)
  1375. {
  1376. /*
  1377. * TODO : We should have conditional compilation to get the capability
  1378. * : We have not yet attahced ATH layer here, so there is no
  1379. * : way to check the HAL capbalities
  1380. */
  1381. spectral_ops_not_registered("get_capability");
  1382. /* TODO : For the time being, we are returning TRUE */
  1383. return true;
  1384. }
  1385. static uint32_t
  1386. null_set_rxfilter(void *arg, int rxfilter)
  1387. {
  1388. spectral_ops_not_registered("set_rxfilter");
  1389. return 1;
  1390. }
  1391. static uint32_t
  1392. null_get_rxfilter(void *arg)
  1393. {
  1394. spectral_ops_not_registered("get_rxfilter");
  1395. return 0;
  1396. }
  1397. static uint32_t
  1398. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  1399. {
  1400. spectral_ops_not_registered("is_spectral_active");
  1401. return 1;
  1402. }
  1403. static uint32_t
  1404. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  1405. {
  1406. spectral_ops_not_registered("is_spectral_enabled");
  1407. return 1;
  1408. }
  1409. static uint32_t
  1410. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  1411. enum spectral_cp_error_code *err)
  1412. {
  1413. spectral_ops_not_registered("start_spectral_scan");
  1414. return 1;
  1415. }
  1416. static uint32_t
  1417. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  1418. {
  1419. spectral_ops_not_registered("stop_spectral_scan");
  1420. return 1;
  1421. }
  1422. static uint32_t
  1423. null_get_extension_channel(void *arg)
  1424. {
  1425. spectral_ops_not_registered("get_extension_channel");
  1426. return 1;
  1427. }
  1428. static int8_t
  1429. null_get_ctl_noisefloor(void *arg)
  1430. {
  1431. spectral_ops_not_registered("get_ctl_noisefloor");
  1432. return 1;
  1433. }
  1434. static int8_t
  1435. null_get_ext_noisefloor(void *arg)
  1436. {
  1437. spectral_ops_not_registered("get_ext_noisefloor");
  1438. return 0;
  1439. }
  1440. static uint32_t
  1441. null_configure_spectral(void *arg, struct spectral_config *params,
  1442. enum spectral_scan_mode smode)
  1443. {
  1444. spectral_ops_not_registered("configure_spectral");
  1445. return 0;
  1446. }
  1447. static uint32_t
  1448. null_get_spectral_config(void *arg, struct spectral_config *params,
  1449. enum spectral_scan_mode smode)
  1450. {
  1451. spectral_ops_not_registered("get_spectral_config");
  1452. return 0;
  1453. }
  1454. static uint32_t
  1455. null_get_ent_spectral_mask(void *arg)
  1456. {
  1457. spectral_ops_not_registered("get_ent_spectral_mask");
  1458. return 0;
  1459. }
  1460. static uint32_t
  1461. null_get_mac_address(void *arg, char *addr)
  1462. {
  1463. spectral_ops_not_registered("get_mac_address");
  1464. return 0;
  1465. }
  1466. static uint32_t
  1467. null_get_current_channel(void *arg)
  1468. {
  1469. spectral_ops_not_registered("get_current_channel");
  1470. return 0;
  1471. }
  1472. static uint32_t
  1473. null_reset_hw(void *arg)
  1474. {
  1475. spectral_ops_not_registered("get_current_channel");
  1476. return 0;
  1477. }
  1478. static uint32_t
  1479. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1480. {
  1481. spectral_ops_not_registered("get_chain_noise_floor");
  1482. return 0;
  1483. }
  1484. static int
  1485. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  1486. uint8_t *data,
  1487. uint32_t datalen,
  1488. struct target_if_spectral_rfqual_info *p_rfqual,
  1489. struct target_if_spectral_chan_info *p_chaninfo,
  1490. uint64_t tsf64,
  1491. struct target_if_spectral_acs_stats *acs_stats)
  1492. {
  1493. spectral_ops_not_registered("spectral_process_phyerr");
  1494. return 0;
  1495. }
  1496. static int
  1497. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  1498. void *payload)
  1499. {
  1500. spectral_ops_not_registered("process_spectral_report");
  1501. return 0;
  1502. }
  1503. /**
  1504. * target_if_spectral_init_dummy_function_table() -
  1505. * Initialize target_if internal
  1506. * Spectral operations to dummy functions
  1507. * @ps: Pointer to Spectral target_if internal private data
  1508. *
  1509. * Initialize all the function pointers in target_if_spectral_ops with
  1510. * dummy functions.
  1511. *
  1512. * Return: None
  1513. */
  1514. static void
  1515. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  1516. {
  1517. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  1518. p_sops->get_tsf64 = null_get_tsf64;
  1519. p_sops->get_capability = null_get_capability;
  1520. p_sops->set_rxfilter = null_set_rxfilter;
  1521. p_sops->get_rxfilter = null_get_rxfilter;
  1522. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  1523. p_sops->is_spectral_active = null_is_spectral_active;
  1524. p_sops->start_spectral_scan = null_start_spectral_scan;
  1525. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  1526. p_sops->get_extension_channel = null_get_extension_channel;
  1527. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  1528. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  1529. p_sops->configure_spectral = null_configure_spectral;
  1530. p_sops->get_spectral_config = null_get_spectral_config;
  1531. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  1532. p_sops->get_mac_address = null_get_mac_address;
  1533. p_sops->get_current_channel = null_get_current_channel;
  1534. p_sops->reset_hw = null_reset_hw;
  1535. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  1536. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  1537. p_sops->process_spectral_report = null_process_spectral_report;
  1538. }
  1539. /**
  1540. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  1541. * operations
  1542. * @spectral: Pointer to Spectral target_if internal private data
  1543. * @p: Pointer to Spectral function table
  1544. *
  1545. * Return: None
  1546. */
  1547. static void
  1548. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  1549. struct target_if_spectral_ops *p)
  1550. {
  1551. struct target_if_spectral_ops *p_sops =
  1552. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1553. p_sops->get_tsf64 = p->get_tsf64;
  1554. p_sops->get_capability = p->get_capability;
  1555. p_sops->set_rxfilter = p->set_rxfilter;
  1556. p_sops->get_rxfilter = p->get_rxfilter;
  1557. p_sops->is_spectral_enabled = p->is_spectral_enabled;
  1558. p_sops->is_spectral_active = p->is_spectral_active;
  1559. p_sops->start_spectral_scan = p->start_spectral_scan;
  1560. p_sops->stop_spectral_scan = p->stop_spectral_scan;
  1561. p_sops->get_extension_channel = p->get_extension_channel;
  1562. p_sops->get_ctl_noisefloor = p->get_ctl_noisefloor;
  1563. p_sops->get_ext_noisefloor = p->get_ext_noisefloor;
  1564. p_sops->configure_spectral = p->configure_spectral;
  1565. p_sops->get_spectral_config = p->get_spectral_config;
  1566. p_sops->get_ent_spectral_mask = p->get_ent_spectral_mask;
  1567. p_sops->get_mac_address = p->get_mac_address;
  1568. p_sops->get_current_channel = p->get_current_channel;
  1569. p_sops->reset_hw = p->reset_hw;
  1570. p_sops->get_chain_noise_floor = p->get_chain_noise_floor;
  1571. p_sops->spectral_process_phyerr = p->spectral_process_phyerr;
  1572. p_sops->process_spectral_report = p->process_spectral_report;
  1573. }
  1574. /**
  1575. * target_if_spectral_clear_stats() - Clear Spectral stats
  1576. * @spectral: Pointer to Spectral target_if internal private data
  1577. *
  1578. * Function to clear spectral stats
  1579. *
  1580. * Return: None
  1581. */
  1582. static void
  1583. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  1584. {
  1585. struct target_if_spectral_ops *p_sops =
  1586. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1587. qdf_mem_zero(&spectral->spectral_stats,
  1588. sizeof(struct target_if_spectral_stats));
  1589. spectral->spectral_stats.last_reset_tstamp =
  1590. p_sops->get_tsf64(spectral);
  1591. }
  1592. /**
  1593. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  1594. * @spectral: Pointer to Spectral target_if internal private data
  1595. *
  1596. * Function to check whether hardware supports spectral
  1597. *
  1598. * Return: True if HW supports Spectral, false if HW does not support Spectral
  1599. */
  1600. static int
  1601. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  1602. {
  1603. struct target_if_spectral_ops *p_sops = NULL;
  1604. struct spectral_caps *pcap = NULL;
  1605. int is_spectral_supported = true;
  1606. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1607. pcap = &spectral->capability;
  1608. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  1609. is_spectral_supported = false;
  1610. spectral_info("SPECTRAL : No PHYDIAG support");
  1611. return is_spectral_supported;
  1612. }
  1613. pcap->phydiag_cap = 1;
  1614. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  1615. is_spectral_supported = false;
  1616. spectral_info("SPECTRAL : No RADAR support");
  1617. return is_spectral_supported;
  1618. }
  1619. pcap->radar_cap = 1;
  1620. if (p_sops->get_capability(spectral,
  1621. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  1622. is_spectral_supported = false;
  1623. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  1624. return is_spectral_supported;
  1625. }
  1626. pcap->spectral_cap = 1;
  1627. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  1628. == false) {
  1629. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  1630. } else {
  1631. pcap->advncd_spectral_cap = 1;
  1632. }
  1633. return is_spectral_supported;
  1634. }
  1635. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1636. /**
  1637. * target_if_spectral_detach_simulation() - De-initialize Spectral
  1638. * Simulation functionality
  1639. * @spectral: Pointer to Spectral target_if internal private data
  1640. *
  1641. * Function to de-initialize Spectral Simulation functionality
  1642. *
  1643. * Return: None
  1644. */
  1645. static void
  1646. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1647. {
  1648. target_if_spectral_sim_detach(spectral);
  1649. }
  1650. #else
  1651. static void
  1652. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1653. {
  1654. }
  1655. #endif
  1656. /**
  1657. * target_if_spectral_detach() - De-initialize target_if Spectral
  1658. * @pdev: Pointer to pdev object
  1659. *
  1660. * Function to detach target_if spectral
  1661. *
  1662. * Return: None
  1663. */
  1664. static void
  1665. target_if_spectral_detach(struct target_if_spectral *spectral)
  1666. {
  1667. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1668. spectral_info("spectral detach");
  1669. if (spectral) {
  1670. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1671. qdf_spinlock_destroy
  1672. (&spectral->param_info[smode].osps_lock);
  1673. target_if_spectral_detach_simulation(spectral);
  1674. qdf_spinlock_destroy(&spectral->spectral_lock);
  1675. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  1676. qdf_mem_free(spectral);
  1677. spectral = NULL;
  1678. }
  1679. }
  1680. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1681. /**
  1682. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  1683. * functionality
  1684. * @spectral: Pointer to Spectral target_if internal private data
  1685. *
  1686. * Function to initialize spectral simulation functionality
  1687. *
  1688. * Return: 0 on success, negative error code on failure
  1689. */
  1690. static int
  1691. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1692. {
  1693. if (target_if_spectral_sim_attach(spectral)) {
  1694. qdf_mem_free(spectral);
  1695. return -EPERM;
  1696. }
  1697. return 0;
  1698. }
  1699. #else
  1700. static int
  1701. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1702. {
  1703. return 0;
  1704. }
  1705. #endif
  1706. /**
  1707. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  1708. * functionality for the given pdev
  1709. * @pdev: Pointer to pdev object
  1710. *
  1711. * Function to initialize pointer to spectral target_if internal private data
  1712. *
  1713. * Return: On success, pointer to Spectral target_if internal private data, on
  1714. * failure, NULL
  1715. */
  1716. void *
  1717. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  1718. {
  1719. struct target_if_spectral_ops *p_sops = NULL;
  1720. struct target_if_spectral *spectral = NULL;
  1721. uint32_t target_type;
  1722. uint32_t target_revision;
  1723. struct wlan_objmgr_psoc *psoc;
  1724. struct wlan_lmac_if_target_tx_ops *tx_ops;
  1725. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1726. if (!pdev) {
  1727. spectral_err("SPECTRAL: pdev is NULL!");
  1728. return NULL;
  1729. }
  1730. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  1731. sizeof(struct target_if_spectral));
  1732. if (!spectral)
  1733. return spectral;
  1734. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  1735. /* Store pdev in Spectral */
  1736. spectral->pdev_obj = pdev;
  1737. psoc = wlan_pdev_get_psoc(pdev);
  1738. tx_ops = &psoc->soc_cb.tx_ops.target_tx_ops;
  1739. if (tx_ops->tgt_get_tgt_type) {
  1740. target_type = tx_ops->tgt_get_tgt_type(psoc);
  1741. } else {
  1742. qdf_mem_free(spectral);
  1743. return NULL;
  1744. }
  1745. if (tx_ops->tgt_get_tgt_revision) {
  1746. target_revision = tx_ops->tgt_get_tgt_revision(psoc);
  1747. } else {
  1748. qdf_mem_free(spectral);
  1749. return NULL;
  1750. }
  1751. /* init the function ptr table */
  1752. target_if_spectral_init_dummy_function_table(spectral);
  1753. /* get spectral function table */
  1754. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1755. /* TODO : Should this be called here of after ath_attach ? */
  1756. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  1757. spectral_info("HAL_CAP_PHYDIAG : Capable");
  1758. /* TODO: Need to fix the capablity check for RADAR */
  1759. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  1760. spectral_info("HAL_CAP_RADAR : Capable");
  1761. /* TODO : Need to fix the capablity check for SPECTRAL */
  1762. /* TODO : Should this be called here of after ath_attach ? */
  1763. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  1764. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  1765. qdf_spinlock_create(&spectral->spectral_lock);
  1766. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  1767. target_if_spectral_clear_stats(spectral);
  1768. if (target_type == TARGET_TYPE_QCA8074V2)
  1769. spectral->fftbin_size_war =
  1770. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  1771. else if (target_type == TARGET_TYPE_QCA8074 ||
  1772. target_type == TARGET_TYPE_QCA6018 ||
  1773. target_type == TARGET_TYPE_QCA6390)
  1774. spectral->fftbin_size_war =
  1775. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  1776. else
  1777. spectral->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  1778. if (target_type == TARGET_TYPE_QCA8074 ||
  1779. target_type == TARGET_TYPE_QCA8074V2 ||
  1780. target_type == TARGET_TYPE_QCA6018) {
  1781. spectral->inband_fftbin_size_adj = 1;
  1782. spectral->null_fftbin_adj = 1;
  1783. } else {
  1784. spectral->inband_fftbin_size_adj = 0;
  1785. spectral->null_fftbin_adj = 0;
  1786. }
  1787. if ((target_type == TARGET_TYPE_QCA8074) ||
  1788. (target_type == TARGET_TYPE_QCA8074V2) ||
  1789. (target_type == TARGET_TYPE_QCA6018) ||
  1790. (target_type == TARGET_TYPE_QCN9000) ||
  1791. (target_type == TARGET_TYPE_QCA6290) ||
  1792. (target_type == TARGET_TYPE_QCA6390)) {
  1793. spectral->spectral_gen = SPECTRAL_GEN3;
  1794. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  1795. spectral->tag_sscan_summary_exp =
  1796. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  1797. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  1798. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  1799. spectral->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3;
  1800. spectral->fft_size_max = SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3;
  1801. } else {
  1802. spectral->spectral_gen = SPECTRAL_GEN2;
  1803. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  1804. spectral->tag_sscan_summary_exp =
  1805. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  1806. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  1807. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  1808. spectral->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1809. spectral->fft_size_max = SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1810. }
  1811. target_if_init_spectral_param_properties(spectral);
  1812. /* Init spectral capability */
  1813. if (target_if_init_spectral_capability(spectral) !=
  1814. QDF_STATUS_SUCCESS) {
  1815. qdf_mem_free(spectral);
  1816. return NULL;
  1817. }
  1818. if (target_if_spectral_attach_simulation(spectral) < 0)
  1819. return NULL;
  1820. target_if_init_spectral_ops(spectral);
  1821. /* Spectral mode specific init */
  1822. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1823. spectral->last_fft_timestamp[smode] = 0;
  1824. spectral->timestamp_war_offset[smode] = 0;
  1825. spectral->params_valid[smode] = false;
  1826. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  1827. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  1828. }
  1829. target_if_spectral_register_funcs(spectral, &spectral_ops);
  1830. if (target_if_spectral_check_hw_capability(spectral) == false) {
  1831. target_if_spectral_detach(spectral);
  1832. spectral = NULL;
  1833. } else {
  1834. /*
  1835. * TODO: Once the driver architecture transitions to chipset
  1836. * versioning based checks, reflect this here.
  1837. */
  1838. spectral->is_160_format = false;
  1839. spectral->is_lb_edge_extrabins_format = false;
  1840. spectral->is_rb_edge_extrabins_format = false;
  1841. if (target_type == TARGET_TYPE_QCA9984 ||
  1842. target_type == TARGET_TYPE_QCA9888) {
  1843. spectral->is_160_format = true;
  1844. spectral->is_lb_edge_extrabins_format = true;
  1845. spectral->is_rb_edge_extrabins_format = true;
  1846. } else if ((target_type == TARGET_TYPE_AR900B) &&
  1847. (target_revision == AR900B_REV_2)) {
  1848. spectral->is_rb_edge_extrabins_format = true;
  1849. }
  1850. if (target_type == TARGET_TYPE_QCA9984 ||
  1851. target_type == TARGET_TYPE_QCA9888)
  1852. spectral->is_sec80_rssi_war_required = true;
  1853. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  1854. if (spectral->spectral_gen == SPECTRAL_GEN3)
  1855. init_160mhz_delivery_state_machine(spectral);
  1856. }
  1857. return spectral;
  1858. }
  1859. /**
  1860. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  1861. * functionality for the given pdev
  1862. * @pdev: Pointer to pdev object
  1863. *
  1864. * Function to de-initialize pointer to spectral target_if internal private data
  1865. *
  1866. * Return: None
  1867. */
  1868. void
  1869. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  1870. {
  1871. struct target_if_spectral *spectral = NULL;
  1872. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1873. if (!spectral) {
  1874. spectral_err("SPECTRAL : Module doesn't exist");
  1875. return;
  1876. }
  1877. target_if_spectral_detach(spectral);
  1878. return;
  1879. }
  1880. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  1881. * corresponding translation for Agile channel width.
  1882. * Translation schema of different operating modes:
  1883. * 20 -> 20, 40 -> 40, (80 & 160 & 80_80) -> 80.
  1884. * @chwidth: Channel width enum.
  1885. *
  1886. * Return: The translated channel width enum.
  1887. */
  1888. static enum phy_ch_width
  1889. target_if_spectral_find_agile_width(enum phy_ch_width chwidth)
  1890. {
  1891. switch (chwidth) {
  1892. case CH_WIDTH_20MHZ:
  1893. return CH_WIDTH_20MHZ;
  1894. case CH_WIDTH_40MHZ:
  1895. return CH_WIDTH_40MHZ;
  1896. case CH_WIDTH_80MHZ:
  1897. case CH_WIDTH_80P80MHZ:
  1898. case CH_WIDTH_160MHZ:
  1899. return CH_WIDTH_80MHZ;
  1900. default:
  1901. spectral_err("Invalid chwidth enum %d", chwidth);
  1902. return CH_WIDTH_INVALID;
  1903. }
  1904. }
  1905. /**
  1906. * target_if_calculate_center_freq() - Helper routine to
  1907. * check whether given frequency is center frequency of a
  1908. * WLAN channel
  1909. *
  1910. * @spectral: Pointer to Spectral object
  1911. * @chan_freq: Center frequency of a WLAN channel
  1912. * @is_valid: Indicates whether given frequency is valid
  1913. *
  1914. * Return: QDF_STATUS
  1915. */
  1916. static QDF_STATUS
  1917. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  1918. uint32_t chan_freq,
  1919. bool *is_valid)
  1920. {
  1921. struct regulatory_channel *cur_chan_list;
  1922. int i;
  1923. if (!pdev) {
  1924. spectral_err("pdev object is null");
  1925. return QDF_STATUS_E_FAILURE;
  1926. }
  1927. if (!is_valid) {
  1928. spectral_err("is valid argument is null");
  1929. return QDF_STATUS_E_FAILURE;
  1930. }
  1931. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  1932. if (!cur_chan_list)
  1933. return QDF_STATUS_E_FAILURE;
  1934. if (wlan_reg_get_current_chan_list(
  1935. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  1936. spectral_err("Failed to get cur_chan list");
  1937. qdf_mem_free(cur_chan_list);
  1938. return QDF_STATUS_E_FAILURE;
  1939. }
  1940. *is_valid = false;
  1941. for (i = 0; i < NUM_CHANNELS; i++) {
  1942. uint32_t flags;
  1943. uint32_t center_freq;
  1944. flags = cur_chan_list[i].chan_flags;
  1945. center_freq = cur_chan_list[i].center_freq;
  1946. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  1947. (center_freq == chan_freq)) {
  1948. *is_valid = true;
  1949. break;
  1950. }
  1951. }
  1952. qdf_mem_free(cur_chan_list);
  1953. return QDF_STATUS_SUCCESS;
  1954. }
  1955. /**
  1956. * target_if_calculate_center_freq() - Helper routine to
  1957. * find the center frequency of the agile span from a
  1958. * WLAN channel center frequency
  1959. *
  1960. * @spectral: Pointer to Spectral object
  1961. * @chan_freq: Center frequency of a WLAN channel
  1962. * @center_freq: Pointer to center frequency
  1963. *
  1964. * Return: QDF_STATUS
  1965. */
  1966. static QDF_STATUS
  1967. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  1968. uint16_t chan_freq,
  1969. uint16_t *center_freq)
  1970. {
  1971. struct wlan_objmgr_vdev *vdev;
  1972. enum phy_ch_width ch_width;
  1973. enum phy_ch_width agile_ch_width;
  1974. uint16_t chan_num;
  1975. if (!spectral) {
  1976. spectral_err("spectral target if object is null");
  1977. return QDF_STATUS_E_FAILURE;
  1978. }
  1979. if (!center_freq) {
  1980. spectral_err("center_freq argument is null");
  1981. return QDF_STATUS_E_FAILURE;
  1982. }
  1983. chan_num = wlan_reg_freq_to_chan(spectral->pdev_obj, chan_freq);
  1984. vdev = target_if_spectral_get_vdev(spectral);
  1985. if (!vdev) {
  1986. spectral_err("vdev is NULL");
  1987. return QDF_STATUS_E_FAILURE;
  1988. }
  1989. ch_width = target_if_vdev_get_ch_width(vdev);
  1990. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1991. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  1992. if (agile_ch_width == CH_WIDTH_20MHZ) {
  1993. *center_freq = chan_freq;
  1994. } else {
  1995. uint16_t start_freq;
  1996. uint16_t end_freq;
  1997. const struct bonded_channel *bonded_chan_ptr = NULL;
  1998. wlan_reg_get_5g_bonded_channel_and_state
  1999. (spectral->pdev_obj, chan_num, agile_ch_width,
  2000. &bonded_chan_ptr);
  2001. if (!bonded_chan_ptr) {
  2002. spectral_err("Bonded channel is not found");
  2003. return QDF_STATUS_E_FAILURE;
  2004. }
  2005. start_freq = wlan_reg_chan_to_freq(spectral->pdev_obj,
  2006. bonded_chan_ptr->start_ch);
  2007. end_freq = wlan_reg_chan_to_freq(spectral->pdev_obj,
  2008. bonded_chan_ptr->end_ch);
  2009. *center_freq = (start_freq + end_freq) >> 1;
  2010. }
  2011. return QDF_STATUS_SUCCESS;
  2012. }
  2013. /**
  2014. * target_if_validate_center_freq() - Helper routine to
  2015. * validate user provided agile center frequency
  2016. *
  2017. * @spectral: Pointer to Spectral object
  2018. * @center_freq: User provided agile span center frequency
  2019. * @is_valid: Indicates whether agile span center frequency is valid
  2020. *
  2021. * Return: QDF_STATUS
  2022. */
  2023. static QDF_STATUS
  2024. target_if_validate_center_freq(struct target_if_spectral *spectral,
  2025. uint16_t center_freq,
  2026. bool *is_valid)
  2027. {
  2028. struct wlan_objmgr_vdev *vdev;
  2029. enum phy_ch_width ch_width;
  2030. enum phy_ch_width agile_ch_width;
  2031. uint16_t chan_num;
  2032. struct wlan_objmgr_pdev *pdev;
  2033. QDF_STATUS status;
  2034. if (!spectral) {
  2035. spectral_err("spectral target if object is null");
  2036. return QDF_STATUS_E_FAILURE;
  2037. }
  2038. if (!is_valid) {
  2039. spectral_err("is_valid argument is null");
  2040. return QDF_STATUS_E_FAILURE;
  2041. }
  2042. pdev = spectral->pdev_obj;
  2043. vdev = target_if_spectral_get_vdev(spectral);
  2044. if (!vdev) {
  2045. spectral_err("vdev is NULL");
  2046. return QDF_STATUS_E_FAILURE;
  2047. }
  2048. ch_width = target_if_vdev_get_ch_width(vdev);
  2049. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2050. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2051. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2052. status = target_if_is_center_freq_of_any_chan
  2053. (pdev, center_freq, is_valid);
  2054. if (QDF_IS_STATUS_ERROR(status))
  2055. return QDF_STATUS_E_FAILURE;
  2056. } else {
  2057. uint16_t start_freq;
  2058. uint16_t end_freq;
  2059. const struct bonded_channel *bonded_chan_ptr = NULL;
  2060. bool is_chan;
  2061. status = target_if_is_center_freq_of_any_chan
  2062. (pdev, center_freq + 10, &is_chan);
  2063. if (QDF_IS_STATUS_ERROR(status))
  2064. return QDF_STATUS_E_FAILURE;
  2065. if (is_chan) {
  2066. uint32_t calulated_center_freq;
  2067. chan_num = wlan_reg_freq_to_chan(pdev,
  2068. center_freq + 10);
  2069. wlan_reg_get_5g_bonded_channel_and_state
  2070. (pdev, chan_num, agile_ch_width,
  2071. &bonded_chan_ptr);
  2072. if (!bonded_chan_ptr) {
  2073. spectral_err("Bonded channel is not found");
  2074. return QDF_STATUS_E_FAILURE;
  2075. }
  2076. start_freq = wlan_reg_chan_to_freq
  2077. (pdev, bonded_chan_ptr->start_ch);
  2078. end_freq = wlan_reg_chan_to_freq
  2079. (pdev, bonded_chan_ptr->end_ch);
  2080. calulated_center_freq = (start_freq + end_freq) >> 1;
  2081. *is_valid = (center_freq == calulated_center_freq);
  2082. } else {
  2083. *is_valid = false;
  2084. }
  2085. }
  2086. return QDF_STATUS_SUCCESS;
  2087. }
  2088. /**
  2089. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  2090. * check whether agile span overlaps with current operating band.
  2091. *
  2092. * @spectral: Pointer to Spectral object
  2093. * @ss_frequency: Agile span center frequency
  2094. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  2095. *
  2096. * Helper routine to check whether agile span overlaps with current
  2097. * operating band.
  2098. *
  2099. * Return: QDF_STATUS
  2100. */
  2101. static QDF_STATUS
  2102. target_if_is_agile_span_overlap_with_operating_span
  2103. (struct target_if_spectral *spectral,
  2104. uint32_t ss_frequency,
  2105. bool *is_overlapping)
  2106. {
  2107. uint32_t chan_num;
  2108. enum phy_ch_width ch_width;
  2109. enum phy_ch_width agile_ch_width;
  2110. const struct bonded_channel *bonded_chan_ptr = NULL;
  2111. struct wlan_objmgr_vdev *vdev;
  2112. struct wlan_objmgr_pdev *pdev;
  2113. int16_t chan_freq;
  2114. uint32_t op_start_freq;
  2115. uint32_t op_end_freq;
  2116. uint32_t agile_start_freq;
  2117. uint32_t agile_end_freq;
  2118. uint32_t cfreq2;
  2119. if (!spectral) {
  2120. spectral_err("Spectral object is NULL");
  2121. return QDF_STATUS_E_FAILURE;
  2122. }
  2123. pdev = spectral->pdev_obj;
  2124. if (!pdev) {
  2125. spectral_err("pdev object is NULL");
  2126. return QDF_STATUS_E_FAILURE;
  2127. }
  2128. if (!is_overlapping) {
  2129. spectral_err("Argument(is_overlapping) is NULL");
  2130. return QDF_STATUS_E_FAILURE;
  2131. }
  2132. vdev = target_if_spectral_get_vdev(spectral);
  2133. if (!vdev) {
  2134. spectral_err("vdev is NULL");
  2135. return QDF_STATUS_E_FAILURE;
  2136. }
  2137. ch_width = target_if_vdev_get_ch_width(vdev);
  2138. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2139. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2140. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2141. if (cfreq2 < 0)
  2142. return QDF_STATUS_E_FAILURE;
  2143. chan_num = wlan_reg_freq_to_chan(pdev, chan_freq);
  2144. if (ch_width == CH_WIDTH_20MHZ) {
  2145. op_start_freq = chan_freq - 10;
  2146. op_end_freq = chan_freq + 10;
  2147. } else {
  2148. wlan_reg_get_5g_bonded_channel_and_state
  2149. (pdev, chan_num, ch_width, &bonded_chan_ptr);
  2150. if (!bonded_chan_ptr) {
  2151. spectral_err("Bonded channel is not found");
  2152. return QDF_STATUS_E_FAILURE;
  2153. }
  2154. op_start_freq =
  2155. wlan_reg_chan_to_freq(pdev,
  2156. bonded_chan_ptr->start_ch) - 10;
  2157. op_end_freq =
  2158. wlan_reg_chan_to_freq(pdev,
  2159. bonded_chan_ptr->end_ch) + 10;
  2160. }
  2161. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2162. if (agile_ch_width == CH_WIDTH_INVALID)
  2163. return QDF_STATUS_E_FAILURE;
  2164. agile_start_freq = ss_frequency -
  2165. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2166. agile_end_freq = ss_frequency +
  2167. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2168. if (agile_end_freq <= op_start_freq || op_end_freq <= agile_start_freq)
  2169. *is_overlapping = false;
  2170. else
  2171. *is_overlapping = true;
  2172. /* Use non zero cfreq2 to identify 80p80 */
  2173. if (cfreq2) {
  2174. uint32_t sec80_start_feq;
  2175. uint32_t sec80_end_freq;
  2176. sec80_start_feq = cfreq2 - 40;
  2177. sec80_end_freq = cfreq2 + 40;
  2178. if ((agile_end_freq > sec80_start_feq) &&
  2179. (sec80_end_freq > agile_start_freq))
  2180. *is_overlapping = true;
  2181. }
  2182. return QDF_STATUS_SUCCESS;
  2183. }
  2184. /**
  2185. * _target_if_set_spectral_config() - Set spectral config
  2186. * @spectral: Pointer to spectral object
  2187. * @threshtype: config type
  2188. * @value: config value
  2189. * @smode: Spectral scan mode
  2190. * @err: Spectral error code
  2191. *
  2192. * API to set spectral configurations
  2193. *
  2194. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2195. */
  2196. static QDF_STATUS
  2197. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  2198. const uint32_t threshtype, const uint32_t value,
  2199. const enum spectral_scan_mode smode,
  2200. enum spectral_cp_error_code *err)
  2201. {
  2202. struct spectral_config params;
  2203. struct target_if_spectral_ops *p_sops;
  2204. struct spectral_config *sparams;
  2205. QDF_STATUS status;
  2206. bool is_overlapping;
  2207. uint16_t agile_cfreq;
  2208. bool is_valid_chan;
  2209. if (!err) {
  2210. spectral_err("Error code argument is null");
  2211. QDF_ASSERT(0);
  2212. }
  2213. *err = SPECTRAL_SCAN_ERR_INVALID;
  2214. if (!spectral) {
  2215. spectral_err("spectral object is NULL");
  2216. return QDF_STATUS_E_FAILURE;
  2217. }
  2218. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2219. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2220. spectral_err("Invalid Spectral mode %u", smode);
  2221. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2222. return QDF_STATUS_E_FAILURE;
  2223. }
  2224. sparams = &spectral->params[smode];
  2225. if (!spectral->params_valid[smode]) {
  2226. target_if_spectral_info_read(spectral,
  2227. smode,
  2228. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2229. &spectral->params[smode],
  2230. sizeof(spectral->params[smode]));
  2231. spectral->params_valid[smode] = true;
  2232. }
  2233. switch (threshtype) {
  2234. case SPECTRAL_PARAM_FFT_PERIOD:
  2235. sparams->ss_fft_period = value;
  2236. break;
  2237. case SPECTRAL_PARAM_SCAN_PERIOD:
  2238. sparams->ss_period = value;
  2239. break;
  2240. case SPECTRAL_PARAM_SCAN_COUNT:
  2241. sparams->ss_count = value;
  2242. break;
  2243. case SPECTRAL_PARAM_SHORT_REPORT:
  2244. sparams->ss_short_report = (!!value) ? true : false;
  2245. break;
  2246. case SPECTRAL_PARAM_SPECT_PRI:
  2247. sparams->ss_spectral_pri = (!!value) ? true : false;
  2248. break;
  2249. case SPECTRAL_PARAM_FFT_SIZE:
  2250. if ((value < spectral->fft_size_min) ||
  2251. (value > spectral->fft_size_max)) {
  2252. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2253. return QDF_STATUS_E_FAILURE;
  2254. }
  2255. sparams->ss_fft_size = value;
  2256. break;
  2257. case SPECTRAL_PARAM_GC_ENA:
  2258. sparams->ss_gc_ena = !!value;
  2259. break;
  2260. case SPECTRAL_PARAM_RESTART_ENA:
  2261. sparams->ss_restart_ena = !!value;
  2262. break;
  2263. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  2264. sparams->ss_noise_floor_ref = value;
  2265. break;
  2266. case SPECTRAL_PARAM_INIT_DELAY:
  2267. sparams->ss_init_delay = value;
  2268. break;
  2269. case SPECTRAL_PARAM_NB_TONE_THR:
  2270. sparams->ss_nb_tone_thr = value;
  2271. break;
  2272. case SPECTRAL_PARAM_STR_BIN_THR:
  2273. sparams->ss_str_bin_thr = value;
  2274. break;
  2275. case SPECTRAL_PARAM_WB_RPT_MODE:
  2276. sparams->ss_wb_rpt_mode = !!value;
  2277. break;
  2278. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  2279. sparams->ss_rssi_rpt_mode = !!value;
  2280. break;
  2281. case SPECTRAL_PARAM_RSSI_THR:
  2282. sparams->ss_rssi_thr = value;
  2283. break;
  2284. case SPECTRAL_PARAM_PWR_FORMAT:
  2285. sparams->ss_pwr_format = !!value;
  2286. break;
  2287. case SPECTRAL_PARAM_RPT_MODE:
  2288. if ((value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  2289. (value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  2290. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2291. return QDF_STATUS_E_FAILURE;
  2292. }
  2293. sparams->ss_rpt_mode = value;
  2294. break;
  2295. case SPECTRAL_PARAM_BIN_SCALE:
  2296. sparams->ss_bin_scale = value;
  2297. break;
  2298. case SPECTRAL_PARAM_DBM_ADJ:
  2299. sparams->ss_dbm_adj = !!value;
  2300. break;
  2301. case SPECTRAL_PARAM_CHN_MASK:
  2302. sparams->ss_chn_mask = value;
  2303. break;
  2304. case SPECTRAL_PARAM_FREQUENCY:
  2305. status = target_if_is_center_freq_of_any_chan
  2306. (spectral->pdev_obj, value, &is_valid_chan);
  2307. if (QDF_IS_STATUS_ERROR(status))
  2308. return QDF_STATUS_E_FAILURE;
  2309. if (is_valid_chan) {
  2310. status = target_if_calculate_center_freq(spectral,
  2311. value,
  2312. &agile_cfreq);
  2313. if (QDF_IS_STATUS_ERROR(status)) {
  2314. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2315. return QDF_STATUS_E_FAILURE;
  2316. }
  2317. } else {
  2318. bool is_valid_agile_cfreq;
  2319. status = target_if_validate_center_freq
  2320. (spectral, value, &is_valid_agile_cfreq);
  2321. if (QDF_IS_STATUS_ERROR(status))
  2322. return QDF_STATUS_E_FAILURE;
  2323. if (!is_valid_agile_cfreq) {
  2324. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2325. spectral_err("Invalid agile center frequency");
  2326. return QDF_STATUS_E_FAILURE;
  2327. }
  2328. agile_cfreq = value;
  2329. }
  2330. status = target_if_is_agile_span_overlap_with_operating_span
  2331. (spectral, agile_cfreq, &is_overlapping);
  2332. if (QDF_IS_STATUS_ERROR(status))
  2333. return QDF_STATUS_E_FAILURE;
  2334. if (is_overlapping) {
  2335. spectral_err("Agile span overlapping with current BW");
  2336. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2337. return QDF_STATUS_E_FAILURE;
  2338. }
  2339. sparams->ss_frequency = agile_cfreq;
  2340. break;
  2341. }
  2342. p_sops->configure_spectral(spectral, sparams, smode);
  2343. /* only to validate the writes */
  2344. p_sops->get_spectral_config(spectral, &params, smode);
  2345. return QDF_STATUS_SUCCESS;
  2346. }
  2347. QDF_STATUS
  2348. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  2349. const uint32_t threshtype, const uint32_t value,
  2350. const enum spectral_scan_mode smode,
  2351. enum spectral_cp_error_code *err)
  2352. {
  2353. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  2354. struct target_if_spectral *spectral;
  2355. QDF_STATUS status;
  2356. if (!err) {
  2357. spectral_err("Error code argument is null");
  2358. QDF_ASSERT(0);
  2359. }
  2360. *err = SPECTRAL_SCAN_ERR_INVALID;
  2361. if (!pdev) {
  2362. spectral_err("pdev object is NULL");
  2363. return QDF_STATUS_E_FAILURE;
  2364. }
  2365. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2366. if (!spectral) {
  2367. spectral_err("spectral object is NULL");
  2368. return QDF_STATUS_E_FAILURE;
  2369. }
  2370. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2371. spectral_err("Invalid Spectral mode %u", smode);
  2372. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2373. return QDF_STATUS_E_FAILURE;
  2374. }
  2375. if (!spectral->properties[smode][threshtype].supported) {
  2376. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  2377. threshtype, smode);
  2378. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  2379. return QDF_STATUS_E_FAILURE;
  2380. }
  2381. if (spectral->properties[smode][threshtype].common_all_modes) {
  2382. spectral_warn("Setting Spectral parameter %u for all modes",
  2383. threshtype);
  2384. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  2385. status = _target_if_set_spectral_config
  2386. (spectral, threshtype, value,
  2387. mode, err);
  2388. if (QDF_IS_STATUS_ERROR(status))
  2389. return QDF_STATUS_E_FAILURE;
  2390. }
  2391. return QDF_STATUS_SUCCESS;
  2392. }
  2393. return _target_if_set_spectral_config(spectral, threshtype,
  2394. value, smode, err);
  2395. }
  2396. /**
  2397. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  2398. * @fft_len: FFT length
  2399. * @pdev: Pointer to pdev object
  2400. *
  2401. * API to get fft bin count for a given fft length
  2402. *
  2403. * Return: FFt bin count
  2404. */
  2405. static int
  2406. target_if_get_fft_bin_count(int fft_len)
  2407. {
  2408. int bin_count = 0;
  2409. switch (fft_len) {
  2410. case 5:
  2411. bin_count = 16;
  2412. break;
  2413. case 6:
  2414. bin_count = 32;
  2415. break;
  2416. case 7:
  2417. bin_count = 64;
  2418. break;
  2419. case 8:
  2420. bin_count = 128;
  2421. break;
  2422. case 9:
  2423. bin_count = 256;
  2424. break;
  2425. default:
  2426. break;
  2427. }
  2428. return bin_count;
  2429. }
  2430. /**
  2431. * target_if_init_upper_lower_flags() - Initializes control and extension
  2432. * segment flags
  2433. * @fft_len: FFT length
  2434. * @pdev: Pointer to pdev object
  2435. *
  2436. * API to initialize the control and extension flags with the lower/upper
  2437. * segment based on the HT mode
  2438. *
  2439. * Return: FFt bin count
  2440. */
  2441. static void
  2442. target_if_init_upper_lower_flags(struct target_if_spectral *spectral)
  2443. {
  2444. int current_channel = 0;
  2445. int ext_channel = 0;
  2446. struct target_if_spectral_ops *p_sops =
  2447. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2448. current_channel = p_sops->get_current_channel(spectral);
  2449. ext_channel = p_sops->get_extension_channel(spectral);
  2450. if ((current_channel == 0) || (ext_channel == 0))
  2451. return;
  2452. if (spectral->sc_spectral_20_40_mode) {
  2453. /* HT40 mode */
  2454. if (ext_channel < current_channel) {
  2455. spectral->lower_is_extension = 1;
  2456. spectral->upper_is_control = 1;
  2457. spectral->lower_is_control = 0;
  2458. spectral->upper_is_extension = 0;
  2459. } else {
  2460. spectral->lower_is_extension = 0;
  2461. spectral->upper_is_control = 0;
  2462. spectral->lower_is_control = 1;
  2463. spectral->upper_is_extension = 1;
  2464. }
  2465. } else {
  2466. /* HT20 mode, lower is always control */
  2467. spectral->lower_is_extension = 0;
  2468. spectral->upper_is_control = 0;
  2469. spectral->lower_is_control = 1;
  2470. spectral->upper_is_extension = 0;
  2471. }
  2472. }
  2473. /**
  2474. * target_if_get_spectral_config() - Get spectral configuration
  2475. * @pdev: Pointer to pdev object
  2476. * @param: Pointer to spectral_config structure in which the configuration
  2477. * should be returned
  2478. * @smode: Spectral scan mode
  2479. *
  2480. * API to get the current spectral configuration
  2481. *
  2482. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2483. */
  2484. QDF_STATUS
  2485. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  2486. struct spectral_config *param,
  2487. enum spectral_scan_mode smode)
  2488. {
  2489. struct target_if_spectral_ops *p_sops = NULL;
  2490. struct target_if_spectral *spectral = NULL;
  2491. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2492. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2493. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2494. spectral_err("Invalid Spectral mode %u", smode);
  2495. return QDF_STATUS_E_FAILURE;
  2496. }
  2497. qdf_mem_zero(param, sizeof(struct spectral_config));
  2498. p_sops->get_spectral_config(spectral, param, smode);
  2499. return QDF_STATUS_SUCCESS;
  2500. }
  2501. /**
  2502. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  2503. * parameters
  2504. * @spectral: Pointer to Spectral target_if internal private data
  2505. * @spectral_params: Pointer to Spectral parameters
  2506. * @smode: Spectral scan mode
  2507. * @err: Spectral error code
  2508. *
  2509. * Enable use of desired Spectral parameters by configuring them into HW, and
  2510. * starting Spectral scan
  2511. *
  2512. * Return: 0 on success, 1 on failure
  2513. */
  2514. int
  2515. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  2516. struct spectral_config *spectral_params,
  2517. enum spectral_scan_mode smode,
  2518. enum spectral_cp_error_code *err)
  2519. {
  2520. int extension_channel = 0;
  2521. int current_channel = 0;
  2522. struct target_if_spectral_ops *p_sops = NULL;
  2523. struct wlan_objmgr_vdev *vdev = NULL;
  2524. if (!spectral) {
  2525. spectral_err("Spectral LMAC object is NULL");
  2526. return 1;
  2527. }
  2528. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2529. spectral_err("Invalid Spectral mode %u", smode);
  2530. return 1;
  2531. }
  2532. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2533. if (!p_sops) {
  2534. spectral_err("p_sops is NULL");
  2535. return 1;
  2536. }
  2537. spectral->sc_spectral_noise_pwr_cal =
  2538. spectral_params->ss_spectral_pri ? 1 : 0;
  2539. /* check if extension channel is present */
  2540. extension_channel = p_sops->get_extension_channel(spectral);
  2541. current_channel = p_sops->get_current_channel(spectral);
  2542. vdev = target_if_spectral_get_vdev(spectral);
  2543. if (!vdev)
  2544. return 1;
  2545. spectral->ch_width = target_if_vdev_get_ch_width(vdev);
  2546. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2547. if (spectral->ch_width == CH_WIDTH_INVALID)
  2548. return 1;
  2549. if (spectral->capability.advncd_spectral_cap) {
  2550. spectral->lb_edge_extrabins = 0;
  2551. spectral->rb_edge_extrabins = 0;
  2552. if (spectral->is_lb_edge_extrabins_format &&
  2553. spectral->params[smode].ss_rpt_mode == 2) {
  2554. spectral->lb_edge_extrabins = 4;
  2555. }
  2556. if (spectral->is_rb_edge_extrabins_format &&
  2557. spectral->params[smode].ss_rpt_mode == 2) {
  2558. spectral->rb_edge_extrabins = 4;
  2559. }
  2560. if (spectral->ch_width == CH_WIDTH_20MHZ) {
  2561. spectral->sc_spectral_20_40_mode = 0;
  2562. spectral->spectral_numbins =
  2563. target_if_get_fft_bin_count(
  2564. spectral->params[smode].ss_fft_size);
  2565. spectral->spectral_fft_len =
  2566. target_if_get_fft_bin_count(
  2567. spectral->params[smode].ss_fft_size);
  2568. spectral->spectral_data_len =
  2569. target_if_get_fft_bin_count(
  2570. spectral->params[smode].ss_fft_size);
  2571. /*
  2572. * Initialize classifier params to be sent to user
  2573. * space classifier
  2574. */
  2575. spectral->classifier_params.lower_chan_in_mhz =
  2576. current_channel;
  2577. spectral->classifier_params.upper_chan_in_mhz = 0;
  2578. } else if (spectral->ch_width == CH_WIDTH_40MHZ) {
  2579. /* TODO : Remove this variable */
  2580. spectral->sc_spectral_20_40_mode = 1;
  2581. spectral->spectral_numbins =
  2582. target_if_get_fft_bin_count(
  2583. spectral->params[smode].ss_fft_size);
  2584. spectral->spectral_fft_len =
  2585. target_if_get_fft_bin_count(
  2586. spectral->params[smode].ss_fft_size);
  2587. spectral->spectral_data_len =
  2588. target_if_get_fft_bin_count(
  2589. spectral->params[smode].ss_fft_size);
  2590. /*
  2591. * Initialize classifier params to be sent to user
  2592. * space classifier
  2593. */
  2594. if (extension_channel < current_channel) {
  2595. spectral->classifier_params.lower_chan_in_mhz =
  2596. extension_channel;
  2597. spectral->classifier_params.upper_chan_in_mhz =
  2598. current_channel;
  2599. } else {
  2600. spectral->classifier_params.lower_chan_in_mhz =
  2601. current_channel;
  2602. spectral->classifier_params.upper_chan_in_mhz =
  2603. extension_channel;
  2604. }
  2605. } else if (spectral->ch_width == CH_WIDTH_80MHZ) {
  2606. /* Set the FFT Size */
  2607. /* TODO : Remove this variable */
  2608. spectral->sc_spectral_20_40_mode = 0;
  2609. spectral->spectral_numbins =
  2610. target_if_get_fft_bin_count(
  2611. spectral->params[smode].ss_fft_size);
  2612. spectral->spectral_fft_len =
  2613. target_if_get_fft_bin_count(
  2614. spectral->params[smode].ss_fft_size);
  2615. spectral->spectral_data_len =
  2616. target_if_get_fft_bin_count(
  2617. spectral->params[smode].ss_fft_size);
  2618. /*
  2619. * Initialize classifier params to be sent to user
  2620. * space classifier
  2621. */
  2622. spectral->classifier_params.lower_chan_in_mhz =
  2623. current_channel;
  2624. spectral->classifier_params.upper_chan_in_mhz = 0;
  2625. /*
  2626. * Initialize classifier params to be sent to user
  2627. * space classifier
  2628. */
  2629. if (extension_channel < current_channel) {
  2630. spectral->classifier_params.lower_chan_in_mhz =
  2631. extension_channel;
  2632. spectral->classifier_params.upper_chan_in_mhz =
  2633. current_channel;
  2634. } else {
  2635. spectral->classifier_params.lower_chan_in_mhz =
  2636. current_channel;
  2637. spectral->classifier_params.upper_chan_in_mhz =
  2638. extension_channel;
  2639. }
  2640. } else if (spectral->ch_width == CH_WIDTH_160MHZ) {
  2641. /* Set the FFT Size */
  2642. /* The below applies to both 160 and 80+80 cases */
  2643. /* TODO : Remove this variable */
  2644. spectral->sc_spectral_20_40_mode = 0;
  2645. spectral->spectral_numbins =
  2646. target_if_get_fft_bin_count(
  2647. spectral->params[smode].ss_fft_size);
  2648. spectral->spectral_fft_len =
  2649. target_if_get_fft_bin_count(
  2650. spectral->params[smode].ss_fft_size);
  2651. spectral->spectral_data_len =
  2652. target_if_get_fft_bin_count(
  2653. spectral->params[smode].ss_fft_size);
  2654. /*
  2655. * Initialize classifier params to be sent to user
  2656. * space classifier
  2657. */
  2658. spectral->classifier_params.lower_chan_in_mhz =
  2659. current_channel;
  2660. spectral->classifier_params.upper_chan_in_mhz = 0;
  2661. /*
  2662. * Initialize classifier params to be sent to user
  2663. * space classifier
  2664. */
  2665. if (extension_channel < current_channel) {
  2666. spectral->classifier_params.lower_chan_in_mhz =
  2667. extension_channel;
  2668. spectral->classifier_params.upper_chan_in_mhz =
  2669. current_channel;
  2670. } else {
  2671. spectral->classifier_params.lower_chan_in_mhz =
  2672. current_channel;
  2673. spectral->classifier_params.upper_chan_in_mhz =
  2674. extension_channel;
  2675. }
  2676. }
  2677. if (spectral->spectral_numbins) {
  2678. spectral->spectral_numbins +=
  2679. spectral->lb_edge_extrabins;
  2680. spectral->spectral_numbins +=
  2681. spectral->rb_edge_extrabins;
  2682. }
  2683. if (spectral->spectral_fft_len) {
  2684. spectral->spectral_fft_len +=
  2685. spectral->lb_edge_extrabins;
  2686. spectral->spectral_fft_len +=
  2687. spectral->rb_edge_extrabins;
  2688. }
  2689. if (spectral->spectral_data_len) {
  2690. spectral->spectral_data_len +=
  2691. spectral->lb_edge_extrabins;
  2692. spectral->spectral_data_len +=
  2693. spectral->rb_edge_extrabins;
  2694. }
  2695. } else {
  2696. /*
  2697. * The decision to find 20/40 mode is found based on the
  2698. * presence of extension channel
  2699. * instead of channel width, as the channel width can
  2700. * dynamically change
  2701. */
  2702. if (extension_channel == 0) {
  2703. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  2704. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  2705. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  2706. spectral->spectral_data_len =
  2707. SPECTRAL_HT20_TOTAL_DATA_LEN;
  2708. /* only valid in 20-40 mode */
  2709. spectral->spectral_lower_max_index_offset = -1;
  2710. /* only valid in 20-40 mode */
  2711. spectral->spectral_upper_max_index_offset = -1;
  2712. spectral->spectral_max_index_offset =
  2713. spectral->spectral_fft_len + 2;
  2714. spectral->sc_spectral_20_40_mode = 0;
  2715. /*
  2716. * Initialize classifier params to be sent to user
  2717. * space classifier
  2718. */
  2719. spectral->classifier_params.lower_chan_in_mhz =
  2720. current_channel;
  2721. spectral->classifier_params.upper_chan_in_mhz = 0;
  2722. } else {
  2723. spectral->spectral_numbins =
  2724. SPECTRAL_HT40_TOTAL_NUM_BINS;
  2725. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  2726. spectral->spectral_data_len =
  2727. SPECTRAL_HT40_TOTAL_DATA_LEN;
  2728. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  2729. /* only valid in 20 mode */
  2730. spectral->spectral_max_index_offset = -1;
  2731. spectral->spectral_lower_max_index_offset =
  2732. spectral->spectral_fft_len + 2;
  2733. spectral->spectral_upper_max_index_offset =
  2734. spectral->spectral_fft_len + 5;
  2735. spectral->sc_spectral_20_40_mode = 1;
  2736. /*
  2737. * Initialize classifier params to be sent to user
  2738. * space classifier
  2739. */
  2740. if (extension_channel < current_channel) {
  2741. spectral->classifier_params.lower_chan_in_mhz =
  2742. extension_channel;
  2743. spectral->classifier_params.upper_chan_in_mhz =
  2744. current_channel;
  2745. } else {
  2746. spectral->classifier_params.lower_chan_in_mhz =
  2747. current_channel;
  2748. spectral->classifier_params.upper_chan_in_mhz =
  2749. extension_channel;
  2750. }
  2751. }
  2752. }
  2753. spectral->send_single_packet = 0;
  2754. spectral->classifier_params.spectral_20_40_mode =
  2755. spectral->sc_spectral_20_40_mode;
  2756. spectral->classifier_params.spectral_dc_index =
  2757. spectral->spectral_dc_index;
  2758. spectral->spectral_sent_msg = 0;
  2759. spectral->classify_scan = 0;
  2760. spectral->num_spectral_data = 0;
  2761. if (!p_sops->is_spectral_active(spectral, smode)) {
  2762. p_sops->configure_spectral(spectral, spectral_params, smode);
  2763. p_sops->start_spectral_scan(spectral, smode, err);
  2764. spectral->timestamp_war_offset[smode] = 0;
  2765. spectral->last_fft_timestamp[smode] = 0;
  2766. }
  2767. /* get current spectral configuration */
  2768. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  2769. target_if_init_upper_lower_flags(spectral);
  2770. return 0;
  2771. }
  2772. /**
  2773. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  2774. * Agile DFS
  2775. * @psoc: Pointer to psoc
  2776. * @object: Pointer to pdev
  2777. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  2778. *
  2779. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  2780. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  2781. *
  2782. * Return: void
  2783. */
  2784. static void
  2785. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  2786. void *object, void *arg)
  2787. {
  2788. bool *is_aspectral_prohibited = arg;
  2789. struct wlan_objmgr_pdev *cur_pdev = object;
  2790. bool is_agile_dfs_enabled_cur_pdev = false;
  2791. QDF_STATUS status;
  2792. qdf_assert_always(is_aspectral_prohibited);
  2793. if (*is_aspectral_prohibited)
  2794. return;
  2795. qdf_assert_always(psoc);
  2796. qdf_assert_always(cur_pdev);
  2797. status = ucfg_dfs_get_agile_precac_enable
  2798. (cur_pdev,
  2799. &is_agile_dfs_enabled_cur_pdev);
  2800. if (QDF_IS_STATUS_ERROR(status)) {
  2801. spectral_err("Get agile precac failed, prohibiting aSpectral");
  2802. *is_aspectral_prohibited = true;
  2803. return;
  2804. }
  2805. if (is_agile_dfs_enabled_cur_pdev) {
  2806. spectral_err("aDFS is in progress on one of the pdevs");
  2807. *is_aspectral_prohibited = true;
  2808. }
  2809. }
  2810. /**
  2811. * target_if_get_curr_band() - Get current operating band of pdev
  2812. *
  2813. * @spectral: pointer to spectral object
  2814. *
  2815. * API to get current operating band of a given pdev.
  2816. *
  2817. * Return: if success enum band_info, BAND_UNKNOWN in case of failure
  2818. */
  2819. static enum band_info
  2820. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev)
  2821. {
  2822. struct wlan_objmgr_vdev *vdev;
  2823. int16_t chan_freq;
  2824. enum band_info cur_band;
  2825. uint32_t chan_num;
  2826. if (!pdev) {
  2827. spectral_err("pdev is NULL");
  2828. return BAND_UNKNOWN;
  2829. }
  2830. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  2831. if (!vdev) {
  2832. spectral_debug("vdev is NULL");
  2833. return BAND_UNKNOWN;
  2834. }
  2835. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2836. chan_num = wlan_reg_freq_to_chan(pdev, chan_freq);
  2837. cur_band = wlan_reg_chan_to_band(chan_num);
  2838. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2839. return cur_band;
  2840. }
  2841. /**
  2842. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  2843. * any of the 5G pdevs
  2844. * @psoc: Pointer to psoc
  2845. * @object: Pointer to pdev
  2846. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  2847. * progress in any 5G pdevs
  2848. *
  2849. * Return: void
  2850. */
  2851. static void
  2852. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  2853. void *object, void *arg)
  2854. {
  2855. enum band_info band;
  2856. bool *is_agile_scan_inprog_5g_pdev = arg;
  2857. struct target_if_spectral *spectral;
  2858. struct wlan_objmgr_pdev *cur_pdev = object;
  2859. struct target_if_spectral_ops *p_sops;
  2860. if (*is_agile_scan_inprog_5g_pdev)
  2861. return;
  2862. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  2863. if (!spectral) {
  2864. spectral_err("target if spectral handle is NULL");
  2865. return;
  2866. }
  2867. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2868. band = target_if_get_curr_band(cur_pdev);
  2869. if (band == BAND_UNKNOWN) {
  2870. spectral_debug("Failed to get current band");
  2871. return;
  2872. }
  2873. if (band == BAND_5G &&
  2874. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  2875. *is_agile_scan_inprog_5g_pdev = true;
  2876. }
  2877. QDF_STATUS
  2878. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  2879. const enum spectral_scan_mode smode,
  2880. enum spectral_cp_error_code *err)
  2881. {
  2882. struct target_if_spectral_ops *p_sops;
  2883. struct target_if_spectral *spectral;
  2884. struct wlan_objmgr_psoc *psoc;
  2885. enum band_info band;
  2886. if (!err) {
  2887. spectral_err("Error code argument is null");
  2888. QDF_ASSERT(0);
  2889. }
  2890. *err = SPECTRAL_SCAN_ERR_INVALID;
  2891. psoc = wlan_pdev_get_psoc(pdev);
  2892. if (!psoc) {
  2893. spectral_err("psoc is null");
  2894. return QDF_STATUS_E_FAILURE;
  2895. }
  2896. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2897. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2898. spectral_err("Invalid Spectral mode %u", smode);
  2899. return QDF_STATUS_E_FAILURE;
  2900. }
  2901. if (!pdev) {
  2902. spectral_err("pdev object is NUll");
  2903. return QDF_STATUS_E_FAILURE;
  2904. }
  2905. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2906. if (!spectral) {
  2907. spectral_err("Spectral LMAC object is NUll");
  2908. return QDF_STATUS_E_FAILURE;
  2909. }
  2910. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2911. band = target_if_get_curr_band(spectral->pdev_obj);
  2912. if (band == BAND_UNKNOWN) {
  2913. spectral_err("Failed to get current band");
  2914. return QDF_STATUS_E_FAILURE;
  2915. }
  2916. if ((band == BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  2917. struct target_psoc_info *tgt_hdl;
  2918. enum wmi_host_hw_mode_config_type mode;
  2919. bool is_agile_scan_inprog_5g_pdev;
  2920. if (p_sops->is_spectral_active(spectral,
  2921. SPECTRAL_SCAN_MODE_AGILE)) {
  2922. spectral_err("Agile Scan in progress in current pdev");
  2923. return QDF_STATUS_E_FAILURE;
  2924. }
  2925. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  2926. if (!tgt_hdl) {
  2927. target_if_err("target_psoc_info is null");
  2928. return QDF_STATUS_E_FAILURE;
  2929. }
  2930. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  2931. switch (mode) {
  2932. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  2933. case WMI_HOST_HW_MODE_SBS:
  2934. case WMI_HOST_HW_MODE_DBS_SBS:
  2935. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  2936. is_agile_scan_inprog_5g_pdev = false;
  2937. wlan_objmgr_iterate_obj_list
  2938. (psoc, WLAN_PDEV_OP,
  2939. target_if_is_agile_scan_active_in_5g,
  2940. &is_agile_scan_inprog_5g_pdev, 0,
  2941. WLAN_SPECTRAL_ID);
  2942. break;
  2943. default:
  2944. is_agile_scan_inprog_5g_pdev = false;
  2945. break;
  2946. }
  2947. if (is_agile_scan_inprog_5g_pdev) {
  2948. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  2949. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2950. return QDF_STATUS_E_FAILURE;
  2951. }
  2952. }
  2953. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  2954. bool is_aspectral_prohibited = false;
  2955. QDF_STATUS status;
  2956. status = wlan_objmgr_iterate_obj_list
  2957. (psoc, WLAN_PDEV_OP,
  2958. target_if_is_aspectral_prohibited_by_adfs,
  2959. &is_aspectral_prohibited, 0,
  2960. WLAN_SPECTRAL_ID);
  2961. if (QDF_IS_STATUS_ERROR(status)) {
  2962. spectral_err("Failed to iterate over pdevs");
  2963. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2964. return QDF_STATUS_E_FAILURE;
  2965. }
  2966. if (is_aspectral_prohibited) {
  2967. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2968. return QDF_STATUS_E_FAILURE;
  2969. }
  2970. }
  2971. if (!spectral->params_valid[smode]) {
  2972. target_if_spectral_info_read(spectral,
  2973. smode,
  2974. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2975. &spectral->params[smode],
  2976. sizeof(spectral->params[smode]));
  2977. spectral->params_valid[smode] = true;
  2978. }
  2979. qdf_spin_lock(&spectral->spectral_lock);
  2980. if (smode == SPECTRAL_SCAN_MODE_AGILE &&
  2981. !spectral->params[smode].ss_frequency) {
  2982. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  2983. qdf_spin_unlock(&spectral->spectral_lock);
  2984. return QDF_STATUS_E_FAILURE;
  2985. }
  2986. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  2987. QDF_STATUS status;
  2988. bool is_overlapping;
  2989. status = target_if_is_agile_span_overlap_with_operating_span
  2990. (spectral,
  2991. spectral->params[smode].ss_frequency,
  2992. &is_overlapping);
  2993. if (QDF_IS_STATUS_ERROR(status)) {
  2994. qdf_spin_unlock(&spectral->spectral_lock);
  2995. return QDF_STATUS_E_FAILURE;
  2996. }
  2997. if (is_overlapping) {
  2998. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2999. qdf_spin_unlock(&spectral->spectral_lock);
  3000. return QDF_STATUS_E_FAILURE;
  3001. }
  3002. }
  3003. target_if_spectral_scan_enable_params(spectral,
  3004. &spectral->params[smode], smode,
  3005. err);
  3006. qdf_spin_unlock(&spectral->spectral_lock);
  3007. return QDF_STATUS_SUCCESS;
  3008. }
  3009. QDF_STATUS
  3010. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3011. const enum spectral_scan_mode smode,
  3012. enum spectral_cp_error_code *err)
  3013. {
  3014. struct target_if_spectral_ops *p_sops;
  3015. struct target_if_spectral *spectral;
  3016. if (!err) {
  3017. spectral_err("Error code argument is null");
  3018. QDF_ASSERT(0);
  3019. }
  3020. *err = SPECTRAL_SCAN_ERR_INVALID;
  3021. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3022. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3023. spectral_err("Invalid Spectral mode %u", smode);
  3024. return QDF_STATUS_E_FAILURE;
  3025. }
  3026. if (!pdev) {
  3027. spectral_err("pdev object is NUll ");
  3028. return QDF_STATUS_E_FAILURE;
  3029. }
  3030. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3031. if (!spectral) {
  3032. spectral_err("Spectral LMAC object is NUll ");
  3033. return QDF_STATUS_E_FAILURE;
  3034. }
  3035. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3036. qdf_spin_lock(&spectral->spectral_lock);
  3037. p_sops->stop_spectral_scan(spectral, smode);
  3038. if (spectral->classify_scan) {
  3039. /* TODO : Check if this logic is necessary */
  3040. spectral->detects_control_channel = 0;
  3041. spectral->detects_extension_channel = 0;
  3042. spectral->detects_above_dc = 0;
  3043. spectral->detects_below_dc = 0;
  3044. spectral->classify_scan = 0;
  3045. }
  3046. spectral->send_single_packet = 0;
  3047. spectral->sc_spectral_scan = 0;
  3048. qdf_spin_unlock(&spectral->spectral_lock);
  3049. return QDF_STATUS_SUCCESS;
  3050. }
  3051. /**
  3052. * target_if_is_spectral_active() - Get whether Spectral is active
  3053. * @pdev: Pointer to pdev object
  3054. * @smode: Spectral scan mode
  3055. *
  3056. * API to get whether Spectral is active
  3057. *
  3058. * Return: True if Spectral is active, false if Spectral is not active
  3059. */
  3060. bool
  3061. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  3062. const enum spectral_scan_mode smode)
  3063. {
  3064. struct target_if_spectral *spectral = NULL;
  3065. struct target_if_spectral_ops *p_sops = NULL;
  3066. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3067. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3068. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3069. spectral_err("Invalid Spectral mode %u", smode);
  3070. return QDF_STATUS_E_FAILURE;
  3071. }
  3072. return p_sops->is_spectral_active(spectral, smode);
  3073. }
  3074. /**
  3075. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  3076. * @pdev: Pointer to pdev object
  3077. * @smode: Spectral scan mode
  3078. *
  3079. * API to get whether Spectral is enabled
  3080. *
  3081. * Return: True if Spectral is enabled, false if Spectral is not enabled
  3082. */
  3083. bool
  3084. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  3085. enum spectral_scan_mode smode)
  3086. {
  3087. struct target_if_spectral *spectral = NULL;
  3088. struct target_if_spectral_ops *p_sops = NULL;
  3089. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3090. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3091. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3092. spectral_err("Invalid Spectral mode %u", smode);
  3093. return QDF_STATUS_E_FAILURE;
  3094. }
  3095. return p_sops->is_spectral_enabled(spectral, smode);
  3096. }
  3097. /**
  3098. * target_if_set_debug_level() - Set debug level for Spectral
  3099. * @pdev: Pointer to pdev object
  3100. * @debug_level: Debug level
  3101. *
  3102. * API to set the debug level for Spectral
  3103. *
  3104. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3105. */
  3106. QDF_STATUS
  3107. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  3108. {
  3109. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  3110. return QDF_STATUS_SUCCESS;
  3111. }
  3112. /**
  3113. * target_if_get_debug_level() - Get debug level for Spectral
  3114. * @pdev: Pointer to pdev object
  3115. *
  3116. * API to get the debug level for Spectral
  3117. *
  3118. * Return: Current debug level
  3119. */
  3120. uint32_t
  3121. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  3122. {
  3123. return spectral_debug_level;
  3124. }
  3125. /**
  3126. * target_if_get_spectral_capinfo() - Get Spectral capability information
  3127. * @pdev: Pointer to pdev object
  3128. * @scaps: Buffer into which data should be copied
  3129. *
  3130. * API to get the spectral capability information
  3131. *
  3132. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3133. */
  3134. QDF_STATUS
  3135. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  3136. struct spectral_caps *scaps)
  3137. {
  3138. struct target_if_spectral *spectral = NULL;
  3139. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3140. qdf_mem_copy(scaps, &spectral->capability,
  3141. sizeof(struct spectral_caps));
  3142. return QDF_STATUS_SUCCESS;
  3143. }
  3144. /**
  3145. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  3146. * @pdev: Pointer to pdev object
  3147. * @stats: Buffer into which data should be copied
  3148. *
  3149. * API to get the spectral diagnostic statistics
  3150. *
  3151. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3152. */
  3153. QDF_STATUS
  3154. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  3155. struct spectral_diag_stats *stats)
  3156. {
  3157. struct target_if_spectral *spectral = NULL;
  3158. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3159. qdf_mem_copy(stats, &spectral->diag_stats,
  3160. sizeof(struct spectral_diag_stats));
  3161. return QDF_STATUS_SUCCESS;
  3162. }
  3163. /**
  3164. * target_if_register_wmi_spectral_cmd_ops() - Register wmi_spectral_cmd_ops
  3165. * @cmd_ops: Pointer to the structure having wmi_spectral_cmd function pointers
  3166. * @pdev: Pointer to pdev object
  3167. *
  3168. * API for register wmi_spectral_cmd_ops in spectral internal data structure
  3169. *
  3170. * Return: void
  3171. */
  3172. void
  3173. target_if_register_wmi_spectral_cmd_ops(struct wlan_objmgr_pdev *pdev,
  3174. struct wmi_spectral_cmd_ops *cmd_ops)
  3175. {
  3176. struct target_if_spectral *spectral =
  3177. get_target_if_spectral_handle_from_pdev(pdev);
  3178. if (!spectral) {
  3179. spectral_err("Spectral LMAC object is null");
  3180. return;
  3181. }
  3182. spectral->param_wmi_cmd_ops = *cmd_ops;
  3183. }
  3184. /**
  3185. * target_if_register_netlink_cb() - Register Netlink callbacks
  3186. * @pdev: Pointer to pdev object
  3187. * @nl_cb: Netlink callbacks to register
  3188. *
  3189. * Return: void
  3190. */
  3191. static void
  3192. target_if_register_netlink_cb(
  3193. struct wlan_objmgr_pdev *pdev,
  3194. struct spectral_nl_cb *nl_cb)
  3195. {
  3196. struct target_if_spectral *spectral = NULL;
  3197. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3198. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  3199. if (spectral->use_nl_bcast)
  3200. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  3201. else
  3202. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  3203. }
  3204. /**
  3205. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  3206. * Netlink messages to the application layer
  3207. * @pdev: Pointer to pdev object
  3208. *
  3209. * Return: true for broadcast, false for unicast
  3210. */
  3211. static bool
  3212. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  3213. {
  3214. struct target_if_spectral *spectral = NULL;
  3215. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3216. return spectral->use_nl_bcast;
  3217. }
  3218. /**
  3219. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  3220. * @pdev: Pointer to pdev object
  3221. *
  3222. * Return: void
  3223. */
  3224. static void
  3225. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  3226. {
  3227. struct target_if_spectral *spectral = NULL;
  3228. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3229. if (!spectral) {
  3230. spectral_err("SPECTRAL : Module doesn't exist");
  3231. return;
  3232. }
  3233. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  3234. }
  3235. static int
  3236. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  3237. void *payload)
  3238. {
  3239. struct target_if_spectral *spectral = NULL;
  3240. struct target_if_spectral_ops *p_sops = NULL;
  3241. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3242. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3243. return p_sops->process_spectral_report(pdev, payload);
  3244. }
  3245. void
  3246. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3247. {
  3248. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  3249. target_if_pdev_spectral_init;
  3250. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  3251. target_if_pdev_spectral_deinit;
  3252. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  3253. target_if_set_spectral_config;
  3254. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  3255. target_if_get_spectral_config;
  3256. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  3257. target_if_start_spectral_scan;
  3258. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  3259. target_if_stop_spectral_scan;
  3260. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  3261. target_if_is_spectral_active;
  3262. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  3263. target_if_is_spectral_enabled;
  3264. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  3265. target_if_set_debug_level;
  3266. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  3267. target_if_get_debug_level;
  3268. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  3269. target_if_get_spectral_capinfo;
  3270. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  3271. target_if_get_spectral_diagstats;
  3272. tx_ops->sptrl_tx_ops.sptrlto_register_wmi_spectral_cmd_ops =
  3273. target_if_register_wmi_spectral_cmd_ops;
  3274. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  3275. target_if_register_netlink_cb;
  3276. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  3277. target_if_use_nl_bcast;
  3278. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  3279. target_if_deregister_netlink_cb;
  3280. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  3281. target_if_process_spectral_report;
  3282. }
  3283. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  3284. void
  3285. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  3286. uint16_t cw_int, uint32_t dcs_enabled)
  3287. {
  3288. struct spectral_samp_msg *msg = NULL;
  3289. struct target_if_spectral_ops *p_sops = NULL;
  3290. struct target_if_spectral *spectral = NULL;
  3291. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3292. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  3293. spectral->pdev_obj,
  3294. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  3295. SPECTRAL_MSG_BUF_NEW);
  3296. if (msg) {
  3297. msg->int_type = cw_int ?
  3298. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  3299. msg->dcs_enabled = dcs_enabled;
  3300. msg->signature = SPECTRAL_SIGNATURE;
  3301. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3302. p_sops->get_mac_address(spectral, msg->macaddr);
  3303. if (spectral->send_phy_data
  3304. (pdev,
  3305. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  3306. spectral->spectral_sent_msg++;
  3307. }
  3308. }
  3309. qdf_export_symbol(target_if_spectral_send_intf_found_msg);