target_if_spectral.c 159 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856
  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. struct spectral_tgt_ops ops_tgt;
  43. static void target_if_spectral_get_firstvdev_pdev(struct wlan_objmgr_pdev *pdev,
  44. void *obj, void *arg)
  45. {
  46. struct wlan_objmgr_vdev *vdev = obj;
  47. struct wlan_objmgr_vdev **first_vdev = arg;
  48. if (!(*first_vdev))
  49. *first_vdev = vdev;
  50. }
  51. struct wlan_objmgr_vdev *
  52. target_if_spectral_get_vdev(struct target_if_spectral *spectral,
  53. enum spectral_scan_mode smode)
  54. {
  55. struct wlan_objmgr_pdev *pdev = NULL;
  56. struct wlan_objmgr_vdev *first_vdev = NULL;
  57. qdf_assert_always(spectral);
  58. pdev = spectral->pdev_obj;
  59. qdf_assert_always(pdev);
  60. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  61. spectral_err("Invalid Spectral mode %u", smode);
  62. return NULL;
  63. }
  64. if (spectral->vdev_id[smode] != WLAN_INVALID_VDEV_ID) {
  65. first_vdev = wlan_objmgr_get_vdev_by_id_from_pdev(
  66. pdev, spectral->vdev_id[smode],
  67. WLAN_SPECTRAL_ID);
  68. return first_vdev;
  69. }
  70. if (wlan_objmgr_pdev_try_get_ref(pdev, WLAN_SPECTRAL_ID) !=
  71. QDF_STATUS_SUCCESS) {
  72. spectral_err("Unable to get pdev reference.");
  73. return NULL;
  74. }
  75. wlan_objmgr_pdev_iterate_obj_list(pdev, WLAN_VDEV_OP,
  76. target_if_spectral_get_firstvdev_pdev,
  77. &first_vdev, 0, WLAN_SPECTRAL_ID);
  78. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  79. if (!first_vdev)
  80. return NULL;
  81. if (wlan_objmgr_vdev_try_get_ref(first_vdev, WLAN_SPECTRAL_ID) !=
  82. QDF_STATUS_SUCCESS)
  83. first_vdev = NULL;
  84. return first_vdev;
  85. }
  86. /**
  87. * target_if_send_vdev_spectral_configure_cmd() - Send WMI command to configure
  88. * spectral parameters
  89. * @spectral: Pointer to Spectral target_if internal private data
  90. * @smode: Spectral scan mode
  91. * @param: Pointer to spectral_config giving the Spectral configuration
  92. *
  93. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  94. */
  95. static int
  96. target_if_send_vdev_spectral_configure_cmd(struct target_if_spectral *spectral,
  97. enum spectral_scan_mode smode,
  98. struct spectral_config *param)
  99. {
  100. struct vdev_spectral_configure_params sparam;
  101. struct wlan_objmgr_psoc *psoc;
  102. struct wlan_objmgr_pdev *pdev = NULL;
  103. struct wlan_objmgr_vdev *vdev = NULL;
  104. struct target_if_psoc_spectral *psoc_spectral;
  105. qdf_assert_always(spectral && param);
  106. pdev = spectral->pdev_obj;
  107. qdf_assert_always(pdev);
  108. psoc = wlan_pdev_get_psoc(pdev);
  109. if (!psoc) {
  110. spectral_err("psoc is null");
  111. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  112. }
  113. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  114. if (!psoc_spectral) {
  115. spectral_err("psoc spectral object is null");
  116. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  117. }
  118. vdev = target_if_spectral_get_vdev(spectral, smode);
  119. if (!vdev)
  120. return QDF_STATUS_E_NOENT;
  121. qdf_mem_zero(&sparam, sizeof(sparam));
  122. sparam.vdev_id = wlan_vdev_get_id(vdev);
  123. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  124. sparam.count = param->ss_count;
  125. sparam.period = param->ss_period;
  126. sparam.spectral_pri = param->ss_spectral_pri;
  127. sparam.fft_size = param->ss_fft_size;
  128. sparam.gc_enable = param->ss_gc_ena;
  129. sparam.restart_enable = param->ss_restart_ena;
  130. sparam.noise_floor_ref = param->ss_noise_floor_ref;
  131. sparam.init_delay = param->ss_init_delay;
  132. sparam.nb_tone_thr = param->ss_nb_tone_thr;
  133. sparam.str_bin_thr = param->ss_str_bin_thr;
  134. sparam.wb_rpt_mode = param->ss_wb_rpt_mode;
  135. sparam.rssi_rpt_mode = param->ss_rssi_rpt_mode;
  136. sparam.rssi_thr = param->ss_rssi_thr;
  137. sparam.pwr_format = param->ss_pwr_format;
  138. sparam.rpt_mode = param->ss_rpt_mode;
  139. sparam.bin_scale = param->ss_bin_scale;
  140. sparam.dbm_adj = param->ss_dbm_adj;
  141. sparam.chn_mask = param->ss_chn_mask;
  142. sparam.mode = smode;
  143. sparam.center_freq1 = param->ss_frequency.cfreq1;
  144. sparam.center_freq2 = param->ss_frequency.cfreq2;
  145. sparam.chan_width = spectral->ch_width[smode];
  146. return psoc_spectral->wmi_ops.wmi_spectral_configure_cmd_send(
  147. GET_WMI_HDL_FROM_PDEV(pdev), &sparam);
  148. }
  149. /**
  150. * target_if_send_vdev_spectral_enable_cmd() - Send WMI command to
  151. * enable/disable Spectral
  152. * @spectral: Pointer to Spectral target_if internal private data
  153. * @smode: Spectral scan mode
  154. * @is_spectral_active_valid: Flag to indicate if spectral activate (trigger) is
  155. * valid
  156. * @is_spectral_active: Value of spectral activate
  157. * @is_spectral_enabled_valid: Flag to indicate if spectral enable is valid
  158. * @is_spectral_enabled: Value of spectral enable
  159. *
  160. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  161. */
  162. static int
  163. target_if_send_vdev_spectral_enable_cmd(struct target_if_spectral *spectral,
  164. enum spectral_scan_mode smode,
  165. uint8_t is_spectral_active_valid,
  166. uint8_t is_spectral_active,
  167. uint8_t is_spectral_enabled_valid,
  168. uint8_t is_spectral_enabled)
  169. {
  170. struct vdev_spectral_enable_params param;
  171. struct wlan_objmgr_psoc *psoc;
  172. struct wlan_objmgr_pdev *pdev = NULL;
  173. struct wlan_objmgr_vdev *vdev = NULL;
  174. struct target_if_psoc_spectral *psoc_spectral;
  175. qdf_assert_always(spectral);
  176. pdev = spectral->pdev_obj;
  177. qdf_assert_always(pdev);
  178. psoc = wlan_pdev_get_psoc(pdev);
  179. if (!psoc) {
  180. spectral_err("psoc is null");
  181. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  182. }
  183. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  184. if (!psoc_spectral) {
  185. spectral_err("psoc spectral object is null");
  186. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  187. }
  188. vdev = target_if_spectral_get_vdev(spectral, smode);
  189. if (!vdev)
  190. return QDF_STATUS_E_NOENT;
  191. qdf_mem_zero(&param, sizeof(param));
  192. param.vdev_id = wlan_vdev_get_id(vdev);
  193. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  194. param.active_valid = is_spectral_active_valid;
  195. param.enabled_valid = is_spectral_enabled_valid;
  196. param.active = is_spectral_active;
  197. param.enabled = is_spectral_enabled;
  198. param.mode = smode;
  199. return psoc_spectral->wmi_ops.wmi_spectral_enable_cmd_send(
  200. GET_WMI_HDL_FROM_PDEV(pdev), &param);
  201. }
  202. /**
  203. * target_if_spectral_info_init_defaults() - Helper function to load defaults
  204. * for Spectral information (parameters and state) into cache.
  205. * @spectral: Pointer to Spectral target_if internal private data
  206. * @smode: Spectral scan mode
  207. *
  208. * It is assumed that the caller has obtained the requisite lock if applicable.
  209. * Note that this is currently treated as a temporary function. Ideally, we
  210. * would like to get defaults from the firmware.
  211. *
  212. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  213. */
  214. static QDF_STATUS
  215. target_if_spectral_info_init_defaults(struct target_if_spectral *spectral,
  216. enum spectral_scan_mode smode)
  217. {
  218. struct target_if_spectral_param_state_info *info;
  219. struct wlan_objmgr_vdev *vdev = NULL;
  220. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  221. spectral_err("Invalid Spectral mode %u", smode);
  222. return QDF_STATUS_E_FAILURE;
  223. }
  224. info = &spectral->param_info[smode];
  225. /* State */
  226. info->osps_cache.osc_spectral_active = SPECTRAL_SCAN_ACTIVE_DEFAULT;
  227. info->osps_cache.osc_spectral_enabled = SPECTRAL_SCAN_ENABLE_DEFAULT;
  228. /* Parameters */
  229. info->osps_cache.osc_params.ss_count = SPECTRAL_SCAN_COUNT_DEFAULT;
  230. if (spectral->spectral_gen == SPECTRAL_GEN3)
  231. info->osps_cache.osc_params.ss_period =
  232. SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT;
  233. else
  234. info->osps_cache.osc_params.ss_period =
  235. SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT;
  236. info->osps_cache.osc_params.ss_spectral_pri =
  237. SPECTRAL_SCAN_PRIORITY_DEFAULT;
  238. info->osps_cache.osc_params.ss_fft_size =
  239. SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  240. info->osps_cache.osc_params.ss_gc_ena = SPECTRAL_SCAN_GC_ENA_DEFAULT;
  241. info->osps_cache.osc_params.ss_restart_ena =
  242. SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  243. info->osps_cache.osc_params.ss_noise_floor_ref =
  244. SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  245. info->osps_cache.osc_params.ss_init_delay =
  246. SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  247. info->osps_cache.osc_params.ss_nb_tone_thr =
  248. SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  249. info->osps_cache.osc_params.ss_str_bin_thr =
  250. SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  251. info->osps_cache.osc_params.ss_wb_rpt_mode =
  252. SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  253. info->osps_cache.osc_params.ss_rssi_rpt_mode =
  254. SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  255. info->osps_cache.osc_params.ss_rssi_thr =
  256. SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  257. info->osps_cache.osc_params.ss_pwr_format =
  258. SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  259. info->osps_cache.osc_params.ss_rpt_mode =
  260. SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  261. info->osps_cache.osc_params.ss_bin_scale =
  262. SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  263. info->osps_cache.osc_params.ss_dbm_adj = SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  264. vdev = target_if_spectral_get_vdev(spectral, smode);
  265. if (!vdev)
  266. return QDF_STATUS_E_NOENT;
  267. info->osps_cache.osc_params.ss_chn_mask =
  268. wlan_vdev_mlme_get_rxchainmask(vdev);
  269. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  270. info->osps_cache.osc_params.ss_short_report =
  271. SPECTRAL_SCAN_SHORT_REPORT_DEFAULT;
  272. info->osps_cache.osc_params.ss_fft_period =
  273. SPECTRAL_SCAN_FFT_PERIOD_DEFAULT;
  274. info->osps_cache.osc_params.ss_frequency.cfreq1 =
  275. SPECTRAL_SCAN_FREQUENCY_DEFAULT;
  276. info->osps_cache.osc_params.ss_frequency.cfreq2 =
  277. SPECTRAL_SCAN_FREQUENCY_DEFAULT;
  278. /* The cache is now valid */
  279. info->osps_cache.osc_is_valid = 1;
  280. return QDF_STATUS_SUCCESS;
  281. }
  282. /**
  283. * target_if_log_read_spectral_active() - Helper function to log whether
  284. * spectral is active after reading cache
  285. * @function_name: Function name
  286. * @output: whether spectral is active or not
  287. *
  288. * Helper function to log whether spectral is active after reading cache
  289. *
  290. * Return: none
  291. */
  292. static void
  293. target_if_log_read_spectral_active(
  294. const char *function_name,
  295. unsigned char output)
  296. {
  297. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE. Returning val=%u",
  298. function_name, output);
  299. }
  300. /**
  301. * target_if_log_read_spectral_enabled() - Helper function to log whether
  302. * spectral is enabled after reading cache
  303. * @function_name: Function name
  304. * @output: whether spectral is enabled or not
  305. *
  306. * Helper function to log whether spectral is enabled after reading cache
  307. *
  308. * Return: none
  309. */
  310. static void
  311. target_if_log_read_spectral_enabled(
  312. const char *function_name,
  313. unsigned char output)
  314. {
  315. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED. Returning val=%u",
  316. function_name, output);
  317. }
  318. /**
  319. * target_if_log_read_spectral_enabled() - Helper function to log spectral
  320. * parameters after reading cache
  321. * @function_name: Function name
  322. * @pparam: Spectral parameters
  323. *
  324. * Helper function to log spectral parameters after reading cache
  325. *
  326. * Return: none
  327. */
  328. static void
  329. target_if_log_read_spectral_params(
  330. const char *function_name,
  331. struct spectral_config *pparam)
  332. {
  333. 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_frequency1=%u\nss_frequency2=%u\n",
  334. function_name,
  335. pparam->ss_count,
  336. pparam->ss_period,
  337. pparam->ss_spectral_pri,
  338. pparam->ss_fft_size,
  339. pparam->ss_gc_ena,
  340. pparam->ss_restart_ena,
  341. (int8_t)pparam->ss_noise_floor_ref,
  342. pparam->ss_init_delay,
  343. pparam->ss_nb_tone_thr,
  344. pparam->ss_str_bin_thr,
  345. pparam->ss_wb_rpt_mode,
  346. pparam->ss_rssi_rpt_mode,
  347. (int8_t)pparam->ss_rssi_thr,
  348. pparam->ss_pwr_format,
  349. pparam->ss_rpt_mode,
  350. pparam->ss_bin_scale,
  351. pparam->ss_dbm_adj,
  352. pparam->ss_chn_mask,
  353. pparam->ss_frequency.cfreq1,
  354. pparam->ss_frequency.cfreq2);
  355. }
  356. /**
  357. * target_if_log_read_spectral_active_catch_validate() - Helper function to
  358. * log whether spectral is active after intializing the cache
  359. * @function_name: Function name
  360. * @output: whether spectral is active or not
  361. *
  362. * Helper function to log whether spectral is active after intializing cache
  363. *
  364. * Return: none
  365. */
  366. static void
  367. target_if_log_read_spectral_active_catch_validate(
  368. const char *function_name,
  369. unsigned char output)
  370. {
  371. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE on initial cache validation\nReturning val=%u",
  372. function_name, output);
  373. }
  374. /**
  375. * target_if_log_read_spectral_enabled_catch_validate() - Helper function to
  376. * log whether spectral is enabled after intializing the cache
  377. * @function_name: Function name
  378. * @output: whether spectral is enabled or not
  379. *
  380. * Helper function to log whether spectral is enabled after intializing cache
  381. *
  382. * Return: none
  383. */
  384. static void
  385. target_if_log_read_spectral_enabled_catch_validate(
  386. const char *function_name,
  387. unsigned char output)
  388. {
  389. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED on initial cache validation\nReturning val=%u\n",
  390. function_name, output);
  391. }
  392. /**
  393. * target_if_log_read_spectral_params_catch_validate() - Helper function to
  394. * log spectral parameters after intializing the cache
  395. * @function_name: Function name
  396. * @pparam: Spectral parameters
  397. *
  398. * Helper function to log spectral parameters after intializing the cache
  399. *
  400. * Return: none
  401. */
  402. static void
  403. target_if_log_read_spectral_params_catch_validate(
  404. const char *function_name,
  405. struct spectral_config *pparam)
  406. {
  407. 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",
  408. function_name,
  409. pparam->ss_count,
  410. pparam->ss_period,
  411. pparam->ss_spectral_pri,
  412. pparam->ss_fft_size,
  413. pparam->ss_gc_ena,
  414. pparam->ss_restart_ena,
  415. (int8_t)pparam->ss_noise_floor_ref,
  416. pparam->ss_init_delay,
  417. pparam->ss_nb_tone_thr,
  418. pparam->ss_str_bin_thr,
  419. pparam->ss_wb_rpt_mode,
  420. pparam->ss_rssi_rpt_mode,
  421. (int8_t)pparam->ss_rssi_thr,
  422. pparam->ss_pwr_format,
  423. pparam->ss_rpt_mode,
  424. pparam->ss_bin_scale,
  425. pparam->ss_dbm_adj, pparam->ss_chn_mask);
  426. }
  427. /**
  428. * target_if_spectral_info_read() - Read spectral information from the cache.
  429. * @spectral: Pointer to Spectral target_if internal private data
  430. * @smode: Spectral scan mode
  431. * @specifier: target_if_spectral_info enumeration specifying which
  432. * information is required
  433. * @output: Void output pointer into which the information will be read
  434. * @output_len: size of object pointed to by output pointer
  435. *
  436. * Read spectral parameters or the desired state information from the cache.
  437. *
  438. * Return: 0 on success, negative error code on failure
  439. */
  440. static int
  441. target_if_spectral_info_read(
  442. struct target_if_spectral *spectral,
  443. enum spectral_scan_mode smode,
  444. enum target_if_spectral_info specifier,
  445. void *output, int output_len)
  446. {
  447. /*
  448. * Note: This function is designed to be able to accommodate
  449. * WMI reads for defaults, non-cacheable information, etc
  450. * if required.
  451. */
  452. struct target_if_spectral_param_state_info *info;
  453. int is_cacheable = 0;
  454. int init_def_retval = 0;
  455. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  456. spectral_err("Invalid Spectral mode %u", smode);
  457. return -EINVAL;
  458. }
  459. info = &spectral->param_info[smode];
  460. if (!output)
  461. return -EINVAL;
  462. switch (specifier) {
  463. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  464. if (output_len != sizeof(info->osps_cache.osc_spectral_active))
  465. return -EINVAL;
  466. is_cacheable = 1;
  467. break;
  468. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  469. if (output_len != sizeof(info->osps_cache.osc_spectral_enabled))
  470. return -EINVAL;
  471. is_cacheable = 1;
  472. break;
  473. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  474. if (output_len != sizeof(info->osps_cache.osc_params))
  475. return -EINVAL;
  476. is_cacheable = 1;
  477. break;
  478. default:
  479. spectral_err("Unknown target_if_spectral_info specifier");
  480. return -EINVAL;
  481. }
  482. qdf_spin_lock_bh(&info->osps_lock);
  483. if (is_cacheable) {
  484. if (info->osps_cache.osc_is_valid) {
  485. switch (specifier) {
  486. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  487. qdf_mem_copy(
  488. output,
  489. &info->osps_cache.osc_spectral_active,
  490. sizeof(info->osps_cache.osc_spectral_active));
  491. target_if_log_read_spectral_active(
  492. __func__,
  493. *((unsigned char *)output));
  494. break;
  495. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  496. qdf_mem_copy(
  497. output,
  498. &info->osps_cache.osc_spectral_enabled,
  499. sizeof(
  500. info->osps_cache.osc_spectral_enabled));
  501. target_if_log_read_spectral_enabled(
  502. __func__,
  503. *((unsigned char *)output));
  504. break;
  505. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  506. qdf_mem_copy(
  507. output,
  508. &info->osps_cache.osc_params,
  509. sizeof(info->osps_cache.osc_params));
  510. target_if_log_read_spectral_params(
  511. __func__,
  512. (struct spectral_config *)output);
  513. break;
  514. default:
  515. /* We can't reach this point */
  516. break;
  517. }
  518. qdf_spin_unlock_bh(&info->osps_lock);
  519. return 0;
  520. }
  521. }
  522. /* Cache is invalid */
  523. /*
  524. * If WMI Reads are implemented to fetch defaults/non-cacheable info,
  525. * then the below implementation will change
  526. */
  527. init_def_retval =
  528. target_if_spectral_info_init_defaults(spectral, smode);
  529. if (init_def_retval != QDF_STATUS_SUCCESS) {
  530. qdf_spin_unlock_bh(&info->osps_lock);
  531. if (init_def_retval == QDF_STATUS_E_NOENT)
  532. return -ENOENT;
  533. else
  534. return -EINVAL;
  535. }
  536. /* target_if_spectral_info_init_defaults() has set cache to valid */
  537. switch (specifier) {
  538. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  539. qdf_mem_copy(output,
  540. &info->osps_cache.osc_spectral_active,
  541. sizeof(info->osps_cache.osc_spectral_active));
  542. target_if_log_read_spectral_active_catch_validate(
  543. __func__,
  544. *((unsigned char *)output));
  545. break;
  546. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  547. qdf_mem_copy(output,
  548. &info->osps_cache.osc_spectral_enabled,
  549. sizeof(info->osps_cache.osc_spectral_enabled));
  550. target_if_log_read_spectral_enabled_catch_validate(
  551. __func__,
  552. *((unsigned char *)output));
  553. break;
  554. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  555. qdf_mem_copy(output,
  556. &info->osps_cache.osc_params,
  557. sizeof(info->osps_cache.osc_params));
  558. target_if_log_read_spectral_params_catch_validate(
  559. __func__,
  560. (struct spectral_config *)output);
  561. break;
  562. default:
  563. /* We can't reach this point */
  564. break;
  565. }
  566. qdf_spin_unlock_bh(&info->osps_lock);
  567. return 0;
  568. }
  569. /**
  570. * target_if_log_write_spectral_active() - Helper function to log inputs and
  571. * return value of call to configure the Spectral 'active' configuration,
  572. * TARGET_IF_SPECTRAL_INFO_ACTIVE into firmware
  573. * @function_name: Function name in which this is called
  574. * @pval: whether spectral is active or not
  575. * @ret: return value of the firmware write function
  576. *
  577. * Return: none
  578. */
  579. static void
  580. target_if_log_write_spectral_active(
  581. const char *function_name,
  582. uint8_t pval,
  583. int ret)
  584. {
  585. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE with val=%u status=%d",
  586. function_name, pval, ret);
  587. }
  588. /**
  589. * target_if_log_write_spectral_enabled() - Helper function to log inputs and
  590. * return value of call to configure the Spectral 'enabled' configuration,
  591. * TARGET_IF_SPECTRAL_INFO_ENABLED into firmware
  592. * @function_name: Function name in which this is called
  593. * @pval: whether spectral is enabled or not
  594. * @ret: return value of the firmware write function
  595. *
  596. * Return: none
  597. */
  598. static void
  599. target_if_log_write_spectral_enabled(
  600. const char *function_name,
  601. uint8_t pval,
  602. int ret)
  603. {
  604. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED with val=%u status=%d",
  605. function_name, pval, ret);
  606. }
  607. /**
  608. * target_if_log_write_spectral_params() - Helper function to log inputs and
  609. * return value of call to configure Spectral parameters,
  610. * TARGET_IF_SPECTRAL_INFO_PARAMS into firmware
  611. * @param: Spectral parameters
  612. * @function_name: Function name in which this is called
  613. * @ret: return value of the firmware write function
  614. *
  615. * Return: none
  616. */
  617. static void
  618. target_if_log_write_spectral_params(
  619. struct spectral_config *param,
  620. const char *function_name,
  621. int ret)
  622. {
  623. 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_frequency1=%u\nss_frequency2=%u\nstatus = %d",
  624. function_name,
  625. param->ss_count,
  626. param->ss_period,
  627. param->ss_spectral_pri,
  628. param->ss_fft_size,
  629. param->ss_gc_ena,
  630. param->ss_restart_ena,
  631. (int8_t)param->ss_noise_floor_ref,
  632. param->ss_init_delay,
  633. param->ss_nb_tone_thr,
  634. param->ss_str_bin_thr,
  635. param->ss_wb_rpt_mode,
  636. param->ss_rssi_rpt_mode,
  637. (int8_t)param->ss_rssi_thr,
  638. param->ss_pwr_format,
  639. param->ss_rpt_mode,
  640. param->ss_bin_scale,
  641. param->ss_dbm_adj,
  642. param->ss_chn_mask,
  643. param->ss_frequency.cfreq1,
  644. param->ss_frequency.cfreq2,
  645. ret);
  646. }
  647. /**
  648. * target_if_spectral_info_write() - Write Spectral information to the
  649. * firmware, and update cache
  650. * @spectral: Pointer to Spectral target_if internal private data
  651. * @smode: Spectral scan mode
  652. * @specifier: target_if_spectral_info enumeration specifying which
  653. * information is involved
  654. * @input: void input pointer containing the information to be written
  655. * @input_len: size of object pointed to by input pointer
  656. *
  657. * Write Spectral parameters or the desired state information to
  658. * the firmware, and update cache
  659. *
  660. * Return: 0 on success, negative error code on failure
  661. */
  662. static int
  663. target_if_spectral_info_write(
  664. struct target_if_spectral *spectral,
  665. enum spectral_scan_mode smode,
  666. enum target_if_spectral_info specifier,
  667. void *input, int input_len)
  668. {
  669. struct target_if_spectral_param_state_info *info;
  670. int ret;
  671. uint8_t *pval = NULL;
  672. struct spectral_config *param = NULL;
  673. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  674. spectral_err("Invalid Spectral mode %u", smode);
  675. return -EINVAL;
  676. }
  677. info = &spectral->param_info[smode];
  678. if (!input)
  679. return -EINVAL;
  680. switch (specifier) {
  681. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  682. if (input_len != sizeof(info->osps_cache.osc_spectral_active))
  683. return -EINVAL;
  684. pval = (uint8_t *)input;
  685. qdf_spin_lock_bh(&info->osps_lock);
  686. ret = target_if_send_vdev_spectral_enable_cmd(spectral, smode,
  687. 1, *pval, 0, 0);
  688. target_if_log_write_spectral_active(
  689. __func__,
  690. *pval,
  691. ret);
  692. if (ret < 0) {
  693. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  694. ret);
  695. qdf_spin_unlock_bh(&info->osps_lock);
  696. return ret;
  697. }
  698. info->osps_cache.osc_spectral_active = *pval;
  699. /* The cache is now valid */
  700. info->osps_cache.osc_is_valid = 1;
  701. qdf_spin_unlock_bh(&info->osps_lock);
  702. break;
  703. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  704. if (input_len != sizeof(info->osps_cache.osc_spectral_enabled))
  705. return -EINVAL;
  706. pval = (uint8_t *)input;
  707. qdf_spin_lock_bh(&info->osps_lock);
  708. ret = target_if_send_vdev_spectral_enable_cmd(spectral, smode,
  709. 0, 0, 1, *pval);
  710. target_if_log_write_spectral_enabled(
  711. __func__,
  712. *pval,
  713. ret);
  714. if (ret < 0) {
  715. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  716. ret);
  717. qdf_spin_unlock_bh(&info->osps_lock);
  718. return ret;
  719. }
  720. info->osps_cache.osc_spectral_enabled = *pval;
  721. /* The cache is now valid */
  722. info->osps_cache.osc_is_valid = 1;
  723. qdf_spin_unlock_bh(&info->osps_lock);
  724. break;
  725. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  726. if (input_len != sizeof(info->osps_cache.osc_params))
  727. return -EINVAL;
  728. param = (struct spectral_config *)input;
  729. qdf_spin_lock_bh(&info->osps_lock);
  730. ret = target_if_send_vdev_spectral_configure_cmd(spectral,
  731. smode, param);
  732. target_if_log_write_spectral_params(
  733. param,
  734. __func__,
  735. ret);
  736. if (ret < 0) {
  737. spectral_err("target_if_send_vdev_spectral_configure_cmd failed with error=%d",
  738. ret);
  739. qdf_spin_unlock_bh(&info->osps_lock);
  740. return ret;
  741. }
  742. qdf_mem_copy(&info->osps_cache.osc_params,
  743. param, sizeof(info->osps_cache.osc_params));
  744. /* The cache is now valid */
  745. info->osps_cache.osc_is_valid = 1;
  746. qdf_spin_unlock_bh(&info->osps_lock);
  747. break;
  748. default:
  749. spectral_err("Unknown target_if_spectral_info specifier");
  750. return -EINVAL;
  751. }
  752. return 0;
  753. }
  754. /**
  755. * target_if_spectral_get_tsf64() - Function to get the TSF value
  756. * @arg: Pointer to handle for Spectral target_if internal private data
  757. *
  758. * Get the last TSF received in WMI buffer
  759. *
  760. * Return: TSF value
  761. */
  762. static uint64_t
  763. target_if_spectral_get_tsf64(void *arg)
  764. {
  765. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  766. return spectral->tsf64;
  767. }
  768. /**
  769. * target_if_spectral_get_capability() - Function to get whether a
  770. * given Spectral hardware capability is available
  771. * @arg: Pointer to handle for Spectral target_if internal private data
  772. * @type: Spectral hardware capability type
  773. *
  774. * Get whether a given Spectral hardware capability is available
  775. *
  776. * Return: True if the capability is available, false if the capability is not
  777. * available
  778. */
  779. uint32_t
  780. target_if_spectral_get_capability(void *arg, enum spectral_capability_type type)
  781. {
  782. int status = STATUS_FAIL;
  783. switch (type) {
  784. case SPECTRAL_CAP_PHYDIAG:
  785. case SPECTRAL_CAP_RADAR:
  786. case SPECTRAL_CAP_SPECTRAL_SCAN:
  787. case SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN:
  788. status = STATUS_PASS;
  789. break;
  790. default:
  791. status = STATUS_FAIL;
  792. }
  793. return status;
  794. }
  795. /**
  796. * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
  797. * @arg: Pointer to handle for Spectral target_if internal private data
  798. * @rxfilter: Rx filter to be used
  799. *
  800. * Note: This is only a placeholder function. It is not currently required since
  801. * FW should be taking care of setting the required filters.
  802. *
  803. * Return: 0
  804. */
  805. uint32_t
  806. target_if_spectral_set_rxfilter(void *arg, int rxfilter)
  807. {
  808. /*
  809. * Will not be required since enabling of spectral in firmware
  810. * will take care of this
  811. */
  812. return 0;
  813. }
  814. /**
  815. * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
  816. * @arg: Pointer to handle for Spectral target_if internal private data
  817. *
  818. * Note: This is only a placeholder function. It is not currently required since
  819. * FW should be taking care of setting the required filters.
  820. *
  821. * Return: 0
  822. */
  823. uint32_t
  824. target_if_spectral_get_rxfilter(void *arg)
  825. {
  826. /*
  827. * Will not be required since enabling of spectral in firmware
  828. * will take care of this
  829. */
  830. return 0;
  831. }
  832. /**
  833. * target_if_sops_is_spectral_active() - Get whether Spectral is active
  834. * @arg: Pointer to handle for Spectral target_if internal private data
  835. * @smode: Spectral scan mode
  836. *
  837. * Function to check whether Spectral is active
  838. *
  839. * Return: True if Spectral is active, false if Spectral is not active
  840. */
  841. uint32_t
  842. target_if_sops_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  843. {
  844. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  845. uint8_t val = 0;
  846. int ret;
  847. ret = target_if_spectral_info_read(
  848. spectral,
  849. smode,
  850. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  851. &val, sizeof(val));
  852. if (ret != 0) {
  853. /*
  854. * Could not determine if Spectral is active.
  855. * Return false as a safe value.
  856. * XXX: Consider changing the function prototype
  857. * to be able to indicate failure to fetch value.
  858. */
  859. return 0;
  860. }
  861. return val;
  862. }
  863. /**
  864. * target_if_sops_is_spectral_enabled() - Get whether Spectral is enabled
  865. * @arg: Pointer to handle for Spectral target_if internal private data
  866. * @smode: Spectral scan mode
  867. *
  868. * Function to check whether Spectral is enabled
  869. *
  870. * Return: True if Spectral is enabled, false if Spectral is not enabled
  871. */
  872. uint32_t
  873. target_if_sops_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  874. {
  875. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  876. uint8_t val = 0;
  877. int ret;
  878. ret = target_if_spectral_info_read(
  879. spectral,
  880. smode,
  881. TARGET_IF_SPECTRAL_INFO_ENABLED,
  882. &val, sizeof(val));
  883. if (ret != 0) {
  884. /*
  885. * Could not determine if Spectral is enabled.
  886. * Return false as a safe value.
  887. * XXX: Consider changing the function prototype
  888. * to be able to indicate failure to fetch value.
  889. */
  890. return 0;
  891. }
  892. return val;
  893. }
  894. /**
  895. * target_if_sops_start_spectral_scan() - Start Spectral scan
  896. * @arg: Pointer to handle for Spectral target_if internal private data
  897. * @smode: Spectral scan mode
  898. * @err: Spectral error code
  899. *
  900. * Function to start spectral scan
  901. *
  902. * Return: 0 on success else failure
  903. */
  904. uint32_t
  905. target_if_sops_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  906. enum spectral_cp_error_code *err)
  907. {
  908. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  909. uint8_t val = 1;
  910. uint8_t enabled = 0;
  911. int ret;
  912. ret = target_if_spectral_info_read(
  913. spectral,
  914. smode,
  915. TARGET_IF_SPECTRAL_INFO_ENABLED,
  916. &enabled, sizeof(enabled));
  917. if (ret != 0) {
  918. /*
  919. * Could not determine if Spectral is enabled. Assume we need
  920. * to enable it
  921. */
  922. enabled = 0;
  923. }
  924. if (!enabled) {
  925. ret = target_if_spectral_info_write(
  926. spectral,
  927. smode,
  928. TARGET_IF_SPECTRAL_INFO_ENABLED,
  929. &val, sizeof(val));
  930. if (ret != 0)
  931. return ret;
  932. }
  933. ret = target_if_spectral_info_write(
  934. spectral,
  935. smode,
  936. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  937. &val, sizeof(val));
  938. if (ret != 0)
  939. return ret;
  940. return 0;
  941. }
  942. /**
  943. * target_if_sops_stop_spectral_scan() - Stop Spectral scan
  944. * @arg: Pointer to handle for Spectral target_if internal private data
  945. * @smode: Spectral scan mode
  946. *
  947. * Function to stop spectral scan
  948. *
  949. * Return: 0 on success else failure
  950. */
  951. uint32_t
  952. target_if_sops_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  953. {
  954. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  955. uint8_t val = 0;
  956. int tempret, ret = 0;
  957. uint8_t enabled = 0;
  958. tempret = target_if_spectral_info_read(
  959. spectral,
  960. smode,
  961. TARGET_IF_SPECTRAL_INFO_ENABLED,
  962. &enabled, sizeof(enabled));
  963. if (tempret)
  964. /*
  965. * Could not determine if Spectral is enabled. Assume scan is
  966. * not in progress
  967. */
  968. enabled = 0;
  969. /* if scan is not enabled, no need to send stop to FW */
  970. if (!enabled)
  971. return -EPERM;
  972. tempret = target_if_spectral_info_write(
  973. spectral,
  974. smode,
  975. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  976. &val, sizeof(val));
  977. if (tempret != 0)
  978. ret = tempret;
  979. tempret = target_if_spectral_info_write(
  980. spectral,
  981. smode,
  982. TARGET_IF_SPECTRAL_INFO_ENABLED,
  983. &val, sizeof(val));
  984. if (tempret != 0)
  985. ret = tempret;
  986. return ret;
  987. }
  988. /**
  989. * target_if_spectral_get_extension_channel() - Get the Extension channel
  990. * @arg: Pointer to handle for Spectral target_if internal private data
  991. * @smode: Spectral scan mode
  992. *
  993. * Function to get the current Extension channel (in MHz)
  994. *
  995. * Return: Current Extension channel (in MHz) on success, 0 on failure or if
  996. * extension channel is not present.
  997. */
  998. uint32_t
  999. target_if_spectral_get_extension_channel(void *arg,
  1000. enum spectral_scan_mode smode)
  1001. {
  1002. /*
  1003. * XXX: Once we expand to use cases where Spectral could be activated
  1004. * without a channel being set to VDEV, we need to consider returning a
  1005. * negative value in case of failure and having all callers handle this.
  1006. */
  1007. struct target_if_spectral *spectral = NULL;
  1008. struct wlan_objmgr_vdev *vdev = NULL;
  1009. uint16_t sec20chan_freq = 0;
  1010. qdf_assert_always(arg);
  1011. spectral = (struct target_if_spectral *)arg;
  1012. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1013. spectral_err("Invalid Spectral mode %u", smode);
  1014. return 0;
  1015. }
  1016. vdev = target_if_spectral_get_vdev(spectral, smode);
  1017. if (!vdev)
  1018. return 0;
  1019. if (target_if_vdev_get_sec20chan_freq_mhz(vdev, &sec20chan_freq) < 0) {
  1020. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1021. return 0;
  1022. }
  1023. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1024. return sec20chan_freq;
  1025. }
  1026. /**
  1027. * target_if_spectral_get_current_channel() - Get the current channel
  1028. * @arg: Pointer to handle for Spectral target_if internal private data
  1029. * @smode: Spectral scan mode
  1030. *
  1031. * Function to get the current channel (in MHz)
  1032. *
  1033. * Return: Current channel (in MHz) on success, 0 on failure
  1034. */
  1035. uint32_t
  1036. target_if_spectral_get_current_channel(void *arg, enum spectral_scan_mode smode)
  1037. {
  1038. /*
  1039. * XXX: Once we expand to use cases where Spectral could be activated
  1040. * without a channel being set to VDEV, we need to consider returning a
  1041. * negative value in case of failure and having all callers handle this.
  1042. */
  1043. struct target_if_spectral *spectral = NULL;
  1044. int16_t chan_freq = 0;
  1045. struct wlan_objmgr_vdev *vdev = NULL;
  1046. qdf_assert_always(arg);
  1047. spectral = (struct target_if_spectral *)arg;
  1048. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1049. spectral_err("Invalid Spectral mode %u", smode);
  1050. return 0;
  1051. }
  1052. vdev = target_if_spectral_get_vdev(spectral, smode);
  1053. if (!vdev)
  1054. return 0;
  1055. chan_freq = target_if_vdev_get_chan_freq(vdev);
  1056. if (chan_freq < 0) {
  1057. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1058. return 0;
  1059. }
  1060. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1061. return chan_freq;
  1062. }
  1063. /**
  1064. * target_if_spectral_reset_hw() - Reset the hardware
  1065. * @arg: Pointer to handle for Spectral target_if internal private data
  1066. *
  1067. * This is only a placeholder since it is not currently required in the offload
  1068. * case.
  1069. *
  1070. * Return: 0
  1071. */
  1072. uint32_t
  1073. target_if_spectral_reset_hw(void *arg)
  1074. {
  1075. not_yet_implemented();
  1076. return 0;
  1077. }
  1078. /**
  1079. * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
  1080. * Noisefloor history buffer
  1081. * @arg: Pointer to handle for Spectral target_if internal private data
  1082. * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
  1083. *
  1084. * This is only a placeholder since it is not currently required in the offload
  1085. * case.
  1086. *
  1087. * Return: 0
  1088. */
  1089. uint32_t
  1090. target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1091. {
  1092. not_yet_implemented();
  1093. return 0;
  1094. }
  1095. /**
  1096. * target_if_spectral_get_ext_noisefloor() - Get the extension channel
  1097. * noisefloor
  1098. * @arg: Pointer to handle for Spectral target_if internal private data
  1099. *
  1100. * This is only a placeholder since it is not currently required in the offload
  1101. * case.
  1102. *
  1103. * Return: 0
  1104. */
  1105. int8_t
  1106. target_if_spectral_get_ext_noisefloor(void *arg)
  1107. {
  1108. not_yet_implemented();
  1109. return 0;
  1110. }
  1111. /**
  1112. * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
  1113. * @arg: Pointer to handle for Spectral target_if internal private data
  1114. *
  1115. * This is only a placeholder since it is not currently required in the offload
  1116. * case.
  1117. *
  1118. * Return: 0
  1119. */
  1120. int8_t
  1121. target_if_spectral_get_ctl_noisefloor(void *arg)
  1122. {
  1123. not_yet_implemented();
  1124. return 0;
  1125. }
  1126. /**
  1127. * target_if_spectral_sops_configure_params() - Configure user supplied Spectral
  1128. * parameters
  1129. * @arg: Pointer to handle for Spectral target_if internal private data
  1130. * @params: Spectral parameters
  1131. * @smode: Spectral scan mode
  1132. *
  1133. * Function to configure spectral parameters
  1134. *
  1135. * Return: 0 on success else failure
  1136. */
  1137. uint32_t
  1138. target_if_spectral_sops_configure_params(
  1139. void *arg, struct spectral_config *params,
  1140. enum spectral_scan_mode smode)
  1141. {
  1142. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1143. return target_if_spectral_info_write(
  1144. spectral,
  1145. smode,
  1146. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1147. params, sizeof(*params));
  1148. }
  1149. /**
  1150. * target_if_spectral_sops_get_params() - Get user configured Spectral
  1151. * parameters
  1152. * @arg: Pointer to handle for Spectral target_if internal private data
  1153. * @params: Pointer to buffer into which Spectral parameters should be copied
  1154. * @smode: Spectral scan mode
  1155. *
  1156. * Function to get the configured spectral parameters
  1157. *
  1158. * Return: 0 on success else failure
  1159. */
  1160. uint32_t
  1161. target_if_spectral_sops_get_params(void *arg, struct spectral_config *params,
  1162. enum spectral_scan_mode smode)
  1163. {
  1164. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1165. return target_if_spectral_info_read(
  1166. spectral,
  1167. smode,
  1168. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1169. params, sizeof(*params));
  1170. }
  1171. /**
  1172. * target_if_spectral_get_ent_mask() - Get enterprise mask
  1173. * @arg: Pointer to handle for Spectral target_if internal private data
  1174. *
  1175. * This is only a placeholder since it is not currently required in the offload
  1176. * case.
  1177. *
  1178. * Return: 0
  1179. */
  1180. static uint32_t
  1181. target_if_spectral_get_ent_mask(void *arg)
  1182. {
  1183. not_yet_implemented();
  1184. return 0;
  1185. }
  1186. /**
  1187. * target_if_spectral_get_macaddr() - Get radio MAC address
  1188. * @arg: Pointer to handle for Spectral target_if internal private data
  1189. * @addr: Pointer to buffer into which MAC address should be copied
  1190. *
  1191. * Function to get the MAC address of the pdev
  1192. *
  1193. * Return: 0 on success, -1 on failure
  1194. */
  1195. static uint32_t
  1196. target_if_spectral_get_macaddr(void *arg, char *addr)
  1197. {
  1198. uint8_t *myaddr = NULL;
  1199. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1200. struct wlan_objmgr_pdev *pdev = NULL;
  1201. pdev = spectral->pdev_obj;
  1202. wlan_pdev_obj_lock(pdev);
  1203. myaddr = wlan_pdev_get_hw_macaddr(pdev);
  1204. wlan_pdev_obj_unlock(pdev);
  1205. qdf_mem_copy(addr, myaddr, QDF_MAC_ADDR_SIZE);
  1206. return 0;
  1207. }
  1208. /**
  1209. * target_if_init_spectral_param_min_max() - Initialize Spectral parameter
  1210. * min and max values
  1211. *
  1212. * @param_min_max: Pointer to Spectral parameter min and max structure
  1213. * @gen: Spectral HW generation
  1214. * @target_type: Target type
  1215. *
  1216. * Initialize Spectral parameter min and max values
  1217. *
  1218. * Return: QDF_STATUS
  1219. */
  1220. static QDF_STATUS
  1221. target_if_init_spectral_param_min_max(
  1222. struct spectral_param_min_max *param_min_max,
  1223. enum spectral_gen gen, uint32_t target_type)
  1224. {
  1225. switch (gen) {
  1226. case SPECTRAL_GEN3:
  1227. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3;
  1228. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1229. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1230. if (target_type == TARGET_TYPE_QCN9000 ||
  1231. target_type == TARGET_TYPE_QCN9100 ||
  1232. target_type == TARGET_TYPE_QCA5018 ||
  1233. target_type == TARGET_TYPE_QCA6490) {
  1234. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1235. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1236. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1237. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1238. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1239. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1240. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1241. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1242. } else {
  1243. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1244. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1245. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1246. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1247. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1248. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1249. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1250. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1251. }
  1252. break;
  1253. case SPECTRAL_GEN2:
  1254. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1255. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1256. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1257. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1258. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1259. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1260. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1261. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1262. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1263. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1264. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1265. break;
  1266. default:
  1267. spectral_err("Invalid spectral generation %d", gen);
  1268. return QDF_STATUS_E_INVAL;
  1269. }
  1270. return QDF_STATUS_SUCCESS;
  1271. }
  1272. /**
  1273. * target_if_init_spectral_param_properties() - Initialize Spectral parameter
  1274. * properties
  1275. * @spectral: Pointer to Spectral target_if internal private data
  1276. *
  1277. * Initialize Spectral parameter properties
  1278. *
  1279. * Return: QDF_STATUS
  1280. */
  1281. static QDF_STATUS
  1282. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1283. {
  1284. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1285. int param;
  1286. /* Initialize default values for properties.
  1287. * Default values are supported for all the parameters for all modes
  1288. * and allows different values for each mode for all the parameters .
  1289. */
  1290. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1291. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1292. spectral->properties[smode][param].supported = true;
  1293. spectral->properties[smode][param].common_all_modes =
  1294. false;
  1295. }
  1296. }
  1297. /* Once FW advertisement is in place remove this hard coding */
  1298. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1299. spectral->properties[SPECTRAL_SCAN_MODE_NORMAL]
  1300. [SPECTRAL_PARAM_FREQUENCY].supported = false;
  1301. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1302. spectral->properties[smode]
  1303. [SPECTRAL_PARAM_SPECT_PRI].common_all_modes = true;
  1304. spectral->properties[smode]
  1305. [SPECTRAL_PARAM_SCAN_PERIOD].common_all_modes = true;
  1306. spectral->properties[smode]
  1307. [SPECTRAL_PARAM_INIT_DELAY].common_all_modes = true;
  1308. }
  1309. return QDF_STATUS_SUCCESS;
  1310. }
  1311. QDF_STATUS
  1312. target_if_init_spectral_capability(struct target_if_spectral *spectral,
  1313. uint32_t target_type)
  1314. {
  1315. struct wlan_objmgr_psoc *psoc;
  1316. struct wlan_objmgr_pdev *pdev;
  1317. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  1318. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  1319. struct target_psoc_info *tgt_psoc_info;
  1320. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  1321. struct spectral_caps *pcap = &spectral->capability;
  1322. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  1323. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  1324. struct wlan_psoc_host_chainmask_table *table;
  1325. int j;
  1326. uint32_t table_id;
  1327. pdev = spectral->pdev_obj;
  1328. psoc = wlan_pdev_get_psoc(pdev);
  1329. if (!psoc) {
  1330. spectral_err("psoc is null");
  1331. return QDF_STATUS_E_FAILURE;
  1332. }
  1333. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  1334. if (!tgt_psoc_info) {
  1335. spectral_err("target_psoc_info is null");
  1336. return QDF_STATUS_E_FAILURE;
  1337. }
  1338. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  1339. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  1340. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  1341. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  1342. /* XXX : Workaround: Set Spectral capability */
  1343. pcap = &spectral->capability;
  1344. pcap->phydiag_cap = 1;
  1345. pcap->radar_cap = 1;
  1346. pcap->spectral_cap = 1;
  1347. pcap->advncd_spectral_cap = 1;
  1348. pcap->hw_gen = spectral->spectral_gen;
  1349. if (spectral->spectral_gen >= SPECTRAL_GEN3) {
  1350. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  1351. if (!mac_phy_cap_arr) {
  1352. spectral_err("mac phy cap array is null");
  1353. return QDF_STATUS_E_FAILURE;
  1354. }
  1355. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  1356. if (!mac_phy_cap) {
  1357. spectral_err("mac phy cap is null");
  1358. return QDF_STATUS_E_FAILURE;
  1359. }
  1360. table_id = mac_phy_cap->chainmask_table_id;
  1361. table = &ext_svc_param->chainmask_table[table_id];
  1362. if (!table) {
  1363. spectral_err("chainmask table not found");
  1364. return QDF_STATUS_E_FAILURE;
  1365. }
  1366. for (j = 0; j < table->num_valid_chainmasks; j++) {
  1367. pcap->agile_spectral_cap |=
  1368. table->cap_list[j].supports_aSpectral;
  1369. pcap->agile_spectral_cap_160 |=
  1370. table->cap_list[j].supports_aSpectral_160;
  1371. }
  1372. pcap->agile_spectral_cap_80p80 = pcap->agile_spectral_cap_160;
  1373. } else {
  1374. pcap->agile_spectral_cap = false;
  1375. pcap->agile_spectral_cap_160 = false;
  1376. pcap->agile_spectral_cap_80p80 = false;
  1377. }
  1378. if (scaling_params) {
  1379. for (param_idx = 0; param_idx < num_bin_scaling_params;
  1380. param_idx++) {
  1381. if (scaling_params[param_idx].pdev_id == pdev_id) {
  1382. pcap->is_scaling_params_populated = true;
  1383. pcap->formula_id =
  1384. scaling_params[param_idx].formula_id;
  1385. pcap->low_level_offset =
  1386. scaling_params[param_idx].low_level_offset;
  1387. pcap->high_level_offset =
  1388. scaling_params[param_idx].high_level_offset;
  1389. pcap->rssi_thr =
  1390. scaling_params[param_idx].rssi_thr;
  1391. pcap->default_agc_max_gain =
  1392. scaling_params[param_idx].default_agc_max_gain;
  1393. break;
  1394. }
  1395. }
  1396. }
  1397. pcap->num_detectors_20mhz = 1;
  1398. pcap->num_detectors_40mhz = 1;
  1399. pcap->num_detectors_80mhz = 1;
  1400. if (target_type == TARGET_TYPE_QCN9000 ||
  1401. target_type == TARGET_TYPE_QCN9100 ||
  1402. target_type == TARGET_TYPE_QCA6490) {
  1403. pcap->num_detectors_160mhz = 1;
  1404. pcap->num_detectors_80p80mhz = 1;
  1405. } else {
  1406. pcap->num_detectors_160mhz = 2;
  1407. pcap->num_detectors_80p80mhz = 2;
  1408. }
  1409. return QDF_STATUS_SUCCESS;
  1410. }
  1411. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1412. /**
  1413. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1414. * internal operations with functions related to spectral simulation
  1415. * @p_sops: spectral low level ops table
  1416. *
  1417. * Initialize spectral target_if internal operations with functions
  1418. * related to spectral simulation
  1419. *
  1420. * Return: None
  1421. */
  1422. static void
  1423. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1424. {
  1425. /*
  1426. * Spectral simulation is currently intended for platform transitions
  1427. * where underlying HW support may not be available for some time.
  1428. * Hence, we do not currently provide a runtime switch to turn the
  1429. * simulation on or off.
  1430. * In case of future requirements where runtime switches are required,
  1431. * this can be added. But it is suggested to use application layer
  1432. * simulation as far as possible in such cases, since the main
  1433. * use of record and replay of samples would concern higher
  1434. * level sample processing rather than lower level delivery.
  1435. */
  1436. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  1437. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  1438. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  1439. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  1440. p_sops->configure_spectral =
  1441. target_if_spectral_sops_sim_configure_params;
  1442. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  1443. }
  1444. #else
  1445. /**
  1446. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1447. * internal operations
  1448. * @p_sops: spectral low level ops table
  1449. *
  1450. * Return: None
  1451. */
  1452. static void
  1453. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1454. {
  1455. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  1456. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  1457. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  1458. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  1459. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  1460. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  1461. }
  1462. #endif
  1463. /**
  1464. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  1465. * operations common to all Spectral chipset generations
  1466. *
  1467. * Initializes target_if_spectral_ops common to all chipset generations
  1468. *
  1469. * Return: None
  1470. */
  1471. static void
  1472. target_if_init_spectral_ops_common(void)
  1473. {
  1474. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1475. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  1476. p_sops->get_capability = target_if_spectral_get_capability;
  1477. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  1478. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  1479. target_if_init_spectral_simulation_ops(p_sops);
  1480. p_sops->get_extension_channel =
  1481. target_if_spectral_get_extension_channel;
  1482. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  1483. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  1484. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  1485. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  1486. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  1487. p_sops->reset_hw = target_if_spectral_reset_hw;
  1488. p_sops->get_chain_noise_floor =
  1489. target_if_spectral_get_chain_noise_floor;
  1490. }
  1491. /**
  1492. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  1493. * operations specific to Spectral chipset generation 2.
  1494. *
  1495. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  1496. *
  1497. * Return: None
  1498. */
  1499. static void
  1500. target_if_init_spectral_ops_gen2(void)
  1501. {
  1502. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1503. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  1504. }
  1505. #ifdef BIG_ENDIAN_HOST
  1506. /**
  1507. * target_if_spectral_init_byte_swap_funcs_gen3() - Initialize byte-swap
  1508. * operations for Spectral chipset generation 3.
  1509. *
  1510. * @p_sops: Spectral function pointer table
  1511. *
  1512. * Return: None
  1513. */
  1514. static void
  1515. target_if_spectral_init_byte_swap_funcs_gen3(
  1516. struct target_if_spectral_ops *p_sops)
  1517. {
  1518. qdf_assert_always(p_sops);
  1519. /* None of current Gen3 chipsets support byte-swap inside the target.
  1520. * so, Host would have to implement the byte-swap for these chipsets.
  1521. *
  1522. * If a chipset supports byte-swap inside the target itself in future,
  1523. * then, for that chipset, initialize these function pointers with
  1524. * NULL based on the capability advertisement.
  1525. */
  1526. p_sops->byte_swap_headers = target_if_byte_swap_spectral_headers_gen3;
  1527. p_sops->byte_swap_fft_bins = target_if_byte_swap_spectral_fft_bins_gen3;
  1528. }
  1529. #else
  1530. static void
  1531. target_if_spectral_init_byte_swap_funcs_gen3(
  1532. struct target_if_spectral_ops *p_sops)
  1533. {
  1534. qdf_assert_always(p_sops);
  1535. /* Byte-swap is not required for little-endian Hosts */
  1536. p_sops->byte_swap_headers = NULL;
  1537. p_sops->byte_swap_fft_bins = NULL;
  1538. }
  1539. #endif /* BIG_ENDIAN_HOST */
  1540. /**
  1541. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  1542. * operations specific to Spectral chipset generation 3.
  1543. *
  1544. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  1545. *
  1546. * Return: None
  1547. */
  1548. static void
  1549. target_if_init_spectral_ops_gen3(void)
  1550. {
  1551. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1552. p_sops->process_spectral_report =
  1553. target_if_spectral_process_report_gen3;
  1554. target_if_spectral_init_byte_swap_funcs_gen3(p_sops);
  1555. }
  1556. /**
  1557. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  1558. * operations.
  1559. * @spectral: Pointer to Spectral target_if internal private data
  1560. *
  1561. * Initializes all function pointers in target_if_spectral_ops for
  1562. * all generations
  1563. *
  1564. * Return: None
  1565. */
  1566. static void
  1567. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  1568. {
  1569. target_if_init_spectral_ops_common();
  1570. if (spectral->spectral_gen == SPECTRAL_GEN2)
  1571. target_if_init_spectral_ops_gen2();
  1572. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  1573. target_if_init_spectral_ops_gen3();
  1574. else
  1575. spectral_err("Invalid Spectral generation");
  1576. }
  1577. /*
  1578. * Dummy Functions:
  1579. * These functions are initially registered to avoid any crashes due to
  1580. * invocation of spectral functions before they are registered.
  1581. */
  1582. static uint64_t
  1583. null_get_tsf64(void *arg)
  1584. {
  1585. spectral_ops_not_registered("get_tsf64");
  1586. return 0;
  1587. }
  1588. static uint32_t
  1589. null_get_capability(void *arg, enum spectral_capability_type type)
  1590. {
  1591. /*
  1592. * TODO : We should have conditional compilation to get the capability
  1593. * : We have not yet attahced ATH layer here, so there is no
  1594. * : way to check the HAL capbalities
  1595. */
  1596. spectral_ops_not_registered("get_capability");
  1597. /* TODO : For the time being, we are returning TRUE */
  1598. return true;
  1599. }
  1600. static uint32_t
  1601. null_set_rxfilter(void *arg, int rxfilter)
  1602. {
  1603. spectral_ops_not_registered("set_rxfilter");
  1604. return 1;
  1605. }
  1606. static uint32_t
  1607. null_get_rxfilter(void *arg)
  1608. {
  1609. spectral_ops_not_registered("get_rxfilter");
  1610. return 0;
  1611. }
  1612. static uint32_t
  1613. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  1614. {
  1615. spectral_ops_not_registered("is_spectral_active");
  1616. return 1;
  1617. }
  1618. static uint32_t
  1619. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  1620. {
  1621. spectral_ops_not_registered("is_spectral_enabled");
  1622. return 1;
  1623. }
  1624. static uint32_t
  1625. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  1626. enum spectral_cp_error_code *err)
  1627. {
  1628. spectral_ops_not_registered("start_spectral_scan");
  1629. return 1;
  1630. }
  1631. static uint32_t
  1632. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  1633. {
  1634. spectral_ops_not_registered("stop_spectral_scan");
  1635. return 1;
  1636. }
  1637. static uint32_t
  1638. null_get_extension_channel(void *arg, enum spectral_scan_mode smode)
  1639. {
  1640. spectral_ops_not_registered("get_extension_channel");
  1641. return 1;
  1642. }
  1643. static int8_t
  1644. null_get_ctl_noisefloor(void *arg)
  1645. {
  1646. spectral_ops_not_registered("get_ctl_noisefloor");
  1647. return 1;
  1648. }
  1649. static int8_t
  1650. null_get_ext_noisefloor(void *arg)
  1651. {
  1652. spectral_ops_not_registered("get_ext_noisefloor");
  1653. return 0;
  1654. }
  1655. static uint32_t
  1656. null_configure_spectral(void *arg, struct spectral_config *params,
  1657. enum spectral_scan_mode smode)
  1658. {
  1659. spectral_ops_not_registered("configure_spectral");
  1660. return 0;
  1661. }
  1662. static uint32_t
  1663. null_get_spectral_config(void *arg, struct spectral_config *params,
  1664. enum spectral_scan_mode smode)
  1665. {
  1666. spectral_ops_not_registered("get_spectral_config");
  1667. return 0;
  1668. }
  1669. static uint32_t
  1670. null_get_ent_spectral_mask(void *arg)
  1671. {
  1672. spectral_ops_not_registered("get_ent_spectral_mask");
  1673. return 0;
  1674. }
  1675. static uint32_t
  1676. null_get_mac_address(void *arg, char *addr)
  1677. {
  1678. spectral_ops_not_registered("get_mac_address");
  1679. return 0;
  1680. }
  1681. static uint32_t
  1682. null_get_current_channel(void *arg, enum spectral_scan_mode smode)
  1683. {
  1684. spectral_ops_not_registered("get_current_channel");
  1685. return 0;
  1686. }
  1687. static uint32_t
  1688. null_reset_hw(void *arg)
  1689. {
  1690. spectral_ops_not_registered("get_current_channel");
  1691. return 0;
  1692. }
  1693. static uint32_t
  1694. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1695. {
  1696. spectral_ops_not_registered("get_chain_noise_floor");
  1697. return 0;
  1698. }
  1699. static int
  1700. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  1701. uint8_t *data,
  1702. uint32_t datalen,
  1703. struct target_if_spectral_rfqual_info *p_rfqual,
  1704. struct target_if_spectral_chan_info *p_chaninfo,
  1705. uint64_t tsf64,
  1706. struct target_if_spectral_acs_stats *acs_stats)
  1707. {
  1708. spectral_ops_not_registered("spectral_process_phyerr");
  1709. return 0;
  1710. }
  1711. static int
  1712. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  1713. void *payload)
  1714. {
  1715. spectral_ops_not_registered("process_spectral_report");
  1716. return 0;
  1717. }
  1718. /**
  1719. * target_if_spectral_init_dummy_function_table() -
  1720. * Initialize target_if internal
  1721. * Spectral operations to dummy functions
  1722. * @ps: Pointer to Spectral target_if internal private data
  1723. *
  1724. * Initialize all the function pointers in target_if_spectral_ops with
  1725. * dummy functions.
  1726. *
  1727. * Return: None
  1728. */
  1729. static void
  1730. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  1731. {
  1732. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  1733. p_sops->get_tsf64 = null_get_tsf64;
  1734. p_sops->get_capability = null_get_capability;
  1735. p_sops->set_rxfilter = null_set_rxfilter;
  1736. p_sops->get_rxfilter = null_get_rxfilter;
  1737. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  1738. p_sops->is_spectral_active = null_is_spectral_active;
  1739. p_sops->start_spectral_scan = null_start_spectral_scan;
  1740. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  1741. p_sops->get_extension_channel = null_get_extension_channel;
  1742. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  1743. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  1744. p_sops->configure_spectral = null_configure_spectral;
  1745. p_sops->get_spectral_config = null_get_spectral_config;
  1746. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  1747. p_sops->get_mac_address = null_get_mac_address;
  1748. p_sops->get_current_channel = null_get_current_channel;
  1749. p_sops->reset_hw = null_reset_hw;
  1750. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  1751. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  1752. p_sops->process_spectral_report = null_process_spectral_report;
  1753. }
  1754. /**
  1755. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  1756. * operations
  1757. * @spectral: Pointer to Spectral target_if internal private data
  1758. * @p: Pointer to Spectral function table
  1759. *
  1760. * Return: None
  1761. */
  1762. static void
  1763. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  1764. struct target_if_spectral_ops *p)
  1765. {
  1766. struct target_if_spectral_ops *p_sops =
  1767. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1768. *p_sops = *p;
  1769. }
  1770. /**
  1771. * target_if_spectral_clear_stats() - Clear Spectral stats
  1772. * @spectral: Pointer to Spectral target_if internal private data
  1773. *
  1774. * Function to clear spectral stats
  1775. *
  1776. * Return: None
  1777. */
  1778. static void
  1779. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  1780. {
  1781. struct target_if_spectral_ops *p_sops =
  1782. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1783. qdf_mem_zero(&spectral->spectral_stats,
  1784. sizeof(struct target_if_spectral_stats));
  1785. spectral->spectral_stats.last_reset_tstamp =
  1786. p_sops->get_tsf64(spectral);
  1787. }
  1788. /**
  1789. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  1790. * @spectral: Pointer to Spectral target_if internal private data
  1791. *
  1792. * Function to check whether hardware supports spectral
  1793. *
  1794. * Return: True if HW supports Spectral, false if HW does not support Spectral
  1795. */
  1796. static int
  1797. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  1798. {
  1799. struct target_if_spectral_ops *p_sops = NULL;
  1800. struct spectral_caps *pcap = NULL;
  1801. int is_spectral_supported = true;
  1802. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1803. pcap = &spectral->capability;
  1804. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  1805. is_spectral_supported = false;
  1806. spectral_info("SPECTRAL : No PHYDIAG support");
  1807. return is_spectral_supported;
  1808. }
  1809. pcap->phydiag_cap = 1;
  1810. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  1811. is_spectral_supported = false;
  1812. spectral_info("SPECTRAL : No RADAR support");
  1813. return is_spectral_supported;
  1814. }
  1815. pcap->radar_cap = 1;
  1816. if (p_sops->get_capability(spectral,
  1817. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  1818. is_spectral_supported = false;
  1819. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  1820. return is_spectral_supported;
  1821. }
  1822. pcap->spectral_cap = 1;
  1823. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  1824. == false) {
  1825. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  1826. } else {
  1827. pcap->advncd_spectral_cap = 1;
  1828. }
  1829. return is_spectral_supported;
  1830. }
  1831. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1832. /**
  1833. * target_if_spectral_detach_simulation() - De-initialize Spectral
  1834. * Simulation functionality
  1835. * @spectral: Pointer to Spectral target_if internal private data
  1836. *
  1837. * Function to de-initialize Spectral Simulation functionality
  1838. *
  1839. * Return: None
  1840. */
  1841. static void
  1842. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1843. {
  1844. target_if_spectral_sim_detach(spectral);
  1845. }
  1846. #else
  1847. static void
  1848. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1849. {
  1850. }
  1851. #endif
  1852. /**
  1853. * target_if_spectral_detach() - De-initialize target_if Spectral
  1854. * @pdev: Pointer to pdev object
  1855. *
  1856. * Function to detach target_if spectral
  1857. *
  1858. * Return: None
  1859. */
  1860. static void
  1861. target_if_spectral_detach(struct target_if_spectral *spectral)
  1862. {
  1863. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1864. spectral_info("spectral detach");
  1865. if (spectral) {
  1866. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1867. qdf_spinlock_destroy
  1868. (&spectral->param_info[smode].osps_lock);
  1869. target_if_spectral_detach_simulation(spectral);
  1870. qdf_spinlock_destroy(&spectral->spectral_lock);
  1871. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  1872. qdf_mem_free(spectral);
  1873. spectral = NULL;
  1874. }
  1875. }
  1876. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1877. /**
  1878. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  1879. * functionality
  1880. * @spectral: Pointer to Spectral target_if internal private data
  1881. *
  1882. * Function to initialize spectral simulation functionality
  1883. *
  1884. * Return: 0 on success, negative error code on failure
  1885. */
  1886. static int
  1887. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1888. {
  1889. if (target_if_spectral_sim_attach(spectral)) {
  1890. qdf_mem_free(spectral);
  1891. return -EPERM;
  1892. }
  1893. return 0;
  1894. }
  1895. #else
  1896. static int
  1897. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1898. {
  1899. return 0;
  1900. }
  1901. #endif
  1902. /**
  1903. * target_if_spectral_len_adj_swar_init() - Initialize FFT bin length adjustment
  1904. * related info
  1905. * @swar: Pointer to Spectral FFT bin length adjustment SWAR params
  1906. * @target_type: Target type
  1907. *
  1908. * Function to Initialize parameters related to Spectral FFT bin
  1909. * length adjustment SWARs.
  1910. *
  1911. * Return: void
  1912. */
  1913. static void
  1914. target_if_spectral_len_adj_swar_init(struct spectral_fft_bin_len_adj_swar *swar,
  1915. uint32_t target_type)
  1916. {
  1917. if (target_type == TARGET_TYPE_QCA8074V2 ||
  1918. target_type == TARGET_TYPE_QCN9000 ||
  1919. target_type == TARGET_TYPE_QCN9100 ||
  1920. target_type == TARGET_TYPE_QCA5018 ||
  1921. target_type == TARGET_TYPE_QCA6750 ||
  1922. target_type == TARGET_TYPE_QCA6490)
  1923. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  1924. else if (target_type == TARGET_TYPE_QCA8074 ||
  1925. target_type == TARGET_TYPE_QCA6018 ||
  1926. target_type == TARGET_TYPE_QCA6390)
  1927. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  1928. else
  1929. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  1930. if (target_type == TARGET_TYPE_QCA8074 ||
  1931. target_type == TARGET_TYPE_QCA8074V2 ||
  1932. target_type == TARGET_TYPE_QCA6018 ||
  1933. target_type == TARGET_TYPE_QCN9100 ||
  1934. target_type == TARGET_TYPE_QCA5018 ||
  1935. target_type == TARGET_TYPE_QCN9000 ||
  1936. target_type == TARGET_TYPE_QCA6490) {
  1937. swar->inband_fftbin_size_adj = 1;
  1938. swar->null_fftbin_adj = 1;
  1939. } else {
  1940. swar->inband_fftbin_size_adj = 0;
  1941. swar->null_fftbin_adj = 0;
  1942. }
  1943. if (target_type == TARGET_TYPE_QCA8074V2)
  1944. swar->packmode_fftbin_size_adj = 1;
  1945. else
  1946. swar->packmode_fftbin_size_adj = 0;
  1947. }
  1948. /**
  1949. * target_if_spectral_report_params_init() - Initialize parameters which
  1950. * describes the structure of Spectral reports
  1951. *
  1952. * @rparams: Pointer to Spectral report parameter object
  1953. * @target_type: target type
  1954. *
  1955. * Function to Initialize parameters related to the structure of Spectral
  1956. * reports.
  1957. *
  1958. * Return: void
  1959. */
  1960. static void
  1961. target_if_spectral_report_params_init(
  1962. struct spectral_report_params *rparams,
  1963. uint32_t target_type)
  1964. {
  1965. enum spectral_scan_mode smode;
  1966. /* This entries are currently used by gen3 chipsets only. Hence
  1967. * initialization is done for gen3 alone. In future if other generations
  1968. * needs to use them they have to add proper initial values.
  1969. */
  1970. if (target_type == TARGET_TYPE_QCN9000 ||
  1971. target_type == TARGET_TYPE_QCN9100 ||
  1972. target_type == TARGET_TYPE_QCA5018 ||
  1973. target_type == TARGET_TYPE_QCA6750 ||
  1974. target_type == TARGET_TYPE_QCA6490) {
  1975. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_2;
  1976. rparams->num_spectral_detectors =
  1977. NUM_SPECTRAL_DETECTORS_GEN3_V2;
  1978. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1979. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1980. rparams->fragmentation_160[smode] = false;
  1981. rparams->max_agile_ch_width = CH_WIDTH_80P80MHZ;
  1982. } else {
  1983. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_1;
  1984. rparams->num_spectral_detectors =
  1985. NUM_SPECTRAL_DETECTORS_GEN3_V1;
  1986. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1987. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1988. rparams->fragmentation_160[smode] = true;
  1989. rparams->max_agile_ch_width = CH_WIDTH_80MHZ;
  1990. }
  1991. switch (rparams->version) {
  1992. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1993. rparams->ssumaary_padding_bytes =
  1994. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1;
  1995. rparams->fft_report_hdr_len =
  1996. FFT_REPORT_HEADER_LENGTH_GEN3_V1;
  1997. break;
  1998. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1999. rparams->ssumaary_padding_bytes =
  2000. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2;
  2001. rparams->fft_report_hdr_len =
  2002. FFT_REPORT_HEADER_LENGTH_GEN3_V2;
  2003. break;
  2004. default:
  2005. qdf_assert_always(0);
  2006. }
  2007. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_0] =
  2008. SPECTRAL_SCAN_MODE_NORMAL;
  2009. if (target_type == TARGET_TYPE_QCN9000 ||
  2010. target_type == TARGET_TYPE_QCN9100 ||
  2011. target_type == TARGET_TYPE_QCA6490) {
  2012. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2013. SPECTRAL_SCAN_MODE_AGILE;
  2014. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2015. SPECTRAL_SCAN_MODE_INVALID;
  2016. } else {
  2017. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2018. SPECTRAL_SCAN_MODE_NORMAL;
  2019. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2020. SPECTRAL_SCAN_MODE_AGILE;
  2021. }
  2022. }
  2023. /**
  2024. * target_if_spectral_timestamp_war_init() - Initialize Spectral timestamp WAR
  2025. * related info
  2026. * @twar: Pointer to Spectral timstamp WAR related info
  2027. *
  2028. * Function to Initialize parameters related to Spectral timestamp WAR
  2029. *
  2030. * Return: void
  2031. */
  2032. static void
  2033. target_if_spectral_timestamp_war_init(struct spectral_timestamp_war *twar)
  2034. {
  2035. enum spectral_scan_mode smode;
  2036. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2037. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2038. twar->last_fft_timestamp[smode] = 0;
  2039. twar->timestamp_war_offset[smode] = 0;
  2040. }
  2041. twar->target_reset_count = 0;
  2042. }
  2043. /**
  2044. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  2045. * functionality for the given pdev
  2046. * @pdev: Pointer to pdev object
  2047. *
  2048. * Function to initialize pointer to spectral target_if internal private data
  2049. *
  2050. * Return: On success, pointer to Spectral target_if internal private data, on
  2051. * failure, NULL
  2052. */
  2053. void *
  2054. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  2055. {
  2056. struct target_if_spectral_ops *p_sops = NULL;
  2057. struct target_if_spectral *spectral = NULL;
  2058. uint32_t target_type;
  2059. uint32_t target_revision;
  2060. struct wlan_objmgr_psoc *psoc;
  2061. struct wlan_lmac_if_target_tx_ops *tgt_tx_ops;
  2062. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  2063. QDF_STATUS status;
  2064. struct wlan_lmac_if_tx_ops *tx_ops;
  2065. if (!pdev) {
  2066. spectral_err("SPECTRAL: pdev is NULL!");
  2067. return NULL;
  2068. }
  2069. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  2070. sizeof(struct target_if_spectral));
  2071. if (!spectral)
  2072. return spectral;
  2073. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  2074. /* Store pdev in Spectral */
  2075. spectral->pdev_obj = pdev;
  2076. spectral->vdev_id[SPECTRAL_SCAN_MODE_NORMAL] = WLAN_INVALID_VDEV_ID;
  2077. spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE] = WLAN_INVALID_VDEV_ID;
  2078. psoc = wlan_pdev_get_psoc(pdev);
  2079. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  2080. if (!tx_ops) {
  2081. spectral_err("tx_ops is NULL");
  2082. qdf_mem_free(spectral);
  2083. return NULL;
  2084. }
  2085. tgt_tx_ops = &tx_ops->target_tx_ops;
  2086. if (tgt_tx_ops->tgt_get_tgt_type) {
  2087. target_type = tgt_tx_ops->tgt_get_tgt_type(psoc);
  2088. } else {
  2089. qdf_mem_free(spectral);
  2090. return NULL;
  2091. }
  2092. if (tgt_tx_ops->tgt_get_tgt_revision) {
  2093. target_revision = tgt_tx_ops->tgt_get_tgt_revision(psoc);
  2094. } else {
  2095. qdf_mem_free(spectral);
  2096. return NULL;
  2097. }
  2098. /* init the function ptr table */
  2099. target_if_spectral_init_dummy_function_table(spectral);
  2100. /* get spectral function table */
  2101. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2102. /* TODO : Should this be called here of after ath_attach ? */
  2103. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  2104. spectral_info("HAL_CAP_PHYDIAG : Capable");
  2105. /* TODO: Need to fix the capablity check for RADAR */
  2106. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  2107. spectral_info("HAL_CAP_RADAR : Capable");
  2108. /* TODO : Need to fix the capablity check for SPECTRAL */
  2109. /* TODO : Should this be called here of after ath_attach ? */
  2110. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  2111. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  2112. qdf_spinlock_create(&spectral->spectral_lock);
  2113. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  2114. target_if_spectral_clear_stats(spectral);
  2115. if (target_type == TARGET_TYPE_QCA8074 ||
  2116. target_type == TARGET_TYPE_QCA8074V2 ||
  2117. target_type == TARGET_TYPE_QCA6018 ||
  2118. target_type == TARGET_TYPE_QCA5018 ||
  2119. target_type == TARGET_TYPE_QCA6390 ||
  2120. target_type == TARGET_TYPE_QCN9100 ||
  2121. target_type == TARGET_TYPE_QCA6490 ||
  2122. target_type == TARGET_TYPE_QCN9000 ||
  2123. target_type == TARGET_TYPE_QCA6750)
  2124. spectral->direct_dma_support = true;
  2125. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  2126. target_type);
  2127. target_if_spectral_report_params_init(&spectral->rparams, target_type);
  2128. if ((target_type == TARGET_TYPE_QCA8074) ||
  2129. (target_type == TARGET_TYPE_QCA8074V2) ||
  2130. (target_type == TARGET_TYPE_QCA6018) ||
  2131. (target_type == TARGET_TYPE_QCA5018) ||
  2132. (target_type == TARGET_TYPE_QCN9100) ||
  2133. (target_type == TARGET_TYPE_QCN9000) ||
  2134. (target_type == TARGET_TYPE_QCA6290) ||
  2135. (target_type == TARGET_TYPE_QCA6390) ||
  2136. (target_type == TARGET_TYPE_QCA6490) ||
  2137. (target_type == TARGET_TYPE_QCA6750)) {
  2138. spectral->spectral_gen = SPECTRAL_GEN3;
  2139. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  2140. spectral->tag_sscan_summary_exp =
  2141. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  2142. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  2143. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  2144. } else {
  2145. spectral->spectral_gen = SPECTRAL_GEN2;
  2146. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  2147. spectral->tag_sscan_summary_exp =
  2148. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  2149. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  2150. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  2151. }
  2152. status = target_if_init_spectral_param_min_max(
  2153. &spectral->param_min_max,
  2154. spectral->spectral_gen, target_type);
  2155. if (QDF_IS_STATUS_ERROR(status)) {
  2156. spectral_err("Failed to initialize parameter min max values");
  2157. goto fail;
  2158. }
  2159. target_if_init_spectral_param_properties(spectral);
  2160. /* Init spectral capability */
  2161. if (target_if_init_spectral_capability(spectral, target_type) !=
  2162. QDF_STATUS_SUCCESS) {
  2163. qdf_mem_free(spectral);
  2164. return NULL;
  2165. }
  2166. if (target_if_spectral_attach_simulation(spectral) < 0)
  2167. return NULL;
  2168. target_if_init_spectral_ops(spectral);
  2169. target_if_spectral_timestamp_war_init(&spectral->timestamp_war);
  2170. /* Spectral mode specific init */
  2171. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2172. spectral->params_valid[smode] = false;
  2173. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  2174. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  2175. }
  2176. target_if_spectral_register_funcs(spectral, &spectral_ops);
  2177. if (target_if_spectral_check_hw_capability(spectral) == false) {
  2178. goto fail;
  2179. } else {
  2180. /*
  2181. * TODO: Once the driver architecture transitions to chipset
  2182. * versioning based checks, reflect this here.
  2183. */
  2184. spectral->is_160_format = false;
  2185. spectral->is_lb_edge_extrabins_format = false;
  2186. spectral->is_rb_edge_extrabins_format = false;
  2187. if (target_type == TARGET_TYPE_QCA9984 ||
  2188. target_type == TARGET_TYPE_QCA9888) {
  2189. spectral->is_160_format = true;
  2190. spectral->is_lb_edge_extrabins_format = true;
  2191. spectral->is_rb_edge_extrabins_format = true;
  2192. } else if ((target_type == TARGET_TYPE_AR900B) &&
  2193. (target_revision == AR900B_REV_2)) {
  2194. spectral->is_rb_edge_extrabins_format = true;
  2195. }
  2196. if (target_type == TARGET_TYPE_QCA9984 ||
  2197. target_type == TARGET_TYPE_QCA9888)
  2198. spectral->is_sec80_rssi_war_required = true;
  2199. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  2200. if (spectral->spectral_gen == SPECTRAL_GEN3)
  2201. init_160mhz_delivery_state_machine(spectral);
  2202. }
  2203. return spectral;
  2204. fail:
  2205. target_if_spectral_detach(spectral);
  2206. return NULL;
  2207. }
  2208. /**
  2209. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  2210. * functionality for the given pdev
  2211. * @pdev: Pointer to pdev object
  2212. *
  2213. * Function to de-initialize pointer to spectral target_if internal private data
  2214. *
  2215. * Return: None
  2216. */
  2217. void
  2218. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  2219. {
  2220. struct target_if_spectral *spectral = NULL;
  2221. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2222. if (!spectral) {
  2223. spectral_err("SPECTRAL : Module doesn't exist");
  2224. return;
  2225. }
  2226. target_if_spectral_detach(spectral);
  2227. return;
  2228. }
  2229. /**
  2230. * target_if_psoc_spectral_deinit() - De-initialize target_if Spectral
  2231. * functionality for the given psoc
  2232. * @psoc: Pointer to psoc object
  2233. *
  2234. * Function to de-initialize pointer to psoc spectral target_if internal
  2235. * private data
  2236. *
  2237. * Return: None
  2238. */
  2239. static void
  2240. target_if_psoc_spectral_deinit(struct wlan_objmgr_psoc *psoc)
  2241. {
  2242. struct target_if_psoc_spectral *psoc_spectral;
  2243. if (!psoc) {
  2244. spectral_err("psoc is null");
  2245. return;
  2246. }
  2247. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  2248. if (!psoc_spectral) {
  2249. spectral_err("Spectral target_if psoc object is null");
  2250. return;
  2251. }
  2252. qdf_mem_free(psoc_spectral);
  2253. }
  2254. /**
  2255. * target_if_psoc_spectral_init() - Initialize target_if Spectral
  2256. * functionality for the given psoc
  2257. * @psoc: Pointer to psoc object
  2258. *
  2259. * Function to initialize pointer to psoc spectral target_if internal
  2260. * private data
  2261. *
  2262. * Return: On success, pointer to Spectral psoc target_if internal
  2263. * private data, on failure, NULL
  2264. */
  2265. static void *
  2266. target_if_psoc_spectral_init(struct wlan_objmgr_psoc *psoc)
  2267. {
  2268. struct target_if_psoc_spectral *psoc_spectral = NULL;
  2269. if (!psoc) {
  2270. spectral_err("psoc is null");
  2271. goto fail;
  2272. }
  2273. psoc_spectral = (struct target_if_psoc_spectral *)qdf_mem_malloc(
  2274. sizeof(struct target_if_psoc_spectral));
  2275. if (!psoc_spectral) {
  2276. spectral_err("Spectral lmac psoc object allocation failed");
  2277. goto fail;
  2278. }
  2279. psoc_spectral->psoc_obj = psoc;
  2280. return psoc_spectral;
  2281. fail:
  2282. if (psoc_spectral)
  2283. target_if_psoc_spectral_deinit(psoc);
  2284. return psoc_spectral;
  2285. }
  2286. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  2287. * corresponding translation for Agile channel width.
  2288. * @spectral: pointer to Spectral object
  2289. * @chwidth: operating channel width
  2290. * @is_80_80_agile: Indicates an 80+80 agile Scan request
  2291. *
  2292. * Return: The translated channel width enum.
  2293. */
  2294. static enum phy_ch_width
  2295. target_if_spectral_find_agile_width(struct target_if_spectral *spectral,
  2296. enum phy_ch_width chwidth,
  2297. bool is_80_80_agile)
  2298. {
  2299. enum phy_ch_width agile_width;
  2300. struct wlan_objmgr_pdev *pdev;
  2301. struct wlan_objmgr_psoc *psoc;
  2302. if (!spectral) {
  2303. spectral_err("Spectral object is null");
  2304. return CH_WIDTH_INVALID;
  2305. }
  2306. pdev = spectral->pdev_obj;
  2307. if (!pdev) {
  2308. spectral_err("pdev is null");
  2309. return CH_WIDTH_INVALID;
  2310. }
  2311. psoc = wlan_pdev_get_psoc(pdev);
  2312. if (!psoc) {
  2313. spectral_err("psoc is null");
  2314. return CH_WIDTH_INVALID;
  2315. }
  2316. switch (chwidth) {
  2317. case CH_WIDTH_20MHZ:
  2318. agile_width = CH_WIDTH_20MHZ;
  2319. break;
  2320. case CH_WIDTH_40MHZ:
  2321. agile_width = CH_WIDTH_40MHZ;
  2322. break;
  2323. case CH_WIDTH_80MHZ:
  2324. agile_width = CH_WIDTH_80MHZ;
  2325. break;
  2326. case CH_WIDTH_80P80MHZ:
  2327. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  2328. WLAN_SOC_RESTRICTED_80P80_SUPPORT) && !is_80_80_agile)
  2329. agile_width = CH_WIDTH_160MHZ;
  2330. else
  2331. agile_width = CH_WIDTH_80P80MHZ;
  2332. if (agile_width > spectral->rparams.max_agile_ch_width)
  2333. agile_width = spectral->rparams.max_agile_ch_width;
  2334. break;
  2335. case CH_WIDTH_160MHZ:
  2336. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  2337. WLAN_SOC_RESTRICTED_80P80_SUPPORT) && is_80_80_agile)
  2338. agile_width = CH_WIDTH_80P80MHZ;
  2339. else
  2340. agile_width = CH_WIDTH_160MHZ;
  2341. if (agile_width > spectral->rparams.max_agile_ch_width)
  2342. agile_width = spectral->rparams.max_agile_ch_width;
  2343. break;
  2344. default:
  2345. spectral_err("Invalid channel width %d", chwidth);
  2346. agile_width = CH_WIDTH_INVALID;
  2347. break;
  2348. }
  2349. return agile_width;
  2350. }
  2351. /**
  2352. * target_if_calculate_center_freq() - Helper routine to
  2353. * check whether given frequency is center frequency of a
  2354. * WLAN channel
  2355. *
  2356. * @spectral: Pointer to Spectral object
  2357. * @chan_freq: Center frequency of a WLAN channel
  2358. * @is_valid: Indicates whether given frequency is valid
  2359. *
  2360. * Return: QDF_STATUS
  2361. */
  2362. static QDF_STATUS
  2363. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  2364. uint32_t chan_freq,
  2365. bool *is_valid)
  2366. {
  2367. struct regulatory_channel *cur_chan_list;
  2368. int i;
  2369. if (!pdev) {
  2370. spectral_err("pdev object is null");
  2371. return QDF_STATUS_E_FAILURE;
  2372. }
  2373. if (!is_valid) {
  2374. spectral_err("is valid argument is null");
  2375. return QDF_STATUS_E_FAILURE;
  2376. }
  2377. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  2378. if (!cur_chan_list)
  2379. return QDF_STATUS_E_FAILURE;
  2380. if (wlan_reg_get_current_chan_list(
  2381. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  2382. spectral_err("Failed to get cur_chan list");
  2383. qdf_mem_free(cur_chan_list);
  2384. return QDF_STATUS_E_FAILURE;
  2385. }
  2386. *is_valid = false;
  2387. for (i = 0; i < NUM_CHANNELS; i++) {
  2388. uint32_t flags;
  2389. uint32_t center_freq;
  2390. flags = cur_chan_list[i].chan_flags;
  2391. center_freq = cur_chan_list[i].center_freq;
  2392. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  2393. (center_freq == chan_freq)) {
  2394. *is_valid = true;
  2395. break;
  2396. }
  2397. }
  2398. qdf_mem_free(cur_chan_list);
  2399. return QDF_STATUS_SUCCESS;
  2400. }
  2401. /**
  2402. * target_if_calculate_center_freq() - Helper routine to
  2403. * find the center frequency of the agile span from a
  2404. * WLAN channel center frequency
  2405. *
  2406. * @spectral: Pointer to Spectral object
  2407. * @ch_width: Channel width array
  2408. * @chan_freq: Center frequency of a WLAN channel
  2409. * @center_freq: Pointer to center frequency
  2410. *
  2411. * Return: QDF_STATUS
  2412. */
  2413. static QDF_STATUS
  2414. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  2415. enum phy_ch_width *ch_width,
  2416. uint16_t chan_freq,
  2417. uint16_t *center_freq)
  2418. {
  2419. enum phy_ch_width agile_ch_width;
  2420. if (!spectral) {
  2421. spectral_err("spectral target if object is null");
  2422. return QDF_STATUS_E_FAILURE;
  2423. }
  2424. if (!ch_width) {
  2425. spectral_err("Channel width array is null");
  2426. return QDF_STATUS_E_INVAL;
  2427. }
  2428. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2429. if (!center_freq) {
  2430. spectral_err("center_freq argument is null");
  2431. return QDF_STATUS_E_FAILURE;
  2432. }
  2433. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2434. *center_freq = chan_freq;
  2435. } else {
  2436. uint16_t start_freq;
  2437. uint16_t end_freq;
  2438. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2439. enum channel_state state;
  2440. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2441. (spectral->pdev_obj, chan_freq, agile_ch_width,
  2442. &bonded_chan_ptr);
  2443. if (state == CHANNEL_STATE_DISABLE ||
  2444. state == CHANNEL_STATE_INVALID) {
  2445. spectral_err("Channel state is disable or invalid");
  2446. return QDF_STATUS_E_FAILURE;
  2447. }
  2448. if (!bonded_chan_ptr) {
  2449. spectral_err("Bonded channel is not found");
  2450. return QDF_STATUS_E_FAILURE;
  2451. }
  2452. start_freq = bonded_chan_ptr->start_freq;
  2453. end_freq = bonded_chan_ptr->end_freq;
  2454. *center_freq = (start_freq + end_freq) >> 1;
  2455. }
  2456. return QDF_STATUS_SUCCESS;
  2457. }
  2458. /**
  2459. * target_if_validate_center_freq() - Helper routine to
  2460. * validate user provided agile center frequency
  2461. *
  2462. * @spectral: Pointer to Spectral object
  2463. * @ch_width: Channel width array
  2464. * @center_freq: User provided agile span center frequency
  2465. * @is_valid: Indicates whether agile span center frequency is valid
  2466. *
  2467. * Return: QDF_STATUS
  2468. */
  2469. static QDF_STATUS
  2470. target_if_validate_center_freq(struct target_if_spectral *spectral,
  2471. enum phy_ch_width *ch_width,
  2472. uint16_t center_freq,
  2473. bool *is_valid)
  2474. {
  2475. enum phy_ch_width agile_ch_width;
  2476. struct wlan_objmgr_pdev *pdev;
  2477. QDF_STATUS status;
  2478. if (!spectral) {
  2479. spectral_err("spectral target if object is null");
  2480. return QDF_STATUS_E_FAILURE;
  2481. }
  2482. if (!ch_width) {
  2483. spectral_err("channel width array is null");
  2484. return QDF_STATUS_E_INVAL;
  2485. }
  2486. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2487. if (!is_valid) {
  2488. spectral_err("is_valid argument is null");
  2489. return QDF_STATUS_E_FAILURE;
  2490. }
  2491. pdev = spectral->pdev_obj;
  2492. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2493. status = target_if_is_center_freq_of_any_chan
  2494. (pdev, center_freq, is_valid);
  2495. if (QDF_IS_STATUS_ERROR(status))
  2496. return QDF_STATUS_E_FAILURE;
  2497. } else {
  2498. uint16_t start_freq;
  2499. uint16_t end_freq;
  2500. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2501. bool is_chan;
  2502. status = target_if_is_center_freq_of_any_chan
  2503. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2504. &is_chan);
  2505. if (QDF_IS_STATUS_ERROR(status))
  2506. return QDF_STATUS_E_FAILURE;
  2507. if (is_chan) {
  2508. uint32_t calulated_center_freq;
  2509. enum channel_state st;
  2510. st = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2511. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2512. agile_ch_width,
  2513. &bonded_chan_ptr);
  2514. if (st == CHANNEL_STATE_DISABLE ||
  2515. st == CHANNEL_STATE_INVALID) {
  2516. spectral_err("Channel state disable/invalid");
  2517. return QDF_STATUS_E_FAILURE;
  2518. }
  2519. if (!bonded_chan_ptr) {
  2520. spectral_err("Bonded channel is not found");
  2521. return QDF_STATUS_E_FAILURE;
  2522. }
  2523. start_freq = bonded_chan_ptr->start_freq;
  2524. end_freq = bonded_chan_ptr->end_freq;
  2525. calulated_center_freq = (start_freq + end_freq) >> 1;
  2526. *is_valid = (center_freq == calulated_center_freq);
  2527. } else {
  2528. *is_valid = false;
  2529. }
  2530. }
  2531. return QDF_STATUS_SUCCESS;
  2532. }
  2533. /**
  2534. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  2535. * check whether agile span overlaps with current operating band.
  2536. *
  2537. * @spectral: Pointer to Spectral object
  2538. * @ch_width: Channel width array
  2539. * @center_freq: Agile span center frequency
  2540. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  2541. *
  2542. * Helper routine to check whether agile span overlaps with current
  2543. * operating band.
  2544. *
  2545. * Return: QDF_STATUS
  2546. */
  2547. static QDF_STATUS
  2548. target_if_is_agile_span_overlap_with_operating_span
  2549. (struct target_if_spectral *spectral,
  2550. enum phy_ch_width *ch_width,
  2551. struct spectral_config_frequency *center_freq,
  2552. bool *is_overlapping)
  2553. {
  2554. enum phy_ch_width op_ch_width;
  2555. enum phy_ch_width agile_ch_width;
  2556. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2557. struct wlan_objmgr_vdev *vdev;
  2558. struct wlan_objmgr_pdev *pdev;
  2559. int16_t chan_freq;
  2560. uint32_t op_start_freq;
  2561. uint32_t op_end_freq;
  2562. uint32_t agile_start_freq;
  2563. uint32_t agile_end_freq;
  2564. uint32_t cfreq2;
  2565. if (!spectral) {
  2566. spectral_err("Spectral object is NULL");
  2567. return QDF_STATUS_E_FAILURE;
  2568. }
  2569. pdev = spectral->pdev_obj;
  2570. if (!pdev) {
  2571. spectral_err("pdev object is NULL");
  2572. return QDF_STATUS_E_FAILURE;
  2573. }
  2574. if (!ch_width) {
  2575. spectral_err("channel width array is null");
  2576. return QDF_STATUS_E_FAILURE;
  2577. }
  2578. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  2579. if (op_ch_width == CH_WIDTH_INVALID) {
  2580. spectral_err("Invalid channel width");
  2581. return QDF_STATUS_E_INVAL;
  2582. }
  2583. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2584. if (agile_ch_width == CH_WIDTH_INVALID) {
  2585. spectral_err("Invalid channel width");
  2586. return QDF_STATUS_E_INVAL;
  2587. }
  2588. if (!is_overlapping) {
  2589. spectral_err("Argument(is_overlapping) is NULL");
  2590. return QDF_STATUS_E_FAILURE;
  2591. }
  2592. *is_overlapping = false;
  2593. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  2594. if (!vdev) {
  2595. spectral_err("vdev is NULL");
  2596. return QDF_STATUS_E_FAILURE;
  2597. }
  2598. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2599. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2600. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2601. if (cfreq2 < 0) {
  2602. spectral_err("cfreq2 is invalid");
  2603. return QDF_STATUS_E_FAILURE;
  2604. }
  2605. if (op_ch_width == CH_WIDTH_20MHZ) {
  2606. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  2607. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  2608. } else {
  2609. enum channel_state state;
  2610. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2611. (pdev, chan_freq, op_ch_width, &bonded_chan_ptr);
  2612. if (state == CHANNEL_STATE_DISABLE ||
  2613. state == CHANNEL_STATE_INVALID) {
  2614. spectral_err("Channel state is disable or invalid");
  2615. return QDF_STATUS_E_FAILURE;
  2616. }
  2617. if (!bonded_chan_ptr) {
  2618. spectral_err("Bonded channel is not found");
  2619. return QDF_STATUS_E_FAILURE;
  2620. }
  2621. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  2622. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  2623. }
  2624. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  2625. agile_start_freq = center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  2626. agile_end_freq = center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  2627. if (agile_end_freq > op_start_freq &&
  2628. op_end_freq > agile_start_freq)
  2629. *is_overlapping = true;
  2630. agile_start_freq = center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  2631. agile_end_freq = center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  2632. if (agile_end_freq > op_start_freq &&
  2633. op_end_freq > agile_start_freq)
  2634. *is_overlapping = true;
  2635. } else {
  2636. agile_start_freq = center_freq->cfreq1 -
  2637. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2638. agile_end_freq = center_freq->cfreq1 +
  2639. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2640. if (agile_end_freq > op_start_freq &&
  2641. op_end_freq > agile_start_freq)
  2642. *is_overlapping = true;
  2643. }
  2644. if (op_ch_width == CH_WIDTH_80P80MHZ) {
  2645. uint32_t sec80_start_feq;
  2646. uint32_t sec80_end_freq;
  2647. sec80_start_feq = cfreq2 - FREQ_OFFSET_40MHZ;
  2648. sec80_end_freq = cfreq2 + FREQ_OFFSET_40MHZ;
  2649. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  2650. agile_start_freq =
  2651. center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  2652. agile_end_freq =
  2653. center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  2654. if (agile_end_freq > sec80_start_feq &&
  2655. sec80_end_freq > agile_start_freq)
  2656. *is_overlapping = true;
  2657. agile_start_freq =
  2658. center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  2659. agile_end_freq =
  2660. center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  2661. if (agile_end_freq > sec80_start_feq &&
  2662. sec80_end_freq > agile_start_freq)
  2663. *is_overlapping = true;
  2664. } else {
  2665. agile_start_freq = center_freq->cfreq1 -
  2666. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2667. agile_end_freq = center_freq->cfreq1 +
  2668. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2669. if (agile_end_freq > sec80_start_feq &&
  2670. sec80_end_freq > agile_start_freq)
  2671. *is_overlapping = true;
  2672. }
  2673. }
  2674. return QDF_STATUS_SUCCESS;
  2675. }
  2676. /**
  2677. * target_if_spectral_populate_chwidth() - Helper routine to
  2678. * populate channel width for different Spectral modes
  2679. *
  2680. * @spectral: Pointer to Spectral object
  2681. * @ch_width: Channel width array
  2682. * @is_80_80_agile: Indicates whether 80+80 agile scan is requested
  2683. *
  2684. * Helper routine to populate channel width for different Spectral modes
  2685. *
  2686. * Return: QDF_STATUS
  2687. */
  2688. static QDF_STATUS
  2689. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral,
  2690. enum phy_ch_width *ch_width,
  2691. bool is_80_80_agile) {
  2692. struct wlan_objmgr_vdev *vdev;
  2693. enum spectral_scan_mode smode;
  2694. enum phy_ch_width vdev_ch_width;
  2695. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2696. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2697. ch_width[smode] = CH_WIDTH_INVALID;
  2698. if (!spectral) {
  2699. spectral_err("Spectral object is null");
  2700. return QDF_STATUS_E_INVAL;
  2701. }
  2702. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_NORMAL);
  2703. if (!vdev) {
  2704. spectral_err("vdev is null");
  2705. return QDF_STATUS_E_FAILURE;
  2706. }
  2707. vdev_ch_width = target_if_vdev_get_ch_width(vdev);
  2708. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2709. if (vdev_ch_width == CH_WIDTH_INVALID) {
  2710. spectral_err("Invalid channel width %d", vdev_ch_width);
  2711. return QDF_STATUS_E_FAILURE;
  2712. }
  2713. ch_width[SPECTRAL_SCAN_MODE_NORMAL] = vdev_ch_width;
  2714. ch_width[SPECTRAL_SCAN_MODE_AGILE] =
  2715. target_if_spectral_find_agile_width(spectral, vdev_ch_width,
  2716. is_80_80_agile);
  2717. return QDF_STATUS_SUCCESS;
  2718. }
  2719. /**
  2720. * target_if_spectral_is_valid_80p80_freq() - API to check whether given
  2721. * (cfreq1, cfreq2) pair forms a valid 80+80 combination
  2722. * @pdev: pointer to pdev
  2723. * @cfreq1: center frequency 1
  2724. * @cfreq2: center frequency 2
  2725. *
  2726. * API to check whether given (cfreq1, cfreq2) pair forms a valid 80+80
  2727. * combination
  2728. *
  2729. * Return: true or false
  2730. */
  2731. static bool
  2732. target_if_spectral_is_valid_80p80_freq(struct wlan_objmgr_pdev *pdev,
  2733. uint32_t cfreq1, uint32_t cfreq2)
  2734. {
  2735. struct ch_params ch_params;
  2736. enum channel_state chan_state1;
  2737. enum channel_state chan_state2;
  2738. struct wlan_objmgr_psoc *psoc;
  2739. qdf_assert_always(pdev);
  2740. psoc = wlan_pdev_get_psoc(pdev);
  2741. qdf_assert_always(psoc);
  2742. /* In restricted 80P80 MHz enabled, only one 80+80 MHz
  2743. * channel is supported with cfreq=5690 and cfreq=5775.
  2744. */
  2745. if (wlan_psoc_nif_fw_ext_cap_get(
  2746. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  2747. return CHAN_WITHIN_RESTRICTED_80P80(cfreq1, cfreq2);
  2748. ch_params.center_freq_seg1 = wlan_reg_freq_to_chan(pdev, cfreq2);
  2749. ch_params.mhz_freq_seg1 = cfreq2;
  2750. ch_params.ch_width = CH_WIDTH_80P80MHZ;
  2751. wlan_reg_set_channel_params_for_freq(pdev, cfreq1 - FREQ_OFFSET_10MHZ,
  2752. 0, &ch_params);
  2753. if (ch_params.ch_width != CH_WIDTH_80P80MHZ)
  2754. return false;
  2755. if (ch_params.mhz_freq_seg0 != cfreq1 ||
  2756. ch_params.mhz_freq_seg1 != cfreq2)
  2757. return false;
  2758. chan_state1 = wlan_reg_get_5g_bonded_channel_state_for_freq(
  2759. pdev,
  2760. ch_params.mhz_freq_seg0 - FREQ_OFFSET_10MHZ,
  2761. CH_WIDTH_80MHZ);
  2762. if ((chan_state1 == CHANNEL_STATE_DISABLE) ||
  2763. (chan_state1 == CHANNEL_STATE_INVALID))
  2764. return false;
  2765. chan_state2 = wlan_reg_get_5g_bonded_channel_state_for_freq(
  2766. pdev,
  2767. ch_params.mhz_freq_seg1 - FREQ_OFFSET_10MHZ,
  2768. CH_WIDTH_80MHZ);
  2769. if ((chan_state2 == CHANNEL_STATE_DISABLE) ||
  2770. (chan_state2 == CHANNEL_STATE_INVALID))
  2771. return false;
  2772. if (abs(ch_params.mhz_freq_seg0 - ch_params.mhz_freq_seg1) <=
  2773. FREQ_OFFSET_80MHZ)
  2774. return false;
  2775. return true;
  2776. }
  2777. /**
  2778. * _target_if_set_spectral_config() - Set spectral config
  2779. * @spectral: Pointer to spectral object
  2780. * @param: Spectral parameter id and value
  2781. * @smode: Spectral scan mode
  2782. * @err: Spectral error code
  2783. *
  2784. * API to set spectral configurations
  2785. *
  2786. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2787. */
  2788. static QDF_STATUS
  2789. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  2790. const struct spectral_cp_param *param,
  2791. const enum spectral_scan_mode smode,
  2792. enum spectral_cp_error_code *err)
  2793. {
  2794. struct spectral_config params;
  2795. struct target_if_spectral_ops *p_sops;
  2796. struct spectral_config *sparams;
  2797. QDF_STATUS status;
  2798. bool is_overlapping;
  2799. uint16_t agile_cfreq;
  2800. bool is_valid_chan;
  2801. struct spectral_param_min_max *param_min_max;
  2802. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  2803. enum spectral_scan_mode m;
  2804. struct spectral_config_frequency center_freq = {0};
  2805. if (!err) {
  2806. spectral_err("Error code argument is null");
  2807. QDF_ASSERT(0);
  2808. return QDF_STATUS_E_FAILURE;
  2809. }
  2810. *err = SPECTRAL_SCAN_ERR_INVALID;
  2811. if (!param) {
  2812. spectral_err("Parameter object is null");
  2813. return QDF_STATUS_E_FAILURE;
  2814. }
  2815. if (!spectral) {
  2816. spectral_err("spectral object is NULL");
  2817. return QDF_STATUS_E_FAILURE;
  2818. }
  2819. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2820. param_min_max = &spectral->param_min_max;
  2821. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2822. spectral_err("Invalid Spectral mode %u", smode);
  2823. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2824. return QDF_STATUS_E_FAILURE;
  2825. }
  2826. sparams = &spectral->params[smode];
  2827. m = SPECTRAL_SCAN_MODE_NORMAL;
  2828. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  2829. ch_width[m] = CH_WIDTH_INVALID;
  2830. if (!spectral->params_valid[smode]) {
  2831. target_if_spectral_info_read(spectral,
  2832. smode,
  2833. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2834. &spectral->params[smode],
  2835. sizeof(spectral->params[smode]));
  2836. spectral->params_valid[smode] = true;
  2837. }
  2838. switch (param->id) {
  2839. case SPECTRAL_PARAM_FFT_PERIOD:
  2840. sparams->ss_fft_period = param->value;
  2841. break;
  2842. case SPECTRAL_PARAM_SCAN_PERIOD:
  2843. sparams->ss_period = param->value;
  2844. break;
  2845. case SPECTRAL_PARAM_SCAN_COUNT:
  2846. sparams->ss_count = param->value;
  2847. break;
  2848. case SPECTRAL_PARAM_SHORT_REPORT:
  2849. sparams->ss_short_report = (!!param->value) ? true : false;
  2850. break;
  2851. case SPECTRAL_PARAM_SPECT_PRI:
  2852. sparams->ss_spectral_pri = (!!param->value) ? true : false;
  2853. break;
  2854. case SPECTRAL_PARAM_FFT_SIZE:
  2855. status = target_if_spectral_populate_chwidth
  2856. (spectral, ch_width, spectral->params
  2857. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  2858. if (QDF_IS_STATUS_ERROR(status))
  2859. return QDF_STATUS_E_FAILURE;
  2860. if ((param->value < param_min_max->fft_size_min) ||
  2861. (param->value > param_min_max->fft_size_max
  2862. [ch_width[smode]])) {
  2863. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2864. return QDF_STATUS_E_FAILURE;
  2865. }
  2866. sparams->ss_fft_size = param->value;
  2867. break;
  2868. case SPECTRAL_PARAM_GC_ENA:
  2869. sparams->ss_gc_ena = !!param->value;
  2870. break;
  2871. case SPECTRAL_PARAM_RESTART_ENA:
  2872. sparams->ss_restart_ena = !!param->value;
  2873. break;
  2874. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  2875. sparams->ss_noise_floor_ref = param->value;
  2876. break;
  2877. case SPECTRAL_PARAM_INIT_DELAY:
  2878. sparams->ss_init_delay = param->value;
  2879. break;
  2880. case SPECTRAL_PARAM_NB_TONE_THR:
  2881. sparams->ss_nb_tone_thr = param->value;
  2882. break;
  2883. case SPECTRAL_PARAM_STR_BIN_THR:
  2884. sparams->ss_str_bin_thr = param->value;
  2885. break;
  2886. case SPECTRAL_PARAM_WB_RPT_MODE:
  2887. sparams->ss_wb_rpt_mode = !!param->value;
  2888. break;
  2889. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  2890. sparams->ss_rssi_rpt_mode = !!param->value;
  2891. break;
  2892. case SPECTRAL_PARAM_RSSI_THR:
  2893. sparams->ss_rssi_thr = param->value;
  2894. break;
  2895. case SPECTRAL_PARAM_PWR_FORMAT:
  2896. sparams->ss_pwr_format = !!param->value;
  2897. break;
  2898. case SPECTRAL_PARAM_RPT_MODE:
  2899. if ((param->value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  2900. (param->value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  2901. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2902. return QDF_STATUS_E_FAILURE;
  2903. }
  2904. sparams->ss_rpt_mode = param->value;
  2905. break;
  2906. case SPECTRAL_PARAM_BIN_SCALE:
  2907. sparams->ss_bin_scale = param->value;
  2908. break;
  2909. case SPECTRAL_PARAM_DBM_ADJ:
  2910. sparams->ss_dbm_adj = !!param->value;
  2911. break;
  2912. case SPECTRAL_PARAM_CHN_MASK:
  2913. sparams->ss_chn_mask = param->value;
  2914. break;
  2915. case SPECTRAL_PARAM_FREQUENCY:
  2916. status = target_if_spectral_populate_chwidth(
  2917. spectral, ch_width, param->freq.cfreq2 > 0);
  2918. if (QDF_IS_STATUS_ERROR(status)) {
  2919. spectral_err("Failed to populate channel width");
  2920. return QDF_STATUS_E_FAILURE;
  2921. }
  2922. if (ch_width[smode] != CH_WIDTH_80P80MHZ &&
  2923. param->freq.cfreq2) {
  2924. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2925. spectral_err("Non zero cfreq2 expected for 80p80 only");
  2926. return QDF_STATUS_E_INVAL;
  2927. }
  2928. if (ch_width[smode] == CH_WIDTH_80P80MHZ &&
  2929. !param->freq.cfreq2) {
  2930. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2931. spectral_err("Non zero cfreq2 expected for 80p80");
  2932. return QDF_STATUS_E_INVAL;
  2933. }
  2934. status = target_if_is_center_freq_of_any_chan
  2935. (spectral->pdev_obj, param->freq.cfreq1,
  2936. &is_valid_chan);
  2937. if (QDF_IS_STATUS_ERROR(status))
  2938. return QDF_STATUS_E_FAILURE;
  2939. if (is_valid_chan) {
  2940. status = target_if_calculate_center_freq(
  2941. spectral, ch_width,
  2942. param->freq.cfreq1,
  2943. &agile_cfreq);
  2944. if (QDF_IS_STATUS_ERROR(status)) {
  2945. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2946. return QDF_STATUS_E_FAILURE;
  2947. }
  2948. } else {
  2949. bool is_valid_agile_cfreq;
  2950. status = target_if_validate_center_freq
  2951. (spectral, ch_width, param->freq.cfreq1,
  2952. &is_valid_agile_cfreq);
  2953. if (QDF_IS_STATUS_ERROR(status))
  2954. return QDF_STATUS_E_FAILURE;
  2955. if (!is_valid_agile_cfreq) {
  2956. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2957. spectral_err("Invalid agile center frequency");
  2958. return QDF_STATUS_E_FAILURE;
  2959. }
  2960. agile_cfreq = param->freq.cfreq1;
  2961. }
  2962. center_freq.cfreq1 = agile_cfreq;
  2963. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  2964. status = target_if_is_center_freq_of_any_chan
  2965. (spectral->pdev_obj, param->freq.cfreq2,
  2966. &is_valid_chan);
  2967. if (QDF_IS_STATUS_ERROR(status))
  2968. return QDF_STATUS_E_FAILURE;
  2969. if (is_valid_chan) {
  2970. status = target_if_calculate_center_freq(
  2971. spectral, ch_width,
  2972. param->freq.cfreq2,
  2973. &agile_cfreq);
  2974. if (QDF_IS_STATUS_ERROR(status)) {
  2975. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2976. return QDF_STATUS_E_FAILURE;
  2977. }
  2978. } else {
  2979. bool is_valid_agile_cfreq;
  2980. status = target_if_validate_center_freq
  2981. (spectral, ch_width, param->freq.cfreq2,
  2982. &is_valid_agile_cfreq);
  2983. if (QDF_IS_STATUS_ERROR(status))
  2984. return QDF_STATUS_E_FAILURE;
  2985. if (!is_valid_agile_cfreq) {
  2986. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2987. spectral_err("Invalid agile center frequency");
  2988. return QDF_STATUS_E_FAILURE;
  2989. }
  2990. agile_cfreq = param->freq.cfreq2;
  2991. }
  2992. center_freq.cfreq2 = agile_cfreq;
  2993. }
  2994. status = target_if_is_agile_span_overlap_with_operating_span
  2995. (spectral, ch_width,
  2996. &center_freq, &is_overlapping);
  2997. if (QDF_IS_STATUS_ERROR(status))
  2998. return QDF_STATUS_E_FAILURE;
  2999. if (is_overlapping) {
  3000. spectral_err("Agile freq %u, %u overlaps with operating span",
  3001. center_freq.cfreq1, center_freq.cfreq2);
  3002. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3003. return QDF_STATUS_E_FAILURE;
  3004. }
  3005. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  3006. bool is_valid_80p80;
  3007. is_valid_80p80 = target_if_spectral_is_valid_80p80_freq(
  3008. spectral->pdev_obj,
  3009. center_freq.cfreq1,
  3010. center_freq.cfreq2);
  3011. if (!is_valid_80p80) {
  3012. spectral_err("Agile freq %u, %u is invalid 80+80 combination",
  3013. center_freq.cfreq1,
  3014. center_freq.cfreq2);
  3015. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3016. return QDF_STATUS_E_FAILURE;
  3017. }
  3018. }
  3019. sparams->ss_frequency.cfreq1 = center_freq.cfreq1;
  3020. sparams->ss_frequency.cfreq2 = center_freq.cfreq2;
  3021. break;
  3022. }
  3023. p_sops->configure_spectral(spectral, sparams, smode);
  3024. /* only to validate the writes */
  3025. p_sops->get_spectral_config(spectral, &params, smode);
  3026. return QDF_STATUS_SUCCESS;
  3027. }
  3028. QDF_STATUS
  3029. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  3030. const struct spectral_cp_param *param,
  3031. const enum spectral_scan_mode smode,
  3032. enum spectral_cp_error_code *err)
  3033. {
  3034. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  3035. struct target_if_spectral *spectral;
  3036. QDF_STATUS status;
  3037. if (!err) {
  3038. spectral_err("Error code argument is null");
  3039. QDF_ASSERT(0);
  3040. return QDF_STATUS_E_FAILURE;
  3041. }
  3042. *err = SPECTRAL_SCAN_ERR_INVALID;
  3043. if (!pdev) {
  3044. spectral_err("pdev object is NULL");
  3045. return QDF_STATUS_E_FAILURE;
  3046. }
  3047. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3048. if (!spectral) {
  3049. spectral_err("spectral object is NULL");
  3050. return QDF_STATUS_E_FAILURE;
  3051. }
  3052. if (!param) {
  3053. spectral_err("parameter object is NULL");
  3054. return QDF_STATUS_E_FAILURE;
  3055. }
  3056. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3057. spectral_err("Invalid Spectral mode %u", smode);
  3058. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3059. return QDF_STATUS_E_FAILURE;
  3060. }
  3061. if (!spectral->properties[smode][param->id].supported) {
  3062. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  3063. param->id, smode);
  3064. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  3065. return QDF_STATUS_E_FAILURE;
  3066. }
  3067. if (spectral->properties[smode][param->id].common_all_modes) {
  3068. spectral_warn("Setting Spectral parameter %u for all modes",
  3069. param->id);
  3070. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  3071. status = _target_if_set_spectral_config
  3072. (spectral, param, mode, err);
  3073. if (QDF_IS_STATUS_ERROR(status))
  3074. return QDF_STATUS_E_FAILURE;
  3075. }
  3076. return QDF_STATUS_SUCCESS;
  3077. }
  3078. return _target_if_set_spectral_config(spectral, param, smode, err);
  3079. }
  3080. /**
  3081. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  3082. * @fft_len: FFT length
  3083. * @pdev: Pointer to pdev object
  3084. *
  3085. * API to get fft bin count for a given fft length
  3086. *
  3087. * Return: FFt bin count
  3088. */
  3089. static int
  3090. target_if_get_fft_bin_count(int fft_len)
  3091. {
  3092. int bin_count = 0;
  3093. switch (fft_len) {
  3094. case 5:
  3095. bin_count = 16;
  3096. break;
  3097. case 6:
  3098. bin_count = 32;
  3099. break;
  3100. case 7:
  3101. bin_count = 64;
  3102. break;
  3103. case 8:
  3104. bin_count = 128;
  3105. break;
  3106. case 9:
  3107. bin_count = 256;
  3108. break;
  3109. default:
  3110. break;
  3111. }
  3112. return bin_count;
  3113. }
  3114. /**
  3115. * target_if_init_upper_lower_flags() - Initializes control and extension
  3116. * segment flags
  3117. * @spectral: pointer to target if spectral object
  3118. * @smode: Spectral scan mode
  3119. *
  3120. * API to initialize the control and extension flags with the lower/upper
  3121. * segment based on the HT mode
  3122. *
  3123. * Return: FFt bin count
  3124. */
  3125. static void
  3126. target_if_init_upper_lower_flags(struct target_if_spectral *spectral,
  3127. enum spectral_scan_mode smode)
  3128. {
  3129. int current_channel = 0;
  3130. int ext_channel = 0;
  3131. struct target_if_spectral_ops *p_sops =
  3132. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3133. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3134. spectral_err("Invalid Spectral mode %u", smode);
  3135. return;
  3136. }
  3137. current_channel = p_sops->get_current_channel(spectral, smode);
  3138. ext_channel = p_sops->get_extension_channel(spectral, smode);
  3139. if ((current_channel == 0) || (ext_channel == 0))
  3140. return;
  3141. if (spectral->sc_spectral_20_40_mode) {
  3142. /* HT40 mode */
  3143. if (ext_channel < current_channel) {
  3144. spectral->lower_is_extension = 1;
  3145. spectral->upper_is_control = 1;
  3146. spectral->lower_is_control = 0;
  3147. spectral->upper_is_extension = 0;
  3148. } else {
  3149. spectral->lower_is_extension = 0;
  3150. spectral->upper_is_control = 0;
  3151. spectral->lower_is_control = 1;
  3152. spectral->upper_is_extension = 1;
  3153. }
  3154. } else {
  3155. /* HT20 mode, lower is always control */
  3156. spectral->lower_is_extension = 0;
  3157. spectral->upper_is_control = 0;
  3158. spectral->lower_is_control = 1;
  3159. spectral->upper_is_extension = 0;
  3160. }
  3161. }
  3162. /**
  3163. * target_if_get_spectral_config() - Get spectral configuration
  3164. * @pdev: Pointer to pdev object
  3165. * @param: Pointer to spectral_config structure in which the configuration
  3166. * should be returned
  3167. * @smode: Spectral scan mode
  3168. *
  3169. * API to get the current spectral configuration
  3170. *
  3171. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3172. */
  3173. QDF_STATUS
  3174. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  3175. struct spectral_config *param,
  3176. enum spectral_scan_mode smode)
  3177. {
  3178. struct target_if_spectral_ops *p_sops = NULL;
  3179. struct target_if_spectral *spectral = NULL;
  3180. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3181. if (!spectral) {
  3182. spectral_err("SPECTRAL : Module doesn't exist");
  3183. return QDF_STATUS_E_FAILURE;
  3184. }
  3185. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3186. if (!p_sops) {
  3187. spectral_err("p_sops is null");
  3188. return QDF_STATUS_E_FAILURE;
  3189. }
  3190. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3191. spectral_err("Invalid Spectral mode %u", smode);
  3192. return QDF_STATUS_E_FAILURE;
  3193. }
  3194. qdf_mem_zero(param, sizeof(struct spectral_config));
  3195. p_sops->get_spectral_config(spectral, param, smode);
  3196. return QDF_STATUS_SUCCESS;
  3197. }
  3198. /**
  3199. * target_if_spectral_get_num_detectors() - Get number of Spectral detectors
  3200. * @spectral: Pointer to target if Spectral object
  3201. * @ch_width: channel width
  3202. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  3203. *
  3204. * API to get number of Spectral detectors used for scan in the given channel
  3205. * width.
  3206. *
  3207. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  3208. */
  3209. static QDF_STATUS
  3210. target_if_spectral_get_num_detectors(struct target_if_spectral *spectral,
  3211. enum phy_ch_width ch_width,
  3212. uint32_t *num_detectors)
  3213. {
  3214. if (!spectral) {
  3215. spectral_err("target if spectral object is null");
  3216. return QDF_STATUS_E_INVAL;
  3217. }
  3218. if (ch_width >= CH_WIDTH_INVALID) {
  3219. spectral_err("Invalid channel width %d", ch_width);
  3220. return QDF_STATUS_E_INVAL;
  3221. }
  3222. if (!num_detectors) {
  3223. spectral_err("Invalid argument, number of detectors");
  3224. return QDF_STATUS_E_INVAL;
  3225. }
  3226. switch (ch_width) {
  3227. case CH_WIDTH_20MHZ:
  3228. *num_detectors = spectral->capability.num_detectors_20mhz;
  3229. break;
  3230. case CH_WIDTH_40MHZ:
  3231. *num_detectors = spectral->capability.num_detectors_40mhz;
  3232. break;
  3233. case CH_WIDTH_80MHZ:
  3234. *num_detectors = spectral->capability.num_detectors_80mhz;
  3235. break;
  3236. case CH_WIDTH_160MHZ:
  3237. *num_detectors = spectral->capability.num_detectors_160mhz;
  3238. break;
  3239. case CH_WIDTH_80P80MHZ:
  3240. *num_detectors = spectral->capability.num_detectors_80p80mhz;
  3241. break;
  3242. default:
  3243. spectral_err("Unsupported channel width %d", ch_width);
  3244. return QDF_STATUS_E_INVAL;
  3245. }
  3246. return QDF_STATUS_SUCCESS;
  3247. }
  3248. /**
  3249. * target_if_spectral_finite_scan_init() - Initializations required for finite
  3250. * Spectral scan
  3251. * @spectral: Pointer to target of Spctral object
  3252. * @smode: Spectral scan mode
  3253. *
  3254. * This routine initializes the finite Spectral scan. Finite Spectral scan is
  3255. * triggered by configuring a non zero scan count.
  3256. *
  3257. * Return: QDF_STATUS_SUCCESS on success
  3258. */
  3259. static QDF_STATUS
  3260. target_if_spectral_finite_scan_init(struct target_if_spectral *spectral,
  3261. enum spectral_scan_mode smode)
  3262. {
  3263. struct target_if_finite_spectral_scan_params *finite_scan;
  3264. enum phy_ch_width ch_width;
  3265. uint32_t num_detectors;
  3266. QDF_STATUS status;
  3267. uint16_t sscan_count;
  3268. if (!spectral) {
  3269. spectral_err("target if spectral object is null");
  3270. return QDF_STATUS_E_INVAL;
  3271. }
  3272. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3273. spectral_err("Invalid Spectral mode");
  3274. return QDF_STATUS_E_INVAL;
  3275. }
  3276. ch_width = spectral->ch_width[smode];
  3277. status = target_if_spectral_get_num_detectors(spectral, ch_width,
  3278. &num_detectors);
  3279. if (QDF_IS_STATUS_ERROR(status)) {
  3280. spectral_err("Failed to get number of detectors");
  3281. return QDF_STATUS_E_FAILURE;
  3282. }
  3283. finite_scan = &spectral->finite_scan[smode];
  3284. sscan_count = spectral->params[smode].ss_count;
  3285. finite_scan->finite_spectral_scan = true;
  3286. finite_scan->num_reports_expected = num_detectors * sscan_count;
  3287. return QDF_STATUS_SUCCESS;
  3288. }
  3289. /**
  3290. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  3291. * parameters
  3292. * @spectral: Pointer to Spectral target_if internal private data
  3293. * @spectral_params: Pointer to Spectral parameters
  3294. * @smode: Spectral scan mode
  3295. * @err: Spectral error code
  3296. *
  3297. * Enable use of desired Spectral parameters by configuring them into HW, and
  3298. * starting Spectral scan
  3299. *
  3300. * Return: 0 on success, 1 on failure
  3301. */
  3302. int
  3303. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  3304. struct spectral_config *spectral_params,
  3305. enum spectral_scan_mode smode,
  3306. enum spectral_cp_error_code *err)
  3307. {
  3308. int extension_channel = 0;
  3309. int current_channel = 0;
  3310. struct target_if_spectral_ops *p_sops = NULL;
  3311. QDF_STATUS status;
  3312. struct wlan_objmgr_pdev *pdev;
  3313. struct wlan_objmgr_psoc *psoc;
  3314. if (!spectral) {
  3315. spectral_err("Spectral LMAC object is NULL");
  3316. return 1;
  3317. }
  3318. pdev = spectral->pdev_obj;
  3319. if (!pdev) {
  3320. spectral_err("pdev is null");
  3321. return QDF_STATUS_E_INVAL;
  3322. }
  3323. psoc = wlan_pdev_get_psoc(pdev);
  3324. if (!psoc) {
  3325. spectral_err("psoc is null");
  3326. return QDF_STATUS_E_INVAL;
  3327. }
  3328. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3329. spectral_err("Invalid Spectral mode %u", smode);
  3330. return 1;
  3331. }
  3332. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3333. if (!p_sops) {
  3334. spectral_err("p_sops is NULL");
  3335. return 1;
  3336. }
  3337. spectral->sc_spectral_noise_pwr_cal =
  3338. spectral_params->ss_spectral_pri ? 1 : 0;
  3339. /* check if extension channel is present */
  3340. extension_channel = p_sops->get_extension_channel(spectral, smode);
  3341. current_channel = p_sops->get_current_channel(spectral, smode);
  3342. status = target_if_spectral_populate_chwidth(
  3343. spectral, spectral->ch_width,
  3344. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  3345. ss_frequency.cfreq2 > 0);
  3346. if (QDF_IS_STATUS_ERROR(status)) {
  3347. spectral_err("Failed to get channel widths");
  3348. return 1;
  3349. }
  3350. if (spectral->capability.advncd_spectral_cap) {
  3351. spectral->lb_edge_extrabins = 0;
  3352. spectral->rb_edge_extrabins = 0;
  3353. if (spectral->is_lb_edge_extrabins_format &&
  3354. spectral->params[smode].ss_rpt_mode == 2) {
  3355. spectral->lb_edge_extrabins = 4;
  3356. }
  3357. if (spectral->is_rb_edge_extrabins_format &&
  3358. spectral->params[smode].ss_rpt_mode == 2) {
  3359. spectral->rb_edge_extrabins = 4;
  3360. }
  3361. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  3362. spectral->sc_spectral_20_40_mode = 0;
  3363. spectral->spectral_numbins =
  3364. target_if_get_fft_bin_count(
  3365. spectral->params[smode].ss_fft_size);
  3366. spectral->spectral_fft_len =
  3367. target_if_get_fft_bin_count(
  3368. spectral->params[smode].ss_fft_size);
  3369. spectral->spectral_data_len =
  3370. target_if_get_fft_bin_count(
  3371. spectral->params[smode].ss_fft_size);
  3372. /*
  3373. * Initialize classifier params to be sent to user
  3374. * space classifier
  3375. */
  3376. spectral->classifier_params.lower_chan_in_mhz =
  3377. current_channel;
  3378. spectral->classifier_params.upper_chan_in_mhz = 0;
  3379. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  3380. /* TODO : Remove this variable */
  3381. spectral->sc_spectral_20_40_mode = 1;
  3382. spectral->spectral_numbins =
  3383. target_if_get_fft_bin_count(
  3384. spectral->params[smode].ss_fft_size);
  3385. spectral->spectral_fft_len =
  3386. target_if_get_fft_bin_count(
  3387. spectral->params[smode].ss_fft_size);
  3388. spectral->spectral_data_len =
  3389. target_if_get_fft_bin_count(
  3390. spectral->params[smode].ss_fft_size);
  3391. /*
  3392. * Initialize classifier params to be sent to user
  3393. * space classifier
  3394. */
  3395. if (extension_channel < current_channel) {
  3396. spectral->classifier_params.lower_chan_in_mhz =
  3397. extension_channel;
  3398. spectral->classifier_params.upper_chan_in_mhz =
  3399. current_channel;
  3400. } else {
  3401. spectral->classifier_params.lower_chan_in_mhz =
  3402. current_channel;
  3403. spectral->classifier_params.upper_chan_in_mhz =
  3404. extension_channel;
  3405. }
  3406. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  3407. /* Set the FFT Size */
  3408. /* TODO : Remove this variable */
  3409. spectral->sc_spectral_20_40_mode = 0;
  3410. spectral->spectral_numbins =
  3411. target_if_get_fft_bin_count(
  3412. spectral->params[smode].ss_fft_size);
  3413. spectral->spectral_fft_len =
  3414. target_if_get_fft_bin_count(
  3415. spectral->params[smode].ss_fft_size);
  3416. spectral->spectral_data_len =
  3417. target_if_get_fft_bin_count(
  3418. spectral->params[smode].ss_fft_size);
  3419. /*
  3420. * Initialize classifier params to be sent to user
  3421. * space classifier
  3422. */
  3423. spectral->classifier_params.lower_chan_in_mhz =
  3424. current_channel;
  3425. spectral->classifier_params.upper_chan_in_mhz = 0;
  3426. /*
  3427. * Initialize classifier params to be sent to user
  3428. * space classifier
  3429. */
  3430. if (extension_channel < current_channel) {
  3431. spectral->classifier_params.lower_chan_in_mhz =
  3432. extension_channel;
  3433. spectral->classifier_params.upper_chan_in_mhz =
  3434. current_channel;
  3435. } else {
  3436. spectral->classifier_params.lower_chan_in_mhz =
  3437. current_channel;
  3438. spectral->classifier_params.upper_chan_in_mhz =
  3439. extension_channel;
  3440. }
  3441. } else if (is_ch_width_160_or_80p80(
  3442. spectral->ch_width[smode])) {
  3443. /* Set the FFT Size */
  3444. /* The below applies to both 160 and 80+80 cases */
  3445. /* TODO : Remove this variable */
  3446. spectral->sc_spectral_20_40_mode = 0;
  3447. spectral->spectral_numbins =
  3448. target_if_get_fft_bin_count(
  3449. spectral->params[smode].ss_fft_size);
  3450. spectral->spectral_fft_len =
  3451. target_if_get_fft_bin_count(
  3452. spectral->params[smode].ss_fft_size);
  3453. spectral->spectral_data_len =
  3454. target_if_get_fft_bin_count(
  3455. spectral->params[smode].ss_fft_size);
  3456. /*
  3457. * Initialize classifier params to be sent to user
  3458. * space classifier
  3459. */
  3460. spectral->classifier_params.lower_chan_in_mhz =
  3461. current_channel;
  3462. spectral->classifier_params.upper_chan_in_mhz = 0;
  3463. /*
  3464. * Initialize classifier params to be sent to user
  3465. * space classifier
  3466. */
  3467. if (extension_channel < current_channel) {
  3468. spectral->classifier_params.lower_chan_in_mhz =
  3469. extension_channel;
  3470. spectral->classifier_params.upper_chan_in_mhz =
  3471. current_channel;
  3472. } else {
  3473. spectral->classifier_params.lower_chan_in_mhz =
  3474. current_channel;
  3475. spectral->classifier_params.upper_chan_in_mhz =
  3476. extension_channel;
  3477. }
  3478. }
  3479. if (spectral->spectral_numbins) {
  3480. spectral->spectral_numbins +=
  3481. spectral->lb_edge_extrabins;
  3482. spectral->spectral_numbins +=
  3483. spectral->rb_edge_extrabins;
  3484. }
  3485. if (spectral->spectral_fft_len) {
  3486. spectral->spectral_fft_len +=
  3487. spectral->lb_edge_extrabins;
  3488. spectral->spectral_fft_len +=
  3489. spectral->rb_edge_extrabins;
  3490. }
  3491. if (spectral->spectral_data_len) {
  3492. spectral->spectral_data_len +=
  3493. spectral->lb_edge_extrabins;
  3494. spectral->spectral_data_len +=
  3495. spectral->rb_edge_extrabins;
  3496. }
  3497. } else {
  3498. /*
  3499. * The decision to find 20/40 mode is found based on the
  3500. * presence of extension channel
  3501. * instead of channel width, as the channel width can
  3502. * dynamically change
  3503. */
  3504. if (extension_channel == 0) {
  3505. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  3506. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  3507. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  3508. spectral->spectral_data_len =
  3509. SPECTRAL_HT20_TOTAL_DATA_LEN;
  3510. /* only valid in 20-40 mode */
  3511. spectral->spectral_lower_max_index_offset = -1;
  3512. /* only valid in 20-40 mode */
  3513. spectral->spectral_upper_max_index_offset = -1;
  3514. spectral->spectral_max_index_offset =
  3515. spectral->spectral_fft_len + 2;
  3516. spectral->sc_spectral_20_40_mode = 0;
  3517. /*
  3518. * Initialize classifier params to be sent to user
  3519. * space classifier
  3520. */
  3521. spectral->classifier_params.lower_chan_in_mhz =
  3522. current_channel;
  3523. spectral->classifier_params.upper_chan_in_mhz = 0;
  3524. } else {
  3525. spectral->spectral_numbins =
  3526. SPECTRAL_HT40_TOTAL_NUM_BINS;
  3527. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  3528. spectral->spectral_data_len =
  3529. SPECTRAL_HT40_TOTAL_DATA_LEN;
  3530. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  3531. /* only valid in 20 mode */
  3532. spectral->spectral_max_index_offset = -1;
  3533. spectral->spectral_lower_max_index_offset =
  3534. spectral->spectral_fft_len + 2;
  3535. spectral->spectral_upper_max_index_offset =
  3536. spectral->spectral_fft_len + 5;
  3537. spectral->sc_spectral_20_40_mode = 1;
  3538. /*
  3539. * Initialize classifier params to be sent to user
  3540. * space classifier
  3541. */
  3542. if (extension_channel < current_channel) {
  3543. spectral->classifier_params.lower_chan_in_mhz =
  3544. extension_channel;
  3545. spectral->classifier_params.upper_chan_in_mhz =
  3546. current_channel;
  3547. } else {
  3548. spectral->classifier_params.lower_chan_in_mhz =
  3549. current_channel;
  3550. spectral->classifier_params.upper_chan_in_mhz =
  3551. extension_channel;
  3552. }
  3553. }
  3554. }
  3555. spectral->send_single_packet = 0;
  3556. spectral->classifier_params.spectral_20_40_mode =
  3557. spectral->sc_spectral_20_40_mode;
  3558. spectral->classifier_params.spectral_dc_index =
  3559. spectral->spectral_dc_index;
  3560. spectral->spectral_sent_msg = 0;
  3561. spectral->classify_scan = 0;
  3562. spectral->num_spectral_data = 0;
  3563. if (!p_sops->is_spectral_active(spectral, smode)) {
  3564. p_sops->configure_spectral(spectral, spectral_params, smode);
  3565. spectral->rparams.marker[smode].is_valid = false;
  3566. if (spectral->params[smode].ss_count) {
  3567. status = target_if_spectral_finite_scan_init(spectral,
  3568. smode);
  3569. if (QDF_IS_STATUS_ERROR(status)) {
  3570. spectral_err("Failed to init finite scan");
  3571. return 1;
  3572. }
  3573. }
  3574. p_sops->start_spectral_scan(spectral, smode, err);
  3575. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  3576. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  3577. }
  3578. /* get current spectral configuration */
  3579. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  3580. target_if_init_upper_lower_flags(spectral, smode);
  3581. return 0;
  3582. }
  3583. /**
  3584. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  3585. * Agile DFS
  3586. * @psoc: Pointer to psoc
  3587. * @object: Pointer to pdev
  3588. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  3589. *
  3590. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  3591. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  3592. *
  3593. * Return: void
  3594. */
  3595. static void
  3596. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  3597. void *object, void *arg)
  3598. {
  3599. bool *is_aspectral_prohibited = arg;
  3600. struct wlan_objmgr_pdev *cur_pdev = object;
  3601. bool is_agile_dfs_enabled_cur_pdev = false;
  3602. QDF_STATUS status;
  3603. qdf_assert_always(is_aspectral_prohibited);
  3604. if (*is_aspectral_prohibited)
  3605. return;
  3606. qdf_assert_always(psoc);
  3607. qdf_assert_always(cur_pdev);
  3608. status = ucfg_dfs_get_agile_precac_enable
  3609. (cur_pdev,
  3610. &is_agile_dfs_enabled_cur_pdev);
  3611. if (QDF_IS_STATUS_ERROR(status)) {
  3612. spectral_err("Get agile precac failed, prohibiting aSpectral");
  3613. *is_aspectral_prohibited = true;
  3614. return;
  3615. }
  3616. if (is_agile_dfs_enabled_cur_pdev) {
  3617. spectral_err("aDFS is in progress on one of the pdevs");
  3618. *is_aspectral_prohibited = true;
  3619. }
  3620. }
  3621. /**
  3622. * target_if_get_curr_band() - Get current operating band of pdev
  3623. *
  3624. * @pdev: pointer to pdev object
  3625. *
  3626. * API to get current operating band of a given pdev.
  3627. *
  3628. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  3629. */
  3630. static enum reg_wifi_band
  3631. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id)
  3632. {
  3633. struct wlan_objmgr_vdev *vdev;
  3634. int16_t chan_freq;
  3635. enum reg_wifi_band cur_band;
  3636. if (!pdev) {
  3637. spectral_err("pdev is NULL");
  3638. return REG_BAND_UNKNOWN;
  3639. }
  3640. if (vdev_id == WLAN_INVALID_VDEV_ID)
  3641. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  3642. else
  3643. vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, vdev_id,
  3644. WLAN_SPECTRAL_ID);
  3645. if (!vdev) {
  3646. spectral_debug("vdev is NULL");
  3647. return REG_BAND_UNKNOWN;
  3648. }
  3649. chan_freq = target_if_vdev_get_chan_freq(vdev);
  3650. cur_band = wlan_reg_freq_to_band(chan_freq);
  3651. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3652. return cur_band;
  3653. }
  3654. /**
  3655. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  3656. * any of the 5G pdevs
  3657. * @psoc: Pointer to psoc
  3658. * @object: Pointer to pdev
  3659. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  3660. * progress in any 5G pdevs
  3661. *
  3662. * Return: void
  3663. */
  3664. static void
  3665. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  3666. void *object, void *arg)
  3667. {
  3668. enum reg_wifi_band band;
  3669. bool *is_agile_scan_inprog_5g_pdev = arg;
  3670. struct target_if_spectral *spectral;
  3671. struct wlan_objmgr_pdev *cur_pdev = object;
  3672. struct target_if_spectral_ops *p_sops;
  3673. if (*is_agile_scan_inprog_5g_pdev)
  3674. return;
  3675. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  3676. if (!spectral) {
  3677. spectral_err("target if spectral handle is NULL");
  3678. return;
  3679. }
  3680. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3681. band = target_if_get_curr_band(
  3682. cur_pdev, spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE]);
  3683. if (band == REG_BAND_UNKNOWN) {
  3684. spectral_debug("Failed to get current band");
  3685. return;
  3686. }
  3687. if (band == REG_BAND_5G &&
  3688. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  3689. *is_agile_scan_inprog_5g_pdev = true;
  3690. }
  3691. /**
  3692. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  3693. * for current vdev rx chainmask.
  3694. *
  3695. * @spectral: Pointer to Spectral object
  3696. * @is_supported: Pointer to is_supported
  3697. *
  3698. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3699. */
  3700. static QDF_STATUS
  3701. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  3702. bool *is_supported)
  3703. {
  3704. struct wlan_objmgr_vdev *vdev;
  3705. uint8_t vdev_rxchainmask;
  3706. struct wlan_objmgr_psoc *psoc;
  3707. struct wlan_objmgr_pdev *pdev;
  3708. struct target_psoc_info *tgt_psoc_info;
  3709. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  3710. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  3711. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  3712. struct wlan_psoc_host_chainmask_table *table;
  3713. int j;
  3714. uint32_t table_id;
  3715. enum phy_ch_width ch_width;
  3716. uint8_t pdev_id;
  3717. if (!spectral) {
  3718. spectral_err("spectral target if object is null");
  3719. return QDF_STATUS_E_FAILURE;
  3720. }
  3721. if (!is_supported) {
  3722. spectral_err("is supported argument is null");
  3723. return QDF_STATUS_E_FAILURE;
  3724. }
  3725. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  3726. spectral_err("HW Agile mode is not supported up to gen 2");
  3727. return QDF_STATUS_E_FAILURE;
  3728. }
  3729. pdev = spectral->pdev_obj;
  3730. if (!pdev) {
  3731. spectral_err("pdev is null");
  3732. return QDF_STATUS_E_FAILURE;
  3733. }
  3734. psoc = wlan_pdev_get_psoc(pdev);
  3735. if (!psoc) {
  3736. spectral_err("psoc is null");
  3737. return QDF_STATUS_E_FAILURE;
  3738. }
  3739. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  3740. if (!vdev) {
  3741. spectral_err("First vdev is NULL");
  3742. return QDF_STATUS_E_FAILURE;
  3743. }
  3744. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  3745. if (!vdev_rxchainmask) {
  3746. spectral_err("vdev rx chainmask is zero");
  3747. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3748. return QDF_STATUS_E_FAILURE;
  3749. }
  3750. ch_width = target_if_vdev_get_ch_width(vdev);
  3751. if (ch_width == CH_WIDTH_INVALID) {
  3752. spectral_err("Invalid channel width");
  3753. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3754. return QDF_STATUS_E_FAILURE;
  3755. }
  3756. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3757. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  3758. if (!tgt_psoc_info) {
  3759. spectral_err("target_psoc_info is null");
  3760. return QDF_STATUS_E_FAILURE;
  3761. }
  3762. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  3763. if (!ext_svc_param) {
  3764. spectral_err("Extended service ready param null");
  3765. return QDF_STATUS_E_FAILURE;
  3766. }
  3767. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  3768. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  3769. if (!mac_phy_cap_arr) {
  3770. spectral_err("mac phy cap array is null");
  3771. return QDF_STATUS_E_FAILURE;
  3772. }
  3773. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  3774. if (!mac_phy_cap) {
  3775. spectral_err("mac phy cap is null");
  3776. return QDF_STATUS_E_FAILURE;
  3777. }
  3778. table_id = mac_phy_cap->chainmask_table_id;
  3779. table = &ext_svc_param->chainmask_table[table_id];
  3780. if (!table) {
  3781. spectral_err("chainmask table not found");
  3782. return QDF_STATUS_E_FAILURE;
  3783. }
  3784. for (j = 0; j < table->num_valid_chainmasks; j++) {
  3785. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  3786. if (ch_width <= CH_WIDTH_80MHZ)
  3787. *is_supported =
  3788. table->cap_list[j].supports_aSpectral;
  3789. else
  3790. *is_supported =
  3791. table->cap_list[j].supports_aSpectral_160;
  3792. break;
  3793. }
  3794. }
  3795. if (j == table->num_valid_chainmasks) {
  3796. spectral_err("vdev rx chainmask %u not found in table id = %u",
  3797. vdev_rxchainmask, table_id);
  3798. return QDF_STATUS_E_FAILURE;
  3799. }
  3800. return QDF_STATUS_SUCCESS;
  3801. }
  3802. QDF_STATUS
  3803. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3804. uint8_t vdev_id,
  3805. const enum spectral_scan_mode smode,
  3806. enum spectral_cp_error_code *err)
  3807. {
  3808. struct target_if_spectral_ops *p_sops;
  3809. struct target_if_spectral *spectral;
  3810. struct wlan_objmgr_psoc *psoc;
  3811. enum reg_wifi_band band;
  3812. if (!err) {
  3813. spectral_err("Error code argument is null");
  3814. QDF_ASSERT(0);
  3815. return QDF_STATUS_E_FAILURE;
  3816. }
  3817. *err = SPECTRAL_SCAN_ERR_INVALID;
  3818. if (!pdev) {
  3819. spectral_err("pdev object is NUll");
  3820. return QDF_STATUS_E_FAILURE;
  3821. }
  3822. psoc = wlan_pdev_get_psoc(pdev);
  3823. if (!psoc) {
  3824. spectral_err("psoc is null");
  3825. return QDF_STATUS_E_FAILURE;
  3826. }
  3827. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3828. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3829. spectral_err("Invalid Spectral mode %u", smode);
  3830. return QDF_STATUS_E_FAILURE;
  3831. }
  3832. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3833. if (!spectral) {
  3834. spectral_err("Spectral LMAC object is NUll");
  3835. return QDF_STATUS_E_FAILURE;
  3836. }
  3837. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3838. if (!p_sops) {
  3839. spectral_err("p_sops is null");
  3840. return QDF_STATUS_E_FAILURE;
  3841. }
  3842. if (p_sops->is_spectral_active(spectral, smode)) {
  3843. spectral_err("spectral in progress in current pdev, mode %d",
  3844. smode);
  3845. return QDF_STATUS_E_FAILURE;
  3846. }
  3847. spectral->vdev_id[smode] = vdev_id;
  3848. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3849. QDF_STATUS status;
  3850. bool is_supported = false;
  3851. status = target_if_is_agile_supported_cur_chmask(spectral,
  3852. &is_supported);
  3853. if (QDF_IS_STATUS_ERROR(status)) {
  3854. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3855. return QDF_STATUS_E_FAILURE;
  3856. }
  3857. if (!is_supported) {
  3858. spectral_err("aSpectral unsupported for cur chainmask");
  3859. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3860. return QDF_STATUS_E_FAILURE;
  3861. }
  3862. }
  3863. band = target_if_get_curr_band(spectral->pdev_obj, vdev_id);
  3864. if (band == REG_BAND_UNKNOWN) {
  3865. spectral_err("Failed to get current band");
  3866. return QDF_STATUS_E_FAILURE;
  3867. }
  3868. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  3869. struct target_psoc_info *tgt_hdl;
  3870. enum wmi_host_hw_mode_config_type mode;
  3871. bool is_agile_scan_inprog_5g_pdev;
  3872. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  3873. if (!tgt_hdl) {
  3874. target_if_err("target_psoc_info is null");
  3875. return QDF_STATUS_E_FAILURE;
  3876. }
  3877. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  3878. switch (mode) {
  3879. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  3880. case WMI_HOST_HW_MODE_SBS:
  3881. case WMI_HOST_HW_MODE_DBS_SBS:
  3882. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  3883. is_agile_scan_inprog_5g_pdev = false;
  3884. wlan_objmgr_iterate_obj_list
  3885. (psoc, WLAN_PDEV_OP,
  3886. target_if_is_agile_scan_active_in_5g,
  3887. &is_agile_scan_inprog_5g_pdev, 0,
  3888. WLAN_SPECTRAL_ID);
  3889. break;
  3890. default:
  3891. is_agile_scan_inprog_5g_pdev = false;
  3892. break;
  3893. }
  3894. if (is_agile_scan_inprog_5g_pdev) {
  3895. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  3896. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3897. return QDF_STATUS_E_FAILURE;
  3898. }
  3899. }
  3900. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3901. bool is_aspectral_prohibited = false;
  3902. QDF_STATUS status;
  3903. status = wlan_objmgr_iterate_obj_list
  3904. (psoc, WLAN_PDEV_OP,
  3905. target_if_is_aspectral_prohibited_by_adfs,
  3906. &is_aspectral_prohibited, 0,
  3907. WLAN_SPECTRAL_ID);
  3908. if (QDF_IS_STATUS_ERROR(status)) {
  3909. spectral_err("Failed to iterate over pdevs");
  3910. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3911. return QDF_STATUS_E_FAILURE;
  3912. }
  3913. if (is_aspectral_prohibited) {
  3914. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3915. return QDF_STATUS_E_FAILURE;
  3916. }
  3917. }
  3918. if (!spectral->params_valid[smode]) {
  3919. target_if_spectral_info_read(spectral,
  3920. smode,
  3921. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3922. &spectral->params[smode],
  3923. sizeof(spectral->params[smode]));
  3924. spectral->params_valid[smode] = true;
  3925. }
  3926. qdf_spin_lock(&spectral->spectral_lock);
  3927. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3928. QDF_STATUS status;
  3929. bool is_overlapping;
  3930. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  3931. enum spectral_scan_mode m;
  3932. enum phy_ch_width op_ch_width;
  3933. enum phy_ch_width agile_ch_width;
  3934. m = SPECTRAL_SCAN_MODE_NORMAL;
  3935. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  3936. ch_width[m] = CH_WIDTH_INVALID;
  3937. status = target_if_spectral_populate_chwidth
  3938. (spectral, ch_width, spectral->params
  3939. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  3940. if (QDF_IS_STATUS_ERROR(status)) {
  3941. qdf_spin_unlock(&spectral->spectral_lock);
  3942. spectral_err("Failed to populate channel width");
  3943. return QDF_STATUS_E_FAILURE;
  3944. }
  3945. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  3946. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3947. if (!spectral->params[smode].ss_frequency.cfreq1 ||
  3948. (agile_ch_width == CH_WIDTH_80P80MHZ &&
  3949. !spectral->params[smode].ss_frequency.cfreq2)) {
  3950. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  3951. qdf_spin_unlock(&spectral->spectral_lock);
  3952. return QDF_STATUS_E_FAILURE;
  3953. }
  3954. status = target_if_is_agile_span_overlap_with_operating_span
  3955. (spectral, ch_width,
  3956. &spectral->params[smode].ss_frequency,
  3957. &is_overlapping);
  3958. if (QDF_IS_STATUS_ERROR(status)) {
  3959. qdf_spin_unlock(&spectral->spectral_lock);
  3960. return QDF_STATUS_E_FAILURE;
  3961. }
  3962. if (is_overlapping) {
  3963. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3964. qdf_spin_unlock(&spectral->spectral_lock);
  3965. return QDF_STATUS_E_FAILURE;
  3966. }
  3967. }
  3968. target_if_spectral_scan_enable_params(spectral,
  3969. &spectral->params[smode], smode,
  3970. err);
  3971. qdf_spin_unlock(&spectral->spectral_lock);
  3972. return QDF_STATUS_SUCCESS;
  3973. }
  3974. QDF_STATUS
  3975. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3976. const enum spectral_scan_mode smode,
  3977. enum spectral_cp_error_code *err)
  3978. {
  3979. struct target_if_spectral_ops *p_sops;
  3980. struct target_if_spectral *spectral;
  3981. if (!err) {
  3982. spectral_err("Error code argument is null");
  3983. QDF_ASSERT(0);
  3984. return QDF_STATUS_E_FAILURE;
  3985. }
  3986. *err = SPECTRAL_SCAN_ERR_INVALID;
  3987. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3988. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3989. spectral_err("Invalid Spectral mode %u", smode);
  3990. return QDF_STATUS_E_FAILURE;
  3991. }
  3992. if (!pdev) {
  3993. spectral_err("pdev object is NUll ");
  3994. return QDF_STATUS_E_FAILURE;
  3995. }
  3996. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3997. if (!spectral) {
  3998. spectral_err("Spectral LMAC object is NUll ");
  3999. return QDF_STATUS_E_FAILURE;
  4000. }
  4001. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4002. qdf_spin_lock(&spectral->spectral_lock);
  4003. p_sops->stop_spectral_scan(spectral, smode);
  4004. if (spectral->classify_scan) {
  4005. /* TODO : Check if this logic is necessary */
  4006. spectral->detects_control_channel = 0;
  4007. spectral->detects_extension_channel = 0;
  4008. spectral->detects_above_dc = 0;
  4009. spectral->detects_below_dc = 0;
  4010. spectral->classify_scan = 0;
  4011. }
  4012. spectral->send_single_packet = 0;
  4013. spectral->sc_spectral_scan = 0;
  4014. qdf_spin_unlock(&spectral->spectral_lock);
  4015. return QDF_STATUS_SUCCESS;
  4016. }
  4017. /**
  4018. * target_if_is_spectral_active() - Get whether Spectral is active
  4019. * @pdev: Pointer to pdev object
  4020. * @smode: Spectral scan mode
  4021. *
  4022. * API to get whether Spectral is active
  4023. *
  4024. * Return: True if Spectral is active, false if Spectral is not active
  4025. */
  4026. bool
  4027. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  4028. const enum spectral_scan_mode smode)
  4029. {
  4030. struct target_if_spectral *spectral = NULL;
  4031. struct target_if_spectral_ops *p_sops = NULL;
  4032. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4033. if (!spectral) {
  4034. spectral_err("SPECTRAL : Module doesn't exist");
  4035. return QDF_STATUS_E_FAILURE;
  4036. }
  4037. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4038. if (!p_sops) {
  4039. spectral_err("p_sops is null");
  4040. return QDF_STATUS_E_FAILURE;
  4041. }
  4042. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4043. spectral_err("Invalid Spectral mode %u", smode);
  4044. return QDF_STATUS_E_FAILURE;
  4045. }
  4046. return p_sops->is_spectral_active(spectral, smode);
  4047. }
  4048. /**
  4049. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  4050. * @pdev: Pointer to pdev object
  4051. * @smode: Spectral scan mode
  4052. *
  4053. * API to get whether Spectral is enabled
  4054. *
  4055. * Return: True if Spectral is enabled, false if Spectral is not enabled
  4056. */
  4057. bool
  4058. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  4059. enum spectral_scan_mode smode)
  4060. {
  4061. struct target_if_spectral *spectral = NULL;
  4062. struct target_if_spectral_ops *p_sops = NULL;
  4063. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4064. if (!spectral) {
  4065. spectral_err("SPECTRAL : Module doesn't exist");
  4066. return QDF_STATUS_E_FAILURE;
  4067. }
  4068. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4069. if (!p_sops) {
  4070. spectral_err("p_sops is null");
  4071. return QDF_STATUS_E_FAILURE;
  4072. }
  4073. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4074. spectral_err("Invalid Spectral mode %u", smode);
  4075. return QDF_STATUS_E_FAILURE;
  4076. }
  4077. return p_sops->is_spectral_enabled(spectral, smode);
  4078. }
  4079. #ifdef DIRECT_BUF_RX_DEBUG
  4080. /**
  4081. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  4082. * @pdev: Pointer to pdev object
  4083. * @enable: Enable/Disable Spectral DMA ring debug
  4084. *
  4085. * Start/stop Spectral DMA ring debug based on @enable.
  4086. * Also save the state for future use.
  4087. *
  4088. * Return: QDF_STATUS of operation
  4089. */
  4090. static QDF_STATUS
  4091. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  4092. {
  4093. struct target_if_spectral *spectral;
  4094. struct wlan_lmac_if_tx_ops *tx_ops;
  4095. struct wlan_objmgr_psoc *psoc;
  4096. if (!pdev)
  4097. return QDF_STATUS_E_FAILURE;
  4098. psoc = wlan_pdev_get_psoc(pdev);
  4099. if (!psoc) {
  4100. spectral_err("psoc is null");
  4101. return QDF_STATUS_E_INVAL;
  4102. }
  4103. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  4104. if (!tx_ops) {
  4105. spectral_err("tx_ops is NULL");
  4106. return QDF_STATUS_E_INVAL;
  4107. }
  4108. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4109. if (!spectral) {
  4110. spectral_err("Spectal LMAC object is NULL");
  4111. return QDF_STATUS_E_INVAL;
  4112. }
  4113. /* Save the state */
  4114. spectral->dbr_ring_debug = enable;
  4115. if (enable)
  4116. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  4117. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  4118. else
  4119. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  4120. pdev, 0);
  4121. return QDF_STATUS_SUCCESS;
  4122. }
  4123. /**
  4124. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  4125. * @pdev: Pointer to pdev object
  4126. * @enable: Enable/Disable Spectral DMA buffer debug
  4127. *
  4128. * Start/stop Spectral DMA buffer debug based on @enable.
  4129. * Also save the state for future use.
  4130. *
  4131. * Return: QDF_STATUS of operation
  4132. */
  4133. static QDF_STATUS
  4134. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  4135. {
  4136. struct target_if_spectral *spectral;
  4137. struct wlan_lmac_if_tx_ops *tx_ops;
  4138. struct wlan_objmgr_psoc *psoc;
  4139. if (!pdev)
  4140. return QDF_STATUS_E_FAILURE;
  4141. psoc = wlan_pdev_get_psoc(pdev);
  4142. if (!psoc) {
  4143. spectral_err("psoc is null");
  4144. return QDF_STATUS_E_INVAL;
  4145. }
  4146. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  4147. if (!tx_ops) {
  4148. spectral_err("tx_ops is NULL");
  4149. return QDF_STATUS_E_INVAL;
  4150. }
  4151. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4152. if (!spectral) {
  4153. spectral_err("Spectal LMAC object is NULL");
  4154. return QDF_STATUS_E_INVAL;
  4155. }
  4156. /* Save the state */
  4157. spectral->dbr_buff_debug = enable;
  4158. if (enable)
  4159. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  4160. pdev, 0, MEM_POISON_SIGNATURE);
  4161. else
  4162. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  4163. pdev, 0);
  4164. }
  4165. /**
  4166. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  4167. * debug based on the previous state
  4168. * @pdev: Pointer to pdev object
  4169. *
  4170. * Return: QDF_STATUS of operation
  4171. */
  4172. static QDF_STATUS
  4173. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  4174. {
  4175. struct target_if_spectral *spectral;
  4176. if (!pdev) {
  4177. spectral_err("pdev is NULL!");
  4178. return QDF_STATUS_E_FAILURE;
  4179. }
  4180. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4181. if (!spectral) {
  4182. spectral_err("Spectal LMAC object is NULL");
  4183. return QDF_STATUS_E_INVAL;
  4184. }
  4185. if (spectral->dbr_buff_debug)
  4186. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  4187. else
  4188. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  4189. }
  4190. /**
  4191. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  4192. * debug based on the previous state
  4193. * @pdev: Pointer to pdev object
  4194. *
  4195. * Return: QDF_STATUS of operation
  4196. */
  4197. static QDF_STATUS
  4198. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  4199. {
  4200. struct target_if_spectral *spectral;
  4201. if (!pdev) {
  4202. spectral_err("pdev is NULL!");
  4203. return QDF_STATUS_E_FAILURE;
  4204. }
  4205. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4206. if (!spectral) {
  4207. spectral_err("Spectal LMAC object is NULL");
  4208. return QDF_STATUS_E_INVAL;
  4209. }
  4210. if (spectral->dbr_ring_debug)
  4211. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  4212. else
  4213. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  4214. }
  4215. /**
  4216. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  4217. * @pdev: Pointer to pdev object
  4218. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  4219. * @debug_value: Value to be set for @dma_debug_type
  4220. *
  4221. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  4222. * based on @debug_value
  4223. *
  4224. * Return: QDF_STATUS of operation
  4225. */
  4226. static QDF_STATUS
  4227. target_if_spectral_set_dma_debug(
  4228. struct wlan_objmgr_pdev *pdev,
  4229. enum spectral_dma_debug dma_debug_type,
  4230. bool debug_value)
  4231. {
  4232. struct target_if_spectral_ops *p_sops;
  4233. struct wlan_objmgr_psoc *psoc;
  4234. struct wlan_lmac_if_tx_ops *tx_ops;
  4235. struct target_if_spectral *spectral;
  4236. if (!pdev)
  4237. return QDF_STATUS_E_FAILURE;
  4238. psoc = wlan_pdev_get_psoc(pdev);
  4239. if (!psoc) {
  4240. spectral_err("psoc is null");
  4241. return QDF_STATUS_E_INVAL;
  4242. }
  4243. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  4244. if (!tx_ops) {
  4245. spectral_err("tx_ops is NULL");
  4246. return QDF_STATUS_E_FAILURE;
  4247. }
  4248. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  4249. spectral_err("Unable to fetch target type");
  4250. return QDF_STATUS_E_FAILURE;
  4251. }
  4252. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4253. if (!spectral) {
  4254. spectral_err("Spectal LMAC object is NULL");
  4255. return QDF_STATUS_E_INVAL;
  4256. }
  4257. if (spectral->direct_dma_support) {
  4258. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4259. if (p_sops->is_spectral_active(spectral,
  4260. SPECTRAL_SCAN_MODE_NORMAL) ||
  4261. p_sops->is_spectral_active(spectral,
  4262. SPECTRAL_SCAN_MODE_AGILE)) {
  4263. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  4264. return QDF_STATUS_E_FAILURE;
  4265. }
  4266. switch (dma_debug_type) {
  4267. case SPECTRAL_DMA_RING_DEBUG:
  4268. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  4269. break;
  4270. case SPECTRAL_DMA_BUFFER_DEBUG:
  4271. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  4272. break;
  4273. default:
  4274. spectral_err("Unsupported DMA debug type : %d",
  4275. dma_debug_type);
  4276. return QDF_STATUS_E_FAILURE;
  4277. }
  4278. }
  4279. return QDF_STATUS_SUCCESS;
  4280. }
  4281. #endif /* DIRECT_BUF_RX_DEBUG */
  4282. /**
  4283. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  4284. * @pdev: Pointer to pdev object
  4285. *
  4286. * Return: Whether Direct-DMA is supported on this radio
  4287. */
  4288. static bool
  4289. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  4290. {
  4291. struct target_if_spectral *spectral;
  4292. if (!pdev) {
  4293. spectral_err("pdev is NULL!");
  4294. return false;
  4295. }
  4296. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4297. if (!spectral) {
  4298. spectral_err("Spectral LMAC object is NULL");
  4299. return false;
  4300. }
  4301. return spectral->direct_dma_support;
  4302. }
  4303. /**
  4304. * target_if_set_debug_level() - Set debug level for Spectral
  4305. * @pdev: Pointer to pdev object
  4306. * @debug_level: Debug level
  4307. *
  4308. * API to set the debug level for Spectral
  4309. *
  4310. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4311. */
  4312. QDF_STATUS
  4313. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  4314. {
  4315. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  4316. return QDF_STATUS_SUCCESS;
  4317. }
  4318. /**
  4319. * target_if_get_debug_level() - Get debug level for Spectral
  4320. * @pdev: Pointer to pdev object
  4321. *
  4322. * API to get the debug level for Spectral
  4323. *
  4324. * Return: Current debug level
  4325. */
  4326. uint32_t
  4327. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  4328. {
  4329. return spectral_debug_level;
  4330. }
  4331. /**
  4332. * target_if_get_spectral_capinfo() - Get Spectral capability information
  4333. * @pdev: Pointer to pdev object
  4334. * @scaps: Buffer into which data should be copied
  4335. *
  4336. * API to get the spectral capability information
  4337. *
  4338. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4339. */
  4340. QDF_STATUS
  4341. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  4342. struct spectral_caps *scaps)
  4343. {
  4344. struct target_if_spectral *spectral = NULL;
  4345. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4346. if (!spectral) {
  4347. spectral_err("SPECTRAL : Module doesn't exist");
  4348. return QDF_STATUS_E_FAILURE;
  4349. }
  4350. qdf_mem_copy(scaps, &spectral->capability,
  4351. sizeof(struct spectral_caps));
  4352. return QDF_STATUS_SUCCESS;
  4353. }
  4354. /**
  4355. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  4356. * @pdev: Pointer to pdev object
  4357. * @stats: Buffer into which data should be copied
  4358. *
  4359. * API to get the spectral diagnostic statistics
  4360. *
  4361. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4362. */
  4363. QDF_STATUS
  4364. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  4365. struct spectral_diag_stats *stats)
  4366. {
  4367. struct target_if_spectral *spectral = NULL;
  4368. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4369. if (!spectral) {
  4370. spectral_err("SPECTRAL : Module doesn't exist");
  4371. return QDF_STATUS_E_FAILURE;
  4372. }
  4373. qdf_mem_copy(stats, &spectral->diag_stats,
  4374. sizeof(struct spectral_diag_stats));
  4375. return QDF_STATUS_SUCCESS;
  4376. }
  4377. /**
  4378. * target_if_register_spectral_wmi_ops() - Register Spectral WMI operations
  4379. * @psoc: Pointer to psoc object
  4380. * @wmi_ops: Pointer to the structure having Spectral WMI operations
  4381. *
  4382. * API for registering Spectral WMI operations in
  4383. * spectral internal data structure
  4384. *
  4385. * Return: QDF_STATUS
  4386. */
  4387. static QDF_STATUS
  4388. target_if_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
  4389. struct spectral_wmi_ops *wmi_ops)
  4390. {
  4391. struct target_if_psoc_spectral *psoc_spectral;
  4392. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4393. if (!psoc_spectral) {
  4394. spectral_err("Spectral LMAC object is null");
  4395. return QDF_STATUS_E_INVAL;
  4396. }
  4397. psoc_spectral->wmi_ops = *wmi_ops;
  4398. return QDF_STATUS_SUCCESS;
  4399. }
  4400. /**
  4401. * target_if_register_spectral_tgt_ops() - Register Spectral target operations
  4402. * @psoc: Pointer to psoc object
  4403. * @tgt_ops: Pointer to the structure having Spectral target operations
  4404. *
  4405. * API for registering Spectral target operations in
  4406. * spectral internal data structure
  4407. *
  4408. * Return: QDF_STATUS
  4409. */
  4410. static QDF_STATUS
  4411. target_if_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
  4412. struct spectral_tgt_ops *tgt_ops)
  4413. {
  4414. if (!psoc) {
  4415. spectral_err("psoc is null");
  4416. return QDF_STATUS_E_INVAL;
  4417. }
  4418. ops_tgt = *tgt_ops;
  4419. return QDF_STATUS_SUCCESS;
  4420. }
  4421. /**
  4422. * target_if_register_netlink_cb() - Register Netlink callbacks
  4423. * @pdev: Pointer to pdev object
  4424. * @nl_cb: Netlink callbacks to register
  4425. *
  4426. * Return: void
  4427. */
  4428. static void
  4429. target_if_register_netlink_cb(
  4430. struct wlan_objmgr_pdev *pdev,
  4431. struct spectral_nl_cb *nl_cb)
  4432. {
  4433. struct target_if_spectral *spectral = NULL;
  4434. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4435. if (!spectral) {
  4436. spectral_err("SPECTRAL : Module doesn't exist");
  4437. return;
  4438. }
  4439. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  4440. if (spectral->use_nl_bcast)
  4441. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  4442. else
  4443. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  4444. }
  4445. /**
  4446. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  4447. * Netlink messages to the application layer
  4448. * @pdev: Pointer to pdev object
  4449. *
  4450. * Return: true for broadcast, false for unicast
  4451. */
  4452. static bool
  4453. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  4454. {
  4455. struct target_if_spectral *spectral = NULL;
  4456. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4457. if (!spectral) {
  4458. spectral_err("SPECTRAL : Module doesn't exist");
  4459. return false;
  4460. }
  4461. return spectral->use_nl_bcast;
  4462. }
  4463. /**
  4464. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  4465. * @pdev: Pointer to pdev object
  4466. *
  4467. * Return: void
  4468. */
  4469. static void
  4470. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  4471. {
  4472. struct target_if_spectral *spectral = NULL;
  4473. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4474. if (!spectral) {
  4475. spectral_err("SPECTRAL : Module doesn't exist");
  4476. return;
  4477. }
  4478. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  4479. }
  4480. static int
  4481. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  4482. void *payload)
  4483. {
  4484. struct target_if_spectral *spectral = NULL;
  4485. struct target_if_spectral_ops *p_sops = NULL;
  4486. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4487. if (!spectral) {
  4488. spectral_err("SPECTRAL : Module doesn't exist");
  4489. return -EPERM;
  4490. }
  4491. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4492. if (!p_sops) {
  4493. spectral_err("p_sops is null");
  4494. return -EPERM;
  4495. }
  4496. return p_sops->process_spectral_report(pdev, payload);
  4497. }
  4498. #ifdef DIRECT_BUF_RX_DEBUG
  4499. static inline void
  4500. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4501. {
  4502. if (!tx_ops) {
  4503. spectral_err("tx_ops is NULL");
  4504. return;
  4505. }
  4506. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  4507. target_if_spectral_set_dma_debug;
  4508. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  4509. target_if_spectral_check_and_do_dbr_ring_debug;
  4510. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  4511. target_if_spectral_check_and_do_dbr_buff_debug;
  4512. }
  4513. #else
  4514. static inline void
  4515. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4516. {
  4517. }
  4518. #endif
  4519. #if defined(WLAN_CONV_SPECTRAL_ENABLE) && defined(SPECTRAL_MODULIZED_ENABLE)
  4520. /**
  4521. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  4522. * register WMI event handler
  4523. * @psoc: Pointer to psoc object
  4524. * @event_id: Event id
  4525. * @handler_func: Handler function
  4526. * @rx_ctx: Context of WMI event processing
  4527. *
  4528. * Wrapper function to register WMI event handler
  4529. *
  4530. * Return: 0 for success else failure
  4531. */
  4532. static int
  4533. target_if_spectral_wmi_unified_register_event_handler(
  4534. struct wlan_objmgr_psoc *psoc,
  4535. wmi_conv_event_id event_id,
  4536. wmi_unified_event_handler handler_func,
  4537. uint8_t rx_ctx)
  4538. {
  4539. wmi_unified_t wmi_handle;
  4540. struct target_if_psoc_spectral *psoc_spectral;
  4541. QDF_STATUS ret;
  4542. if (!psoc) {
  4543. spectral_err("psoc is null");
  4544. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4545. }
  4546. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4547. if (!wmi_handle) {
  4548. spectral_err("WMI handle is null");
  4549. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4550. }
  4551. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4552. if (!psoc_spectral) {
  4553. spectral_err("spectral object is null");
  4554. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4555. }
  4556. ret = psoc_spectral->wmi_ops.wmi_unified_register_event_handler(
  4557. wmi_handle, event_id, handler_func, rx_ctx);
  4558. return qdf_status_to_os_return(ret);
  4559. }
  4560. /**
  4561. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  4562. * to unregister WMI event handler
  4563. * @psoc: Pointer to psoc object
  4564. * @event_id: Event id
  4565. *
  4566. * Wrapper function to unregister WMI event handler
  4567. *
  4568. * Return: 0 for success else failure
  4569. */
  4570. static int
  4571. target_if_spectral_wmi_unified_unregister_event_handler(
  4572. struct wlan_objmgr_psoc *psoc,
  4573. wmi_conv_event_id event_id)
  4574. {
  4575. wmi_unified_t wmi_handle;
  4576. struct target_if_psoc_spectral *psoc_spectral;
  4577. QDF_STATUS ret;
  4578. if (!psoc) {
  4579. spectral_err("psoc is null");
  4580. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4581. }
  4582. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4583. if (!wmi_handle) {
  4584. spectral_err("WMI handle is null");
  4585. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4586. }
  4587. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4588. if (!psoc_spectral) {
  4589. spectral_err("spectral object is null");
  4590. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4591. }
  4592. ret = psoc_spectral->wmi_ops.wmi_unified_unregister_event_handler(
  4593. wmi_handle, event_id);
  4594. return qdf_status_to_os_return(ret);
  4595. }
  4596. /**
  4597. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  4598. * function to extract fixed parameters from start scan response event
  4599. * @psoc: Pointer to psoc object
  4600. * @evt_buf: Event buffer
  4601. * @param: Start scan response parameters
  4602. *
  4603. * Wrapper function to extract fixed parameters from start scan response event
  4604. *
  4605. * Return: QDF_STATUS
  4606. */
  4607. static QDF_STATUS
  4608. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4609. struct wlan_objmgr_psoc *psoc,
  4610. uint8_t *evt_buf,
  4611. struct spectral_startscan_resp_params *param)
  4612. {
  4613. wmi_unified_t wmi_handle;
  4614. struct target_if_psoc_spectral *psoc_spectral;
  4615. if (!psoc) {
  4616. spectral_err("psoc is null");
  4617. return QDF_STATUS_E_INVAL;
  4618. }
  4619. if (!evt_buf) {
  4620. spectral_err("WMI event buffer is null");
  4621. return QDF_STATUS_E_INVAL;
  4622. }
  4623. if (!param) {
  4624. spectral_err("Spectral startscan response parameters is null");
  4625. return QDF_STATUS_E_INVAL;
  4626. }
  4627. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4628. if (!wmi_handle) {
  4629. spectral_err("WMI handle is null");
  4630. return QDF_STATUS_E_INVAL;
  4631. }
  4632. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4633. if (!psoc_spectral) {
  4634. spectral_err("spectral object is null");
  4635. return QDF_STATUS_E_FAILURE;
  4636. }
  4637. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4638. wmi_handle, evt_buf, param);
  4639. }
  4640. /**
  4641. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  4642. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  4643. * secondary 80 MHz FFT bins
  4644. * @psoc: Pointer to psoc object
  4645. * @evt_buf: Event buffer
  4646. * @param: FFT bin start and end indices
  4647. *
  4648. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  4649. * and secondary 80 MHz FFT bins
  4650. *
  4651. * Return: QDF_STATUS
  4652. */
  4653. static QDF_STATUS
  4654. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  4655. struct wlan_objmgr_psoc *psoc,
  4656. uint8_t *evt_buf,
  4657. struct spectral_fft_bin_markers_160_165mhz *param)
  4658. {
  4659. wmi_unified_t wmi_handle;
  4660. struct target_if_psoc_spectral *psoc_spectral;
  4661. if (!psoc) {
  4662. spectral_err("psoc is null");
  4663. return QDF_STATUS_E_INVAL;
  4664. }
  4665. if (!evt_buf) {
  4666. spectral_err("WMI event buffer is null");
  4667. return QDF_STATUS_E_INVAL;
  4668. }
  4669. if (!param) {
  4670. spectral_err("Spectral FFT bin markers is null");
  4671. return QDF_STATUS_E_INVAL;
  4672. }
  4673. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4674. if (!wmi_handle) {
  4675. spectral_err("WMI handle is null");
  4676. return QDF_STATUS_E_INVAL;
  4677. }
  4678. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4679. if (!psoc_spectral) {
  4680. spectral_err("spectral object is null");
  4681. return QDF_STATUS_E_FAILURE;
  4682. }
  4683. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fft_bin_index(
  4684. wmi_handle, evt_buf, param);
  4685. }
  4686. /**
  4687. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  4688. * object from scn handle
  4689. * @scn: scn handle
  4690. *
  4691. * Wrapper function to get psoc object from scn handle
  4692. *
  4693. * Return: Pointer to psoc object
  4694. */
  4695. static struct wlan_objmgr_psoc *
  4696. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  4697. {
  4698. if (!scn) {
  4699. spectral_err("scn is null");
  4700. return NULL;
  4701. }
  4702. return ops_tgt.tgt_get_psoc_from_scn_hdl(scn);
  4703. }
  4704. #else
  4705. /**
  4706. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  4707. * register WMI event handler
  4708. * @psoc: Pointer to psoc object
  4709. * @event_id: Event id
  4710. * @handler_func: Handler function
  4711. * @rx_ctx: Context of WMI event processing
  4712. *
  4713. * Wrapper function to register WMI event handler
  4714. *
  4715. * Return: 0 for success else failure
  4716. */
  4717. static int
  4718. target_if_spectral_wmi_unified_register_event_handler(
  4719. struct wlan_objmgr_psoc *psoc,
  4720. wmi_conv_event_id event_id,
  4721. wmi_unified_event_handler handler_func,
  4722. uint8_t rx_ctx)
  4723. {
  4724. wmi_unified_t wmi_handle;
  4725. QDF_STATUS ret;
  4726. if (!psoc) {
  4727. spectral_err("psoc is null");
  4728. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4729. }
  4730. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4731. if (!wmi_handle) {
  4732. spectral_err("WMI handle is null");
  4733. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4734. }
  4735. ret = wmi_unified_register_event_handler(wmi_handle, event_id,
  4736. handler_func, rx_ctx);
  4737. return qdf_status_to_os_return(ret);
  4738. }
  4739. /**
  4740. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  4741. * to unregister WMI event handler
  4742. * @psoc: Pointer to psoc object
  4743. * @event_id: Event id
  4744. *
  4745. * Wrapper function to unregister WMI event handler
  4746. *
  4747. * Return: 0 for success else failure
  4748. */
  4749. static int
  4750. target_if_spectral_wmi_unified_unregister_event_handler(
  4751. struct wlan_objmgr_psoc *psoc,
  4752. wmi_conv_event_id event_id)
  4753. {
  4754. wmi_unified_t wmi_handle;
  4755. QDF_STATUS ret;
  4756. if (!psoc) {
  4757. spectral_err("psoc is null");
  4758. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4759. }
  4760. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4761. if (!wmi_handle) {
  4762. spectral_err("WMI handle is null");
  4763. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4764. }
  4765. ret = wmi_unified_unregister_event_handler(wmi_handle, event_id);
  4766. return qdf_status_to_os_return(ret);
  4767. }
  4768. /**
  4769. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  4770. * function to extract fixed parameters from start scan response event
  4771. * @psoc: Pointer to psoc object
  4772. * @evt_buf: Event buffer
  4773. * @param: Start scan response parameters
  4774. *
  4775. * Wrapper function to extract fixed parameters from start scan response event
  4776. *
  4777. * Return: QDF_STATUS
  4778. */
  4779. static QDF_STATUS
  4780. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4781. struct wlan_objmgr_psoc *psoc,
  4782. uint8_t *evt_buf,
  4783. struct spectral_startscan_resp_params *param)
  4784. {
  4785. wmi_unified_t wmi_handle;
  4786. if (!psoc) {
  4787. spectral_err("psoc is null");
  4788. return QDF_STATUS_E_INVAL;
  4789. }
  4790. if (!evt_buf) {
  4791. spectral_err("WMI event buffer is null");
  4792. return QDF_STATUS_E_INVAL;
  4793. }
  4794. if (!param) {
  4795. spectral_err("Spectral startscan response parameters is null");
  4796. return QDF_STATUS_E_INVAL;
  4797. }
  4798. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4799. if (!wmi_handle) {
  4800. spectral_err("WMI handle is null");
  4801. return QDF_STATUS_E_INVAL;
  4802. }
  4803. return wmi_extract_pdev_sscan_fw_cmd_fixed_param(wmi_handle, evt_buf,
  4804. param);
  4805. }
  4806. /**
  4807. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  4808. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  4809. * secondary 80 MHz FFT bins
  4810. * @psoc: Pointer to psoc object
  4811. * @evt_buf: Event buffer
  4812. * @param: FFT bin start and end indices
  4813. *
  4814. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  4815. * and secondary 80 MHz FFT bins
  4816. *
  4817. * Return: QDF_STATUS
  4818. */
  4819. static QDF_STATUS
  4820. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  4821. struct wlan_objmgr_psoc *psoc,
  4822. uint8_t *evt_buf,
  4823. struct spectral_fft_bin_markers_160_165mhz *param)
  4824. {
  4825. wmi_unified_t wmi_handle;
  4826. if (!psoc) {
  4827. spectral_err("psoc is null");
  4828. return QDF_STATUS_E_INVAL;
  4829. }
  4830. if (!evt_buf) {
  4831. spectral_err("WMI event buffer is null");
  4832. return QDF_STATUS_E_INVAL;
  4833. }
  4834. if (!param) {
  4835. spectral_err("Spectral FFT bin markers is null");
  4836. return QDF_STATUS_E_INVAL;
  4837. }
  4838. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4839. if (!wmi_handle) {
  4840. spectral_err("WMI handle is null");
  4841. return QDF_STATUS_E_INVAL;
  4842. }
  4843. return wmi_extract_pdev_sscan_fft_bin_index(wmi_handle, evt_buf, param);
  4844. }
  4845. /**
  4846. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  4847. * object from scn handle
  4848. * @scn: scn handle
  4849. *
  4850. * Wrapper function to get psoc object from scn handle
  4851. *
  4852. * Return: Pointer to psoc object
  4853. */
  4854. static struct wlan_objmgr_psoc *
  4855. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  4856. {
  4857. if (!scn) {
  4858. spectral_err("scn is null");
  4859. return NULL;
  4860. }
  4861. return target_if_get_psoc_from_scn_hdl(scn);
  4862. }
  4863. #endif
  4864. /**
  4865. * target_if_spectral_fw_param_event_handler() - WMI event handler to
  4866. * process start scan response event
  4867. * @scn: Pointer to scn object
  4868. * @data_buf: Pointer to event buffer
  4869. * @data_len: Length of event buffer
  4870. *
  4871. * Return: 0 for success, else failure
  4872. */
  4873. static int
  4874. target_if_spectral_fw_param_event_handler(ol_scn_t scn, uint8_t *data_buf,
  4875. uint32_t data_len)
  4876. {
  4877. QDF_STATUS status;
  4878. struct wlan_objmgr_psoc *psoc;
  4879. struct wlan_objmgr_pdev *pdev;
  4880. struct wmi_unified *wmi_handle;
  4881. struct spectral_startscan_resp_params event_params = {0};
  4882. struct target_if_psoc_spectral *psoc_spectral;
  4883. struct target_if_spectral *spectral;
  4884. if (!scn) {
  4885. spectral_err("scn handle is null");
  4886. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4887. }
  4888. if (!data_buf) {
  4889. spectral_err("WMI event buffer null");
  4890. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4891. }
  4892. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  4893. if (!psoc) {
  4894. spectral_err("psoc is null");
  4895. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4896. }
  4897. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4898. if (!psoc_spectral) {
  4899. spectral_err("spectral object is null");
  4900. return QDF_STATUS_E_FAILURE;
  4901. }
  4902. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4903. if (!wmi_handle) {
  4904. spectral_err("WMI handle is null");
  4905. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4906. }
  4907. status = target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4908. psoc, data_buf, &event_params);
  4909. if (QDF_IS_STATUS_ERROR(status)) {
  4910. spectral_err("unable to extract sscan fw fixed params");
  4911. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4912. }
  4913. pdev = wlan_objmgr_get_pdev_by_id(psoc, event_params.pdev_id,
  4914. WLAN_SPECTRAL_ID);
  4915. if (!pdev) {
  4916. spectral_err("pdev is null");
  4917. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4918. }
  4919. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4920. if (!spectral) {
  4921. spectral_err("spectral object is null");
  4922. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  4923. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4924. }
  4925. if (event_params.num_fft_bin_index == 1) {
  4926. status =
  4927. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  4928. psoc, data_buf,
  4929. &spectral->rparams.marker[event_params.smode]);
  4930. if (QDF_IS_STATUS_ERROR(status)) {
  4931. spectral_err("unable to extract sscan fw fixed params");
  4932. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  4933. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4934. }
  4935. } else {
  4936. spectral->rparams.marker[event_params.smode].is_valid = false;
  4937. }
  4938. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  4939. return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
  4940. }
  4941. static QDF_STATUS
  4942. target_if_spectral_register_events(struct wlan_objmgr_psoc *psoc)
  4943. {
  4944. int ret;
  4945. if (!psoc) {
  4946. spectral_err("psoc is null");
  4947. return QDF_STATUS_E_INVAL;
  4948. }
  4949. ret = target_if_spectral_wmi_unified_register_event_handler(
  4950. psoc,
  4951. wmi_pdev_sscan_fw_param_eventid,
  4952. target_if_spectral_fw_param_event_handler,
  4953. WMI_RX_UMAC_CTX);
  4954. if (ret)
  4955. spectral_debug("event handler not supported, ret=%d", ret);
  4956. return QDF_STATUS_SUCCESS;
  4957. }
  4958. static QDF_STATUS
  4959. target_if_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
  4960. {
  4961. int ret;
  4962. if (!psoc) {
  4963. spectral_err("psoc is null");
  4964. return QDF_STATUS_E_INVAL;
  4965. }
  4966. ret = target_if_spectral_wmi_unified_unregister_event_handler(
  4967. psoc, wmi_pdev_sscan_fw_param_eventid);
  4968. if (ret)
  4969. spectral_debug("Unregister WMI event handler failed, ret = %d",
  4970. ret);
  4971. return QDF_STATUS_SUCCESS;
  4972. }
  4973. void
  4974. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4975. {
  4976. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  4977. target_if_pdev_spectral_init;
  4978. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  4979. target_if_pdev_spectral_deinit;
  4980. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init =
  4981. target_if_psoc_spectral_init;
  4982. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit =
  4983. target_if_psoc_spectral_deinit;
  4984. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  4985. target_if_set_spectral_config;
  4986. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  4987. target_if_get_spectral_config;
  4988. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  4989. target_if_start_spectral_scan;
  4990. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  4991. target_if_stop_spectral_scan;
  4992. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  4993. target_if_is_spectral_active;
  4994. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  4995. target_if_is_spectral_enabled;
  4996. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  4997. target_if_set_debug_level;
  4998. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  4999. target_if_get_debug_level;
  5000. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  5001. target_if_get_spectral_capinfo;
  5002. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  5003. target_if_get_spectral_diagstats;
  5004. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_wmi_ops =
  5005. target_if_register_spectral_wmi_ops;
  5006. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_tgt_ops =
  5007. target_if_register_spectral_tgt_ops;
  5008. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  5009. target_if_register_netlink_cb;
  5010. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  5011. target_if_use_nl_bcast;
  5012. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  5013. target_if_deregister_netlink_cb;
  5014. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  5015. target_if_process_spectral_report;
  5016. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  5017. target_if_spectral_direct_dma_support;
  5018. tx_ops->sptrl_tx_ops.sptrlto_register_events =
  5019. target_if_spectral_register_events;
  5020. tx_ops->sptrl_tx_ops.sptrlto_unregister_events =
  5021. target_if_spectral_unregister_events;
  5022. target_if_sptrl_debug_register_tx_ops(tx_ops);
  5023. }
  5024. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  5025. void
  5026. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  5027. uint16_t cw_int, uint32_t dcs_enabled)
  5028. {
  5029. struct spectral_samp_msg *msg = NULL;
  5030. struct target_if_spectral_ops *p_sops = NULL;
  5031. struct target_if_spectral *spectral = NULL;
  5032. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5033. if (!spectral) {
  5034. spectral_err("SPECTRAL : Module doesn't exist");
  5035. return;
  5036. }
  5037. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5038. if (!p_sops) {
  5039. spectral_err("p_sops is null");
  5040. return;
  5041. }
  5042. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  5043. spectral->pdev_obj,
  5044. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  5045. SPECTRAL_MSG_BUF_NEW);
  5046. if (msg) {
  5047. msg->int_type = cw_int ?
  5048. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  5049. msg->dcs_enabled = dcs_enabled;
  5050. msg->signature = SPECTRAL_SIGNATURE;
  5051. p_sops->get_mac_address(spectral, msg->macaddr);
  5052. if (spectral->send_phy_data
  5053. (pdev,
  5054. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  5055. spectral->spectral_sent_msg++;
  5056. }
  5057. }
  5058. qdf_export_symbol(target_if_spectral_send_intf_found_msg);
  5059. QDF_STATUS
  5060. target_if_spectral_is_finite_scan(struct target_if_spectral *spectral,
  5061. enum spectral_scan_mode smode,
  5062. bool *finite_spectral_scan)
  5063. {
  5064. struct target_if_finite_spectral_scan_params *finite_scan;
  5065. if (!spectral) {
  5066. spectral_err_rl("target if spectral object is null");
  5067. return QDF_STATUS_E_INVAL;
  5068. }
  5069. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5070. spectral_err_rl("invalid spectral mode %d", smode);
  5071. return QDF_STATUS_E_INVAL;
  5072. }
  5073. if (!finite_spectral_scan) {
  5074. spectral_err_rl("Invalid pointer");
  5075. return QDF_STATUS_E_INVAL;
  5076. }
  5077. finite_scan = &spectral->finite_scan[smode];
  5078. *finite_spectral_scan = finite_scan->finite_spectral_scan;
  5079. return QDF_STATUS_SUCCESS;
  5080. }
  5081. QDF_STATUS
  5082. target_if_spectral_finite_scan_update(struct target_if_spectral *spectral,
  5083. enum spectral_scan_mode smode)
  5084. {
  5085. struct target_if_finite_spectral_scan_params *finite_scan;
  5086. if (!spectral) {
  5087. spectral_err_rl("target if spectral object is null");
  5088. return QDF_STATUS_E_INVAL;
  5089. }
  5090. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5091. spectral_err_rl("Invalid Spectral mode");
  5092. return QDF_STATUS_E_INVAL;
  5093. }
  5094. finite_scan = &spectral->finite_scan[smode];
  5095. if (!finite_scan->num_reports_expected) {
  5096. spectral_err_rl("Error, No reports expected");
  5097. return QDF_STATUS_E_FAILURE;
  5098. }
  5099. finite_scan->num_reports_expected--;
  5100. if (!finite_scan->num_reports_expected) {
  5101. QDF_STATUS status;
  5102. enum spectral_cp_error_code err;
  5103. /* received expected number of reports from target, stop scan */
  5104. status = target_if_stop_spectral_scan(spectral->pdev_obj, smode,
  5105. &err);
  5106. if (QDF_IS_STATUS_ERROR(status)) {
  5107. spectral_err_rl("Failed to stop finite Spectral scan");
  5108. return QDF_STATUS_E_FAILURE;
  5109. }
  5110. finite_scan->finite_spectral_scan = false;
  5111. }
  5112. return QDF_STATUS_SUCCESS;
  5113. }