target_if_spectral.c 167 KB

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