target_if_spectral.c 123 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461
  1. /*
  2. * Copyright (c) 2011,2017-2020 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_min_max() - Initialize Spectral parameter
  1157. * min and max values
  1158. *
  1159. * @param_min_max: Pointer to Spectral parameter min and max structure
  1160. * @gen: Spectral HW generation
  1161. * @target_type: Target type
  1162. *
  1163. * Initialize Spectral parameter min and max values
  1164. *
  1165. * Return: QDF_STATUS
  1166. */
  1167. static QDF_STATUS
  1168. target_if_init_spectral_param_min_max(
  1169. struct spectral_param_min_max *param_min_max,
  1170. enum spectral_gen gen, uint32_t target_type)
  1171. {
  1172. switch (gen) {
  1173. case SPECTRAL_GEN3:
  1174. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3;
  1175. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1176. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1177. if (target_type == TARGET_TYPE_QCN9000) {
  1178. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1179. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1180. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1181. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1182. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1183. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1184. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1185. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1186. } else {
  1187. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1188. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1189. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1190. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1191. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1192. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1193. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1194. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1195. }
  1196. break;
  1197. case SPECTRAL_GEN2:
  1198. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1199. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1200. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1201. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1202. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1203. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1204. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1205. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1206. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1207. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1208. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1209. break;
  1210. default:
  1211. spectral_err("Invalid spectral generation %d", gen);
  1212. return QDF_STATUS_E_INVAL;
  1213. }
  1214. return QDF_STATUS_SUCCESS;
  1215. }
  1216. /**
  1217. * target_if_init_spectral_param_properties() - Initialize Spectral parameter
  1218. * properties
  1219. * @spectral: Pointer to Spectral target_if internal private data
  1220. *
  1221. * Initialize Spectral parameter properties
  1222. *
  1223. * Return: QDF_STATUS
  1224. */
  1225. static QDF_STATUS
  1226. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1227. {
  1228. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1229. int param;
  1230. /* Initialize default values for properties.
  1231. * Default values are supported for all the parameters for all modes
  1232. * and allows different values for each mode for all the parameters .
  1233. */
  1234. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1235. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1236. spectral->properties[smode][param].supported = true;
  1237. spectral->properties[smode][param].common_all_modes =
  1238. false;
  1239. }
  1240. }
  1241. /* Once FW advertisement is in place remove this hard coding */
  1242. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1243. spectral->properties[SPECTRAL_SCAN_MODE_NORMAL]
  1244. [SPECTRAL_PARAM_FREQUENCY].supported = false;
  1245. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1246. spectral->properties[smode]
  1247. [SPECTRAL_PARAM_SPECT_PRI].common_all_modes = true;
  1248. spectral->properties[smode]
  1249. [SPECTRAL_PARAM_SCAN_PERIOD].common_all_modes = true;
  1250. spectral->properties[smode]
  1251. [SPECTRAL_PARAM_INIT_DELAY].common_all_modes = true;
  1252. }
  1253. return QDF_STATUS_SUCCESS;
  1254. }
  1255. /**
  1256. * target_if_init_spectral_capability() - Initialize Spectral capability
  1257. * @spectral: Pointer to Spectral target_if internal private data
  1258. *
  1259. * This is a workaround.
  1260. *
  1261. * Return: QDF_STATUS
  1262. */
  1263. QDF_STATUS
  1264. target_if_init_spectral_capability(struct target_if_spectral *spectral)
  1265. {
  1266. struct wlan_objmgr_psoc *psoc;
  1267. struct wlan_objmgr_pdev *pdev;
  1268. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  1269. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  1270. struct target_psoc_info *tgt_psoc_info;
  1271. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  1272. struct spectral_caps *pcap = &spectral->capability;
  1273. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  1274. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  1275. struct wlan_psoc_host_chainmask_table *table;
  1276. int j;
  1277. uint32_t table_id;
  1278. pdev = spectral->pdev_obj;
  1279. psoc = wlan_pdev_get_psoc(pdev);
  1280. if (!psoc) {
  1281. spectral_err("psoc is null");
  1282. return QDF_STATUS_E_FAILURE;
  1283. }
  1284. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  1285. if (!tgt_psoc_info) {
  1286. spectral_err("target_psoc_info is null");
  1287. return QDF_STATUS_E_FAILURE;
  1288. }
  1289. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  1290. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  1291. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  1292. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  1293. /* XXX : Workaround: Set Spectral capability */
  1294. pcap = &spectral->capability;
  1295. pcap->phydiag_cap = 1;
  1296. pcap->radar_cap = 1;
  1297. pcap->spectral_cap = 1;
  1298. pcap->advncd_spectral_cap = 1;
  1299. pcap->hw_gen = spectral->spectral_gen;
  1300. if (spectral->spectral_gen >= SPECTRAL_GEN3) {
  1301. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  1302. if (!mac_phy_cap_arr) {
  1303. spectral_err("mac phy cap array is null");
  1304. return QDF_STATUS_E_FAILURE;
  1305. }
  1306. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  1307. if (!mac_phy_cap) {
  1308. spectral_err("mac phy cap is null");
  1309. return QDF_STATUS_E_FAILURE;
  1310. }
  1311. table_id = mac_phy_cap->chainmask_table_id;
  1312. table = &ext_svc_param->chainmask_table[table_id];
  1313. if (!table) {
  1314. spectral_err("chainmask table not found");
  1315. return QDF_STATUS_E_FAILURE;
  1316. }
  1317. for (j = 0; j < table->num_valid_chainmasks; j++) {
  1318. pcap->agile_spectral_cap |=
  1319. table->cap_list[j].supports_aSpectral;
  1320. pcap->agile_spectral_cap_160 |=
  1321. table->cap_list[j].supports_aSpectral_160;
  1322. }
  1323. pcap->agile_spectral_cap_80p80 = pcap->agile_spectral_cap_160;
  1324. } else {
  1325. pcap->agile_spectral_cap = false;
  1326. pcap->agile_spectral_cap_160 = false;
  1327. pcap->agile_spectral_cap_80p80 = false;
  1328. }
  1329. for (param_idx = 0; param_idx < num_bin_scaling_params; param_idx++) {
  1330. if (scaling_params[param_idx].pdev_id == pdev_id) {
  1331. pcap->is_scaling_params_populated = true;
  1332. pcap->formula_id = scaling_params[param_idx].formula_id;
  1333. pcap->low_level_offset =
  1334. scaling_params[param_idx].low_level_offset;
  1335. pcap->high_level_offset =
  1336. scaling_params[param_idx].high_level_offset;
  1337. pcap->rssi_thr = scaling_params[param_idx].rssi_thr;
  1338. pcap->default_agc_max_gain =
  1339. scaling_params[param_idx].default_agc_max_gain;
  1340. break;
  1341. }
  1342. }
  1343. return QDF_STATUS_SUCCESS;
  1344. }
  1345. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1346. /**
  1347. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1348. * internal operations with functions related to spectral simulation
  1349. * @p_sops: spectral low level ops table
  1350. *
  1351. * Initialize spectral target_if internal operations with functions
  1352. * related to spectral simulation
  1353. *
  1354. * Return: None
  1355. */
  1356. static void
  1357. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1358. {
  1359. /*
  1360. * Spectral simulation is currently intended for platform transitions
  1361. * where underlying HW support may not be available for some time.
  1362. * Hence, we do not currently provide a runtime switch to turn the
  1363. * simulation on or off.
  1364. * In case of future requirements where runtime switches are required,
  1365. * this can be added. But it is suggested to use application layer
  1366. * simulation as far as possible in such cases, since the main
  1367. * use of record and replay of samples would concern higher
  1368. * level sample processing rather than lower level delivery.
  1369. */
  1370. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  1371. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  1372. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  1373. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  1374. p_sops->configure_spectral =
  1375. target_if_spectral_sops_sim_configure_params;
  1376. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  1377. }
  1378. #else
  1379. /**
  1380. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1381. * internal operations
  1382. * @p_sops: spectral low level ops table
  1383. *
  1384. * Return: None
  1385. */
  1386. static void
  1387. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1388. {
  1389. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  1390. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  1391. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  1392. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  1393. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  1394. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  1395. }
  1396. #endif
  1397. /**
  1398. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  1399. * operations common to all Spectral chipset generations
  1400. *
  1401. * Initializes target_if_spectral_ops common to all chipset generations
  1402. *
  1403. * Return: None
  1404. */
  1405. static void
  1406. target_if_init_spectral_ops_common(void)
  1407. {
  1408. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1409. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  1410. p_sops->get_capability = target_if_spectral_get_capability;
  1411. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  1412. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  1413. target_if_init_spectral_simulation_ops(p_sops);
  1414. p_sops->get_extension_channel =
  1415. target_if_spectral_get_extension_channel;
  1416. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  1417. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  1418. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  1419. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  1420. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  1421. p_sops->reset_hw = target_if_spectral_reset_hw;
  1422. p_sops->get_chain_noise_floor =
  1423. target_if_spectral_get_chain_noise_floor;
  1424. }
  1425. /**
  1426. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  1427. * operations specific to Spectral chipset generation 2.
  1428. *
  1429. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  1430. *
  1431. * Return: None
  1432. */
  1433. static void
  1434. target_if_init_spectral_ops_gen2(void)
  1435. {
  1436. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1437. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  1438. }
  1439. /**
  1440. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  1441. * operations specific to Spectral chipset generation 3.
  1442. *
  1443. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  1444. *
  1445. * Return: None
  1446. */
  1447. static void
  1448. target_if_init_spectral_ops_gen3(void)
  1449. {
  1450. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1451. p_sops->process_spectral_report =
  1452. target_if_spectral_process_report_gen3;
  1453. return;
  1454. }
  1455. /**
  1456. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  1457. * operations.
  1458. * @spectral: Pointer to Spectral target_if internal private data
  1459. *
  1460. * Initializes all function pointers in target_if_spectral_ops for
  1461. * all generations
  1462. *
  1463. * Return: None
  1464. */
  1465. static void
  1466. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  1467. {
  1468. target_if_init_spectral_ops_common();
  1469. if (spectral->spectral_gen == SPECTRAL_GEN2)
  1470. target_if_init_spectral_ops_gen2();
  1471. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  1472. target_if_init_spectral_ops_gen3();
  1473. else
  1474. spectral_err("Invalid Spectral generation");
  1475. }
  1476. /*
  1477. * Dummy Functions:
  1478. * These functions are initially registered to avoid any crashes due to
  1479. * invocation of spectral functions before they are registered.
  1480. */
  1481. static uint64_t
  1482. null_get_tsf64(void *arg)
  1483. {
  1484. spectral_ops_not_registered("get_tsf64");
  1485. return 0;
  1486. }
  1487. static uint32_t
  1488. null_get_capability(void *arg, enum spectral_capability_type type)
  1489. {
  1490. /*
  1491. * TODO : We should have conditional compilation to get the capability
  1492. * : We have not yet attahced ATH layer here, so there is no
  1493. * : way to check the HAL capbalities
  1494. */
  1495. spectral_ops_not_registered("get_capability");
  1496. /* TODO : For the time being, we are returning TRUE */
  1497. return true;
  1498. }
  1499. static uint32_t
  1500. null_set_rxfilter(void *arg, int rxfilter)
  1501. {
  1502. spectral_ops_not_registered("set_rxfilter");
  1503. return 1;
  1504. }
  1505. static uint32_t
  1506. null_get_rxfilter(void *arg)
  1507. {
  1508. spectral_ops_not_registered("get_rxfilter");
  1509. return 0;
  1510. }
  1511. static uint32_t
  1512. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  1513. {
  1514. spectral_ops_not_registered("is_spectral_active");
  1515. return 1;
  1516. }
  1517. static uint32_t
  1518. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  1519. {
  1520. spectral_ops_not_registered("is_spectral_enabled");
  1521. return 1;
  1522. }
  1523. static uint32_t
  1524. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  1525. enum spectral_cp_error_code *err)
  1526. {
  1527. spectral_ops_not_registered("start_spectral_scan");
  1528. return 1;
  1529. }
  1530. static uint32_t
  1531. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  1532. {
  1533. spectral_ops_not_registered("stop_spectral_scan");
  1534. return 1;
  1535. }
  1536. static uint32_t
  1537. null_get_extension_channel(void *arg)
  1538. {
  1539. spectral_ops_not_registered("get_extension_channel");
  1540. return 1;
  1541. }
  1542. static int8_t
  1543. null_get_ctl_noisefloor(void *arg)
  1544. {
  1545. spectral_ops_not_registered("get_ctl_noisefloor");
  1546. return 1;
  1547. }
  1548. static int8_t
  1549. null_get_ext_noisefloor(void *arg)
  1550. {
  1551. spectral_ops_not_registered("get_ext_noisefloor");
  1552. return 0;
  1553. }
  1554. static uint32_t
  1555. null_configure_spectral(void *arg, struct spectral_config *params,
  1556. enum spectral_scan_mode smode)
  1557. {
  1558. spectral_ops_not_registered("configure_spectral");
  1559. return 0;
  1560. }
  1561. static uint32_t
  1562. null_get_spectral_config(void *arg, struct spectral_config *params,
  1563. enum spectral_scan_mode smode)
  1564. {
  1565. spectral_ops_not_registered("get_spectral_config");
  1566. return 0;
  1567. }
  1568. static uint32_t
  1569. null_get_ent_spectral_mask(void *arg)
  1570. {
  1571. spectral_ops_not_registered("get_ent_spectral_mask");
  1572. return 0;
  1573. }
  1574. static uint32_t
  1575. null_get_mac_address(void *arg, char *addr)
  1576. {
  1577. spectral_ops_not_registered("get_mac_address");
  1578. return 0;
  1579. }
  1580. static uint32_t
  1581. null_get_current_channel(void *arg)
  1582. {
  1583. spectral_ops_not_registered("get_current_channel");
  1584. return 0;
  1585. }
  1586. static uint32_t
  1587. null_reset_hw(void *arg)
  1588. {
  1589. spectral_ops_not_registered("get_current_channel");
  1590. return 0;
  1591. }
  1592. static uint32_t
  1593. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1594. {
  1595. spectral_ops_not_registered("get_chain_noise_floor");
  1596. return 0;
  1597. }
  1598. static int
  1599. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  1600. uint8_t *data,
  1601. uint32_t datalen,
  1602. struct target_if_spectral_rfqual_info *p_rfqual,
  1603. struct target_if_spectral_chan_info *p_chaninfo,
  1604. uint64_t tsf64,
  1605. struct target_if_spectral_acs_stats *acs_stats)
  1606. {
  1607. spectral_ops_not_registered("spectral_process_phyerr");
  1608. return 0;
  1609. }
  1610. static int
  1611. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  1612. void *payload)
  1613. {
  1614. spectral_ops_not_registered("process_spectral_report");
  1615. return 0;
  1616. }
  1617. /**
  1618. * target_if_spectral_init_dummy_function_table() -
  1619. * Initialize target_if internal
  1620. * Spectral operations to dummy functions
  1621. * @ps: Pointer to Spectral target_if internal private data
  1622. *
  1623. * Initialize all the function pointers in target_if_spectral_ops with
  1624. * dummy functions.
  1625. *
  1626. * Return: None
  1627. */
  1628. static void
  1629. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  1630. {
  1631. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  1632. p_sops->get_tsf64 = null_get_tsf64;
  1633. p_sops->get_capability = null_get_capability;
  1634. p_sops->set_rxfilter = null_set_rxfilter;
  1635. p_sops->get_rxfilter = null_get_rxfilter;
  1636. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  1637. p_sops->is_spectral_active = null_is_spectral_active;
  1638. p_sops->start_spectral_scan = null_start_spectral_scan;
  1639. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  1640. p_sops->get_extension_channel = null_get_extension_channel;
  1641. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  1642. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  1643. p_sops->configure_spectral = null_configure_spectral;
  1644. p_sops->get_spectral_config = null_get_spectral_config;
  1645. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  1646. p_sops->get_mac_address = null_get_mac_address;
  1647. p_sops->get_current_channel = null_get_current_channel;
  1648. p_sops->reset_hw = null_reset_hw;
  1649. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  1650. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  1651. p_sops->process_spectral_report = null_process_spectral_report;
  1652. }
  1653. /**
  1654. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  1655. * operations
  1656. * @spectral: Pointer to Spectral target_if internal private data
  1657. * @p: Pointer to Spectral function table
  1658. *
  1659. * Return: None
  1660. */
  1661. static void
  1662. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  1663. struct target_if_spectral_ops *p)
  1664. {
  1665. struct target_if_spectral_ops *p_sops =
  1666. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1667. p_sops->get_tsf64 = p->get_tsf64;
  1668. p_sops->get_capability = p->get_capability;
  1669. p_sops->set_rxfilter = p->set_rxfilter;
  1670. p_sops->get_rxfilter = p->get_rxfilter;
  1671. p_sops->is_spectral_enabled = p->is_spectral_enabled;
  1672. p_sops->is_spectral_active = p->is_spectral_active;
  1673. p_sops->start_spectral_scan = p->start_spectral_scan;
  1674. p_sops->stop_spectral_scan = p->stop_spectral_scan;
  1675. p_sops->get_extension_channel = p->get_extension_channel;
  1676. p_sops->get_ctl_noisefloor = p->get_ctl_noisefloor;
  1677. p_sops->get_ext_noisefloor = p->get_ext_noisefloor;
  1678. p_sops->configure_spectral = p->configure_spectral;
  1679. p_sops->get_spectral_config = p->get_spectral_config;
  1680. p_sops->get_ent_spectral_mask = p->get_ent_spectral_mask;
  1681. p_sops->get_mac_address = p->get_mac_address;
  1682. p_sops->get_current_channel = p->get_current_channel;
  1683. p_sops->reset_hw = p->reset_hw;
  1684. p_sops->get_chain_noise_floor = p->get_chain_noise_floor;
  1685. p_sops->spectral_process_phyerr = p->spectral_process_phyerr;
  1686. p_sops->process_spectral_report = p->process_spectral_report;
  1687. }
  1688. /**
  1689. * target_if_spectral_clear_stats() - Clear Spectral stats
  1690. * @spectral: Pointer to Spectral target_if internal private data
  1691. *
  1692. * Function to clear spectral stats
  1693. *
  1694. * Return: None
  1695. */
  1696. static void
  1697. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  1698. {
  1699. struct target_if_spectral_ops *p_sops =
  1700. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1701. qdf_mem_zero(&spectral->spectral_stats,
  1702. sizeof(struct target_if_spectral_stats));
  1703. spectral->spectral_stats.last_reset_tstamp =
  1704. p_sops->get_tsf64(spectral);
  1705. }
  1706. /**
  1707. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  1708. * @spectral: Pointer to Spectral target_if internal private data
  1709. *
  1710. * Function to check whether hardware supports spectral
  1711. *
  1712. * Return: True if HW supports Spectral, false if HW does not support Spectral
  1713. */
  1714. static int
  1715. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  1716. {
  1717. struct target_if_spectral_ops *p_sops = NULL;
  1718. struct spectral_caps *pcap = NULL;
  1719. int is_spectral_supported = true;
  1720. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1721. pcap = &spectral->capability;
  1722. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  1723. is_spectral_supported = false;
  1724. spectral_info("SPECTRAL : No PHYDIAG support");
  1725. return is_spectral_supported;
  1726. }
  1727. pcap->phydiag_cap = 1;
  1728. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  1729. is_spectral_supported = false;
  1730. spectral_info("SPECTRAL : No RADAR support");
  1731. return is_spectral_supported;
  1732. }
  1733. pcap->radar_cap = 1;
  1734. if (p_sops->get_capability(spectral,
  1735. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  1736. is_spectral_supported = false;
  1737. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  1738. return is_spectral_supported;
  1739. }
  1740. pcap->spectral_cap = 1;
  1741. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  1742. == false) {
  1743. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  1744. } else {
  1745. pcap->advncd_spectral_cap = 1;
  1746. }
  1747. return is_spectral_supported;
  1748. }
  1749. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1750. /**
  1751. * target_if_spectral_detach_simulation() - De-initialize Spectral
  1752. * Simulation functionality
  1753. * @spectral: Pointer to Spectral target_if internal private data
  1754. *
  1755. * Function to de-initialize Spectral Simulation functionality
  1756. *
  1757. * Return: None
  1758. */
  1759. static void
  1760. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1761. {
  1762. target_if_spectral_sim_detach(spectral);
  1763. }
  1764. #else
  1765. static void
  1766. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1767. {
  1768. }
  1769. #endif
  1770. /**
  1771. * target_if_spectral_detach() - De-initialize target_if Spectral
  1772. * @pdev: Pointer to pdev object
  1773. *
  1774. * Function to detach target_if spectral
  1775. *
  1776. * Return: None
  1777. */
  1778. static void
  1779. target_if_spectral_detach(struct target_if_spectral *spectral)
  1780. {
  1781. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1782. spectral_info("spectral detach");
  1783. if (spectral) {
  1784. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1785. qdf_spinlock_destroy
  1786. (&spectral->param_info[smode].osps_lock);
  1787. target_if_spectral_detach_simulation(spectral);
  1788. qdf_spinlock_destroy(&spectral->spectral_lock);
  1789. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  1790. qdf_mem_free(spectral);
  1791. spectral = NULL;
  1792. }
  1793. }
  1794. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1795. /**
  1796. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  1797. * functionality
  1798. * @spectral: Pointer to Spectral target_if internal private data
  1799. *
  1800. * Function to initialize spectral simulation functionality
  1801. *
  1802. * Return: 0 on success, negative error code on failure
  1803. */
  1804. static int
  1805. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1806. {
  1807. if (target_if_spectral_sim_attach(spectral)) {
  1808. qdf_mem_free(spectral);
  1809. return -EPERM;
  1810. }
  1811. return 0;
  1812. }
  1813. #else
  1814. static int
  1815. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1816. {
  1817. return 0;
  1818. }
  1819. #endif
  1820. /**
  1821. * target_if_spectral_len_adj_swar_init() - Initialize FFT bin length adjustment
  1822. * related info
  1823. * @swar: Pointer to Spectral FFT bin length adjustment SWAR params
  1824. * @target_type: Target type
  1825. *
  1826. * Function to Initialize parameters related to Spectral FFT bin
  1827. * length adjustment SWARs.
  1828. *
  1829. * Return: void
  1830. */
  1831. static void
  1832. target_if_spectral_len_adj_swar_init(struct spectral_fft_bin_len_adj_swar *swar,
  1833. uint32_t target_type)
  1834. {
  1835. if (target_type == TARGET_TYPE_QCA8074V2 ||
  1836. target_type == TARGET_TYPE_QCN9000)
  1837. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  1838. else if (target_type == TARGET_TYPE_QCA8074 ||
  1839. target_type == TARGET_TYPE_QCA6018 ||
  1840. target_type == TARGET_TYPE_QCA6390)
  1841. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  1842. else
  1843. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  1844. if (target_type == TARGET_TYPE_QCA8074 ||
  1845. target_type == TARGET_TYPE_QCA8074V2 ||
  1846. target_type == TARGET_TYPE_QCA6018 ||
  1847. target_type == TARGET_TYPE_QCN9000) {
  1848. swar->inband_fftbin_size_adj = 1;
  1849. swar->null_fftbin_adj = 1;
  1850. } else {
  1851. swar->inband_fftbin_size_adj = 0;
  1852. swar->null_fftbin_adj = 0;
  1853. }
  1854. if (target_type == TARGET_TYPE_QCA8074V2)
  1855. swar->packmode_fftbin_size_adj = 1;
  1856. else
  1857. swar->packmode_fftbin_size_adj = 0;
  1858. }
  1859. /**
  1860. * target_if_spectral_report_params_init() - Initialize parameters which
  1861. * describes the structure of Spectral reports
  1862. *
  1863. * @rparams: Pointer to Spectral report parameter object
  1864. * @target_type: target type
  1865. *
  1866. * Function to Initialize parameters related to the structure of Spectral
  1867. * reports.
  1868. *
  1869. * Return: void
  1870. */
  1871. static void
  1872. target_if_spectral_report_params_init(
  1873. struct spectral_report_params *rparams,
  1874. uint32_t target_type)
  1875. {
  1876. enum spectral_scan_mode smode;
  1877. /* This entries are currently used by gen3 chipsets only. Hence
  1878. * initialization is done for gen3 alone. In future if other generations
  1879. * needs to use them they have to add proper initial values.
  1880. */
  1881. if (target_type == TARGET_TYPE_QCN9000) {
  1882. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_2;
  1883. rparams->num_spectral_detectors =
  1884. NUM_SPECTRAL_DETECTORS_GEN3_V2;
  1885. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1886. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1887. rparams->fragmentation_160[smode] = false;
  1888. } else {
  1889. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_1;
  1890. rparams->num_spectral_detectors =
  1891. NUM_SPECTRAL_DETECTORS_GEN3_V1;
  1892. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1893. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1894. rparams->fragmentation_160[smode] = true;
  1895. }
  1896. switch (rparams->version) {
  1897. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1898. rparams->ssumaary_padding_bytes =
  1899. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1;
  1900. rparams->fft_report_hdr_len =
  1901. FFT_REPORT_HEADER_LENGTH_GEN3_V1;
  1902. break;
  1903. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1904. rparams->ssumaary_padding_bytes =
  1905. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2;
  1906. rparams->fft_report_hdr_len =
  1907. FFT_REPORT_HEADER_LENGTH_GEN3_V2;
  1908. break;
  1909. default:
  1910. qdf_assert_always(0);
  1911. }
  1912. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_0] =
  1913. SPECTRAL_SCAN_MODE_NORMAL;
  1914. if (target_type == TARGET_TYPE_QCN9000) {
  1915. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  1916. SPECTRAL_SCAN_MODE_AGILE;
  1917. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  1918. SPECTRAL_SCAN_MODE_INVALID;
  1919. } else {
  1920. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  1921. SPECTRAL_SCAN_MODE_NORMAL;
  1922. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  1923. SPECTRAL_SCAN_MODE_AGILE;
  1924. }
  1925. }
  1926. /**
  1927. * target_if_spectral_timestamp_war_init() - Initialize Spectral timestamp WAR
  1928. * related info
  1929. * @twar: Pointer to Spectral timstamp WAR related info
  1930. *
  1931. * Function to Initialize parameters related to Spectral timestamp WAR
  1932. *
  1933. * Return: void
  1934. */
  1935. static void
  1936. target_if_spectral_timestamp_war_init(struct spectral_timestamp_war *twar)
  1937. {
  1938. enum spectral_scan_mode smode;
  1939. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1940. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1941. twar->last_fft_timestamp[smode] = 0;
  1942. twar->timestamp_war_offset[smode] = 0;
  1943. }
  1944. twar->target_reset_count = 0;
  1945. }
  1946. /**
  1947. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  1948. * functionality for the given pdev
  1949. * @pdev: Pointer to pdev object
  1950. *
  1951. * Function to initialize pointer to spectral target_if internal private data
  1952. *
  1953. * Return: On success, pointer to Spectral target_if internal private data, on
  1954. * failure, NULL
  1955. */
  1956. void *
  1957. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  1958. {
  1959. struct target_if_spectral_ops *p_sops = NULL;
  1960. struct target_if_spectral *spectral = NULL;
  1961. uint32_t target_type;
  1962. uint32_t target_revision;
  1963. struct wlan_objmgr_psoc *psoc;
  1964. struct wlan_lmac_if_target_tx_ops *tx_ops;
  1965. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1966. QDF_STATUS status;
  1967. if (!pdev) {
  1968. spectral_err("SPECTRAL: pdev is NULL!");
  1969. return NULL;
  1970. }
  1971. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  1972. sizeof(struct target_if_spectral));
  1973. if (!spectral)
  1974. return spectral;
  1975. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  1976. /* Store pdev in Spectral */
  1977. spectral->pdev_obj = pdev;
  1978. psoc = wlan_pdev_get_psoc(pdev);
  1979. tx_ops = &psoc->soc_cb.tx_ops.target_tx_ops;
  1980. if (tx_ops->tgt_get_tgt_type) {
  1981. target_type = tx_ops->tgt_get_tgt_type(psoc);
  1982. } else {
  1983. qdf_mem_free(spectral);
  1984. return NULL;
  1985. }
  1986. if (tx_ops->tgt_get_tgt_revision) {
  1987. target_revision = tx_ops->tgt_get_tgt_revision(psoc);
  1988. } else {
  1989. qdf_mem_free(spectral);
  1990. return NULL;
  1991. }
  1992. /* init the function ptr table */
  1993. target_if_spectral_init_dummy_function_table(spectral);
  1994. /* get spectral function table */
  1995. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1996. /* TODO : Should this be called here of after ath_attach ? */
  1997. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  1998. spectral_info("HAL_CAP_PHYDIAG : Capable");
  1999. /* TODO: Need to fix the capablity check for RADAR */
  2000. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  2001. spectral_info("HAL_CAP_RADAR : Capable");
  2002. /* TODO : Need to fix the capablity check for SPECTRAL */
  2003. /* TODO : Should this be called here of after ath_attach ? */
  2004. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  2005. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  2006. qdf_spinlock_create(&spectral->spectral_lock);
  2007. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  2008. target_if_spectral_clear_stats(spectral);
  2009. if (target_type == TARGET_TYPE_QCA8074 ||
  2010. target_type == TARGET_TYPE_QCA8074V2 ||
  2011. target_type == TARGET_TYPE_QCA6018 ||
  2012. target_type == TARGET_TYPE_QCA6390 ||
  2013. target_type == TARGET_TYPE_QCN9000)
  2014. spectral->direct_dma_support = true;
  2015. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  2016. target_type);
  2017. target_if_spectral_report_params_init(&spectral->rparams, target_type);
  2018. if ((target_type == TARGET_TYPE_QCA8074) ||
  2019. (target_type == TARGET_TYPE_QCA8074V2) ||
  2020. (target_type == TARGET_TYPE_QCA6018) ||
  2021. (target_type == TARGET_TYPE_QCA5018) ||
  2022. (target_type == TARGET_TYPE_QCN9000) ||
  2023. (target_type == TARGET_TYPE_QCA6290) ||
  2024. (target_type == TARGET_TYPE_QCA6390)) {
  2025. spectral->spectral_gen = SPECTRAL_GEN3;
  2026. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  2027. spectral->tag_sscan_summary_exp =
  2028. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  2029. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  2030. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  2031. } else {
  2032. spectral->spectral_gen = SPECTRAL_GEN2;
  2033. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  2034. spectral->tag_sscan_summary_exp =
  2035. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  2036. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  2037. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  2038. }
  2039. status = target_if_init_spectral_param_min_max(
  2040. &spectral->param_min_max,
  2041. spectral->spectral_gen, target_type);
  2042. if (QDF_IS_STATUS_ERROR(status)) {
  2043. spectral_err("Failed to initialize parameter min max values");
  2044. goto fail;
  2045. }
  2046. target_if_init_spectral_param_properties(spectral);
  2047. /* Init spectral capability */
  2048. if (target_if_init_spectral_capability(spectral) !=
  2049. QDF_STATUS_SUCCESS) {
  2050. qdf_mem_free(spectral);
  2051. return NULL;
  2052. }
  2053. if (target_if_spectral_attach_simulation(spectral) < 0)
  2054. return NULL;
  2055. target_if_init_spectral_ops(spectral);
  2056. target_if_spectral_timestamp_war_init(&spectral->timestamp_war);
  2057. /* Spectral mode specific init */
  2058. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2059. spectral->params_valid[smode] = false;
  2060. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  2061. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  2062. }
  2063. target_if_spectral_register_funcs(spectral, &spectral_ops);
  2064. if (target_if_spectral_check_hw_capability(spectral) == false) {
  2065. goto fail;
  2066. } else {
  2067. /*
  2068. * TODO: Once the driver architecture transitions to chipset
  2069. * versioning based checks, reflect this here.
  2070. */
  2071. spectral->is_160_format = false;
  2072. spectral->is_lb_edge_extrabins_format = false;
  2073. spectral->is_rb_edge_extrabins_format = false;
  2074. if (target_type == TARGET_TYPE_QCA9984 ||
  2075. target_type == TARGET_TYPE_QCA9888) {
  2076. spectral->is_160_format = true;
  2077. spectral->is_lb_edge_extrabins_format = true;
  2078. spectral->is_rb_edge_extrabins_format = true;
  2079. } else if ((target_type == TARGET_TYPE_AR900B) &&
  2080. (target_revision == AR900B_REV_2)) {
  2081. spectral->is_rb_edge_extrabins_format = true;
  2082. }
  2083. if (target_type == TARGET_TYPE_QCA9984 ||
  2084. target_type == TARGET_TYPE_QCA9888)
  2085. spectral->is_sec80_rssi_war_required = true;
  2086. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  2087. if (spectral->spectral_gen == SPECTRAL_GEN3)
  2088. init_160mhz_delivery_state_machine(spectral);
  2089. }
  2090. return spectral;
  2091. fail:
  2092. target_if_spectral_detach(spectral);
  2093. return NULL;
  2094. }
  2095. /**
  2096. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  2097. * functionality for the given pdev
  2098. * @pdev: Pointer to pdev object
  2099. *
  2100. * Function to de-initialize pointer to spectral target_if internal private data
  2101. *
  2102. * Return: None
  2103. */
  2104. void
  2105. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  2106. {
  2107. struct target_if_spectral *spectral = NULL;
  2108. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2109. if (!spectral) {
  2110. spectral_err("SPECTRAL : Module doesn't exist");
  2111. return;
  2112. }
  2113. target_if_spectral_detach(spectral);
  2114. return;
  2115. }
  2116. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  2117. * corresponding translation for Agile channel width.
  2118. * Translation schema of different operating modes:
  2119. * 20 -> 20, 40 -> 40, (80 & 160 & 80_80) -> 80.
  2120. * @chwidth: Channel width enum.
  2121. *
  2122. * Return: The translated channel width enum.
  2123. */
  2124. static enum phy_ch_width
  2125. target_if_spectral_find_agile_width(enum phy_ch_width chwidth)
  2126. {
  2127. switch (chwidth) {
  2128. case CH_WIDTH_20MHZ:
  2129. return CH_WIDTH_20MHZ;
  2130. case CH_WIDTH_40MHZ:
  2131. return CH_WIDTH_40MHZ;
  2132. case CH_WIDTH_80MHZ:
  2133. case CH_WIDTH_80P80MHZ:
  2134. case CH_WIDTH_160MHZ:
  2135. return CH_WIDTH_80MHZ;
  2136. default:
  2137. spectral_err("Invalid chwidth enum %d", chwidth);
  2138. return CH_WIDTH_INVALID;
  2139. }
  2140. }
  2141. /**
  2142. * target_if_calculate_center_freq() - Helper routine to
  2143. * check whether given frequency is center frequency of a
  2144. * WLAN channel
  2145. *
  2146. * @spectral: Pointer to Spectral object
  2147. * @chan_freq: Center frequency of a WLAN channel
  2148. * @is_valid: Indicates whether given frequency is valid
  2149. *
  2150. * Return: QDF_STATUS
  2151. */
  2152. static QDF_STATUS
  2153. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  2154. uint32_t chan_freq,
  2155. bool *is_valid)
  2156. {
  2157. struct regulatory_channel *cur_chan_list;
  2158. int i;
  2159. if (!pdev) {
  2160. spectral_err("pdev object is null");
  2161. return QDF_STATUS_E_FAILURE;
  2162. }
  2163. if (!is_valid) {
  2164. spectral_err("is valid argument is null");
  2165. return QDF_STATUS_E_FAILURE;
  2166. }
  2167. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  2168. if (!cur_chan_list)
  2169. return QDF_STATUS_E_FAILURE;
  2170. if (wlan_reg_get_current_chan_list(
  2171. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  2172. spectral_err("Failed to get cur_chan list");
  2173. qdf_mem_free(cur_chan_list);
  2174. return QDF_STATUS_E_FAILURE;
  2175. }
  2176. *is_valid = false;
  2177. for (i = 0; i < NUM_CHANNELS; i++) {
  2178. uint32_t flags;
  2179. uint32_t center_freq;
  2180. flags = cur_chan_list[i].chan_flags;
  2181. center_freq = cur_chan_list[i].center_freq;
  2182. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  2183. (center_freq == chan_freq)) {
  2184. *is_valid = true;
  2185. break;
  2186. }
  2187. }
  2188. qdf_mem_free(cur_chan_list);
  2189. return QDF_STATUS_SUCCESS;
  2190. }
  2191. /**
  2192. * target_if_calculate_center_freq() - Helper routine to
  2193. * find the center frequency of the agile span from a
  2194. * WLAN channel center frequency
  2195. *
  2196. * @spectral: Pointer to Spectral object
  2197. * @chan_freq: Center frequency of a WLAN channel
  2198. * @center_freq: Pointer to center frequency
  2199. *
  2200. * Return: QDF_STATUS
  2201. */
  2202. static QDF_STATUS
  2203. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  2204. uint16_t chan_freq,
  2205. uint16_t *center_freq)
  2206. {
  2207. struct wlan_objmgr_vdev *vdev;
  2208. enum phy_ch_width ch_width;
  2209. enum phy_ch_width agile_ch_width;
  2210. if (!spectral) {
  2211. spectral_err("spectral target if object is null");
  2212. return QDF_STATUS_E_FAILURE;
  2213. }
  2214. if (!center_freq) {
  2215. spectral_err("center_freq argument is null");
  2216. return QDF_STATUS_E_FAILURE;
  2217. }
  2218. vdev = target_if_spectral_get_vdev(spectral);
  2219. if (!vdev) {
  2220. spectral_err("vdev is NULL");
  2221. return QDF_STATUS_E_FAILURE;
  2222. }
  2223. ch_width = target_if_vdev_get_ch_width(vdev);
  2224. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2225. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2226. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2227. *center_freq = chan_freq;
  2228. } else {
  2229. uint16_t start_freq;
  2230. uint16_t end_freq;
  2231. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2232. wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2233. (spectral->pdev_obj, chan_freq, agile_ch_width,
  2234. &bonded_chan_ptr);
  2235. if (!bonded_chan_ptr) {
  2236. spectral_err("Bonded channel is not found");
  2237. return QDF_STATUS_E_FAILURE;
  2238. }
  2239. start_freq = bonded_chan_ptr->start_freq;
  2240. end_freq = bonded_chan_ptr->end_freq;
  2241. *center_freq = (start_freq + end_freq) >> 1;
  2242. }
  2243. return QDF_STATUS_SUCCESS;
  2244. }
  2245. /**
  2246. * target_if_validate_center_freq() - Helper routine to
  2247. * validate user provided agile center frequency
  2248. *
  2249. * @spectral: Pointer to Spectral object
  2250. * @center_freq: User provided agile span center frequency
  2251. * @is_valid: Indicates whether agile span center frequency is valid
  2252. *
  2253. * Return: QDF_STATUS
  2254. */
  2255. static QDF_STATUS
  2256. target_if_validate_center_freq(struct target_if_spectral *spectral,
  2257. uint16_t center_freq,
  2258. bool *is_valid)
  2259. {
  2260. struct wlan_objmgr_vdev *vdev;
  2261. enum phy_ch_width ch_width;
  2262. enum phy_ch_width agile_ch_width;
  2263. struct wlan_objmgr_pdev *pdev;
  2264. QDF_STATUS status;
  2265. if (!spectral) {
  2266. spectral_err("spectral target if object is null");
  2267. return QDF_STATUS_E_FAILURE;
  2268. }
  2269. if (!is_valid) {
  2270. spectral_err("is_valid argument is null");
  2271. return QDF_STATUS_E_FAILURE;
  2272. }
  2273. pdev = spectral->pdev_obj;
  2274. vdev = target_if_spectral_get_vdev(spectral);
  2275. if (!vdev) {
  2276. spectral_err("vdev is NULL");
  2277. return QDF_STATUS_E_FAILURE;
  2278. }
  2279. ch_width = target_if_vdev_get_ch_width(vdev);
  2280. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2281. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2282. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2283. status = target_if_is_center_freq_of_any_chan
  2284. (pdev, center_freq, is_valid);
  2285. if (QDF_IS_STATUS_ERROR(status))
  2286. return QDF_STATUS_E_FAILURE;
  2287. } else {
  2288. uint16_t start_freq;
  2289. uint16_t end_freq;
  2290. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2291. bool is_chan;
  2292. status = target_if_is_center_freq_of_any_chan
  2293. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2294. &is_chan);
  2295. if (QDF_IS_STATUS_ERROR(status))
  2296. return QDF_STATUS_E_FAILURE;
  2297. if (is_chan) {
  2298. uint32_t calulated_center_freq;
  2299. wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2300. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2301. agile_ch_width,
  2302. &bonded_chan_ptr);
  2303. if (!bonded_chan_ptr) {
  2304. spectral_err("Bonded channel is not found");
  2305. return QDF_STATUS_E_FAILURE;
  2306. }
  2307. start_freq = bonded_chan_ptr->start_freq;
  2308. end_freq = bonded_chan_ptr->end_freq;
  2309. calulated_center_freq = (start_freq + end_freq) >> 1;
  2310. *is_valid = (center_freq == calulated_center_freq);
  2311. } else {
  2312. *is_valid = false;
  2313. }
  2314. }
  2315. return QDF_STATUS_SUCCESS;
  2316. }
  2317. /**
  2318. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  2319. * check whether agile span overlaps with current operating band.
  2320. *
  2321. * @spectral: Pointer to Spectral object
  2322. * @ss_frequency: Agile span center frequency
  2323. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  2324. *
  2325. * Helper routine to check whether agile span overlaps with current
  2326. * operating band.
  2327. *
  2328. * Return: QDF_STATUS
  2329. */
  2330. static QDF_STATUS
  2331. target_if_is_agile_span_overlap_with_operating_span
  2332. (struct target_if_spectral *spectral,
  2333. uint32_t ss_frequency,
  2334. bool *is_overlapping)
  2335. {
  2336. enum phy_ch_width ch_width;
  2337. enum phy_ch_width agile_ch_width;
  2338. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2339. struct wlan_objmgr_vdev *vdev;
  2340. struct wlan_objmgr_pdev *pdev;
  2341. int16_t chan_freq;
  2342. uint32_t op_start_freq;
  2343. uint32_t op_end_freq;
  2344. uint32_t agile_start_freq;
  2345. uint32_t agile_end_freq;
  2346. uint32_t cfreq2;
  2347. if (!spectral) {
  2348. spectral_err("Spectral object is NULL");
  2349. return QDF_STATUS_E_FAILURE;
  2350. }
  2351. pdev = spectral->pdev_obj;
  2352. if (!pdev) {
  2353. spectral_err("pdev object is NULL");
  2354. return QDF_STATUS_E_FAILURE;
  2355. }
  2356. if (!is_overlapping) {
  2357. spectral_err("Argument(is_overlapping) is NULL");
  2358. return QDF_STATUS_E_FAILURE;
  2359. }
  2360. vdev = target_if_spectral_get_vdev(spectral);
  2361. if (!vdev) {
  2362. spectral_err("vdev is NULL");
  2363. return QDF_STATUS_E_FAILURE;
  2364. }
  2365. ch_width = target_if_vdev_get_ch_width(vdev);
  2366. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2367. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2368. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2369. if (cfreq2 < 0)
  2370. return QDF_STATUS_E_FAILURE;
  2371. if (ch_width == CH_WIDTH_20MHZ) {
  2372. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  2373. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  2374. } else {
  2375. wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2376. (pdev, chan_freq, ch_width, &bonded_chan_ptr);
  2377. if (!bonded_chan_ptr) {
  2378. spectral_err("Bonded channel is not found");
  2379. return QDF_STATUS_E_FAILURE;
  2380. }
  2381. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  2382. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  2383. }
  2384. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2385. if (agile_ch_width == CH_WIDTH_INVALID)
  2386. return QDF_STATUS_E_FAILURE;
  2387. agile_start_freq = ss_frequency -
  2388. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2389. agile_end_freq = ss_frequency +
  2390. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2391. if (agile_end_freq <= op_start_freq || op_end_freq <= agile_start_freq)
  2392. *is_overlapping = false;
  2393. else
  2394. *is_overlapping = true;
  2395. /* Use non zero cfreq2 to identify 80p80 */
  2396. if (cfreq2) {
  2397. uint32_t sec80_start_feq;
  2398. uint32_t sec80_end_freq;
  2399. sec80_start_feq = cfreq2 - 40;
  2400. sec80_end_freq = cfreq2 + 40;
  2401. if ((agile_end_freq > sec80_start_feq) &&
  2402. (sec80_end_freq > agile_start_freq))
  2403. *is_overlapping = true;
  2404. }
  2405. return QDF_STATUS_SUCCESS;
  2406. }
  2407. /**
  2408. * target_if_spectral_populate_chwidth() - Helper routine to
  2409. * populate channel width for different Spectral modes
  2410. *
  2411. * @spectral: Pointer to Spectral object
  2412. *
  2413. * Helper routine to populate channel width for different Spectral modes
  2414. *
  2415. * Return: QDF_STATUS
  2416. */
  2417. static QDF_STATUS
  2418. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral) {
  2419. struct wlan_objmgr_vdev *vdev;
  2420. enum phy_ch_width vdev_ch_with;
  2421. vdev = target_if_spectral_get_vdev(spectral);
  2422. if (!vdev) {
  2423. spectral_err("vdev is null");
  2424. return QDF_STATUS_E_FAILURE;
  2425. }
  2426. vdev_ch_with = target_if_vdev_get_ch_width(vdev);
  2427. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2428. if (vdev_ch_with == CH_WIDTH_INVALID) {
  2429. spectral_err("Invalid channel width %d", vdev_ch_with);
  2430. return QDF_STATUS_E_FAILURE;
  2431. }
  2432. spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL] = vdev_ch_with;
  2433. spectral->ch_width[SPECTRAL_SCAN_MODE_AGILE] =
  2434. target_if_spectral_find_agile_width(vdev_ch_with);
  2435. return QDF_STATUS_SUCCESS;
  2436. }
  2437. /**
  2438. * _target_if_set_spectral_config() - Set spectral config
  2439. * @spectral: Pointer to spectral object
  2440. * @threshtype: config type
  2441. * @value: config value
  2442. * @smode: Spectral scan mode
  2443. * @err: Spectral error code
  2444. *
  2445. * API to set spectral configurations
  2446. *
  2447. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2448. */
  2449. static QDF_STATUS
  2450. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  2451. const uint32_t threshtype, const uint32_t value,
  2452. const enum spectral_scan_mode smode,
  2453. enum spectral_cp_error_code *err)
  2454. {
  2455. struct spectral_config params;
  2456. struct target_if_spectral_ops *p_sops;
  2457. struct spectral_config *sparams;
  2458. QDF_STATUS status;
  2459. bool is_overlapping;
  2460. uint16_t agile_cfreq;
  2461. bool is_valid_chan;
  2462. struct spectral_param_min_max *param_min_max;
  2463. if (!err) {
  2464. spectral_err("Error code argument is null");
  2465. QDF_ASSERT(0);
  2466. }
  2467. *err = SPECTRAL_SCAN_ERR_INVALID;
  2468. if (!spectral) {
  2469. spectral_err("spectral object is NULL");
  2470. return QDF_STATUS_E_FAILURE;
  2471. }
  2472. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2473. param_min_max = &spectral->param_min_max;
  2474. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2475. spectral_err("Invalid Spectral mode %u", smode);
  2476. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2477. return QDF_STATUS_E_FAILURE;
  2478. }
  2479. sparams = &spectral->params[smode];
  2480. if (!spectral->params_valid[smode]) {
  2481. target_if_spectral_info_read(spectral,
  2482. smode,
  2483. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2484. &spectral->params[smode],
  2485. sizeof(spectral->params[smode]));
  2486. spectral->params_valid[smode] = true;
  2487. }
  2488. switch (threshtype) {
  2489. case SPECTRAL_PARAM_FFT_PERIOD:
  2490. sparams->ss_fft_period = value;
  2491. break;
  2492. case SPECTRAL_PARAM_SCAN_PERIOD:
  2493. sparams->ss_period = value;
  2494. break;
  2495. case SPECTRAL_PARAM_SCAN_COUNT:
  2496. sparams->ss_count = value;
  2497. break;
  2498. case SPECTRAL_PARAM_SHORT_REPORT:
  2499. sparams->ss_short_report = (!!value) ? true : false;
  2500. break;
  2501. case SPECTRAL_PARAM_SPECT_PRI:
  2502. sparams->ss_spectral_pri = (!!value) ? true : false;
  2503. break;
  2504. case SPECTRAL_PARAM_FFT_SIZE:
  2505. status = target_if_spectral_populate_chwidth(spectral);
  2506. if (QDF_IS_STATUS_ERROR(status))
  2507. return QDF_STATUS_E_FAILURE;
  2508. if ((value < param_min_max->fft_size_min) ||
  2509. (value > param_min_max->fft_size_max
  2510. [spectral->ch_width[smode]])) {
  2511. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2512. return QDF_STATUS_E_FAILURE;
  2513. }
  2514. sparams->ss_fft_size = value;
  2515. break;
  2516. case SPECTRAL_PARAM_GC_ENA:
  2517. sparams->ss_gc_ena = !!value;
  2518. break;
  2519. case SPECTRAL_PARAM_RESTART_ENA:
  2520. sparams->ss_restart_ena = !!value;
  2521. break;
  2522. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  2523. sparams->ss_noise_floor_ref = value;
  2524. break;
  2525. case SPECTRAL_PARAM_INIT_DELAY:
  2526. sparams->ss_init_delay = value;
  2527. break;
  2528. case SPECTRAL_PARAM_NB_TONE_THR:
  2529. sparams->ss_nb_tone_thr = value;
  2530. break;
  2531. case SPECTRAL_PARAM_STR_BIN_THR:
  2532. sparams->ss_str_bin_thr = value;
  2533. break;
  2534. case SPECTRAL_PARAM_WB_RPT_MODE:
  2535. sparams->ss_wb_rpt_mode = !!value;
  2536. break;
  2537. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  2538. sparams->ss_rssi_rpt_mode = !!value;
  2539. break;
  2540. case SPECTRAL_PARAM_RSSI_THR:
  2541. sparams->ss_rssi_thr = value;
  2542. break;
  2543. case SPECTRAL_PARAM_PWR_FORMAT:
  2544. sparams->ss_pwr_format = !!value;
  2545. break;
  2546. case SPECTRAL_PARAM_RPT_MODE:
  2547. if ((value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  2548. (value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  2549. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2550. return QDF_STATUS_E_FAILURE;
  2551. }
  2552. sparams->ss_rpt_mode = value;
  2553. break;
  2554. case SPECTRAL_PARAM_BIN_SCALE:
  2555. sparams->ss_bin_scale = value;
  2556. break;
  2557. case SPECTRAL_PARAM_DBM_ADJ:
  2558. sparams->ss_dbm_adj = !!value;
  2559. break;
  2560. case SPECTRAL_PARAM_CHN_MASK:
  2561. sparams->ss_chn_mask = value;
  2562. break;
  2563. case SPECTRAL_PARAM_FREQUENCY:
  2564. status = target_if_is_center_freq_of_any_chan
  2565. (spectral->pdev_obj, value, &is_valid_chan);
  2566. if (QDF_IS_STATUS_ERROR(status))
  2567. return QDF_STATUS_E_FAILURE;
  2568. if (is_valid_chan) {
  2569. status = target_if_calculate_center_freq(spectral,
  2570. value,
  2571. &agile_cfreq);
  2572. if (QDF_IS_STATUS_ERROR(status)) {
  2573. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2574. return QDF_STATUS_E_FAILURE;
  2575. }
  2576. } else {
  2577. bool is_valid_agile_cfreq;
  2578. status = target_if_validate_center_freq
  2579. (spectral, value, &is_valid_agile_cfreq);
  2580. if (QDF_IS_STATUS_ERROR(status))
  2581. return QDF_STATUS_E_FAILURE;
  2582. if (!is_valid_agile_cfreq) {
  2583. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2584. spectral_err("Invalid agile center frequency");
  2585. return QDF_STATUS_E_FAILURE;
  2586. }
  2587. agile_cfreq = value;
  2588. }
  2589. status = target_if_is_agile_span_overlap_with_operating_span
  2590. (spectral, agile_cfreq, &is_overlapping);
  2591. if (QDF_IS_STATUS_ERROR(status))
  2592. return QDF_STATUS_E_FAILURE;
  2593. if (is_overlapping) {
  2594. spectral_err("Agile span overlapping with current BW");
  2595. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2596. return QDF_STATUS_E_FAILURE;
  2597. }
  2598. sparams->ss_frequency = agile_cfreq;
  2599. break;
  2600. }
  2601. p_sops->configure_spectral(spectral, sparams, smode);
  2602. /* only to validate the writes */
  2603. p_sops->get_spectral_config(spectral, &params, smode);
  2604. return QDF_STATUS_SUCCESS;
  2605. }
  2606. QDF_STATUS
  2607. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  2608. const uint32_t threshtype, const uint32_t value,
  2609. const enum spectral_scan_mode smode,
  2610. enum spectral_cp_error_code *err)
  2611. {
  2612. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  2613. struct target_if_spectral *spectral;
  2614. QDF_STATUS status;
  2615. if (!err) {
  2616. spectral_err("Error code argument is null");
  2617. QDF_ASSERT(0);
  2618. }
  2619. *err = SPECTRAL_SCAN_ERR_INVALID;
  2620. if (!pdev) {
  2621. spectral_err("pdev object is NULL");
  2622. return QDF_STATUS_E_FAILURE;
  2623. }
  2624. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2625. if (!spectral) {
  2626. spectral_err("spectral object is NULL");
  2627. return QDF_STATUS_E_FAILURE;
  2628. }
  2629. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2630. spectral_err("Invalid Spectral mode %u", smode);
  2631. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2632. return QDF_STATUS_E_FAILURE;
  2633. }
  2634. if (!spectral->properties[smode][threshtype].supported) {
  2635. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  2636. threshtype, smode);
  2637. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  2638. return QDF_STATUS_E_FAILURE;
  2639. }
  2640. if (spectral->properties[smode][threshtype].common_all_modes) {
  2641. spectral_warn("Setting Spectral parameter %u for all modes",
  2642. threshtype);
  2643. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  2644. status = _target_if_set_spectral_config
  2645. (spectral, threshtype, value,
  2646. mode, err);
  2647. if (QDF_IS_STATUS_ERROR(status))
  2648. return QDF_STATUS_E_FAILURE;
  2649. }
  2650. return QDF_STATUS_SUCCESS;
  2651. }
  2652. return _target_if_set_spectral_config(spectral, threshtype,
  2653. value, smode, err);
  2654. }
  2655. /**
  2656. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  2657. * @fft_len: FFT length
  2658. * @pdev: Pointer to pdev object
  2659. *
  2660. * API to get fft bin count for a given fft length
  2661. *
  2662. * Return: FFt bin count
  2663. */
  2664. static int
  2665. target_if_get_fft_bin_count(int fft_len)
  2666. {
  2667. int bin_count = 0;
  2668. switch (fft_len) {
  2669. case 5:
  2670. bin_count = 16;
  2671. break;
  2672. case 6:
  2673. bin_count = 32;
  2674. break;
  2675. case 7:
  2676. bin_count = 64;
  2677. break;
  2678. case 8:
  2679. bin_count = 128;
  2680. break;
  2681. case 9:
  2682. bin_count = 256;
  2683. break;
  2684. default:
  2685. break;
  2686. }
  2687. return bin_count;
  2688. }
  2689. /**
  2690. * target_if_init_upper_lower_flags() - Initializes control and extension
  2691. * segment flags
  2692. * @fft_len: FFT length
  2693. * @pdev: Pointer to pdev object
  2694. *
  2695. * API to initialize the control and extension flags with the lower/upper
  2696. * segment based on the HT mode
  2697. *
  2698. * Return: FFt bin count
  2699. */
  2700. static void
  2701. target_if_init_upper_lower_flags(struct target_if_spectral *spectral)
  2702. {
  2703. int current_channel = 0;
  2704. int ext_channel = 0;
  2705. struct target_if_spectral_ops *p_sops =
  2706. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2707. current_channel = p_sops->get_current_channel(spectral);
  2708. ext_channel = p_sops->get_extension_channel(spectral);
  2709. if ((current_channel == 0) || (ext_channel == 0))
  2710. return;
  2711. if (spectral->sc_spectral_20_40_mode) {
  2712. /* HT40 mode */
  2713. if (ext_channel < current_channel) {
  2714. spectral->lower_is_extension = 1;
  2715. spectral->upper_is_control = 1;
  2716. spectral->lower_is_control = 0;
  2717. spectral->upper_is_extension = 0;
  2718. } else {
  2719. spectral->lower_is_extension = 0;
  2720. spectral->upper_is_control = 0;
  2721. spectral->lower_is_control = 1;
  2722. spectral->upper_is_extension = 1;
  2723. }
  2724. } else {
  2725. /* HT20 mode, lower is always control */
  2726. spectral->lower_is_extension = 0;
  2727. spectral->upper_is_control = 0;
  2728. spectral->lower_is_control = 1;
  2729. spectral->upper_is_extension = 0;
  2730. }
  2731. }
  2732. /**
  2733. * target_if_get_spectral_config() - Get spectral configuration
  2734. * @pdev: Pointer to pdev object
  2735. * @param: Pointer to spectral_config structure in which the configuration
  2736. * should be returned
  2737. * @smode: Spectral scan mode
  2738. *
  2739. * API to get the current spectral configuration
  2740. *
  2741. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2742. */
  2743. QDF_STATUS
  2744. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  2745. struct spectral_config *param,
  2746. enum spectral_scan_mode smode)
  2747. {
  2748. struct target_if_spectral_ops *p_sops = NULL;
  2749. struct target_if_spectral *spectral = NULL;
  2750. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2751. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2752. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2753. spectral_err("Invalid Spectral mode %u", smode);
  2754. return QDF_STATUS_E_FAILURE;
  2755. }
  2756. qdf_mem_zero(param, sizeof(struct spectral_config));
  2757. p_sops->get_spectral_config(spectral, param, smode);
  2758. return QDF_STATUS_SUCCESS;
  2759. }
  2760. /**
  2761. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  2762. * parameters
  2763. * @spectral: Pointer to Spectral target_if internal private data
  2764. * @spectral_params: Pointer to Spectral parameters
  2765. * @smode: Spectral scan mode
  2766. * @err: Spectral error code
  2767. *
  2768. * Enable use of desired Spectral parameters by configuring them into HW, and
  2769. * starting Spectral scan
  2770. *
  2771. * Return: 0 on success, 1 on failure
  2772. */
  2773. int
  2774. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  2775. struct spectral_config *spectral_params,
  2776. enum spectral_scan_mode smode,
  2777. enum spectral_cp_error_code *err)
  2778. {
  2779. int extension_channel = 0;
  2780. int current_channel = 0;
  2781. struct target_if_spectral_ops *p_sops = NULL;
  2782. QDF_STATUS status;
  2783. if (!spectral) {
  2784. spectral_err("Spectral LMAC object is NULL");
  2785. return 1;
  2786. }
  2787. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2788. spectral_err("Invalid Spectral mode %u", smode);
  2789. return 1;
  2790. }
  2791. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2792. if (!p_sops) {
  2793. spectral_err("p_sops is NULL");
  2794. return 1;
  2795. }
  2796. spectral->sc_spectral_noise_pwr_cal =
  2797. spectral_params->ss_spectral_pri ? 1 : 0;
  2798. /* check if extension channel is present */
  2799. extension_channel = p_sops->get_extension_channel(spectral);
  2800. current_channel = p_sops->get_current_channel(spectral);
  2801. status = target_if_spectral_populate_chwidth(spectral);
  2802. if (QDF_IS_STATUS_ERROR(status)) {
  2803. spectral_err("Failed to get channel widths");
  2804. return 1;
  2805. }
  2806. if (spectral->capability.advncd_spectral_cap) {
  2807. spectral->lb_edge_extrabins = 0;
  2808. spectral->rb_edge_extrabins = 0;
  2809. if (spectral->is_lb_edge_extrabins_format &&
  2810. spectral->params[smode].ss_rpt_mode == 2) {
  2811. spectral->lb_edge_extrabins = 4;
  2812. }
  2813. if (spectral->is_rb_edge_extrabins_format &&
  2814. spectral->params[smode].ss_rpt_mode == 2) {
  2815. spectral->rb_edge_extrabins = 4;
  2816. }
  2817. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  2818. spectral->sc_spectral_20_40_mode = 0;
  2819. spectral->spectral_numbins =
  2820. target_if_get_fft_bin_count(
  2821. spectral->params[smode].ss_fft_size);
  2822. spectral->spectral_fft_len =
  2823. target_if_get_fft_bin_count(
  2824. spectral->params[smode].ss_fft_size);
  2825. spectral->spectral_data_len =
  2826. target_if_get_fft_bin_count(
  2827. spectral->params[smode].ss_fft_size);
  2828. /*
  2829. * Initialize classifier params to be sent to user
  2830. * space classifier
  2831. */
  2832. spectral->classifier_params.lower_chan_in_mhz =
  2833. current_channel;
  2834. spectral->classifier_params.upper_chan_in_mhz = 0;
  2835. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  2836. /* TODO : Remove this variable */
  2837. spectral->sc_spectral_20_40_mode = 1;
  2838. spectral->spectral_numbins =
  2839. target_if_get_fft_bin_count(
  2840. spectral->params[smode].ss_fft_size);
  2841. spectral->spectral_fft_len =
  2842. target_if_get_fft_bin_count(
  2843. spectral->params[smode].ss_fft_size);
  2844. spectral->spectral_data_len =
  2845. target_if_get_fft_bin_count(
  2846. spectral->params[smode].ss_fft_size);
  2847. /*
  2848. * Initialize classifier params to be sent to user
  2849. * space classifier
  2850. */
  2851. if (extension_channel < current_channel) {
  2852. spectral->classifier_params.lower_chan_in_mhz =
  2853. extension_channel;
  2854. spectral->classifier_params.upper_chan_in_mhz =
  2855. current_channel;
  2856. } else {
  2857. spectral->classifier_params.lower_chan_in_mhz =
  2858. current_channel;
  2859. spectral->classifier_params.upper_chan_in_mhz =
  2860. extension_channel;
  2861. }
  2862. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  2863. /* Set the FFT Size */
  2864. /* TODO : Remove this variable */
  2865. spectral->sc_spectral_20_40_mode = 0;
  2866. spectral->spectral_numbins =
  2867. target_if_get_fft_bin_count(
  2868. spectral->params[smode].ss_fft_size);
  2869. spectral->spectral_fft_len =
  2870. target_if_get_fft_bin_count(
  2871. spectral->params[smode].ss_fft_size);
  2872. spectral->spectral_data_len =
  2873. target_if_get_fft_bin_count(
  2874. spectral->params[smode].ss_fft_size);
  2875. /*
  2876. * Initialize classifier params to be sent to user
  2877. * space classifier
  2878. */
  2879. spectral->classifier_params.lower_chan_in_mhz =
  2880. current_channel;
  2881. spectral->classifier_params.upper_chan_in_mhz = 0;
  2882. /*
  2883. * Initialize classifier params to be sent to user
  2884. * space classifier
  2885. */
  2886. if (extension_channel < current_channel) {
  2887. spectral->classifier_params.lower_chan_in_mhz =
  2888. extension_channel;
  2889. spectral->classifier_params.upper_chan_in_mhz =
  2890. current_channel;
  2891. } else {
  2892. spectral->classifier_params.lower_chan_in_mhz =
  2893. current_channel;
  2894. spectral->classifier_params.upper_chan_in_mhz =
  2895. extension_channel;
  2896. }
  2897. } else if (is_ch_width_160_or_80p80(
  2898. spectral->ch_width[smode])) {
  2899. /* Set the FFT Size */
  2900. /* The below applies to both 160 and 80+80 cases */
  2901. /* TODO : Remove this variable */
  2902. spectral->sc_spectral_20_40_mode = 0;
  2903. spectral->spectral_numbins =
  2904. target_if_get_fft_bin_count(
  2905. spectral->params[smode].ss_fft_size);
  2906. spectral->spectral_fft_len =
  2907. target_if_get_fft_bin_count(
  2908. spectral->params[smode].ss_fft_size);
  2909. spectral->spectral_data_len =
  2910. target_if_get_fft_bin_count(
  2911. spectral->params[smode].ss_fft_size);
  2912. /*
  2913. * Initialize classifier params to be sent to user
  2914. * space classifier
  2915. */
  2916. spectral->classifier_params.lower_chan_in_mhz =
  2917. current_channel;
  2918. spectral->classifier_params.upper_chan_in_mhz = 0;
  2919. /*
  2920. * Initialize classifier params to be sent to user
  2921. * space classifier
  2922. */
  2923. if (extension_channel < current_channel) {
  2924. spectral->classifier_params.lower_chan_in_mhz =
  2925. extension_channel;
  2926. spectral->classifier_params.upper_chan_in_mhz =
  2927. current_channel;
  2928. } else {
  2929. spectral->classifier_params.lower_chan_in_mhz =
  2930. current_channel;
  2931. spectral->classifier_params.upper_chan_in_mhz =
  2932. extension_channel;
  2933. }
  2934. }
  2935. if (spectral->spectral_numbins) {
  2936. spectral->spectral_numbins +=
  2937. spectral->lb_edge_extrabins;
  2938. spectral->spectral_numbins +=
  2939. spectral->rb_edge_extrabins;
  2940. }
  2941. if (spectral->spectral_fft_len) {
  2942. spectral->spectral_fft_len +=
  2943. spectral->lb_edge_extrabins;
  2944. spectral->spectral_fft_len +=
  2945. spectral->rb_edge_extrabins;
  2946. }
  2947. if (spectral->spectral_data_len) {
  2948. spectral->spectral_data_len +=
  2949. spectral->lb_edge_extrabins;
  2950. spectral->spectral_data_len +=
  2951. spectral->rb_edge_extrabins;
  2952. }
  2953. } else {
  2954. /*
  2955. * The decision to find 20/40 mode is found based on the
  2956. * presence of extension channel
  2957. * instead of channel width, as the channel width can
  2958. * dynamically change
  2959. */
  2960. if (extension_channel == 0) {
  2961. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  2962. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  2963. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  2964. spectral->spectral_data_len =
  2965. SPECTRAL_HT20_TOTAL_DATA_LEN;
  2966. /* only valid in 20-40 mode */
  2967. spectral->spectral_lower_max_index_offset = -1;
  2968. /* only valid in 20-40 mode */
  2969. spectral->spectral_upper_max_index_offset = -1;
  2970. spectral->spectral_max_index_offset =
  2971. spectral->spectral_fft_len + 2;
  2972. spectral->sc_spectral_20_40_mode = 0;
  2973. /*
  2974. * Initialize classifier params to be sent to user
  2975. * space classifier
  2976. */
  2977. spectral->classifier_params.lower_chan_in_mhz =
  2978. current_channel;
  2979. spectral->classifier_params.upper_chan_in_mhz = 0;
  2980. } else {
  2981. spectral->spectral_numbins =
  2982. SPECTRAL_HT40_TOTAL_NUM_BINS;
  2983. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  2984. spectral->spectral_data_len =
  2985. SPECTRAL_HT40_TOTAL_DATA_LEN;
  2986. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  2987. /* only valid in 20 mode */
  2988. spectral->spectral_max_index_offset = -1;
  2989. spectral->spectral_lower_max_index_offset =
  2990. spectral->spectral_fft_len + 2;
  2991. spectral->spectral_upper_max_index_offset =
  2992. spectral->spectral_fft_len + 5;
  2993. spectral->sc_spectral_20_40_mode = 1;
  2994. /*
  2995. * Initialize classifier params to be sent to user
  2996. * space classifier
  2997. */
  2998. if (extension_channel < current_channel) {
  2999. spectral->classifier_params.lower_chan_in_mhz =
  3000. extension_channel;
  3001. spectral->classifier_params.upper_chan_in_mhz =
  3002. current_channel;
  3003. } else {
  3004. spectral->classifier_params.lower_chan_in_mhz =
  3005. current_channel;
  3006. spectral->classifier_params.upper_chan_in_mhz =
  3007. extension_channel;
  3008. }
  3009. }
  3010. }
  3011. spectral->send_single_packet = 0;
  3012. spectral->classifier_params.spectral_20_40_mode =
  3013. spectral->sc_spectral_20_40_mode;
  3014. spectral->classifier_params.spectral_dc_index =
  3015. spectral->spectral_dc_index;
  3016. spectral->spectral_sent_msg = 0;
  3017. spectral->classify_scan = 0;
  3018. spectral->num_spectral_data = 0;
  3019. if (!p_sops->is_spectral_active(spectral, smode)) {
  3020. p_sops->configure_spectral(spectral, spectral_params, smode);
  3021. p_sops->start_spectral_scan(spectral, smode, err);
  3022. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  3023. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  3024. }
  3025. /* get current spectral configuration */
  3026. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  3027. target_if_init_upper_lower_flags(spectral);
  3028. return 0;
  3029. }
  3030. /**
  3031. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  3032. * Agile DFS
  3033. * @psoc: Pointer to psoc
  3034. * @object: Pointer to pdev
  3035. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  3036. *
  3037. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  3038. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  3039. *
  3040. * Return: void
  3041. */
  3042. static void
  3043. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  3044. void *object, void *arg)
  3045. {
  3046. bool *is_aspectral_prohibited = arg;
  3047. struct wlan_objmgr_pdev *cur_pdev = object;
  3048. bool is_agile_dfs_enabled_cur_pdev = false;
  3049. QDF_STATUS status;
  3050. qdf_assert_always(is_aspectral_prohibited);
  3051. if (*is_aspectral_prohibited)
  3052. return;
  3053. qdf_assert_always(psoc);
  3054. qdf_assert_always(cur_pdev);
  3055. status = ucfg_dfs_get_agile_precac_enable
  3056. (cur_pdev,
  3057. &is_agile_dfs_enabled_cur_pdev);
  3058. if (QDF_IS_STATUS_ERROR(status)) {
  3059. spectral_err("Get agile precac failed, prohibiting aSpectral");
  3060. *is_aspectral_prohibited = true;
  3061. return;
  3062. }
  3063. if (is_agile_dfs_enabled_cur_pdev) {
  3064. spectral_err("aDFS is in progress on one of the pdevs");
  3065. *is_aspectral_prohibited = true;
  3066. }
  3067. }
  3068. /**
  3069. * target_if_get_curr_band() - Get current operating band of pdev
  3070. *
  3071. * @spectral: pointer to spectral object
  3072. *
  3073. * API to get current operating band of a given pdev.
  3074. *
  3075. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  3076. */
  3077. static enum reg_wifi_band
  3078. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev)
  3079. {
  3080. struct wlan_objmgr_vdev *vdev;
  3081. int16_t chan_freq;
  3082. enum reg_wifi_band cur_band;
  3083. if (!pdev) {
  3084. spectral_err("pdev is NULL");
  3085. return REG_BAND_UNKNOWN;
  3086. }
  3087. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  3088. if (!vdev) {
  3089. spectral_debug("vdev is NULL");
  3090. return REG_BAND_UNKNOWN;
  3091. }
  3092. chan_freq = target_if_vdev_get_chan_freq(vdev);
  3093. cur_band = wlan_reg_freq_to_band(chan_freq);
  3094. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3095. return cur_band;
  3096. }
  3097. /**
  3098. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  3099. * any of the 5G pdevs
  3100. * @psoc: Pointer to psoc
  3101. * @object: Pointer to pdev
  3102. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  3103. * progress in any 5G pdevs
  3104. *
  3105. * Return: void
  3106. */
  3107. static void
  3108. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  3109. void *object, void *arg)
  3110. {
  3111. enum reg_wifi_band band;
  3112. bool *is_agile_scan_inprog_5g_pdev = arg;
  3113. struct target_if_spectral *spectral;
  3114. struct wlan_objmgr_pdev *cur_pdev = object;
  3115. struct target_if_spectral_ops *p_sops;
  3116. if (*is_agile_scan_inprog_5g_pdev)
  3117. return;
  3118. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  3119. if (!spectral) {
  3120. spectral_err("target if spectral handle is NULL");
  3121. return;
  3122. }
  3123. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3124. band = target_if_get_curr_band(cur_pdev);
  3125. if (band == REG_BAND_UNKNOWN) {
  3126. spectral_debug("Failed to get current band");
  3127. return;
  3128. }
  3129. if (band == REG_BAND_5G &&
  3130. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  3131. *is_agile_scan_inprog_5g_pdev = true;
  3132. }
  3133. /**
  3134. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  3135. * for current vdev rx chainmask.
  3136. *
  3137. * @spectral: Pointer to Spectral object
  3138. * @is_supported: Pointer to is_supported
  3139. *
  3140. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3141. */
  3142. static QDF_STATUS
  3143. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  3144. bool *is_supported)
  3145. {
  3146. struct wlan_objmgr_vdev *vdev;
  3147. uint8_t vdev_rxchainmask;
  3148. struct wlan_objmgr_psoc *psoc;
  3149. struct wlan_objmgr_pdev *pdev;
  3150. struct target_psoc_info *tgt_psoc_info;
  3151. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  3152. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  3153. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  3154. struct wlan_psoc_host_chainmask_table *table;
  3155. int j;
  3156. uint32_t table_id;
  3157. enum phy_ch_width ch_width;
  3158. uint8_t pdev_id;
  3159. if (!spectral) {
  3160. spectral_err("spectral target if object is null");
  3161. return QDF_STATUS_E_FAILURE;
  3162. }
  3163. if (!is_supported) {
  3164. spectral_err("is supported argument is null");
  3165. return QDF_STATUS_E_FAILURE;
  3166. }
  3167. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  3168. spectral_err("HW Agile mode is not supported up to gen 2");
  3169. return QDF_STATUS_E_FAILURE;
  3170. }
  3171. pdev = spectral->pdev_obj;
  3172. if (!pdev) {
  3173. spectral_err("pdev is null");
  3174. return QDF_STATUS_E_FAILURE;
  3175. }
  3176. psoc = wlan_pdev_get_psoc(pdev);
  3177. if (!psoc) {
  3178. spectral_err("psoc is null");
  3179. return QDF_STATUS_E_FAILURE;
  3180. }
  3181. vdev = target_if_spectral_get_vdev(spectral);
  3182. if (!vdev) {
  3183. spectral_err("First vdev is NULL");
  3184. return QDF_STATUS_E_FAILURE;
  3185. }
  3186. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  3187. if (!vdev_rxchainmask) {
  3188. spectral_err("vdev rx chainmask is zero");
  3189. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3190. return QDF_STATUS_E_FAILURE;
  3191. }
  3192. ch_width = target_if_vdev_get_ch_width(vdev);
  3193. if (ch_width == CH_WIDTH_INVALID) {
  3194. spectral_err("Invalid channel width");
  3195. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3196. return QDF_STATUS_E_FAILURE;
  3197. }
  3198. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3199. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  3200. if (!tgt_psoc_info) {
  3201. spectral_err("target_psoc_info is null");
  3202. return QDF_STATUS_E_FAILURE;
  3203. }
  3204. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  3205. if (!ext_svc_param) {
  3206. spectral_err("Extended service ready param null");
  3207. return QDF_STATUS_E_FAILURE;
  3208. }
  3209. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  3210. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  3211. if (!mac_phy_cap_arr) {
  3212. spectral_err("mac phy cap array is null");
  3213. return QDF_STATUS_E_FAILURE;
  3214. }
  3215. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  3216. if (!mac_phy_cap) {
  3217. spectral_err("mac phy cap is null");
  3218. return QDF_STATUS_E_FAILURE;
  3219. }
  3220. table_id = mac_phy_cap->chainmask_table_id;
  3221. table = &ext_svc_param->chainmask_table[table_id];
  3222. if (!table) {
  3223. spectral_err("chainmask table not found");
  3224. return QDF_STATUS_E_FAILURE;
  3225. }
  3226. for (j = 0; j < table->num_valid_chainmasks; j++) {
  3227. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  3228. if (ch_width <= CH_WIDTH_80MHZ)
  3229. *is_supported =
  3230. table->cap_list[j].supports_aSpectral;
  3231. else
  3232. *is_supported =
  3233. table->cap_list[j].supports_aSpectral_160;
  3234. break;
  3235. }
  3236. }
  3237. if (j == table->num_valid_chainmasks) {
  3238. spectral_err("vdev rx chainmask %u not found in table id = %u",
  3239. vdev_rxchainmask, table_id);
  3240. return QDF_STATUS_E_FAILURE;
  3241. }
  3242. return QDF_STATUS_SUCCESS;
  3243. }
  3244. QDF_STATUS
  3245. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3246. const enum spectral_scan_mode smode,
  3247. enum spectral_cp_error_code *err)
  3248. {
  3249. struct target_if_spectral_ops *p_sops;
  3250. struct target_if_spectral *spectral;
  3251. struct wlan_objmgr_psoc *psoc;
  3252. enum reg_wifi_band band;
  3253. if (!err) {
  3254. spectral_err("Error code argument is null");
  3255. QDF_ASSERT(0);
  3256. }
  3257. *err = SPECTRAL_SCAN_ERR_INVALID;
  3258. psoc = wlan_pdev_get_psoc(pdev);
  3259. if (!psoc) {
  3260. spectral_err("psoc is null");
  3261. return QDF_STATUS_E_FAILURE;
  3262. }
  3263. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3264. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3265. spectral_err("Invalid Spectral mode %u", smode);
  3266. return QDF_STATUS_E_FAILURE;
  3267. }
  3268. if (!pdev) {
  3269. spectral_err("pdev object is NUll");
  3270. return QDF_STATUS_E_FAILURE;
  3271. }
  3272. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3273. if (!spectral) {
  3274. spectral_err("Spectral LMAC object is NUll");
  3275. return QDF_STATUS_E_FAILURE;
  3276. }
  3277. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3278. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3279. QDF_STATUS status;
  3280. bool is_supported = false;
  3281. status = target_if_is_agile_supported_cur_chmask(spectral,
  3282. &is_supported);
  3283. if (QDF_IS_STATUS_ERROR(status)) {
  3284. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3285. return QDF_STATUS_E_FAILURE;
  3286. }
  3287. if (!is_supported) {
  3288. spectral_err("aSpectral unsupported for cur chainmask");
  3289. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3290. return QDF_STATUS_E_FAILURE;
  3291. }
  3292. }
  3293. band = target_if_get_curr_band(spectral->pdev_obj);
  3294. if (band == REG_BAND_UNKNOWN) {
  3295. spectral_err("Failed to get current band");
  3296. return QDF_STATUS_E_FAILURE;
  3297. }
  3298. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  3299. struct target_psoc_info *tgt_hdl;
  3300. enum wmi_host_hw_mode_config_type mode;
  3301. bool is_agile_scan_inprog_5g_pdev;
  3302. if (p_sops->is_spectral_active(spectral,
  3303. SPECTRAL_SCAN_MODE_AGILE)) {
  3304. spectral_err("Agile Scan in progress in current pdev");
  3305. return QDF_STATUS_E_FAILURE;
  3306. }
  3307. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  3308. if (!tgt_hdl) {
  3309. target_if_err("target_psoc_info is null");
  3310. return QDF_STATUS_E_FAILURE;
  3311. }
  3312. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  3313. switch (mode) {
  3314. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  3315. case WMI_HOST_HW_MODE_SBS:
  3316. case WMI_HOST_HW_MODE_DBS_SBS:
  3317. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  3318. is_agile_scan_inprog_5g_pdev = false;
  3319. wlan_objmgr_iterate_obj_list
  3320. (psoc, WLAN_PDEV_OP,
  3321. target_if_is_agile_scan_active_in_5g,
  3322. &is_agile_scan_inprog_5g_pdev, 0,
  3323. WLAN_SPECTRAL_ID);
  3324. break;
  3325. default:
  3326. is_agile_scan_inprog_5g_pdev = false;
  3327. break;
  3328. }
  3329. if (is_agile_scan_inprog_5g_pdev) {
  3330. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  3331. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3332. return QDF_STATUS_E_FAILURE;
  3333. }
  3334. }
  3335. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3336. bool is_aspectral_prohibited = false;
  3337. QDF_STATUS status;
  3338. status = wlan_objmgr_iterate_obj_list
  3339. (psoc, WLAN_PDEV_OP,
  3340. target_if_is_aspectral_prohibited_by_adfs,
  3341. &is_aspectral_prohibited, 0,
  3342. WLAN_SPECTRAL_ID);
  3343. if (QDF_IS_STATUS_ERROR(status)) {
  3344. spectral_err("Failed to iterate over pdevs");
  3345. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3346. return QDF_STATUS_E_FAILURE;
  3347. }
  3348. if (is_aspectral_prohibited) {
  3349. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3350. return QDF_STATUS_E_FAILURE;
  3351. }
  3352. }
  3353. if (!spectral->params_valid[smode]) {
  3354. target_if_spectral_info_read(spectral,
  3355. smode,
  3356. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3357. &spectral->params[smode],
  3358. sizeof(spectral->params[smode]));
  3359. spectral->params_valid[smode] = true;
  3360. }
  3361. qdf_spin_lock(&spectral->spectral_lock);
  3362. if (smode == SPECTRAL_SCAN_MODE_AGILE &&
  3363. !spectral->params[smode].ss_frequency) {
  3364. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  3365. qdf_spin_unlock(&spectral->spectral_lock);
  3366. return QDF_STATUS_E_FAILURE;
  3367. }
  3368. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3369. QDF_STATUS status;
  3370. bool is_overlapping;
  3371. status = target_if_is_agile_span_overlap_with_operating_span
  3372. (spectral,
  3373. spectral->params[smode].ss_frequency,
  3374. &is_overlapping);
  3375. if (QDF_IS_STATUS_ERROR(status)) {
  3376. qdf_spin_unlock(&spectral->spectral_lock);
  3377. return QDF_STATUS_E_FAILURE;
  3378. }
  3379. if (is_overlapping) {
  3380. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3381. qdf_spin_unlock(&spectral->spectral_lock);
  3382. return QDF_STATUS_E_FAILURE;
  3383. }
  3384. }
  3385. target_if_spectral_scan_enable_params(spectral,
  3386. &spectral->params[smode], smode,
  3387. err);
  3388. qdf_spin_unlock(&spectral->spectral_lock);
  3389. return QDF_STATUS_SUCCESS;
  3390. }
  3391. QDF_STATUS
  3392. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3393. const enum spectral_scan_mode smode,
  3394. enum spectral_cp_error_code *err)
  3395. {
  3396. struct target_if_spectral_ops *p_sops;
  3397. struct target_if_spectral *spectral;
  3398. if (!err) {
  3399. spectral_err("Error code argument is null");
  3400. QDF_ASSERT(0);
  3401. }
  3402. *err = SPECTRAL_SCAN_ERR_INVALID;
  3403. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3404. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3405. spectral_err("Invalid Spectral mode %u", smode);
  3406. return QDF_STATUS_E_FAILURE;
  3407. }
  3408. if (!pdev) {
  3409. spectral_err("pdev object is NUll ");
  3410. return QDF_STATUS_E_FAILURE;
  3411. }
  3412. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3413. if (!spectral) {
  3414. spectral_err("Spectral LMAC object is NUll ");
  3415. return QDF_STATUS_E_FAILURE;
  3416. }
  3417. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3418. qdf_spin_lock(&spectral->spectral_lock);
  3419. p_sops->stop_spectral_scan(spectral, smode);
  3420. if (spectral->classify_scan) {
  3421. /* TODO : Check if this logic is necessary */
  3422. spectral->detects_control_channel = 0;
  3423. spectral->detects_extension_channel = 0;
  3424. spectral->detects_above_dc = 0;
  3425. spectral->detects_below_dc = 0;
  3426. spectral->classify_scan = 0;
  3427. }
  3428. spectral->send_single_packet = 0;
  3429. spectral->sc_spectral_scan = 0;
  3430. qdf_spin_unlock(&spectral->spectral_lock);
  3431. return QDF_STATUS_SUCCESS;
  3432. }
  3433. /**
  3434. * target_if_is_spectral_active() - Get whether Spectral is active
  3435. * @pdev: Pointer to pdev object
  3436. * @smode: Spectral scan mode
  3437. *
  3438. * API to get whether Spectral is active
  3439. *
  3440. * Return: True if Spectral is active, false if Spectral is not active
  3441. */
  3442. bool
  3443. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  3444. const enum spectral_scan_mode smode)
  3445. {
  3446. struct target_if_spectral *spectral = NULL;
  3447. struct target_if_spectral_ops *p_sops = NULL;
  3448. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3449. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3450. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3451. spectral_err("Invalid Spectral mode %u", smode);
  3452. return QDF_STATUS_E_FAILURE;
  3453. }
  3454. return p_sops->is_spectral_active(spectral, smode);
  3455. }
  3456. /**
  3457. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  3458. * @pdev: Pointer to pdev object
  3459. * @smode: Spectral scan mode
  3460. *
  3461. * API to get whether Spectral is enabled
  3462. *
  3463. * Return: True if Spectral is enabled, false if Spectral is not enabled
  3464. */
  3465. bool
  3466. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  3467. enum spectral_scan_mode smode)
  3468. {
  3469. struct target_if_spectral *spectral = NULL;
  3470. struct target_if_spectral_ops *p_sops = NULL;
  3471. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3472. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3473. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3474. spectral_err("Invalid Spectral mode %u", smode);
  3475. return QDF_STATUS_E_FAILURE;
  3476. }
  3477. return p_sops->is_spectral_enabled(spectral, smode);
  3478. }
  3479. #ifdef DIRECT_BUF_RX_DEBUG
  3480. /**
  3481. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  3482. * @pdev: Pointer to pdev object
  3483. * @enable: Enable/Disable Spectral DMA ring debug
  3484. *
  3485. * Start/stop Spectral DMA ring debug based on @enable.
  3486. * Also save the state for future use.
  3487. *
  3488. * Return: QDF_STATUS of operation
  3489. */
  3490. static QDF_STATUS
  3491. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3492. {
  3493. struct target_if_spectral *spectral;
  3494. struct wlan_lmac_if_tx_ops *tx_ops;
  3495. struct wlan_objmgr_psoc *psoc;
  3496. if (!pdev)
  3497. return QDF_STATUS_E_FAILURE;
  3498. psoc = wlan_pdev_get_psoc(pdev);
  3499. if (!psoc) {
  3500. spectral_err("psoc is null");
  3501. return QDF_STATUS_E_INVAL;
  3502. }
  3503. tx_ops = &psoc->soc_cb.tx_ops;
  3504. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3505. if (!spectral) {
  3506. spectral_err("Spectal LMAC object is NULL");
  3507. return QDF_STATUS_E_INVAL;
  3508. }
  3509. /* Save the state */
  3510. spectral->dbr_ring_debug = enable;
  3511. if (enable)
  3512. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  3513. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  3514. else
  3515. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  3516. pdev, 0);
  3517. return QDF_STATUS_SUCCESS;
  3518. }
  3519. /**
  3520. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  3521. * @pdev: Pointer to pdev object
  3522. * @enable: Enable/Disable Spectral DMA buffer debug
  3523. *
  3524. * Start/stop Spectral DMA buffer debug based on @enable.
  3525. * Also save the state for future use.
  3526. *
  3527. * Return: QDF_STATUS of operation
  3528. */
  3529. static QDF_STATUS
  3530. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3531. {
  3532. struct target_if_spectral *spectral;
  3533. struct wlan_lmac_if_tx_ops *tx_ops;
  3534. struct wlan_objmgr_psoc *psoc;
  3535. if (!pdev)
  3536. return QDF_STATUS_E_FAILURE;
  3537. psoc = wlan_pdev_get_psoc(pdev);
  3538. if (!psoc) {
  3539. spectral_err("psoc is null");
  3540. return QDF_STATUS_E_INVAL;
  3541. }
  3542. tx_ops = &psoc->soc_cb.tx_ops;
  3543. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3544. if (!spectral) {
  3545. spectral_err("Spectal LMAC object is NULL");
  3546. return QDF_STATUS_E_INVAL;
  3547. }
  3548. /* Save the state */
  3549. spectral->dbr_buff_debug = enable;
  3550. if (enable)
  3551. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  3552. pdev, 0, MEM_POISON_SIGNATURE);
  3553. else
  3554. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  3555. pdev, 0);
  3556. }
  3557. /**
  3558. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  3559. * debug based on the previous state
  3560. * @pdev: Pointer to pdev object
  3561. *
  3562. * Return: QDF_STATUS of operation
  3563. */
  3564. static QDF_STATUS
  3565. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  3566. {
  3567. struct target_if_spectral *spectral;
  3568. if (!pdev) {
  3569. spectral_err("pdev is NULL!");
  3570. return QDF_STATUS_E_FAILURE;
  3571. }
  3572. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3573. if (!spectral) {
  3574. spectral_err("Spectal LMAC object is NULL");
  3575. return QDF_STATUS_E_INVAL;
  3576. }
  3577. if (spectral->dbr_buff_debug)
  3578. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  3579. else
  3580. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  3581. }
  3582. /**
  3583. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  3584. * debug based on the previous state
  3585. * @pdev: Pointer to pdev object
  3586. *
  3587. * Return: QDF_STATUS of operation
  3588. */
  3589. static QDF_STATUS
  3590. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  3591. {
  3592. struct target_if_spectral *spectral;
  3593. if (!pdev) {
  3594. spectral_err("pdev is NULL!");
  3595. return QDF_STATUS_E_FAILURE;
  3596. }
  3597. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3598. if (!spectral) {
  3599. spectral_err("Spectal LMAC object is NULL");
  3600. return QDF_STATUS_E_INVAL;
  3601. }
  3602. if (spectral->dbr_ring_debug)
  3603. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  3604. else
  3605. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  3606. }
  3607. /**
  3608. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  3609. * @pdev: Pointer to pdev object
  3610. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  3611. * @debug_value: Value to be set for @dma_debug_type
  3612. *
  3613. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  3614. * based on @debug_value
  3615. *
  3616. * Return: QDF_STATUS of operation
  3617. */
  3618. static QDF_STATUS
  3619. target_if_spectral_set_dma_debug(
  3620. struct wlan_objmgr_pdev *pdev,
  3621. enum spectral_dma_debug dma_debug_type,
  3622. bool debug_value)
  3623. {
  3624. struct target_if_spectral_ops *p_sops;
  3625. struct wlan_objmgr_psoc *psoc;
  3626. struct wlan_lmac_if_tx_ops *tx_ops;
  3627. struct target_if_spectral *spectral;
  3628. if (!pdev)
  3629. return QDF_STATUS_E_FAILURE;
  3630. psoc = wlan_pdev_get_psoc(pdev);
  3631. if (!psoc) {
  3632. spectral_err("psoc is null");
  3633. return QDF_STATUS_E_INVAL;
  3634. }
  3635. tx_ops = &psoc->soc_cb.tx_ops;
  3636. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  3637. spectral_err("Unable to fetch target type");
  3638. return QDF_STATUS_E_FAILURE;
  3639. }
  3640. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3641. if (!spectral) {
  3642. spectral_err("Spectal LMAC object is NULL");
  3643. return QDF_STATUS_E_INVAL;
  3644. }
  3645. if (spectral->direct_dma_support) {
  3646. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3647. if (p_sops->is_spectral_active(spectral,
  3648. SPECTRAL_SCAN_MODE_NORMAL) ||
  3649. p_sops->is_spectral_active(spectral,
  3650. SPECTRAL_SCAN_MODE_AGILE)) {
  3651. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  3652. return QDF_STATUS_E_FAILURE;
  3653. }
  3654. switch (dma_debug_type) {
  3655. case SPECTRAL_DMA_RING_DEBUG:
  3656. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  3657. break;
  3658. case SPECTRAL_DMA_BUFFER_DEBUG:
  3659. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  3660. break;
  3661. default:
  3662. spectral_err("Unsupported DMA debug type : %d",
  3663. dma_debug_type);
  3664. return QDF_STATUS_E_FAILURE;
  3665. }
  3666. }
  3667. return QDF_STATUS_SUCCESS;
  3668. }
  3669. #endif /* DIRECT_BUF_RX_DEBUG */
  3670. /**
  3671. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  3672. * @pdev: Pointer to pdev object
  3673. *
  3674. * Return: Whether Direct-DMA is supported on this radio
  3675. */
  3676. static bool
  3677. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  3678. {
  3679. struct target_if_spectral *spectral;
  3680. if (!pdev) {
  3681. spectral_err("pdev is NULL!");
  3682. return false;
  3683. }
  3684. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3685. if (!spectral) {
  3686. spectral_err("Spectral LMAC object is NULL");
  3687. return false;
  3688. }
  3689. return spectral->direct_dma_support;
  3690. }
  3691. /**
  3692. * target_if_set_debug_level() - Set debug level for Spectral
  3693. * @pdev: Pointer to pdev object
  3694. * @debug_level: Debug level
  3695. *
  3696. * API to set the debug level for Spectral
  3697. *
  3698. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3699. */
  3700. QDF_STATUS
  3701. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  3702. {
  3703. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  3704. return QDF_STATUS_SUCCESS;
  3705. }
  3706. /**
  3707. * target_if_get_debug_level() - Get debug level for Spectral
  3708. * @pdev: Pointer to pdev object
  3709. *
  3710. * API to get the debug level for Spectral
  3711. *
  3712. * Return: Current debug level
  3713. */
  3714. uint32_t
  3715. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  3716. {
  3717. return spectral_debug_level;
  3718. }
  3719. /**
  3720. * target_if_get_spectral_capinfo() - Get Spectral capability information
  3721. * @pdev: Pointer to pdev object
  3722. * @scaps: Buffer into which data should be copied
  3723. *
  3724. * API to get the spectral capability information
  3725. *
  3726. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3727. */
  3728. QDF_STATUS
  3729. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  3730. struct spectral_caps *scaps)
  3731. {
  3732. struct target_if_spectral *spectral = NULL;
  3733. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3734. qdf_mem_copy(scaps, &spectral->capability,
  3735. sizeof(struct spectral_caps));
  3736. return QDF_STATUS_SUCCESS;
  3737. }
  3738. /**
  3739. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  3740. * @pdev: Pointer to pdev object
  3741. * @stats: Buffer into which data should be copied
  3742. *
  3743. * API to get the spectral diagnostic statistics
  3744. *
  3745. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3746. */
  3747. QDF_STATUS
  3748. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  3749. struct spectral_diag_stats *stats)
  3750. {
  3751. struct target_if_spectral *spectral = NULL;
  3752. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3753. qdf_mem_copy(stats, &spectral->diag_stats,
  3754. sizeof(struct spectral_diag_stats));
  3755. return QDF_STATUS_SUCCESS;
  3756. }
  3757. /**
  3758. * target_if_register_wmi_spectral_cmd_ops() - Register wmi_spectral_cmd_ops
  3759. * @cmd_ops: Pointer to the structure having wmi_spectral_cmd function pointers
  3760. * @pdev: Pointer to pdev object
  3761. *
  3762. * API for register wmi_spectral_cmd_ops in spectral internal data structure
  3763. *
  3764. * Return: void
  3765. */
  3766. void
  3767. target_if_register_wmi_spectral_cmd_ops(struct wlan_objmgr_pdev *pdev,
  3768. struct wmi_spectral_cmd_ops *cmd_ops)
  3769. {
  3770. struct target_if_spectral *spectral =
  3771. get_target_if_spectral_handle_from_pdev(pdev);
  3772. if (!spectral) {
  3773. spectral_err("Spectral LMAC object is null");
  3774. return;
  3775. }
  3776. spectral->param_wmi_cmd_ops = *cmd_ops;
  3777. }
  3778. /**
  3779. * target_if_register_netlink_cb() - Register Netlink callbacks
  3780. * @pdev: Pointer to pdev object
  3781. * @nl_cb: Netlink callbacks to register
  3782. *
  3783. * Return: void
  3784. */
  3785. static void
  3786. target_if_register_netlink_cb(
  3787. struct wlan_objmgr_pdev *pdev,
  3788. struct spectral_nl_cb *nl_cb)
  3789. {
  3790. struct target_if_spectral *spectral = NULL;
  3791. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3792. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  3793. if (spectral->use_nl_bcast)
  3794. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  3795. else
  3796. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  3797. }
  3798. /**
  3799. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  3800. * Netlink messages to the application layer
  3801. * @pdev: Pointer to pdev object
  3802. *
  3803. * Return: true for broadcast, false for unicast
  3804. */
  3805. static bool
  3806. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  3807. {
  3808. struct target_if_spectral *spectral = NULL;
  3809. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3810. return spectral->use_nl_bcast;
  3811. }
  3812. /**
  3813. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  3814. * @pdev: Pointer to pdev object
  3815. *
  3816. * Return: void
  3817. */
  3818. static void
  3819. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  3820. {
  3821. struct target_if_spectral *spectral = NULL;
  3822. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3823. if (!spectral) {
  3824. spectral_err("SPECTRAL : Module doesn't exist");
  3825. return;
  3826. }
  3827. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  3828. }
  3829. static int
  3830. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  3831. void *payload)
  3832. {
  3833. struct target_if_spectral *spectral = NULL;
  3834. struct target_if_spectral_ops *p_sops = NULL;
  3835. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3836. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3837. return p_sops->process_spectral_report(pdev, payload);
  3838. }
  3839. #ifdef DIRECT_BUF_RX_DEBUG
  3840. static inline void
  3841. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3842. {
  3843. if (!tx_ops)
  3844. return;
  3845. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  3846. target_if_spectral_set_dma_debug;
  3847. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  3848. target_if_spectral_check_and_do_dbr_ring_debug;
  3849. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  3850. target_if_spectral_check_and_do_dbr_buff_debug;
  3851. }
  3852. #else
  3853. static inline void
  3854. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3855. {
  3856. }
  3857. #endif
  3858. void
  3859. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3860. {
  3861. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  3862. target_if_pdev_spectral_init;
  3863. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  3864. target_if_pdev_spectral_deinit;
  3865. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  3866. target_if_set_spectral_config;
  3867. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  3868. target_if_get_spectral_config;
  3869. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  3870. target_if_start_spectral_scan;
  3871. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  3872. target_if_stop_spectral_scan;
  3873. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  3874. target_if_is_spectral_active;
  3875. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  3876. target_if_is_spectral_enabled;
  3877. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  3878. target_if_set_debug_level;
  3879. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  3880. target_if_get_debug_level;
  3881. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  3882. target_if_get_spectral_capinfo;
  3883. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  3884. target_if_get_spectral_diagstats;
  3885. tx_ops->sptrl_tx_ops.sptrlto_register_wmi_spectral_cmd_ops =
  3886. target_if_register_wmi_spectral_cmd_ops;
  3887. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  3888. target_if_register_netlink_cb;
  3889. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  3890. target_if_use_nl_bcast;
  3891. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  3892. target_if_deregister_netlink_cb;
  3893. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  3894. target_if_process_spectral_report;
  3895. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  3896. target_if_spectral_direct_dma_support;
  3897. target_if_sptrl_debug_register_tx_ops(tx_ops);
  3898. }
  3899. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  3900. void
  3901. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  3902. uint16_t cw_int, uint32_t dcs_enabled)
  3903. {
  3904. struct spectral_samp_msg *msg = NULL;
  3905. struct target_if_spectral_ops *p_sops = NULL;
  3906. struct target_if_spectral *spectral = NULL;
  3907. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3908. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  3909. spectral->pdev_obj,
  3910. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  3911. SPECTRAL_MSG_BUF_NEW);
  3912. if (msg) {
  3913. msg->int_type = cw_int ?
  3914. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  3915. msg->dcs_enabled = dcs_enabled;
  3916. msg->signature = SPECTRAL_SIGNATURE;
  3917. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3918. p_sops->get_mac_address(spectral, msg->macaddr);
  3919. if (spectral->send_phy_data
  3920. (pdev,
  3921. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  3922. spectral->spectral_sent_msg++;
  3923. }
  3924. }
  3925. qdf_export_symbol(target_if_spectral_send_intf_found_msg);