target_if_spectral.c 132 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770
  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. return QDF_STATUS_E_FAILURE;
  2467. }
  2468. *err = SPECTRAL_SCAN_ERR_INVALID;
  2469. if (!spectral) {
  2470. spectral_err("spectral object is NULL");
  2471. return QDF_STATUS_E_FAILURE;
  2472. }
  2473. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2474. param_min_max = &spectral->param_min_max;
  2475. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2476. spectral_err("Invalid Spectral mode %u", smode);
  2477. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2478. return QDF_STATUS_E_FAILURE;
  2479. }
  2480. sparams = &spectral->params[smode];
  2481. if (!spectral->params_valid[smode]) {
  2482. target_if_spectral_info_read(spectral,
  2483. smode,
  2484. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2485. &spectral->params[smode],
  2486. sizeof(spectral->params[smode]));
  2487. spectral->params_valid[smode] = true;
  2488. }
  2489. switch (threshtype) {
  2490. case SPECTRAL_PARAM_FFT_PERIOD:
  2491. sparams->ss_fft_period = value;
  2492. break;
  2493. case SPECTRAL_PARAM_SCAN_PERIOD:
  2494. sparams->ss_period = value;
  2495. break;
  2496. case SPECTRAL_PARAM_SCAN_COUNT:
  2497. sparams->ss_count = value;
  2498. break;
  2499. case SPECTRAL_PARAM_SHORT_REPORT:
  2500. sparams->ss_short_report = (!!value) ? true : false;
  2501. break;
  2502. case SPECTRAL_PARAM_SPECT_PRI:
  2503. sparams->ss_spectral_pri = (!!value) ? true : false;
  2504. break;
  2505. case SPECTRAL_PARAM_FFT_SIZE:
  2506. status = target_if_spectral_populate_chwidth(spectral);
  2507. if (QDF_IS_STATUS_ERROR(status))
  2508. return QDF_STATUS_E_FAILURE;
  2509. if ((value < param_min_max->fft_size_min) ||
  2510. (value > param_min_max->fft_size_max
  2511. [spectral->ch_width[smode]])) {
  2512. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2513. return QDF_STATUS_E_FAILURE;
  2514. }
  2515. sparams->ss_fft_size = value;
  2516. break;
  2517. case SPECTRAL_PARAM_GC_ENA:
  2518. sparams->ss_gc_ena = !!value;
  2519. break;
  2520. case SPECTRAL_PARAM_RESTART_ENA:
  2521. sparams->ss_restart_ena = !!value;
  2522. break;
  2523. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  2524. sparams->ss_noise_floor_ref = value;
  2525. break;
  2526. case SPECTRAL_PARAM_INIT_DELAY:
  2527. sparams->ss_init_delay = value;
  2528. break;
  2529. case SPECTRAL_PARAM_NB_TONE_THR:
  2530. sparams->ss_nb_tone_thr = value;
  2531. break;
  2532. case SPECTRAL_PARAM_STR_BIN_THR:
  2533. sparams->ss_str_bin_thr = value;
  2534. break;
  2535. case SPECTRAL_PARAM_WB_RPT_MODE:
  2536. sparams->ss_wb_rpt_mode = !!value;
  2537. break;
  2538. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  2539. sparams->ss_rssi_rpt_mode = !!value;
  2540. break;
  2541. case SPECTRAL_PARAM_RSSI_THR:
  2542. sparams->ss_rssi_thr = value;
  2543. break;
  2544. case SPECTRAL_PARAM_PWR_FORMAT:
  2545. sparams->ss_pwr_format = !!value;
  2546. break;
  2547. case SPECTRAL_PARAM_RPT_MODE:
  2548. if ((value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  2549. (value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  2550. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2551. return QDF_STATUS_E_FAILURE;
  2552. }
  2553. sparams->ss_rpt_mode = value;
  2554. break;
  2555. case SPECTRAL_PARAM_BIN_SCALE:
  2556. sparams->ss_bin_scale = value;
  2557. break;
  2558. case SPECTRAL_PARAM_DBM_ADJ:
  2559. sparams->ss_dbm_adj = !!value;
  2560. break;
  2561. case SPECTRAL_PARAM_CHN_MASK:
  2562. sparams->ss_chn_mask = value;
  2563. break;
  2564. case SPECTRAL_PARAM_FREQUENCY:
  2565. status = target_if_is_center_freq_of_any_chan
  2566. (spectral->pdev_obj, value, &is_valid_chan);
  2567. if (QDF_IS_STATUS_ERROR(status))
  2568. return QDF_STATUS_E_FAILURE;
  2569. if (is_valid_chan) {
  2570. status = target_if_calculate_center_freq(spectral,
  2571. value,
  2572. &agile_cfreq);
  2573. if (QDF_IS_STATUS_ERROR(status)) {
  2574. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2575. return QDF_STATUS_E_FAILURE;
  2576. }
  2577. } else {
  2578. bool is_valid_agile_cfreq;
  2579. status = target_if_validate_center_freq
  2580. (spectral, value, &is_valid_agile_cfreq);
  2581. if (QDF_IS_STATUS_ERROR(status))
  2582. return QDF_STATUS_E_FAILURE;
  2583. if (!is_valid_agile_cfreq) {
  2584. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2585. spectral_err("Invalid agile center frequency");
  2586. return QDF_STATUS_E_FAILURE;
  2587. }
  2588. agile_cfreq = value;
  2589. }
  2590. status = target_if_is_agile_span_overlap_with_operating_span
  2591. (spectral, agile_cfreq, &is_overlapping);
  2592. if (QDF_IS_STATUS_ERROR(status))
  2593. return QDF_STATUS_E_FAILURE;
  2594. if (is_overlapping) {
  2595. spectral_err("Agile span overlapping with current BW");
  2596. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2597. return QDF_STATUS_E_FAILURE;
  2598. }
  2599. sparams->ss_frequency = agile_cfreq;
  2600. break;
  2601. }
  2602. p_sops->configure_spectral(spectral, sparams, smode);
  2603. /* only to validate the writes */
  2604. p_sops->get_spectral_config(spectral, &params, smode);
  2605. return QDF_STATUS_SUCCESS;
  2606. }
  2607. QDF_STATUS
  2608. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  2609. const uint32_t threshtype, const uint32_t value,
  2610. const enum spectral_scan_mode smode,
  2611. enum spectral_cp_error_code *err)
  2612. {
  2613. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  2614. struct target_if_spectral *spectral;
  2615. QDF_STATUS status;
  2616. if (!err) {
  2617. spectral_err("Error code argument is null");
  2618. QDF_ASSERT(0);
  2619. return QDF_STATUS_E_FAILURE;
  2620. }
  2621. *err = SPECTRAL_SCAN_ERR_INVALID;
  2622. if (!pdev) {
  2623. spectral_err("pdev object is NULL");
  2624. return QDF_STATUS_E_FAILURE;
  2625. }
  2626. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2627. if (!spectral) {
  2628. spectral_err("spectral object is NULL");
  2629. return QDF_STATUS_E_FAILURE;
  2630. }
  2631. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2632. spectral_err("Invalid Spectral mode %u", smode);
  2633. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2634. return QDF_STATUS_E_FAILURE;
  2635. }
  2636. if (!spectral->properties[smode][threshtype].supported) {
  2637. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  2638. threshtype, smode);
  2639. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  2640. return QDF_STATUS_E_FAILURE;
  2641. }
  2642. if (spectral->properties[smode][threshtype].common_all_modes) {
  2643. spectral_warn("Setting Spectral parameter %u for all modes",
  2644. threshtype);
  2645. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  2646. status = _target_if_set_spectral_config
  2647. (spectral, threshtype, value,
  2648. mode, err);
  2649. if (QDF_IS_STATUS_ERROR(status))
  2650. return QDF_STATUS_E_FAILURE;
  2651. }
  2652. return QDF_STATUS_SUCCESS;
  2653. }
  2654. return _target_if_set_spectral_config(spectral, threshtype,
  2655. value, smode, err);
  2656. }
  2657. /**
  2658. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  2659. * @fft_len: FFT length
  2660. * @pdev: Pointer to pdev object
  2661. *
  2662. * API to get fft bin count for a given fft length
  2663. *
  2664. * Return: FFt bin count
  2665. */
  2666. static int
  2667. target_if_get_fft_bin_count(int fft_len)
  2668. {
  2669. int bin_count = 0;
  2670. switch (fft_len) {
  2671. case 5:
  2672. bin_count = 16;
  2673. break;
  2674. case 6:
  2675. bin_count = 32;
  2676. break;
  2677. case 7:
  2678. bin_count = 64;
  2679. break;
  2680. case 8:
  2681. bin_count = 128;
  2682. break;
  2683. case 9:
  2684. bin_count = 256;
  2685. break;
  2686. default:
  2687. break;
  2688. }
  2689. return bin_count;
  2690. }
  2691. /**
  2692. * target_if_init_upper_lower_flags() - Initializes control and extension
  2693. * segment flags
  2694. * @fft_len: FFT length
  2695. * @pdev: Pointer to pdev object
  2696. *
  2697. * API to initialize the control and extension flags with the lower/upper
  2698. * segment based on the HT mode
  2699. *
  2700. * Return: FFt bin count
  2701. */
  2702. static void
  2703. target_if_init_upper_lower_flags(struct target_if_spectral *spectral)
  2704. {
  2705. int current_channel = 0;
  2706. int ext_channel = 0;
  2707. struct target_if_spectral_ops *p_sops =
  2708. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2709. current_channel = p_sops->get_current_channel(spectral);
  2710. ext_channel = p_sops->get_extension_channel(spectral);
  2711. if ((current_channel == 0) || (ext_channel == 0))
  2712. return;
  2713. if (spectral->sc_spectral_20_40_mode) {
  2714. /* HT40 mode */
  2715. if (ext_channel < current_channel) {
  2716. spectral->lower_is_extension = 1;
  2717. spectral->upper_is_control = 1;
  2718. spectral->lower_is_control = 0;
  2719. spectral->upper_is_extension = 0;
  2720. } else {
  2721. spectral->lower_is_extension = 0;
  2722. spectral->upper_is_control = 0;
  2723. spectral->lower_is_control = 1;
  2724. spectral->upper_is_extension = 1;
  2725. }
  2726. } else {
  2727. /* HT20 mode, lower is always control */
  2728. spectral->lower_is_extension = 0;
  2729. spectral->upper_is_control = 0;
  2730. spectral->lower_is_control = 1;
  2731. spectral->upper_is_extension = 0;
  2732. }
  2733. }
  2734. /**
  2735. * target_if_get_spectral_config() - Get spectral configuration
  2736. * @pdev: Pointer to pdev object
  2737. * @param: Pointer to spectral_config structure in which the configuration
  2738. * should be returned
  2739. * @smode: Spectral scan mode
  2740. *
  2741. * API to get the current spectral configuration
  2742. *
  2743. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2744. */
  2745. QDF_STATUS
  2746. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  2747. struct spectral_config *param,
  2748. enum spectral_scan_mode smode)
  2749. {
  2750. struct target_if_spectral_ops *p_sops = NULL;
  2751. struct target_if_spectral *spectral = NULL;
  2752. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2753. if (!spectral) {
  2754. spectral_err("SPECTRAL : Module doesn't exist");
  2755. return QDF_STATUS_E_FAILURE;
  2756. }
  2757. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2758. if (!p_sops) {
  2759. spectral_err("p_sops is null");
  2760. return QDF_STATUS_E_FAILURE;
  2761. }
  2762. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2763. spectral_err("Invalid Spectral mode %u", smode);
  2764. return QDF_STATUS_E_FAILURE;
  2765. }
  2766. qdf_mem_zero(param, sizeof(struct spectral_config));
  2767. p_sops->get_spectral_config(spectral, param, smode);
  2768. return QDF_STATUS_SUCCESS;
  2769. }
  2770. /**
  2771. * target_if_spectral_init_fft_bin_markers_res_80p80() - Initialize boundaries
  2772. * of primary 80, 5 MHz and secondary 80 FFT bins in restricted 80+80 operation
  2773. *
  2774. * @spectral: Pointer to Spectral object
  2775. *
  2776. * Function to initialize boundaries of primary 80, 5 MHz and secondary 80
  2777. * FFT bins in restricted 80+80 operation.
  2778. *
  2779. * Return: QDF_STATUS
  2780. */
  2781. static QDF_STATUS
  2782. target_if_spectral_init_fft_bin_markers_res_80p80(
  2783. struct target_if_spectral *spectral)
  2784. {
  2785. struct spectral_fft_bin_markers_165mhz *marker;
  2786. int16_t primary_chan_freq;
  2787. uint32_t cfreq2;
  2788. struct wlan_objmgr_vdev *vdev;
  2789. if (!spectral) {
  2790. spectral_err("Spectral object is null");
  2791. return QDF_STATUS_E_INVAL;
  2792. }
  2793. vdev = target_if_spectral_get_vdev(spectral);
  2794. if (!vdev) {
  2795. spectral_info("First vdev is NULL");
  2796. return QDF_STATUS_E_INVAL;
  2797. }
  2798. primary_chan_freq = target_if_vdev_get_chan_freq(vdev);
  2799. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2800. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2801. if (cfreq2 < 0) {
  2802. spectral_err("cfreq2 is invalid");
  2803. return QDF_STATUS_E_INVAL;
  2804. }
  2805. marker = spectral->rparams.marker[SPECTRAL_REPORT_MODE_2];
  2806. marker[SPECTRAL_FFT_SIZE_5].start_5mhz = 8;
  2807. marker[SPECTRAL_FFT_SIZE_5].num_5mhz = 1;
  2808. marker[SPECTRAL_FFT_SIZE_6].start_5mhz = 16;
  2809. marker[SPECTRAL_FFT_SIZE_6].num_5mhz = 1;
  2810. marker[SPECTRAL_FFT_SIZE_7].start_5mhz = 32;
  2811. marker[SPECTRAL_FFT_SIZE_7].num_5mhz = 2;
  2812. marker[SPECTRAL_FFT_SIZE_8].start_5mhz = 64;
  2813. marker[SPECTRAL_FFT_SIZE_8].num_5mhz = 4;
  2814. marker[SPECTRAL_FFT_SIZE_9].start_5mhz = 128;
  2815. marker[SPECTRAL_FFT_SIZE_9].num_5mhz = 8;
  2816. marker[SPECTRAL_FFT_SIZE_10].start_5mhz = 256;
  2817. marker[SPECTRAL_FFT_SIZE_10].num_5mhz = 16;
  2818. marker = spectral->rparams.marker[SPECTRAL_REPORT_MODE_3];
  2819. marker[SPECTRAL_FFT_SIZE_5].start_5mhz = 16;
  2820. marker[SPECTRAL_FFT_SIZE_5].num_5mhz = 1;
  2821. marker[SPECTRAL_FFT_SIZE_6].start_5mhz = 32;
  2822. marker[SPECTRAL_FFT_SIZE_6].num_5mhz = 1;
  2823. marker[SPECTRAL_FFT_SIZE_7].start_5mhz = 64;
  2824. marker[SPECTRAL_FFT_SIZE_7].num_5mhz = 2;
  2825. marker[SPECTRAL_FFT_SIZE_8].start_5mhz = 128;
  2826. marker[SPECTRAL_FFT_SIZE_8].num_5mhz = 4;
  2827. marker[SPECTRAL_FFT_SIZE_9].start_5mhz = 256;
  2828. marker[SPECTRAL_FFT_SIZE_9].num_5mhz = 8;
  2829. marker[SPECTRAL_FFT_SIZE_10].start_5mhz = 512;
  2830. marker[SPECTRAL_FFT_SIZE_10].num_5mhz = 16;
  2831. if (primary_chan_freq < cfreq2) {
  2832. marker = spectral->rparams.marker[SPECTRAL_REPORT_MODE_2];
  2833. marker[SPECTRAL_FFT_SIZE_5].start_pri80 = 0;
  2834. marker[SPECTRAL_FFT_SIZE_5].num_pri80 = 8;
  2835. marker[SPECTRAL_FFT_SIZE_5].start_sec80 = 9;
  2836. marker[SPECTRAL_FFT_SIZE_5].num_sec80 = 8;
  2837. marker[SPECTRAL_FFT_SIZE_6].start_pri80 = 0;
  2838. marker[SPECTRAL_FFT_SIZE_6].num_pri80 = 16;
  2839. marker[SPECTRAL_FFT_SIZE_6].start_sec80 = 17;
  2840. marker[SPECTRAL_FFT_SIZE_6].num_sec80 = 16;
  2841. marker[SPECTRAL_FFT_SIZE_7].start_pri80 = 0;
  2842. marker[SPECTRAL_FFT_SIZE_7].num_pri80 = 32;
  2843. marker[SPECTRAL_FFT_SIZE_7].start_sec80 = 34;
  2844. marker[SPECTRAL_FFT_SIZE_7].num_sec80 = 32;
  2845. marker[SPECTRAL_FFT_SIZE_8].start_pri80 = 0;
  2846. marker[SPECTRAL_FFT_SIZE_8].num_pri80 = 64;
  2847. marker[SPECTRAL_FFT_SIZE_8].start_sec80 = 68;
  2848. marker[SPECTRAL_FFT_SIZE_8].num_sec80 = 64;
  2849. marker[SPECTRAL_FFT_SIZE_9].start_pri80 = 0;
  2850. marker[SPECTRAL_FFT_SIZE_9].num_pri80 = 128;
  2851. marker[SPECTRAL_FFT_SIZE_9].start_sec80 = 136;
  2852. marker[SPECTRAL_FFT_SIZE_9].num_sec80 = 128;
  2853. marker[SPECTRAL_FFT_SIZE_10].start_pri80 = 0;
  2854. marker[SPECTRAL_FFT_SIZE_10].num_pri80 = 256;
  2855. marker[SPECTRAL_FFT_SIZE_10].start_sec80 = 272;
  2856. marker[SPECTRAL_FFT_SIZE_10].num_sec80 = 256;
  2857. marker = spectral->rparams.marker[SPECTRAL_REPORT_MODE_3];
  2858. marker[SPECTRAL_FFT_SIZE_5].start_pri80 = 0;
  2859. marker[SPECTRAL_FFT_SIZE_5].num_pri80 = 16;
  2860. marker[SPECTRAL_FFT_SIZE_5].start_sec80 = 17;
  2861. marker[SPECTRAL_FFT_SIZE_5].num_sec80 = 15;
  2862. marker[SPECTRAL_FFT_SIZE_6].start_pri80 = 0;
  2863. marker[SPECTRAL_FFT_SIZE_6].num_pri80 = 32;
  2864. marker[SPECTRAL_FFT_SIZE_6].start_sec80 = 33;
  2865. marker[SPECTRAL_FFT_SIZE_6].num_sec80 = 31;
  2866. marker[SPECTRAL_FFT_SIZE_7].start_pri80 = 0;
  2867. marker[SPECTRAL_FFT_SIZE_7].num_pri80 = 64;
  2868. marker[SPECTRAL_FFT_SIZE_7].start_sec80 = 66;
  2869. marker[SPECTRAL_FFT_SIZE_7].num_sec80 = 62;
  2870. marker[SPECTRAL_FFT_SIZE_8].start_pri80 = 0;
  2871. marker[SPECTRAL_FFT_SIZE_8].num_pri80 = 128;
  2872. marker[SPECTRAL_FFT_SIZE_8].start_sec80 = 132;
  2873. marker[SPECTRAL_FFT_SIZE_8].num_sec80 = 124;
  2874. marker[SPECTRAL_FFT_SIZE_9].start_pri80 = 0;
  2875. marker[SPECTRAL_FFT_SIZE_9].num_pri80 = 256;
  2876. marker[SPECTRAL_FFT_SIZE_9].start_sec80 = 264;
  2877. marker[SPECTRAL_FFT_SIZE_9].num_sec80 = 248;
  2878. marker[SPECTRAL_FFT_SIZE_10].start_pri80 = 0;
  2879. marker[SPECTRAL_FFT_SIZE_10].num_pri80 = 512;
  2880. marker[SPECTRAL_FFT_SIZE_10].start_sec80 = 528;
  2881. marker[SPECTRAL_FFT_SIZE_10].num_sec80 = 496;
  2882. } else {
  2883. marker = spectral->rparams.marker[SPECTRAL_REPORT_MODE_2];
  2884. marker[SPECTRAL_FFT_SIZE_5].start_sec80 = 0;
  2885. marker[SPECTRAL_FFT_SIZE_5].num_sec80 = 8;
  2886. marker[SPECTRAL_FFT_SIZE_5].start_pri80 = 9;
  2887. marker[SPECTRAL_FFT_SIZE_5].num_pri80 = 8;
  2888. marker[SPECTRAL_FFT_SIZE_6].start_sec80 = 0;
  2889. marker[SPECTRAL_FFT_SIZE_6].num_sec80 = 16;
  2890. marker[SPECTRAL_FFT_SIZE_6].start_pri80 = 17;
  2891. marker[SPECTRAL_FFT_SIZE_6].num_pri80 = 16;
  2892. marker[SPECTRAL_FFT_SIZE_7].start_sec80 = 0;
  2893. marker[SPECTRAL_FFT_SIZE_7].num_sec80 = 32;
  2894. marker[SPECTRAL_FFT_SIZE_7].start_pri80 = 34;
  2895. marker[SPECTRAL_FFT_SIZE_7].num_pri80 = 32;
  2896. marker[SPECTRAL_FFT_SIZE_8].start_sec80 = 0;
  2897. marker[SPECTRAL_FFT_SIZE_8].num_sec80 = 64;
  2898. marker[SPECTRAL_FFT_SIZE_8].start_pri80 = 68;
  2899. marker[SPECTRAL_FFT_SIZE_8].num_pri80 = 64;
  2900. marker[SPECTRAL_FFT_SIZE_9].start_sec80 = 0;
  2901. marker[SPECTRAL_FFT_SIZE_9].num_sec80 = 128;
  2902. marker[SPECTRAL_FFT_SIZE_9].start_pri80 = 136;
  2903. marker[SPECTRAL_FFT_SIZE_9].num_pri80 = 128;
  2904. marker[SPECTRAL_FFT_SIZE_10].start_sec80 = 0;
  2905. marker[SPECTRAL_FFT_SIZE_10].num_sec80 = 256;
  2906. marker[SPECTRAL_FFT_SIZE_10].start_pri80 = 272;
  2907. marker[SPECTRAL_FFT_SIZE_10].num_pri80 = 256;
  2908. marker = spectral->rparams.marker[SPECTRAL_REPORT_MODE_3];
  2909. marker[SPECTRAL_FFT_SIZE_5].start_sec80 = 0;
  2910. marker[SPECTRAL_FFT_SIZE_5].num_sec80 = 16;
  2911. marker[SPECTRAL_FFT_SIZE_5].start_pri80 = 17;
  2912. marker[SPECTRAL_FFT_SIZE_5].num_pri80 = 15;
  2913. marker[SPECTRAL_FFT_SIZE_6].start_sec80 = 0;
  2914. marker[SPECTRAL_FFT_SIZE_6].num_sec80 = 32;
  2915. marker[SPECTRAL_FFT_SIZE_6].start_pri80 = 33;
  2916. marker[SPECTRAL_FFT_SIZE_6].num_pri80 = 31;
  2917. marker[SPECTRAL_FFT_SIZE_7].start_sec80 = 0;
  2918. marker[SPECTRAL_FFT_SIZE_7].num_sec80 = 64;
  2919. marker[SPECTRAL_FFT_SIZE_7].start_pri80 = 66;
  2920. marker[SPECTRAL_FFT_SIZE_7].num_pri80 = 62;
  2921. marker[SPECTRAL_FFT_SIZE_8].start_sec80 = 0;
  2922. marker[SPECTRAL_FFT_SIZE_8].num_sec80 = 128;
  2923. marker[SPECTRAL_FFT_SIZE_8].start_pri80 = 132;
  2924. marker[SPECTRAL_FFT_SIZE_8].num_pri80 = 124;
  2925. marker[SPECTRAL_FFT_SIZE_9].start_sec80 = 0;
  2926. marker[SPECTRAL_FFT_SIZE_9].num_sec80 = 256;
  2927. marker[SPECTRAL_FFT_SIZE_9].start_pri80 = 264;
  2928. marker[SPECTRAL_FFT_SIZE_9].num_pri80 = 248;
  2929. marker[SPECTRAL_FFT_SIZE_10].start_sec80 = 0;
  2930. marker[SPECTRAL_FFT_SIZE_10].num_sec80 = 512;
  2931. marker[SPECTRAL_FFT_SIZE_10].start_pri80 = 528;
  2932. marker[SPECTRAL_FFT_SIZE_10].num_pri80 = 496;
  2933. }
  2934. return QDF_STATUS_SUCCESS;
  2935. }
  2936. /**
  2937. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  2938. * parameters
  2939. * @spectral: Pointer to Spectral target_if internal private data
  2940. * @spectral_params: Pointer to Spectral parameters
  2941. * @smode: Spectral scan mode
  2942. * @err: Spectral error code
  2943. *
  2944. * Enable use of desired Spectral parameters by configuring them into HW, and
  2945. * starting Spectral scan
  2946. *
  2947. * Return: 0 on success, 1 on failure
  2948. */
  2949. int
  2950. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  2951. struct spectral_config *spectral_params,
  2952. enum spectral_scan_mode smode,
  2953. enum spectral_cp_error_code *err)
  2954. {
  2955. int extension_channel = 0;
  2956. int current_channel = 0;
  2957. struct target_if_spectral_ops *p_sops = NULL;
  2958. QDF_STATUS status;
  2959. struct wlan_objmgr_pdev *pdev;
  2960. struct wlan_objmgr_psoc *psoc;
  2961. if (!spectral) {
  2962. spectral_err("Spectral LMAC object is NULL");
  2963. return 1;
  2964. }
  2965. pdev = spectral->pdev_obj;
  2966. if (!pdev) {
  2967. spectral_err("pdev is null");
  2968. return QDF_STATUS_E_INVAL;
  2969. }
  2970. psoc = wlan_pdev_get_psoc(pdev);
  2971. if (!psoc) {
  2972. spectral_err("psoc is null");
  2973. return QDF_STATUS_E_INVAL;
  2974. }
  2975. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2976. spectral_err("Invalid Spectral mode %u", smode);
  2977. return 1;
  2978. }
  2979. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2980. if (!p_sops) {
  2981. spectral_err("p_sops is NULL");
  2982. return 1;
  2983. }
  2984. spectral->sc_spectral_noise_pwr_cal =
  2985. spectral_params->ss_spectral_pri ? 1 : 0;
  2986. /* check if extension channel is present */
  2987. extension_channel = p_sops->get_extension_channel(spectral);
  2988. current_channel = p_sops->get_current_channel(spectral);
  2989. status = target_if_spectral_populate_chwidth(spectral);
  2990. if (QDF_IS_STATUS_ERROR(status)) {
  2991. spectral_err("Failed to get channel widths");
  2992. return 1;
  2993. }
  2994. if (spectral->ch_width[smode] == CH_WIDTH_80P80MHZ &&
  2995. wlan_psoc_nif_fw_ext_cap_get(
  2996. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  2997. status = target_if_spectral_init_fft_bin_markers_res_80p80(
  2998. spectral);
  2999. if (QDF_IS_STATUS_ERROR(status)) {
  3000. spectral_err("Unable to initialize FFT bin boundaries");
  3001. return 1;
  3002. }
  3003. }
  3004. if (spectral->capability.advncd_spectral_cap) {
  3005. spectral->lb_edge_extrabins = 0;
  3006. spectral->rb_edge_extrabins = 0;
  3007. if (spectral->is_lb_edge_extrabins_format &&
  3008. spectral->params[smode].ss_rpt_mode == 2) {
  3009. spectral->lb_edge_extrabins = 4;
  3010. }
  3011. if (spectral->is_rb_edge_extrabins_format &&
  3012. spectral->params[smode].ss_rpt_mode == 2) {
  3013. spectral->rb_edge_extrabins = 4;
  3014. }
  3015. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  3016. spectral->sc_spectral_20_40_mode = 0;
  3017. spectral->spectral_numbins =
  3018. target_if_get_fft_bin_count(
  3019. spectral->params[smode].ss_fft_size);
  3020. spectral->spectral_fft_len =
  3021. target_if_get_fft_bin_count(
  3022. spectral->params[smode].ss_fft_size);
  3023. spectral->spectral_data_len =
  3024. target_if_get_fft_bin_count(
  3025. spectral->params[smode].ss_fft_size);
  3026. /*
  3027. * Initialize classifier params to be sent to user
  3028. * space classifier
  3029. */
  3030. spectral->classifier_params.lower_chan_in_mhz =
  3031. current_channel;
  3032. spectral->classifier_params.upper_chan_in_mhz = 0;
  3033. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  3034. /* TODO : Remove this variable */
  3035. spectral->sc_spectral_20_40_mode = 1;
  3036. spectral->spectral_numbins =
  3037. target_if_get_fft_bin_count(
  3038. spectral->params[smode].ss_fft_size);
  3039. spectral->spectral_fft_len =
  3040. target_if_get_fft_bin_count(
  3041. spectral->params[smode].ss_fft_size);
  3042. spectral->spectral_data_len =
  3043. target_if_get_fft_bin_count(
  3044. spectral->params[smode].ss_fft_size);
  3045. /*
  3046. * Initialize classifier params to be sent to user
  3047. * space classifier
  3048. */
  3049. if (extension_channel < current_channel) {
  3050. spectral->classifier_params.lower_chan_in_mhz =
  3051. extension_channel;
  3052. spectral->classifier_params.upper_chan_in_mhz =
  3053. current_channel;
  3054. } else {
  3055. spectral->classifier_params.lower_chan_in_mhz =
  3056. current_channel;
  3057. spectral->classifier_params.upper_chan_in_mhz =
  3058. extension_channel;
  3059. }
  3060. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  3061. /* Set the FFT Size */
  3062. /* TODO : Remove this variable */
  3063. spectral->sc_spectral_20_40_mode = 0;
  3064. spectral->spectral_numbins =
  3065. target_if_get_fft_bin_count(
  3066. spectral->params[smode].ss_fft_size);
  3067. spectral->spectral_fft_len =
  3068. target_if_get_fft_bin_count(
  3069. spectral->params[smode].ss_fft_size);
  3070. spectral->spectral_data_len =
  3071. target_if_get_fft_bin_count(
  3072. spectral->params[smode].ss_fft_size);
  3073. /*
  3074. * Initialize classifier params to be sent to user
  3075. * space classifier
  3076. */
  3077. spectral->classifier_params.lower_chan_in_mhz =
  3078. current_channel;
  3079. spectral->classifier_params.upper_chan_in_mhz = 0;
  3080. /*
  3081. * Initialize classifier params to be sent to user
  3082. * space classifier
  3083. */
  3084. if (extension_channel < current_channel) {
  3085. spectral->classifier_params.lower_chan_in_mhz =
  3086. extension_channel;
  3087. spectral->classifier_params.upper_chan_in_mhz =
  3088. current_channel;
  3089. } else {
  3090. spectral->classifier_params.lower_chan_in_mhz =
  3091. current_channel;
  3092. spectral->classifier_params.upper_chan_in_mhz =
  3093. extension_channel;
  3094. }
  3095. } else if (is_ch_width_160_or_80p80(
  3096. spectral->ch_width[smode])) {
  3097. /* Set the FFT Size */
  3098. /* The below applies to both 160 and 80+80 cases */
  3099. /* TODO : Remove this variable */
  3100. spectral->sc_spectral_20_40_mode = 0;
  3101. spectral->spectral_numbins =
  3102. target_if_get_fft_bin_count(
  3103. spectral->params[smode].ss_fft_size);
  3104. spectral->spectral_fft_len =
  3105. target_if_get_fft_bin_count(
  3106. spectral->params[smode].ss_fft_size);
  3107. spectral->spectral_data_len =
  3108. target_if_get_fft_bin_count(
  3109. spectral->params[smode].ss_fft_size);
  3110. /*
  3111. * Initialize classifier params to be sent to user
  3112. * space classifier
  3113. */
  3114. spectral->classifier_params.lower_chan_in_mhz =
  3115. current_channel;
  3116. spectral->classifier_params.upper_chan_in_mhz = 0;
  3117. /*
  3118. * Initialize classifier params to be sent to user
  3119. * space classifier
  3120. */
  3121. if (extension_channel < current_channel) {
  3122. spectral->classifier_params.lower_chan_in_mhz =
  3123. extension_channel;
  3124. spectral->classifier_params.upper_chan_in_mhz =
  3125. current_channel;
  3126. } else {
  3127. spectral->classifier_params.lower_chan_in_mhz =
  3128. current_channel;
  3129. spectral->classifier_params.upper_chan_in_mhz =
  3130. extension_channel;
  3131. }
  3132. }
  3133. if (spectral->spectral_numbins) {
  3134. spectral->spectral_numbins +=
  3135. spectral->lb_edge_extrabins;
  3136. spectral->spectral_numbins +=
  3137. spectral->rb_edge_extrabins;
  3138. }
  3139. if (spectral->spectral_fft_len) {
  3140. spectral->spectral_fft_len +=
  3141. spectral->lb_edge_extrabins;
  3142. spectral->spectral_fft_len +=
  3143. spectral->rb_edge_extrabins;
  3144. }
  3145. if (spectral->spectral_data_len) {
  3146. spectral->spectral_data_len +=
  3147. spectral->lb_edge_extrabins;
  3148. spectral->spectral_data_len +=
  3149. spectral->rb_edge_extrabins;
  3150. }
  3151. } else {
  3152. /*
  3153. * The decision to find 20/40 mode is found based on the
  3154. * presence of extension channel
  3155. * instead of channel width, as the channel width can
  3156. * dynamically change
  3157. */
  3158. if (extension_channel == 0) {
  3159. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  3160. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  3161. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  3162. spectral->spectral_data_len =
  3163. SPECTRAL_HT20_TOTAL_DATA_LEN;
  3164. /* only valid in 20-40 mode */
  3165. spectral->spectral_lower_max_index_offset = -1;
  3166. /* only valid in 20-40 mode */
  3167. spectral->spectral_upper_max_index_offset = -1;
  3168. spectral->spectral_max_index_offset =
  3169. spectral->spectral_fft_len + 2;
  3170. spectral->sc_spectral_20_40_mode = 0;
  3171. /*
  3172. * Initialize classifier params to be sent to user
  3173. * space classifier
  3174. */
  3175. spectral->classifier_params.lower_chan_in_mhz =
  3176. current_channel;
  3177. spectral->classifier_params.upper_chan_in_mhz = 0;
  3178. } else {
  3179. spectral->spectral_numbins =
  3180. SPECTRAL_HT40_TOTAL_NUM_BINS;
  3181. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  3182. spectral->spectral_data_len =
  3183. SPECTRAL_HT40_TOTAL_DATA_LEN;
  3184. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  3185. /* only valid in 20 mode */
  3186. spectral->spectral_max_index_offset = -1;
  3187. spectral->spectral_lower_max_index_offset =
  3188. spectral->spectral_fft_len + 2;
  3189. spectral->spectral_upper_max_index_offset =
  3190. spectral->spectral_fft_len + 5;
  3191. spectral->sc_spectral_20_40_mode = 1;
  3192. /*
  3193. * Initialize classifier params to be sent to user
  3194. * space classifier
  3195. */
  3196. if (extension_channel < current_channel) {
  3197. spectral->classifier_params.lower_chan_in_mhz =
  3198. extension_channel;
  3199. spectral->classifier_params.upper_chan_in_mhz =
  3200. current_channel;
  3201. } else {
  3202. spectral->classifier_params.lower_chan_in_mhz =
  3203. current_channel;
  3204. spectral->classifier_params.upper_chan_in_mhz =
  3205. extension_channel;
  3206. }
  3207. }
  3208. }
  3209. spectral->send_single_packet = 0;
  3210. spectral->classifier_params.spectral_20_40_mode =
  3211. spectral->sc_spectral_20_40_mode;
  3212. spectral->classifier_params.spectral_dc_index =
  3213. spectral->spectral_dc_index;
  3214. spectral->spectral_sent_msg = 0;
  3215. spectral->classify_scan = 0;
  3216. spectral->num_spectral_data = 0;
  3217. if (!p_sops->is_spectral_active(spectral, smode)) {
  3218. p_sops->configure_spectral(spectral, spectral_params, smode);
  3219. p_sops->start_spectral_scan(spectral, smode, err);
  3220. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  3221. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  3222. }
  3223. /* get current spectral configuration */
  3224. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  3225. target_if_init_upper_lower_flags(spectral);
  3226. return 0;
  3227. }
  3228. /**
  3229. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  3230. * Agile DFS
  3231. * @psoc: Pointer to psoc
  3232. * @object: Pointer to pdev
  3233. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  3234. *
  3235. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  3236. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  3237. *
  3238. * Return: void
  3239. */
  3240. static void
  3241. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  3242. void *object, void *arg)
  3243. {
  3244. bool *is_aspectral_prohibited = arg;
  3245. struct wlan_objmgr_pdev *cur_pdev = object;
  3246. bool is_agile_dfs_enabled_cur_pdev = false;
  3247. QDF_STATUS status;
  3248. qdf_assert_always(is_aspectral_prohibited);
  3249. if (*is_aspectral_prohibited)
  3250. return;
  3251. qdf_assert_always(psoc);
  3252. qdf_assert_always(cur_pdev);
  3253. status = ucfg_dfs_get_agile_precac_enable
  3254. (cur_pdev,
  3255. &is_agile_dfs_enabled_cur_pdev);
  3256. if (QDF_IS_STATUS_ERROR(status)) {
  3257. spectral_err("Get agile precac failed, prohibiting aSpectral");
  3258. *is_aspectral_prohibited = true;
  3259. return;
  3260. }
  3261. if (is_agile_dfs_enabled_cur_pdev) {
  3262. spectral_err("aDFS is in progress on one of the pdevs");
  3263. *is_aspectral_prohibited = true;
  3264. }
  3265. }
  3266. /**
  3267. * target_if_get_curr_band() - Get current operating band of pdev
  3268. *
  3269. * @spectral: pointer to spectral object
  3270. *
  3271. * API to get current operating band of a given pdev.
  3272. *
  3273. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  3274. */
  3275. static enum reg_wifi_band
  3276. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev)
  3277. {
  3278. struct wlan_objmgr_vdev *vdev;
  3279. int16_t chan_freq;
  3280. enum reg_wifi_band cur_band;
  3281. if (!pdev) {
  3282. spectral_err("pdev is NULL");
  3283. return REG_BAND_UNKNOWN;
  3284. }
  3285. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  3286. if (!vdev) {
  3287. spectral_debug("vdev is NULL");
  3288. return REG_BAND_UNKNOWN;
  3289. }
  3290. chan_freq = target_if_vdev_get_chan_freq(vdev);
  3291. cur_band = wlan_reg_freq_to_band(chan_freq);
  3292. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3293. return cur_band;
  3294. }
  3295. /**
  3296. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  3297. * any of the 5G pdevs
  3298. * @psoc: Pointer to psoc
  3299. * @object: Pointer to pdev
  3300. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  3301. * progress in any 5G pdevs
  3302. *
  3303. * Return: void
  3304. */
  3305. static void
  3306. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  3307. void *object, void *arg)
  3308. {
  3309. enum reg_wifi_band band;
  3310. bool *is_agile_scan_inprog_5g_pdev = arg;
  3311. struct target_if_spectral *spectral;
  3312. struct wlan_objmgr_pdev *cur_pdev = object;
  3313. struct target_if_spectral_ops *p_sops;
  3314. if (*is_agile_scan_inprog_5g_pdev)
  3315. return;
  3316. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  3317. if (!spectral) {
  3318. spectral_err("target if spectral handle is NULL");
  3319. return;
  3320. }
  3321. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3322. band = target_if_get_curr_band(cur_pdev);
  3323. if (band == REG_BAND_UNKNOWN) {
  3324. spectral_debug("Failed to get current band");
  3325. return;
  3326. }
  3327. if (band == REG_BAND_5G &&
  3328. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  3329. *is_agile_scan_inprog_5g_pdev = true;
  3330. }
  3331. /**
  3332. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  3333. * for current vdev rx chainmask.
  3334. *
  3335. * @spectral: Pointer to Spectral object
  3336. * @is_supported: Pointer to is_supported
  3337. *
  3338. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3339. */
  3340. static QDF_STATUS
  3341. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  3342. bool *is_supported)
  3343. {
  3344. struct wlan_objmgr_vdev *vdev;
  3345. uint8_t vdev_rxchainmask;
  3346. struct wlan_objmgr_psoc *psoc;
  3347. struct wlan_objmgr_pdev *pdev;
  3348. struct target_psoc_info *tgt_psoc_info;
  3349. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  3350. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  3351. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  3352. struct wlan_psoc_host_chainmask_table *table;
  3353. int j;
  3354. uint32_t table_id;
  3355. enum phy_ch_width ch_width;
  3356. uint8_t pdev_id;
  3357. if (!spectral) {
  3358. spectral_err("spectral target if object is null");
  3359. return QDF_STATUS_E_FAILURE;
  3360. }
  3361. if (!is_supported) {
  3362. spectral_err("is supported argument is null");
  3363. return QDF_STATUS_E_FAILURE;
  3364. }
  3365. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  3366. spectral_err("HW Agile mode is not supported up to gen 2");
  3367. return QDF_STATUS_E_FAILURE;
  3368. }
  3369. pdev = spectral->pdev_obj;
  3370. if (!pdev) {
  3371. spectral_err("pdev is null");
  3372. return QDF_STATUS_E_FAILURE;
  3373. }
  3374. psoc = wlan_pdev_get_psoc(pdev);
  3375. if (!psoc) {
  3376. spectral_err("psoc is null");
  3377. return QDF_STATUS_E_FAILURE;
  3378. }
  3379. vdev = target_if_spectral_get_vdev(spectral);
  3380. if (!vdev) {
  3381. spectral_err("First vdev is NULL");
  3382. return QDF_STATUS_E_FAILURE;
  3383. }
  3384. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  3385. if (!vdev_rxchainmask) {
  3386. spectral_err("vdev rx chainmask is zero");
  3387. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3388. return QDF_STATUS_E_FAILURE;
  3389. }
  3390. ch_width = target_if_vdev_get_ch_width(vdev);
  3391. if (ch_width == CH_WIDTH_INVALID) {
  3392. spectral_err("Invalid channel width");
  3393. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3394. return QDF_STATUS_E_FAILURE;
  3395. }
  3396. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3397. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  3398. if (!tgt_psoc_info) {
  3399. spectral_err("target_psoc_info is null");
  3400. return QDF_STATUS_E_FAILURE;
  3401. }
  3402. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  3403. if (!ext_svc_param) {
  3404. spectral_err("Extended service ready param null");
  3405. return QDF_STATUS_E_FAILURE;
  3406. }
  3407. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  3408. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  3409. if (!mac_phy_cap_arr) {
  3410. spectral_err("mac phy cap array is null");
  3411. return QDF_STATUS_E_FAILURE;
  3412. }
  3413. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  3414. if (!mac_phy_cap) {
  3415. spectral_err("mac phy cap is null");
  3416. return QDF_STATUS_E_FAILURE;
  3417. }
  3418. table_id = mac_phy_cap->chainmask_table_id;
  3419. table = &ext_svc_param->chainmask_table[table_id];
  3420. if (!table) {
  3421. spectral_err("chainmask table not found");
  3422. return QDF_STATUS_E_FAILURE;
  3423. }
  3424. for (j = 0; j < table->num_valid_chainmasks; j++) {
  3425. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  3426. if (ch_width <= CH_WIDTH_80MHZ)
  3427. *is_supported =
  3428. table->cap_list[j].supports_aSpectral;
  3429. else
  3430. *is_supported =
  3431. table->cap_list[j].supports_aSpectral_160;
  3432. break;
  3433. }
  3434. }
  3435. if (j == table->num_valid_chainmasks) {
  3436. spectral_err("vdev rx chainmask %u not found in table id = %u",
  3437. vdev_rxchainmask, table_id);
  3438. return QDF_STATUS_E_FAILURE;
  3439. }
  3440. return QDF_STATUS_SUCCESS;
  3441. }
  3442. QDF_STATUS
  3443. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3444. const enum spectral_scan_mode smode,
  3445. enum spectral_cp_error_code *err)
  3446. {
  3447. struct target_if_spectral_ops *p_sops;
  3448. struct target_if_spectral *spectral;
  3449. struct wlan_objmgr_psoc *psoc;
  3450. enum reg_wifi_band band;
  3451. if (!err) {
  3452. spectral_err("Error code argument is null");
  3453. QDF_ASSERT(0);
  3454. return QDF_STATUS_E_FAILURE;
  3455. }
  3456. *err = SPECTRAL_SCAN_ERR_INVALID;
  3457. if (!pdev) {
  3458. spectral_err("pdev object is NUll");
  3459. return QDF_STATUS_E_FAILURE;
  3460. }
  3461. psoc = wlan_pdev_get_psoc(pdev);
  3462. if (!psoc) {
  3463. spectral_err("psoc is null");
  3464. return QDF_STATUS_E_FAILURE;
  3465. }
  3466. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3467. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3468. spectral_err("Invalid Spectral mode %u", smode);
  3469. return QDF_STATUS_E_FAILURE;
  3470. }
  3471. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3472. if (!spectral) {
  3473. spectral_err("Spectral LMAC object is NUll");
  3474. return QDF_STATUS_E_FAILURE;
  3475. }
  3476. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3477. if (!p_sops) {
  3478. spectral_err("p_sops is null");
  3479. return QDF_STATUS_E_FAILURE;
  3480. }
  3481. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3482. QDF_STATUS status;
  3483. bool is_supported = false;
  3484. status = target_if_is_agile_supported_cur_chmask(spectral,
  3485. &is_supported);
  3486. if (QDF_IS_STATUS_ERROR(status)) {
  3487. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3488. return QDF_STATUS_E_FAILURE;
  3489. }
  3490. if (!is_supported) {
  3491. spectral_err("aSpectral unsupported for cur chainmask");
  3492. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3493. return QDF_STATUS_E_FAILURE;
  3494. }
  3495. }
  3496. band = target_if_get_curr_band(spectral->pdev_obj);
  3497. if (band == REG_BAND_UNKNOWN) {
  3498. spectral_err("Failed to get current band");
  3499. return QDF_STATUS_E_FAILURE;
  3500. }
  3501. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  3502. struct target_psoc_info *tgt_hdl;
  3503. enum wmi_host_hw_mode_config_type mode;
  3504. bool is_agile_scan_inprog_5g_pdev;
  3505. if (p_sops->is_spectral_active(spectral,
  3506. SPECTRAL_SCAN_MODE_AGILE)) {
  3507. spectral_err("Agile Scan in progress in current pdev");
  3508. return QDF_STATUS_E_FAILURE;
  3509. }
  3510. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  3511. if (!tgt_hdl) {
  3512. target_if_err("target_psoc_info is null");
  3513. return QDF_STATUS_E_FAILURE;
  3514. }
  3515. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  3516. switch (mode) {
  3517. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  3518. case WMI_HOST_HW_MODE_SBS:
  3519. case WMI_HOST_HW_MODE_DBS_SBS:
  3520. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  3521. is_agile_scan_inprog_5g_pdev = false;
  3522. wlan_objmgr_iterate_obj_list
  3523. (psoc, WLAN_PDEV_OP,
  3524. target_if_is_agile_scan_active_in_5g,
  3525. &is_agile_scan_inprog_5g_pdev, 0,
  3526. WLAN_SPECTRAL_ID);
  3527. break;
  3528. default:
  3529. is_agile_scan_inprog_5g_pdev = false;
  3530. break;
  3531. }
  3532. if (is_agile_scan_inprog_5g_pdev) {
  3533. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  3534. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3535. return QDF_STATUS_E_FAILURE;
  3536. }
  3537. }
  3538. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3539. bool is_aspectral_prohibited = false;
  3540. QDF_STATUS status;
  3541. status = wlan_objmgr_iterate_obj_list
  3542. (psoc, WLAN_PDEV_OP,
  3543. target_if_is_aspectral_prohibited_by_adfs,
  3544. &is_aspectral_prohibited, 0,
  3545. WLAN_SPECTRAL_ID);
  3546. if (QDF_IS_STATUS_ERROR(status)) {
  3547. spectral_err("Failed to iterate over pdevs");
  3548. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3549. return QDF_STATUS_E_FAILURE;
  3550. }
  3551. if (is_aspectral_prohibited) {
  3552. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3553. return QDF_STATUS_E_FAILURE;
  3554. }
  3555. }
  3556. if (!spectral->params_valid[smode]) {
  3557. target_if_spectral_info_read(spectral,
  3558. smode,
  3559. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3560. &spectral->params[smode],
  3561. sizeof(spectral->params[smode]));
  3562. spectral->params_valid[smode] = true;
  3563. }
  3564. qdf_spin_lock(&spectral->spectral_lock);
  3565. if (smode == SPECTRAL_SCAN_MODE_AGILE &&
  3566. !spectral->params[smode].ss_frequency) {
  3567. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  3568. qdf_spin_unlock(&spectral->spectral_lock);
  3569. return QDF_STATUS_E_FAILURE;
  3570. }
  3571. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3572. QDF_STATUS status;
  3573. bool is_overlapping;
  3574. status = target_if_is_agile_span_overlap_with_operating_span
  3575. (spectral,
  3576. spectral->params[smode].ss_frequency,
  3577. &is_overlapping);
  3578. if (QDF_IS_STATUS_ERROR(status)) {
  3579. qdf_spin_unlock(&spectral->spectral_lock);
  3580. return QDF_STATUS_E_FAILURE;
  3581. }
  3582. if (is_overlapping) {
  3583. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3584. qdf_spin_unlock(&spectral->spectral_lock);
  3585. return QDF_STATUS_E_FAILURE;
  3586. }
  3587. }
  3588. target_if_spectral_scan_enable_params(spectral,
  3589. &spectral->params[smode], smode,
  3590. err);
  3591. qdf_spin_unlock(&spectral->spectral_lock);
  3592. return QDF_STATUS_SUCCESS;
  3593. }
  3594. QDF_STATUS
  3595. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3596. const enum spectral_scan_mode smode,
  3597. enum spectral_cp_error_code *err)
  3598. {
  3599. struct target_if_spectral_ops *p_sops;
  3600. struct target_if_spectral *spectral;
  3601. if (!err) {
  3602. spectral_err("Error code argument is null");
  3603. QDF_ASSERT(0);
  3604. return QDF_STATUS_E_FAILURE;
  3605. }
  3606. *err = SPECTRAL_SCAN_ERR_INVALID;
  3607. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3608. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3609. spectral_err("Invalid Spectral mode %u", smode);
  3610. return QDF_STATUS_E_FAILURE;
  3611. }
  3612. if (!pdev) {
  3613. spectral_err("pdev object is NUll ");
  3614. return QDF_STATUS_E_FAILURE;
  3615. }
  3616. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3617. if (!spectral) {
  3618. spectral_err("Spectral LMAC object is NUll ");
  3619. return QDF_STATUS_E_FAILURE;
  3620. }
  3621. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3622. qdf_spin_lock(&spectral->spectral_lock);
  3623. p_sops->stop_spectral_scan(spectral, smode);
  3624. if (spectral->classify_scan) {
  3625. /* TODO : Check if this logic is necessary */
  3626. spectral->detects_control_channel = 0;
  3627. spectral->detects_extension_channel = 0;
  3628. spectral->detects_above_dc = 0;
  3629. spectral->detects_below_dc = 0;
  3630. spectral->classify_scan = 0;
  3631. }
  3632. spectral->send_single_packet = 0;
  3633. spectral->sc_spectral_scan = 0;
  3634. qdf_spin_unlock(&spectral->spectral_lock);
  3635. return QDF_STATUS_SUCCESS;
  3636. }
  3637. /**
  3638. * target_if_is_spectral_active() - Get whether Spectral is active
  3639. * @pdev: Pointer to pdev object
  3640. * @smode: Spectral scan mode
  3641. *
  3642. * API to get whether Spectral is active
  3643. *
  3644. * Return: True if Spectral is active, false if Spectral is not active
  3645. */
  3646. bool
  3647. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  3648. const enum spectral_scan_mode smode)
  3649. {
  3650. struct target_if_spectral *spectral = NULL;
  3651. struct target_if_spectral_ops *p_sops = NULL;
  3652. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3653. if (!spectral) {
  3654. spectral_err("SPECTRAL : Module doesn't exist");
  3655. return QDF_STATUS_E_FAILURE;
  3656. }
  3657. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3658. if (!p_sops) {
  3659. spectral_err("p_sops is null");
  3660. return QDF_STATUS_E_FAILURE;
  3661. }
  3662. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3663. spectral_err("Invalid Spectral mode %u", smode);
  3664. return QDF_STATUS_E_FAILURE;
  3665. }
  3666. return p_sops->is_spectral_active(spectral, smode);
  3667. }
  3668. /**
  3669. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  3670. * @pdev: Pointer to pdev object
  3671. * @smode: Spectral scan mode
  3672. *
  3673. * API to get whether Spectral is enabled
  3674. *
  3675. * Return: True if Spectral is enabled, false if Spectral is not enabled
  3676. */
  3677. bool
  3678. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  3679. enum spectral_scan_mode smode)
  3680. {
  3681. struct target_if_spectral *spectral = NULL;
  3682. struct target_if_spectral_ops *p_sops = NULL;
  3683. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3684. if (!spectral) {
  3685. spectral_err("SPECTRAL : Module doesn't exist");
  3686. return QDF_STATUS_E_FAILURE;
  3687. }
  3688. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3689. if (!p_sops) {
  3690. spectral_err("p_sops is null");
  3691. return QDF_STATUS_E_FAILURE;
  3692. }
  3693. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3694. spectral_err("Invalid Spectral mode %u", smode);
  3695. return QDF_STATUS_E_FAILURE;
  3696. }
  3697. return p_sops->is_spectral_enabled(spectral, smode);
  3698. }
  3699. #ifdef DIRECT_BUF_RX_DEBUG
  3700. /**
  3701. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  3702. * @pdev: Pointer to pdev object
  3703. * @enable: Enable/Disable Spectral DMA ring debug
  3704. *
  3705. * Start/stop Spectral DMA ring debug based on @enable.
  3706. * Also save the state for future use.
  3707. *
  3708. * Return: QDF_STATUS of operation
  3709. */
  3710. static QDF_STATUS
  3711. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3712. {
  3713. struct target_if_spectral *spectral;
  3714. struct wlan_lmac_if_tx_ops *tx_ops;
  3715. struct wlan_objmgr_psoc *psoc;
  3716. if (!pdev)
  3717. return QDF_STATUS_E_FAILURE;
  3718. psoc = wlan_pdev_get_psoc(pdev);
  3719. if (!psoc) {
  3720. spectral_err("psoc is null");
  3721. return QDF_STATUS_E_INVAL;
  3722. }
  3723. tx_ops = &psoc->soc_cb.tx_ops;
  3724. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3725. if (!spectral) {
  3726. spectral_err("Spectal LMAC object is NULL");
  3727. return QDF_STATUS_E_INVAL;
  3728. }
  3729. /* Save the state */
  3730. spectral->dbr_ring_debug = enable;
  3731. if (enable)
  3732. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  3733. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  3734. else
  3735. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  3736. pdev, 0);
  3737. return QDF_STATUS_SUCCESS;
  3738. }
  3739. /**
  3740. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  3741. * @pdev: Pointer to pdev object
  3742. * @enable: Enable/Disable Spectral DMA buffer debug
  3743. *
  3744. * Start/stop Spectral DMA buffer debug based on @enable.
  3745. * Also save the state for future use.
  3746. *
  3747. * Return: QDF_STATUS of operation
  3748. */
  3749. static QDF_STATUS
  3750. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3751. {
  3752. struct target_if_spectral *spectral;
  3753. struct wlan_lmac_if_tx_ops *tx_ops;
  3754. struct wlan_objmgr_psoc *psoc;
  3755. if (!pdev)
  3756. return QDF_STATUS_E_FAILURE;
  3757. psoc = wlan_pdev_get_psoc(pdev);
  3758. if (!psoc) {
  3759. spectral_err("psoc is null");
  3760. return QDF_STATUS_E_INVAL;
  3761. }
  3762. tx_ops = &psoc->soc_cb.tx_ops;
  3763. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3764. if (!spectral) {
  3765. spectral_err("Spectal LMAC object is NULL");
  3766. return QDF_STATUS_E_INVAL;
  3767. }
  3768. /* Save the state */
  3769. spectral->dbr_buff_debug = enable;
  3770. if (enable)
  3771. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  3772. pdev, 0, MEM_POISON_SIGNATURE);
  3773. else
  3774. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  3775. pdev, 0);
  3776. }
  3777. /**
  3778. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  3779. * debug based on the previous state
  3780. * @pdev: Pointer to pdev object
  3781. *
  3782. * Return: QDF_STATUS of operation
  3783. */
  3784. static QDF_STATUS
  3785. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  3786. {
  3787. struct target_if_spectral *spectral;
  3788. if (!pdev) {
  3789. spectral_err("pdev is NULL!");
  3790. return QDF_STATUS_E_FAILURE;
  3791. }
  3792. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3793. if (!spectral) {
  3794. spectral_err("Spectal LMAC object is NULL");
  3795. return QDF_STATUS_E_INVAL;
  3796. }
  3797. if (spectral->dbr_buff_debug)
  3798. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  3799. else
  3800. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  3801. }
  3802. /**
  3803. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  3804. * debug based on the previous state
  3805. * @pdev: Pointer to pdev object
  3806. *
  3807. * Return: QDF_STATUS of operation
  3808. */
  3809. static QDF_STATUS
  3810. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  3811. {
  3812. struct target_if_spectral *spectral;
  3813. if (!pdev) {
  3814. spectral_err("pdev is NULL!");
  3815. return QDF_STATUS_E_FAILURE;
  3816. }
  3817. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3818. if (!spectral) {
  3819. spectral_err("Spectal LMAC object is NULL");
  3820. return QDF_STATUS_E_INVAL;
  3821. }
  3822. if (spectral->dbr_ring_debug)
  3823. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  3824. else
  3825. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  3826. }
  3827. /**
  3828. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  3829. * @pdev: Pointer to pdev object
  3830. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  3831. * @debug_value: Value to be set for @dma_debug_type
  3832. *
  3833. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  3834. * based on @debug_value
  3835. *
  3836. * Return: QDF_STATUS of operation
  3837. */
  3838. static QDF_STATUS
  3839. target_if_spectral_set_dma_debug(
  3840. struct wlan_objmgr_pdev *pdev,
  3841. enum spectral_dma_debug dma_debug_type,
  3842. bool debug_value)
  3843. {
  3844. struct target_if_spectral_ops *p_sops;
  3845. struct wlan_objmgr_psoc *psoc;
  3846. struct wlan_lmac_if_tx_ops *tx_ops;
  3847. struct target_if_spectral *spectral;
  3848. if (!pdev)
  3849. return QDF_STATUS_E_FAILURE;
  3850. psoc = wlan_pdev_get_psoc(pdev);
  3851. if (!psoc) {
  3852. spectral_err("psoc is null");
  3853. return QDF_STATUS_E_INVAL;
  3854. }
  3855. tx_ops = &psoc->soc_cb.tx_ops;
  3856. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  3857. spectral_err("Unable to fetch target type");
  3858. return QDF_STATUS_E_FAILURE;
  3859. }
  3860. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3861. if (!spectral) {
  3862. spectral_err("Spectal LMAC object is NULL");
  3863. return QDF_STATUS_E_INVAL;
  3864. }
  3865. if (spectral->direct_dma_support) {
  3866. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3867. if (p_sops->is_spectral_active(spectral,
  3868. SPECTRAL_SCAN_MODE_NORMAL) ||
  3869. p_sops->is_spectral_active(spectral,
  3870. SPECTRAL_SCAN_MODE_AGILE)) {
  3871. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  3872. return QDF_STATUS_E_FAILURE;
  3873. }
  3874. switch (dma_debug_type) {
  3875. case SPECTRAL_DMA_RING_DEBUG:
  3876. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  3877. break;
  3878. case SPECTRAL_DMA_BUFFER_DEBUG:
  3879. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  3880. break;
  3881. default:
  3882. spectral_err("Unsupported DMA debug type : %d",
  3883. dma_debug_type);
  3884. return QDF_STATUS_E_FAILURE;
  3885. }
  3886. }
  3887. return QDF_STATUS_SUCCESS;
  3888. }
  3889. #endif /* DIRECT_BUF_RX_DEBUG */
  3890. /**
  3891. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  3892. * @pdev: Pointer to pdev object
  3893. *
  3894. * Return: Whether Direct-DMA is supported on this radio
  3895. */
  3896. static bool
  3897. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  3898. {
  3899. struct target_if_spectral *spectral;
  3900. if (!pdev) {
  3901. spectral_err("pdev is NULL!");
  3902. return false;
  3903. }
  3904. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3905. if (!spectral) {
  3906. spectral_err("Spectral LMAC object is NULL");
  3907. return false;
  3908. }
  3909. return spectral->direct_dma_support;
  3910. }
  3911. /**
  3912. * target_if_set_debug_level() - Set debug level for Spectral
  3913. * @pdev: Pointer to pdev object
  3914. * @debug_level: Debug level
  3915. *
  3916. * API to set the debug level for Spectral
  3917. *
  3918. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3919. */
  3920. QDF_STATUS
  3921. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  3922. {
  3923. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  3924. return QDF_STATUS_SUCCESS;
  3925. }
  3926. /**
  3927. * target_if_get_debug_level() - Get debug level for Spectral
  3928. * @pdev: Pointer to pdev object
  3929. *
  3930. * API to get the debug level for Spectral
  3931. *
  3932. * Return: Current debug level
  3933. */
  3934. uint32_t
  3935. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  3936. {
  3937. return spectral_debug_level;
  3938. }
  3939. /**
  3940. * target_if_get_spectral_capinfo() - Get Spectral capability information
  3941. * @pdev: Pointer to pdev object
  3942. * @scaps: Buffer into which data should be copied
  3943. *
  3944. * API to get the spectral capability information
  3945. *
  3946. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3947. */
  3948. QDF_STATUS
  3949. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  3950. struct spectral_caps *scaps)
  3951. {
  3952. struct target_if_spectral *spectral = NULL;
  3953. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3954. if (!spectral) {
  3955. spectral_err("SPECTRAL : Module doesn't exist");
  3956. return QDF_STATUS_E_FAILURE;
  3957. }
  3958. qdf_mem_copy(scaps, &spectral->capability,
  3959. sizeof(struct spectral_caps));
  3960. return QDF_STATUS_SUCCESS;
  3961. }
  3962. /**
  3963. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  3964. * @pdev: Pointer to pdev object
  3965. * @stats: Buffer into which data should be copied
  3966. *
  3967. * API to get the spectral diagnostic statistics
  3968. *
  3969. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3970. */
  3971. QDF_STATUS
  3972. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  3973. struct spectral_diag_stats *stats)
  3974. {
  3975. struct target_if_spectral *spectral = NULL;
  3976. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3977. if (!spectral) {
  3978. spectral_err("SPECTRAL : Module doesn't exist");
  3979. return QDF_STATUS_E_FAILURE;
  3980. }
  3981. qdf_mem_copy(stats, &spectral->diag_stats,
  3982. sizeof(struct spectral_diag_stats));
  3983. return QDF_STATUS_SUCCESS;
  3984. }
  3985. /**
  3986. * target_if_register_wmi_spectral_cmd_ops() - Register wmi_spectral_cmd_ops
  3987. * @cmd_ops: Pointer to the structure having wmi_spectral_cmd function pointers
  3988. * @pdev: Pointer to pdev object
  3989. *
  3990. * API for register wmi_spectral_cmd_ops in spectral internal data structure
  3991. *
  3992. * Return: void
  3993. */
  3994. void
  3995. target_if_register_wmi_spectral_cmd_ops(struct wlan_objmgr_pdev *pdev,
  3996. struct wmi_spectral_cmd_ops *cmd_ops)
  3997. {
  3998. struct target_if_spectral *spectral =
  3999. get_target_if_spectral_handle_from_pdev(pdev);
  4000. if (!spectral) {
  4001. spectral_err("Spectral LMAC object is null");
  4002. return;
  4003. }
  4004. spectral->param_wmi_cmd_ops = *cmd_ops;
  4005. }
  4006. /**
  4007. * target_if_register_netlink_cb() - Register Netlink callbacks
  4008. * @pdev: Pointer to pdev object
  4009. * @nl_cb: Netlink callbacks to register
  4010. *
  4011. * Return: void
  4012. */
  4013. static void
  4014. target_if_register_netlink_cb(
  4015. struct wlan_objmgr_pdev *pdev,
  4016. struct spectral_nl_cb *nl_cb)
  4017. {
  4018. struct target_if_spectral *spectral = NULL;
  4019. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4020. if (!spectral) {
  4021. spectral_err("SPECTRAL : Module doesn't exist");
  4022. return;
  4023. }
  4024. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  4025. if (spectral->use_nl_bcast)
  4026. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  4027. else
  4028. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  4029. }
  4030. /**
  4031. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  4032. * Netlink messages to the application layer
  4033. * @pdev: Pointer to pdev object
  4034. *
  4035. * Return: true for broadcast, false for unicast
  4036. */
  4037. static bool
  4038. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  4039. {
  4040. struct target_if_spectral *spectral = NULL;
  4041. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4042. if (!spectral) {
  4043. spectral_err("SPECTRAL : Module doesn't exist");
  4044. return false;
  4045. }
  4046. return spectral->use_nl_bcast;
  4047. }
  4048. /**
  4049. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  4050. * @pdev: Pointer to pdev object
  4051. *
  4052. * Return: void
  4053. */
  4054. static void
  4055. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  4056. {
  4057. struct target_if_spectral *spectral = NULL;
  4058. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4059. if (!spectral) {
  4060. spectral_err("SPECTRAL : Module doesn't exist");
  4061. return;
  4062. }
  4063. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  4064. }
  4065. static int
  4066. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  4067. void *payload)
  4068. {
  4069. struct target_if_spectral *spectral = NULL;
  4070. struct target_if_spectral_ops *p_sops = NULL;
  4071. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4072. if (!spectral) {
  4073. spectral_err("SPECTRAL : Module doesn't exist");
  4074. return -EPERM;
  4075. }
  4076. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4077. if (!p_sops) {
  4078. spectral_err("p_sops is null");
  4079. return -EPERM;
  4080. }
  4081. return p_sops->process_spectral_report(pdev, payload);
  4082. }
  4083. #ifdef DIRECT_BUF_RX_DEBUG
  4084. static inline void
  4085. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4086. {
  4087. if (!tx_ops)
  4088. return;
  4089. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  4090. target_if_spectral_set_dma_debug;
  4091. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  4092. target_if_spectral_check_and_do_dbr_ring_debug;
  4093. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  4094. target_if_spectral_check_and_do_dbr_buff_debug;
  4095. }
  4096. #else
  4097. static inline void
  4098. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4099. {
  4100. }
  4101. #endif
  4102. void
  4103. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4104. {
  4105. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  4106. target_if_pdev_spectral_init;
  4107. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  4108. target_if_pdev_spectral_deinit;
  4109. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  4110. target_if_set_spectral_config;
  4111. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  4112. target_if_get_spectral_config;
  4113. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  4114. target_if_start_spectral_scan;
  4115. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  4116. target_if_stop_spectral_scan;
  4117. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  4118. target_if_is_spectral_active;
  4119. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  4120. target_if_is_spectral_enabled;
  4121. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  4122. target_if_set_debug_level;
  4123. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  4124. target_if_get_debug_level;
  4125. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  4126. target_if_get_spectral_capinfo;
  4127. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  4128. target_if_get_spectral_diagstats;
  4129. tx_ops->sptrl_tx_ops.sptrlto_register_wmi_spectral_cmd_ops =
  4130. target_if_register_wmi_spectral_cmd_ops;
  4131. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  4132. target_if_register_netlink_cb;
  4133. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  4134. target_if_use_nl_bcast;
  4135. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  4136. target_if_deregister_netlink_cb;
  4137. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  4138. target_if_process_spectral_report;
  4139. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  4140. target_if_spectral_direct_dma_support;
  4141. target_if_sptrl_debug_register_tx_ops(tx_ops);
  4142. }
  4143. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  4144. void
  4145. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  4146. uint16_t cw_int, uint32_t dcs_enabled)
  4147. {
  4148. struct spectral_samp_msg *msg = NULL;
  4149. struct target_if_spectral_ops *p_sops = NULL;
  4150. struct target_if_spectral *spectral = NULL;
  4151. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4152. if (!spectral) {
  4153. spectral_err("SPECTRAL : Module doesn't exist");
  4154. return;
  4155. }
  4156. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4157. if (!p_sops) {
  4158. spectral_err("p_sops is null");
  4159. return;
  4160. }
  4161. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  4162. spectral->pdev_obj,
  4163. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  4164. SPECTRAL_MSG_BUF_NEW);
  4165. if (msg) {
  4166. msg->int_type = cw_int ?
  4167. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  4168. msg->dcs_enabled = dcs_enabled;
  4169. msg->signature = SPECTRAL_SIGNATURE;
  4170. p_sops->get_mac_address(spectral, msg->macaddr);
  4171. if (spectral->send_phy_data
  4172. (pdev,
  4173. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  4174. spectral->spectral_sent_msg++;
  4175. }
  4176. }
  4177. qdf_export_symbol(target_if_spectral_send_intf_found_msg);