target_if_spectral.c 105 KB

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