target_if_spectral.c 167 KB

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