target_if_spectral.c 219 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055
  1. /*
  2. * Copyright (c) 2011,2017-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  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. struct target_if_spectral *get_target_if_spectral_handle_from_pdev(
  94. struct wlan_objmgr_pdev *pdev)
  95. {
  96. struct target_if_spectral *spectral;
  97. struct wlan_objmgr_psoc *psoc;
  98. struct wlan_lmac_if_rx_ops *rx_ops;
  99. if (!pdev) {
  100. spectral_err("pdev is null");
  101. return NULL;
  102. }
  103. psoc = wlan_pdev_get_psoc(pdev);
  104. if (!psoc) {
  105. spectral_err("psoc is null");
  106. return NULL;
  107. }
  108. rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
  109. if (!rx_ops) {
  110. spectral_err("rx_ops is null");
  111. return NULL;
  112. }
  113. spectral = (struct target_if_spectral *)
  114. rx_ops->sptrl_rx_ops.sptrlro_get_pdev_target_handle(pdev);
  115. return spectral;
  116. }
  117. qdf_export_symbol(get_target_if_spectral_handle_from_pdev);
  118. /**
  119. * target_if_spectral_get_normal_mode_cap() - API to get normal
  120. * Spectral scan capability of a given pdev
  121. * @pdev: pdev handle
  122. * @normal_mode_disable: Pointer to caller variable
  123. *
  124. * API to get normal Spectral scan mode capability a given pdev.
  125. * This information is derived from the WMI service
  126. * "WMI_SERVICE_SPECTRAL_SCAN_DISABLED".
  127. *
  128. * Return: QDF_STATUS on success
  129. */
  130. static QDF_STATUS
  131. target_if_spectral_get_normal_mode_cap(struct wlan_objmgr_pdev *pdev,
  132. bool *normal_mode_disable)
  133. {
  134. struct wlan_objmgr_psoc *psoc;
  135. struct wmi_unified *wmi_handle;
  136. struct target_if_psoc_spectral *psoc_spectral;
  137. if (!pdev) {
  138. spectral_err("pdev is null");
  139. return QDF_STATUS_E_INVAL;
  140. }
  141. psoc = wlan_pdev_get_psoc(pdev);
  142. if (!psoc) {
  143. spectral_err("psoc is null");
  144. return QDF_STATUS_E_INVAL;
  145. }
  146. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  147. if (!psoc_spectral) {
  148. spectral_err("psoc spectral object is null");
  149. return QDF_STATUS_E_INVAL;
  150. }
  151. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  152. if (!wmi_handle) {
  153. spectral_err("wmi handle is null");
  154. return QDF_STATUS_E_INVAL;
  155. }
  156. *normal_mode_disable = target_if_spectral_wmi_service_enabled(psoc,
  157. wmi_handle, wmi_service_spectral_scan_disabled);
  158. return QDF_STATUS_SUCCESS;
  159. }
  160. /**
  161. * target_if_spectral_get_agile_mode_cap() - API to check agile
  162. * Spectral scan mode capability of a given pdev.
  163. * @pdev: pdev handle
  164. * @agile_cap: Pointer to caller variable
  165. *
  166. * API to check agile Spectral scan mode is disabled for a given pdev.
  167. * This information is derived from the chain mask table entries.
  168. *
  169. * Return: QDF_STATUS on success
  170. */
  171. static QDF_STATUS
  172. target_if_spectral_get_agile_mode_cap(
  173. struct wlan_objmgr_pdev *pdev,
  174. struct target_if_spectral_agile_mode_cap *agile_cap)
  175. {
  176. struct wlan_objmgr_psoc *psoc;
  177. struct target_psoc_info *tgt_psoc_info;
  178. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr;
  179. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap;
  180. uint8_t pdev_id, i;
  181. uint32_t table_id;
  182. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  183. struct wlan_psoc_host_chainmask_table *table;
  184. struct wmi_unified *wmi_handle;
  185. if (!pdev) {
  186. spectral_err("pdev is null");
  187. return QDF_STATUS_E_INVAL;
  188. }
  189. psoc = wlan_pdev_get_psoc(pdev);
  190. if (!psoc) {
  191. spectral_err("psoc is null");
  192. return QDF_STATUS_E_FAILURE;
  193. }
  194. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  195. if (!wmi_handle) {
  196. spectral_err("wmi handle is null");
  197. return QDF_STATUS_E_INVAL;
  198. }
  199. /* Agile Spectral is disabled for legacy targets */
  200. if (!target_if_spectral_wmi_service_enabled(psoc, wmi_handle,
  201. wmi_service_ext_msg)) {
  202. agile_cap->agile_spectral_cap = false;
  203. agile_cap->agile_spectral_cap_160 = false;
  204. agile_cap->agile_spectral_cap_80p80 = false;
  205. agile_cap->agile_spectral_cap_320 = false;
  206. return QDF_STATUS_SUCCESS;
  207. }
  208. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  209. if (!tgt_psoc_info) {
  210. spectral_err("target_psoc_info is null");
  211. return QDF_STATUS_E_FAILURE;
  212. }
  213. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  214. if (!mac_phy_cap_arr) {
  215. spectral_err("mac phy cap array is null");
  216. return QDF_STATUS_E_FAILURE;
  217. }
  218. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  219. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  220. table_id = mac_phy_cap->chainmask_table_id;
  221. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  222. if (!ext_svc_param) {
  223. spectral_err("Extended service ready params null");
  224. return QDF_STATUS_E_FAILURE;
  225. }
  226. table = &ext_svc_param->chainmask_table[table_id];
  227. for (i = 0; i < table->num_valid_chainmasks; i++) {
  228. agile_cap->agile_spectral_cap |=
  229. table->cap_list[i].supports_aSpectral;
  230. agile_cap->agile_spectral_cap_160 |=
  231. table->cap_list[i].supports_aSpectral_160;
  232. agile_cap->agile_spectral_cap_320 |= 0;
  233. }
  234. agile_cap->agile_spectral_cap_80p80 = agile_cap->agile_spectral_cap_160;
  235. return QDF_STATUS_SUCCESS;
  236. }
  237. /**
  238. * target_if_spectral_init_pdev_feature_cap_per_mode() - API to initialize
  239. * Spectral scan pdev feature caps for a given Spectral mode
  240. * @pdev: pdev handle
  241. * @smode: Spectral scan mode
  242. *
  243. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE/
  244. * QDF_STATUS_E_INVAL on failure
  245. */
  246. static QDF_STATUS
  247. target_if_spectral_init_pdev_feature_cap_per_mode(struct wlan_objmgr_pdev *pdev,
  248. enum spectral_scan_mode smode)
  249. {
  250. struct wlan_objmgr_psoc *psoc;
  251. bool normal_mode_disable;
  252. struct target_if_spectral_agile_mode_cap agile_cap = { 0 };
  253. QDF_STATUS status;
  254. if (!pdev) {
  255. spectral_err("pdev is null");
  256. return QDF_STATUS_E_INVAL;
  257. }
  258. psoc = wlan_pdev_get_psoc(pdev);
  259. if (!psoc) {
  260. spectral_err("psoc is null");
  261. return QDF_STATUS_E_INVAL;
  262. }
  263. switch (smode) {
  264. case SPECTRAL_SCAN_MODE_NORMAL:
  265. if (target_if_spectral_is_feature_disabled_psoc(psoc)) {
  266. wlan_pdev_nif_feat_ext_cap_set(
  267. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  268. return QDF_STATUS_SUCCESS;
  269. }
  270. status = target_if_spectral_get_normal_mode_cap(
  271. pdev, &normal_mode_disable);
  272. if (QDF_IS_STATUS_ERROR(status)) {
  273. spectral_err("Failed to get normal spectral scan caps");
  274. return QDF_STATUS_E_FAILURE;
  275. }
  276. if (normal_mode_disable)
  277. wlan_pdev_nif_feat_ext_cap_set(
  278. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  279. else
  280. wlan_pdev_nif_feat_ext_cap_clear(
  281. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  282. break;
  283. case SPECTRAL_SCAN_MODE_AGILE:
  284. if (target_if_spectral_is_feature_disabled_psoc(psoc)) {
  285. wlan_pdev_nif_feat_ext_cap_set(
  286. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  287. wlan_pdev_nif_feat_ext_cap_set(
  288. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  289. wlan_pdev_nif_feat_ext_cap_set(
  290. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  291. wlan_pdev_nif_feat_ext_cap_set(
  292. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  293. return QDF_STATUS_SUCCESS;
  294. }
  295. status = target_if_spectral_get_agile_mode_cap(
  296. pdev, &agile_cap);
  297. if (QDF_IS_STATUS_ERROR(status)) {
  298. spectral_err("Failed to get agile Spectral capability");
  299. return QDF_STATUS_E_FAILURE;
  300. }
  301. if (!agile_cap.agile_spectral_cap)
  302. wlan_pdev_nif_feat_ext_cap_set(
  303. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  304. else
  305. wlan_pdev_nif_feat_ext_cap_clear(
  306. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  307. if (!agile_cap.agile_spectral_cap_160)
  308. wlan_pdev_nif_feat_ext_cap_set(
  309. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  310. else
  311. wlan_pdev_nif_feat_ext_cap_clear(
  312. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  313. if (!agile_cap.agile_spectral_cap_80p80)
  314. wlan_pdev_nif_feat_ext_cap_set(
  315. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  316. else
  317. wlan_pdev_nif_feat_ext_cap_clear(
  318. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  319. if (!agile_cap.agile_spectral_cap_320)
  320. wlan_pdev_nif_feat_ext_cap_set(
  321. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  322. else
  323. wlan_pdev_nif_feat_ext_cap_clear(
  324. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  325. break;
  326. default:
  327. spectral_err("Invalid Spectral scan mode %d", smode);
  328. return QDF_STATUS_E_INVAL;
  329. }
  330. return QDF_STATUS_SUCCESS;
  331. }
  332. /**
  333. * target_if_spectral_init_pdev_feature_caps() - API to initialize
  334. * Spectral scan pdev feature caps for a given pdev
  335. * @pdev: pdev handle
  336. *
  337. * API initialize normal and agile Spectral scan pdev
  338. * feature caps for a given pdev.
  339. *
  340. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  341. */
  342. static QDF_STATUS
  343. target_if_spectral_init_pdev_feature_caps(struct wlan_objmgr_pdev *pdev)
  344. {
  345. enum spectral_scan_mode smode;
  346. if (!pdev) {
  347. spectral_err("pdev is NULL!");
  348. return QDF_STATUS_E_INVAL;
  349. }
  350. smode = SPECTRAL_SCAN_MODE_NORMAL;
  351. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  352. QDF_STATUS status;
  353. status = target_if_spectral_init_pdev_feature_cap_per_mode(
  354. pdev, smode);
  355. if (QDF_IS_STATUS_ERROR(status))
  356. return QDF_STATUS_E_INVAL;
  357. }
  358. return QDF_STATUS_SUCCESS;
  359. }
  360. static void target_if_spectral_get_firstvdev_pdev(struct wlan_objmgr_pdev *pdev,
  361. void *obj, void *arg)
  362. {
  363. struct wlan_objmgr_vdev *vdev = obj;
  364. struct wlan_objmgr_vdev **first_vdev = arg;
  365. if (!(*first_vdev))
  366. *first_vdev = vdev;
  367. }
  368. struct wlan_objmgr_vdev *
  369. target_if_spectral_get_vdev(struct target_if_spectral *spectral,
  370. enum spectral_scan_mode smode)
  371. {
  372. struct wlan_objmgr_pdev *pdev = NULL;
  373. struct wlan_objmgr_vdev *first_vdev = NULL;
  374. qdf_assert_always(spectral);
  375. pdev = spectral->pdev_obj;
  376. qdf_assert_always(pdev);
  377. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  378. spectral_err("Invalid Spectral mode %u", smode);
  379. return NULL;
  380. }
  381. if (spectral->vdev_id[smode] != WLAN_INVALID_VDEV_ID) {
  382. first_vdev = wlan_objmgr_get_vdev_by_id_from_pdev(
  383. pdev, spectral->vdev_id[smode],
  384. WLAN_SPECTRAL_ID);
  385. return first_vdev;
  386. }
  387. if (wlan_objmgr_pdev_try_get_ref(pdev, WLAN_SPECTRAL_ID) !=
  388. QDF_STATUS_SUCCESS) {
  389. spectral_err("Unable to get pdev reference.");
  390. return NULL;
  391. }
  392. wlan_objmgr_pdev_iterate_obj_list(pdev, WLAN_VDEV_OP,
  393. target_if_spectral_get_firstvdev_pdev,
  394. &first_vdev, 0, WLAN_SPECTRAL_ID);
  395. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  396. if (!first_vdev)
  397. return NULL;
  398. if (wlan_objmgr_vdev_try_get_ref(first_vdev, WLAN_SPECTRAL_ID) !=
  399. QDF_STATUS_SUCCESS)
  400. first_vdev = NULL;
  401. return first_vdev;
  402. }
  403. /**
  404. * target_if_send_vdev_spectral_configure_cmd() - Send WMI command to configure
  405. * spectral parameters
  406. * @spectral: Pointer to Spectral target_if internal private data
  407. * @smode: Spectral scan mode
  408. * @param: Pointer to spectral_config giving the Spectral configuration
  409. *
  410. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  411. */
  412. static int
  413. target_if_send_vdev_spectral_configure_cmd(struct target_if_spectral *spectral,
  414. enum spectral_scan_mode smode,
  415. struct spectral_config *param)
  416. {
  417. struct vdev_spectral_configure_params sparam;
  418. struct wlan_objmgr_psoc *psoc;
  419. struct wlan_objmgr_pdev *pdev = NULL;
  420. struct wlan_objmgr_vdev *vdev = NULL;
  421. struct target_if_psoc_spectral *psoc_spectral;
  422. qdf_assert_always(spectral);
  423. qdf_assert_always(param);
  424. pdev = spectral->pdev_obj;
  425. qdf_assert_always(pdev);
  426. psoc = wlan_pdev_get_psoc(pdev);
  427. if (!psoc) {
  428. spectral_err("psoc is null");
  429. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  430. }
  431. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  432. if (!psoc_spectral) {
  433. spectral_err("psoc spectral object is null");
  434. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  435. }
  436. vdev = target_if_spectral_get_vdev(spectral, smode);
  437. if (!vdev)
  438. return QDF_STATUS_E_NOENT;
  439. qdf_mem_zero(&sparam, sizeof(sparam));
  440. sparam.vdev_id = wlan_vdev_get_id(vdev);
  441. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  442. sparam.count = param->ss_count;
  443. sparam.period = param->ss_period;
  444. sparam.fft_recap = param->ss_recapture;
  445. sparam.spectral_pri = param->ss_spectral_pri;
  446. sparam.fft_size = param->ss_fft_size;
  447. sparam.gc_enable = param->ss_gc_ena;
  448. sparam.restart_enable = param->ss_restart_ena;
  449. sparam.noise_floor_ref = param->ss_noise_floor_ref;
  450. sparam.init_delay = param->ss_init_delay;
  451. sparam.nb_tone_thr = param->ss_nb_tone_thr;
  452. sparam.str_bin_thr = param->ss_str_bin_thr;
  453. sparam.wb_rpt_mode = param->ss_wb_rpt_mode;
  454. sparam.rssi_rpt_mode = param->ss_rssi_rpt_mode;
  455. sparam.rssi_thr = param->ss_rssi_thr;
  456. sparam.pwr_format = param->ss_pwr_format;
  457. sparam.rpt_mode = param->ss_rpt_mode;
  458. sparam.bin_scale = param->ss_bin_scale;
  459. sparam.dbm_adj = param->ss_dbm_adj;
  460. sparam.chn_mask = param->ss_chn_mask;
  461. sparam.mode = smode;
  462. sparam.center_freq1 = param->ss_frequency.cfreq1;
  463. sparam.center_freq2 = param->ss_frequency.cfreq2;
  464. sparam.chan_width = param->ss_bandwidth;
  465. return psoc_spectral->wmi_ops.wmi_spectral_configure_cmd_send(
  466. GET_WMI_HDL_FROM_PDEV(pdev), &sparam);
  467. }
  468. /**
  469. * target_if_send_vdev_spectral_enable_cmd() - Send WMI command to
  470. * enable/disable Spectral
  471. * @spectral: Pointer to Spectral target_if internal private data
  472. * @smode: Spectral scan mode
  473. * @is_spectral_active_valid: Flag to indicate if spectral activate (trigger) is
  474. * valid
  475. * @is_spectral_active: Value of spectral activate
  476. * @is_spectral_enabled_valid: Flag to indicate if spectral enable is valid
  477. * @is_spectral_enabled: Value of spectral enable
  478. *
  479. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  480. */
  481. static int
  482. target_if_send_vdev_spectral_enable_cmd(struct target_if_spectral *spectral,
  483. enum spectral_scan_mode smode,
  484. uint8_t is_spectral_active_valid,
  485. uint8_t is_spectral_active,
  486. uint8_t is_spectral_enabled_valid,
  487. uint8_t is_spectral_enabled)
  488. {
  489. struct vdev_spectral_enable_params param;
  490. struct wlan_objmgr_psoc *psoc;
  491. struct wlan_objmgr_pdev *pdev = NULL;
  492. struct wlan_objmgr_vdev *vdev = NULL;
  493. struct target_if_psoc_spectral *psoc_spectral;
  494. qdf_assert_always(spectral);
  495. pdev = spectral->pdev_obj;
  496. qdf_assert_always(pdev);
  497. psoc = wlan_pdev_get_psoc(pdev);
  498. if (!psoc) {
  499. spectral_err("psoc is null");
  500. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  501. }
  502. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  503. if (!psoc_spectral) {
  504. spectral_err("psoc spectral object is null");
  505. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  506. }
  507. vdev = target_if_spectral_get_vdev(spectral, smode);
  508. if (!vdev)
  509. return QDF_STATUS_E_NOENT;
  510. qdf_mem_zero(&param, sizeof(param));
  511. param.vdev_id = wlan_vdev_get_id(vdev);
  512. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  513. param.active_valid = is_spectral_active_valid;
  514. param.enabled_valid = is_spectral_enabled_valid;
  515. param.active = is_spectral_active;
  516. param.enabled = is_spectral_enabled;
  517. param.mode = smode;
  518. return psoc_spectral->wmi_ops.wmi_spectral_enable_cmd_send(
  519. GET_WMI_HDL_FROM_PDEV(pdev), &param);
  520. }
  521. /**
  522. * is_spectral_arch_beryllium() - Check whether the given target Spectral
  523. * architecture is Beryllium
  524. * @target_tpe: Target type
  525. *
  526. * Return: true if the spectral architecture is Beryllium, else false
  527. */
  528. static inline bool is_spectral_arch_beryllium(uint32_t target_tpe)
  529. {
  530. if (target_tpe == TARGET_TYPE_QCN9224)
  531. return true;
  532. return false;
  533. }
  534. /**
  535. * List of supported sscan BWs. Make sure to maintain the array elements in the
  536. * same order of BWs as that of struct spectral_supported_bws bitmap.
  537. */
  538. static const enum phy_ch_width supported_sscan_bw_list[] = {
  539. CH_WIDTH_5MHZ,
  540. CH_WIDTH_10MHZ,
  541. CH_WIDTH_20MHZ,
  542. CH_WIDTH_40MHZ,
  543. CH_WIDTH_80MHZ,
  544. CH_WIDTH_160MHZ,
  545. CH_WIDTH_80P80MHZ,
  546. #ifdef WLAN_FEATURE_11BE
  547. CH_WIDTH_320MHZ,
  548. #endif
  549. };
  550. #define INVALID_SSCAN_BW_POS (-1)
  551. int get_supported_sscan_bw_pos(enum phy_ch_width sscan_bw)
  552. {
  553. int max_pos, pos;
  554. max_pos = QDF_ARRAY_SIZE(supported_sscan_bw_list);
  555. for (pos = 0; pos < max_pos; pos++) {
  556. if (supported_sscan_bw_list[pos] == sscan_bw)
  557. return pos;
  558. }
  559. return INVALID_SSCAN_BW_POS;
  560. }
  561. /**
  562. * target_if_is_sscan_bw_supported() - Check whether the given sscan_bw is
  563. * supported
  564. * @spectral: Spectral LMAC object
  565. * @smode: Spectral scan mode
  566. * @sscan_bw: Spectral scan bandwidth
  567. * @op_bw: operating bandwidth
  568. * @is_bw_supported: Pointer to the caller variable where this function
  569. * populates whether @sscan_bw is supported
  570. * @is_80_80_agile: Indicates an 80+80 agile Scan request
  571. *
  572. * Return: QDF_STATUS of operation
  573. */
  574. static QDF_STATUS
  575. target_if_is_sscan_bw_supported(struct target_if_spectral *spectral,
  576. enum spectral_scan_mode smode,
  577. enum phy_ch_width sscan_bw,
  578. enum phy_ch_width op_bw,
  579. bool *is_bw_supported,
  580. bool is_80_80_agile)
  581. {
  582. struct spectral_supported_bws *supported_bws;
  583. *is_bw_supported = false;
  584. if (op_bw >= CH_WIDTH_INVALID) {
  585. spectral_err("Invalid channel width %d", op_bw);
  586. return QDF_STATUS_E_INVAL;
  587. }
  588. if ((is_80_80_agile && sscan_bw != CH_WIDTH_80P80MHZ) ||
  589. (!is_80_80_agile && sscan_bw == CH_WIDTH_80P80MHZ)) {
  590. *is_bw_supported = false;
  591. return QDF_STATUS_SUCCESS;
  592. }
  593. /* Get the supported sscan bandwidths for this operating bandwidth */
  594. supported_bws = &spectral->supported_bws[smode][op_bw];
  595. *is_bw_supported = supported_bws->bandwidths &
  596. (1 << get_supported_sscan_bw_pos(sscan_bw));
  597. return QDF_STATUS_SUCCESS;
  598. }
  599. /**
  600. * get_max_sscan_bw() - Get the maximum sscan bandwidth for a given operating
  601. * bandwidth
  602. * @spectral: Spectral LMAC object
  603. * @smode: Spectral scan mode
  604. * @op_bw: operating bandwidth
  605. *
  606. * Return: Maximum sscan bandwidth for @op_bw on success, else CH_WIDTH_INVALID
  607. */
  608. static enum phy_ch_width
  609. get_max_sscan_bw(struct target_if_spectral *spectral,
  610. enum spectral_scan_mode smode,
  611. enum phy_ch_width op_bw)
  612. {
  613. int op_bw_pos, pos;
  614. struct spectral_supported_bws *supported_bws;
  615. supported_bws = &spectral->supported_bws[smode][op_bw];
  616. op_bw_pos = get_supported_sscan_bw_pos(op_bw);
  617. /**
  618. * Start with operating bandwidth, and keep reducing the bandwidth until
  619. * a supported sscan BW is found.
  620. */
  621. for (pos = op_bw_pos; pos >= 0; pos--) {
  622. if (supported_bws->bandwidths & (1 << pos))
  623. return supported_sscan_bw_list[pos];
  624. }
  625. return CH_WIDTH_INVALID;
  626. }
  627. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  628. * corresponding translation for Agile channel width.
  629. * @spectral: pointer to Spectral object
  630. * @op_width: operating channel width
  631. * @is_80_80_agile: Indicates an 80+80 agile Scan request
  632. *
  633. * Return: The translated channel width enum.
  634. */
  635. static enum phy_ch_width
  636. target_if_spectral_find_agile_width(struct target_if_spectral *spectral,
  637. enum phy_ch_width op_bw,
  638. bool is_80_80_agile)
  639. {
  640. enum phy_ch_width agile_width;
  641. struct wlan_objmgr_pdev *pdev;
  642. struct wlan_objmgr_psoc *psoc;
  643. if (!spectral) {
  644. spectral_err("Spectral object is null");
  645. return CH_WIDTH_INVALID;
  646. }
  647. pdev = spectral->pdev_obj;
  648. if (!pdev) {
  649. spectral_err("pdev is null");
  650. return CH_WIDTH_INVALID;
  651. }
  652. psoc = wlan_pdev_get_psoc(pdev);
  653. if (!psoc) {
  654. spectral_err("psoc is null");
  655. return CH_WIDTH_INVALID;
  656. }
  657. agile_width = get_max_sscan_bw(spectral, SPECTRAL_SCAN_MODE_AGILE,
  658. op_bw);
  659. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  660. WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  661. switch (op_bw) {
  662. case CH_WIDTH_80P80MHZ:
  663. if (!is_80_80_agile)
  664. agile_width = CH_WIDTH_160MHZ;
  665. else
  666. agile_width = CH_WIDTH_80P80MHZ;
  667. break;
  668. case CH_WIDTH_160MHZ:
  669. if (is_80_80_agile)
  670. agile_width = CH_WIDTH_80P80MHZ;
  671. else
  672. agile_width = CH_WIDTH_160MHZ;
  673. break;
  674. default:
  675. break;
  676. }
  677. }
  678. return agile_width;
  679. }
  680. /**
  681. * get_default_sscan_bw() - Get the default sscan bandwidth for a given
  682. * operating bandwidth
  683. * @spectral: Spectral LMAC object
  684. * @smode: Spectral scan mode
  685. * @is_80_80_agile: Indicates an 80+80 agile Scan request
  686. *
  687. * Return: Default sscan bandwidth for @op_bw on success, else CH_WIDTH_INVALID
  688. */
  689. static enum phy_ch_width
  690. get_default_sscan_bw(struct target_if_spectral *spectral,
  691. enum spectral_scan_mode smode,
  692. bool is_80_80_agile)
  693. {
  694. struct wlan_objmgr_vdev *vdev;
  695. enum phy_ch_width vdev_ch_width, sscan_width;
  696. vdev = target_if_spectral_get_vdev(spectral, smode);
  697. if (!vdev) {
  698. spectral_err("vdev is null");
  699. return CH_WIDTH_INVALID;
  700. }
  701. vdev_ch_width = target_if_vdev_get_ch_width(vdev);
  702. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  703. if (vdev_ch_width >= CH_WIDTH_INVALID) {
  704. spectral_err("Invalid vdev channel width %d", vdev_ch_width);
  705. return CH_WIDTH_INVALID;
  706. }
  707. switch (smode) {
  708. case SPECTRAL_SCAN_MODE_NORMAL:
  709. sscan_width = get_max_sscan_bw(spectral, smode, vdev_ch_width);
  710. break;
  711. case SPECTRAL_SCAN_MODE_AGILE:
  712. sscan_width = target_if_spectral_find_agile_width(
  713. spectral, vdev_ch_width, is_80_80_agile);
  714. break;
  715. default:
  716. sscan_width = CH_WIDTH_INVALID;
  717. break;
  718. }
  719. return sscan_width;
  720. }
  721. /**
  722. * target_if_spectral_info_init_defaults() - Helper function to load defaults
  723. * for Spectral information (parameters and state) into cache.
  724. * @spectral: Pointer to Spectral target_if internal private data
  725. * @smode: Spectral scan mode
  726. *
  727. * It is assumed that the caller has obtained the requisite lock if applicable.
  728. * Note that this is currently treated as a temporary function. Ideally, we
  729. * would like to get defaults from the firmware.
  730. *
  731. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  732. */
  733. static QDF_STATUS
  734. target_if_spectral_info_init_defaults(struct target_if_spectral *spectral,
  735. enum spectral_scan_mode smode)
  736. {
  737. struct target_if_spectral_param_state_info *info;
  738. struct wlan_objmgr_vdev *vdev = NULL;
  739. enum phy_ch_width sscan_bw;
  740. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  741. spectral_err("Invalid Spectral mode %u", smode);
  742. return QDF_STATUS_E_FAILURE;
  743. }
  744. info = &spectral->param_info[smode];
  745. /* State */
  746. info->osps_cache.osc_spectral_active = SPECTRAL_SCAN_ACTIVE_DEFAULT;
  747. info->osps_cache.osc_spectral_enabled = SPECTRAL_SCAN_ENABLE_DEFAULT;
  748. /* Parameters */
  749. info->osps_cache.osc_params.ss_count = SPECTRAL_SCAN_COUNT_DEFAULT;
  750. if (spectral->spectral_gen == SPECTRAL_GEN3)
  751. info->osps_cache.osc_params.ss_period =
  752. SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT;
  753. else
  754. info->osps_cache.osc_params.ss_period =
  755. SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT;
  756. info->osps_cache.osc_params.ss_recapture =
  757. SPECTRAL_FFT_RECAPTURE_DEFAULT;
  758. info->osps_cache.osc_params.ss_spectral_pri =
  759. SPECTRAL_SCAN_PRIORITY_DEFAULT;
  760. info->osps_cache.osc_params.ss_fft_size =
  761. SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  762. info->osps_cache.osc_params.ss_gc_ena = SPECTRAL_SCAN_GC_ENA_DEFAULT;
  763. info->osps_cache.osc_params.ss_restart_ena =
  764. SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  765. info->osps_cache.osc_params.ss_noise_floor_ref =
  766. SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  767. info->osps_cache.osc_params.ss_init_delay =
  768. SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  769. info->osps_cache.osc_params.ss_nb_tone_thr =
  770. SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  771. info->osps_cache.osc_params.ss_str_bin_thr =
  772. SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  773. info->osps_cache.osc_params.ss_wb_rpt_mode =
  774. SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  775. info->osps_cache.osc_params.ss_rssi_rpt_mode =
  776. SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  777. info->osps_cache.osc_params.ss_rssi_thr =
  778. SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  779. info->osps_cache.osc_params.ss_pwr_format =
  780. SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  781. info->osps_cache.osc_params.ss_rpt_mode =
  782. SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  783. info->osps_cache.osc_params.ss_bin_scale =
  784. SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  785. info->osps_cache.osc_params.ss_dbm_adj = SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  786. vdev = target_if_spectral_get_vdev(spectral, smode);
  787. if (!vdev)
  788. return QDF_STATUS_E_NOENT;
  789. info->osps_cache.osc_params.ss_chn_mask =
  790. wlan_vdev_mlme_get_rxchainmask(vdev);
  791. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  792. info->osps_cache.osc_params.ss_short_report =
  793. SPECTRAL_SCAN_SHORT_REPORT_DEFAULT;
  794. info->osps_cache.osc_params.ss_fft_period =
  795. SPECTRAL_SCAN_FFT_PERIOD_DEFAULT;
  796. info->osps_cache.osc_params.ss_frequency.cfreq1 =
  797. SPECTRAL_SCAN_FREQUENCY_DEFAULT;
  798. info->osps_cache.osc_params.ss_frequency.cfreq2 =
  799. SPECTRAL_SCAN_FREQUENCY_DEFAULT;
  800. sscan_bw = get_default_sscan_bw(spectral, smode, false);
  801. if (sscan_bw >= CH_WIDTH_INVALID) {
  802. spectral_err("Invalid sscan BW %u", sscan_bw);
  803. return QDF_STATUS_E_FAILURE;
  804. }
  805. info->osps_cache.osc_params.ss_bandwidth = sscan_bw;
  806. /* The cache is now valid */
  807. info->osps_cache.osc_is_valid = 1;
  808. return QDF_STATUS_SUCCESS;
  809. }
  810. /**
  811. * target_if_log_read_spectral_active() - Helper function to log whether
  812. * spectral is active after reading cache
  813. * @function_name: Function name
  814. * @output: whether spectral is active or not
  815. *
  816. * Helper function to log whether spectral is active after reading cache
  817. *
  818. * Return: none
  819. */
  820. static void
  821. target_if_log_read_spectral_active(
  822. const char *function_name,
  823. unsigned char output)
  824. {
  825. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE. Returning val=%u",
  826. function_name, output);
  827. }
  828. /**
  829. * target_if_log_read_spectral_enabled() - Helper function to log whether
  830. * spectral is enabled after reading cache
  831. * @function_name: Function name
  832. * @output: whether spectral is enabled or not
  833. *
  834. * Helper function to log whether spectral is enabled after reading cache
  835. *
  836. * Return: none
  837. */
  838. static void
  839. target_if_log_read_spectral_enabled(
  840. const char *function_name,
  841. unsigned char output)
  842. {
  843. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED. Returning val=%u",
  844. function_name, output);
  845. }
  846. /**
  847. * target_if_log_read_spectral_enabled() - Helper function to log spectral
  848. * parameters after reading cache
  849. * @function_name: Function name
  850. * @pparam: Spectral parameters
  851. *
  852. * Helper function to log spectral parameters after reading cache
  853. *
  854. * Return: none
  855. */
  856. static void
  857. target_if_log_read_spectral_params(
  858. const char *function_name,
  859. struct spectral_config *pparam)
  860. {
  861. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_PARAMS. Returning following params:\nss_count = %u\nss_period = %u\nss_recapture = %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",
  862. function_name,
  863. pparam->ss_count,
  864. pparam->ss_period,
  865. pparam->ss_recapture,
  866. pparam->ss_spectral_pri,
  867. pparam->ss_fft_size,
  868. pparam->ss_gc_ena,
  869. pparam->ss_restart_ena,
  870. (int8_t)pparam->ss_noise_floor_ref,
  871. pparam->ss_init_delay,
  872. pparam->ss_nb_tone_thr,
  873. pparam->ss_str_bin_thr,
  874. pparam->ss_wb_rpt_mode,
  875. pparam->ss_rssi_rpt_mode,
  876. (int8_t)pparam->ss_rssi_thr,
  877. pparam->ss_pwr_format,
  878. pparam->ss_rpt_mode,
  879. pparam->ss_bin_scale,
  880. pparam->ss_dbm_adj,
  881. pparam->ss_chn_mask,
  882. pparam->ss_frequency.cfreq1,
  883. pparam->ss_frequency.cfreq2);
  884. }
  885. /**
  886. * target_if_log_read_spectral_active_catch_validate() - Helper function to
  887. * log whether spectral is active after intializing the cache
  888. * @function_name: Function name
  889. * @output: whether spectral is active or not
  890. *
  891. * Helper function to log whether spectral is active after intializing cache
  892. *
  893. * Return: none
  894. */
  895. static void
  896. target_if_log_read_spectral_active_catch_validate(
  897. const char *function_name,
  898. unsigned char output)
  899. {
  900. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE on initial cache validation\nReturning val=%u",
  901. function_name, output);
  902. }
  903. /**
  904. * target_if_log_read_spectral_enabled_catch_validate() - Helper function to
  905. * log whether spectral is enabled after intializing the cache
  906. * @function_name: Function name
  907. * @output: whether spectral is enabled or not
  908. *
  909. * Helper function to log whether spectral is enabled after intializing cache
  910. *
  911. * Return: none
  912. */
  913. static void
  914. target_if_log_read_spectral_enabled_catch_validate(
  915. const char *function_name,
  916. unsigned char output)
  917. {
  918. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED on initial cache validation\nReturning val=%u\n",
  919. function_name, output);
  920. }
  921. /**
  922. * target_if_log_read_spectral_params_catch_validate() - Helper function to
  923. * log spectral parameters after intializing the cache
  924. * @function_name: Function name
  925. * @pparam: Spectral parameters
  926. *
  927. * Helper function to log spectral parameters after intializing the cache
  928. *
  929. * Return: none
  930. */
  931. static void
  932. target_if_log_read_spectral_params_catch_validate(
  933. const char *function_name,
  934. struct spectral_config *pparam)
  935. {
  936. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_PARAMS on initial cache validation\nReturning following params:\nss_count = %u\nss_period = %u\nss_recapture = %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",
  937. function_name,
  938. pparam->ss_count,
  939. pparam->ss_period,
  940. pparam->ss_recapture,
  941. pparam->ss_spectral_pri,
  942. pparam->ss_fft_size,
  943. pparam->ss_gc_ena,
  944. pparam->ss_restart_ena,
  945. (int8_t)pparam->ss_noise_floor_ref,
  946. pparam->ss_init_delay,
  947. pparam->ss_nb_tone_thr,
  948. pparam->ss_str_bin_thr,
  949. pparam->ss_wb_rpt_mode,
  950. pparam->ss_rssi_rpt_mode,
  951. (int8_t)pparam->ss_rssi_thr,
  952. pparam->ss_pwr_format,
  953. pparam->ss_rpt_mode,
  954. pparam->ss_bin_scale,
  955. pparam->ss_dbm_adj, pparam->ss_chn_mask);
  956. }
  957. /**
  958. * target_if_spectral_info_read() - Read spectral information from the cache.
  959. * @spectral: Pointer to Spectral target_if internal private data
  960. * @smode: Spectral scan mode
  961. * @specifier: target_if_spectral_info enumeration specifying which
  962. * information is required
  963. * @output: Void output pointer into which the information will be read
  964. * @output_len: size of object pointed to by output pointer
  965. *
  966. * Read spectral parameters or the desired state information from the cache.
  967. *
  968. * Return: 0 on success, negative error code on failure
  969. */
  970. static int
  971. target_if_spectral_info_read(
  972. struct target_if_spectral *spectral,
  973. enum spectral_scan_mode smode,
  974. enum target_if_spectral_info specifier,
  975. void *output, int output_len)
  976. {
  977. /*
  978. * Note: This function is designed to be able to accommodate
  979. * WMI reads for defaults, non-cacheable information, etc
  980. * if required.
  981. */
  982. struct target_if_spectral_param_state_info *info;
  983. int is_cacheable = 0;
  984. int init_def_retval = 0;
  985. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  986. spectral_err("Invalid Spectral mode %u", smode);
  987. return -EINVAL;
  988. }
  989. info = &spectral->param_info[smode];
  990. if (!output)
  991. return -EINVAL;
  992. switch (specifier) {
  993. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  994. if (output_len != sizeof(info->osps_cache.osc_spectral_active))
  995. return -EINVAL;
  996. is_cacheable = 1;
  997. break;
  998. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  999. if (output_len != sizeof(info->osps_cache.osc_spectral_enabled))
  1000. return -EINVAL;
  1001. is_cacheable = 1;
  1002. break;
  1003. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  1004. if (output_len != sizeof(info->osps_cache.osc_params))
  1005. return -EINVAL;
  1006. is_cacheable = 1;
  1007. break;
  1008. default:
  1009. spectral_err("Unknown target_if_spectral_info specifier");
  1010. return -EINVAL;
  1011. }
  1012. qdf_spin_lock_bh(&info->osps_lock);
  1013. if (is_cacheable) {
  1014. if (info->osps_cache.osc_is_valid) {
  1015. switch (specifier) {
  1016. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  1017. qdf_mem_copy(
  1018. output,
  1019. &info->osps_cache.osc_spectral_active,
  1020. sizeof(info->osps_cache.osc_spectral_active));
  1021. target_if_log_read_spectral_active(
  1022. __func__,
  1023. *((unsigned char *)output));
  1024. break;
  1025. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  1026. qdf_mem_copy(
  1027. output,
  1028. &info->osps_cache.osc_spectral_enabled,
  1029. sizeof(
  1030. info->osps_cache.osc_spectral_enabled));
  1031. target_if_log_read_spectral_enabled(
  1032. __func__,
  1033. *((unsigned char *)output));
  1034. break;
  1035. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  1036. qdf_mem_copy(
  1037. output,
  1038. &info->osps_cache.osc_params,
  1039. sizeof(info->osps_cache.osc_params));
  1040. target_if_log_read_spectral_params(
  1041. __func__,
  1042. (struct spectral_config *)output);
  1043. break;
  1044. default:
  1045. /* We can't reach this point */
  1046. break;
  1047. }
  1048. qdf_spin_unlock_bh(&info->osps_lock);
  1049. return 0;
  1050. }
  1051. }
  1052. /* Cache is invalid */
  1053. /*
  1054. * If WMI Reads are implemented to fetch defaults/non-cacheable info,
  1055. * then the below implementation will change
  1056. */
  1057. init_def_retval =
  1058. target_if_spectral_info_init_defaults(spectral, smode);
  1059. if (init_def_retval != QDF_STATUS_SUCCESS) {
  1060. qdf_spin_unlock_bh(&info->osps_lock);
  1061. if (init_def_retval == QDF_STATUS_E_NOENT)
  1062. return -ENOENT;
  1063. else
  1064. return -EINVAL;
  1065. }
  1066. /* target_if_spectral_info_init_defaults() has set cache to valid */
  1067. switch (specifier) {
  1068. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  1069. qdf_mem_copy(output,
  1070. &info->osps_cache.osc_spectral_active,
  1071. sizeof(info->osps_cache.osc_spectral_active));
  1072. target_if_log_read_spectral_active_catch_validate(
  1073. __func__,
  1074. *((unsigned char *)output));
  1075. break;
  1076. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  1077. qdf_mem_copy(output,
  1078. &info->osps_cache.osc_spectral_enabled,
  1079. sizeof(info->osps_cache.osc_spectral_enabled));
  1080. target_if_log_read_spectral_enabled_catch_validate(
  1081. __func__,
  1082. *((unsigned char *)output));
  1083. break;
  1084. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  1085. qdf_mem_copy(output,
  1086. &info->osps_cache.osc_params,
  1087. sizeof(info->osps_cache.osc_params));
  1088. target_if_log_read_spectral_params_catch_validate(
  1089. __func__,
  1090. (struct spectral_config *)output);
  1091. break;
  1092. default:
  1093. /* We can't reach this point */
  1094. break;
  1095. }
  1096. qdf_spin_unlock_bh(&info->osps_lock);
  1097. return 0;
  1098. }
  1099. /**
  1100. * target_if_log_write_spectral_active() - Helper function to log inputs and
  1101. * return value of call to configure the Spectral 'active' configuration,
  1102. * TARGET_IF_SPECTRAL_INFO_ACTIVE into firmware
  1103. * @function_name: Function name in which this is called
  1104. * @pval: whether spectral is active or not
  1105. * @ret: return value of the firmware write function
  1106. *
  1107. * Return: none
  1108. */
  1109. static void
  1110. target_if_log_write_spectral_active(
  1111. const char *function_name,
  1112. uint8_t pval,
  1113. int ret)
  1114. {
  1115. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE with val=%u status=%d",
  1116. function_name, pval, ret);
  1117. }
  1118. /**
  1119. * target_if_log_write_spectral_enabled() - Helper function to log inputs and
  1120. * return value of call to configure the Spectral 'enabled' configuration,
  1121. * TARGET_IF_SPECTRAL_INFO_ENABLED into firmware
  1122. * @function_name: Function name in which this is called
  1123. * @pval: whether spectral is enabled or not
  1124. * @ret: return value of the firmware write function
  1125. *
  1126. * Return: none
  1127. */
  1128. static void
  1129. target_if_log_write_spectral_enabled(
  1130. const char *function_name,
  1131. uint8_t pval,
  1132. int ret)
  1133. {
  1134. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED with val=%u status=%d",
  1135. function_name, pval, ret);
  1136. }
  1137. /**
  1138. * target_if_log_write_spectral_params() - Helper function to log inputs and
  1139. * return value of call to configure Spectral parameters,
  1140. * TARGET_IF_SPECTRAL_INFO_PARAMS into firmware
  1141. * @param: Spectral parameters
  1142. * @function_name: Function name in which this is called
  1143. * @ret: return value of the firmware write function
  1144. *
  1145. * Return: none
  1146. */
  1147. static void
  1148. target_if_log_write_spectral_params(
  1149. struct spectral_config *param,
  1150. const char *function_name,
  1151. int ret)
  1152. {
  1153. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_PARAMS. Params:\nss_count = %u\nss_period = %u\nss_recapture = %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",
  1154. function_name,
  1155. param->ss_count,
  1156. param->ss_period,
  1157. param->ss_recapture,
  1158. param->ss_spectral_pri,
  1159. param->ss_fft_size,
  1160. param->ss_gc_ena,
  1161. param->ss_restart_ena,
  1162. (int8_t)param->ss_noise_floor_ref,
  1163. param->ss_init_delay,
  1164. param->ss_nb_tone_thr,
  1165. param->ss_str_bin_thr,
  1166. param->ss_wb_rpt_mode,
  1167. param->ss_rssi_rpt_mode,
  1168. (int8_t)param->ss_rssi_thr,
  1169. param->ss_pwr_format,
  1170. param->ss_rpt_mode,
  1171. param->ss_bin_scale,
  1172. param->ss_dbm_adj,
  1173. param->ss_chn_mask,
  1174. param->ss_frequency.cfreq1,
  1175. param->ss_frequency.cfreq2,
  1176. ret);
  1177. }
  1178. /**
  1179. * target_if_spectral_info_write() - Write Spectral information to the
  1180. * firmware, and update cache
  1181. * @spectral: Pointer to Spectral target_if internal private data
  1182. * @smode: Spectral scan mode
  1183. * @specifier: target_if_spectral_info enumeration specifying which
  1184. * information is involved
  1185. * @input: void input pointer containing the information to be written
  1186. * @input_len: size of object pointed to by input pointer
  1187. *
  1188. * Write Spectral parameters or the desired state information to
  1189. * the firmware, and update cache
  1190. *
  1191. * Return: 0 on success, negative error code on failure
  1192. */
  1193. static int
  1194. target_if_spectral_info_write(
  1195. struct target_if_spectral *spectral,
  1196. enum spectral_scan_mode smode,
  1197. enum target_if_spectral_info specifier,
  1198. void *input, int input_len)
  1199. {
  1200. struct target_if_spectral_param_state_info *info;
  1201. int ret;
  1202. uint8_t *pval = NULL;
  1203. struct spectral_config *param = NULL;
  1204. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1205. spectral_err("Invalid Spectral mode %u", smode);
  1206. return -EINVAL;
  1207. }
  1208. info = &spectral->param_info[smode];
  1209. if (!input)
  1210. return -EINVAL;
  1211. switch (specifier) {
  1212. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  1213. if (input_len != sizeof(info->osps_cache.osc_spectral_active))
  1214. return -EINVAL;
  1215. pval = (uint8_t *)input;
  1216. qdf_spin_lock_bh(&info->osps_lock);
  1217. ret = target_if_send_vdev_spectral_enable_cmd(spectral, smode,
  1218. 1, *pval, 0, 0);
  1219. target_if_log_write_spectral_active(
  1220. __func__,
  1221. *pval,
  1222. ret);
  1223. if (ret < 0) {
  1224. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  1225. ret);
  1226. qdf_spin_unlock_bh(&info->osps_lock);
  1227. return ret;
  1228. }
  1229. info->osps_cache.osc_spectral_active = *pval;
  1230. /* The cache is now valid */
  1231. info->osps_cache.osc_is_valid = 1;
  1232. qdf_spin_unlock_bh(&info->osps_lock);
  1233. break;
  1234. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  1235. if (input_len != sizeof(info->osps_cache.osc_spectral_enabled))
  1236. return -EINVAL;
  1237. pval = (uint8_t *)input;
  1238. qdf_spin_lock_bh(&info->osps_lock);
  1239. ret = target_if_send_vdev_spectral_enable_cmd(spectral, smode,
  1240. 0, 0, 1, *pval);
  1241. target_if_log_write_spectral_enabled(
  1242. __func__,
  1243. *pval,
  1244. ret);
  1245. if (ret < 0) {
  1246. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  1247. ret);
  1248. qdf_spin_unlock_bh(&info->osps_lock);
  1249. return ret;
  1250. }
  1251. info->osps_cache.osc_spectral_enabled = *pval;
  1252. /* The cache is now valid */
  1253. info->osps_cache.osc_is_valid = 1;
  1254. qdf_spin_unlock_bh(&info->osps_lock);
  1255. break;
  1256. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  1257. if (input_len != sizeof(info->osps_cache.osc_params))
  1258. return -EINVAL;
  1259. param = (struct spectral_config *)input;
  1260. qdf_spin_lock_bh(&info->osps_lock);
  1261. ret = target_if_send_vdev_spectral_configure_cmd(spectral,
  1262. smode, param);
  1263. target_if_log_write_spectral_params(
  1264. param,
  1265. __func__,
  1266. ret);
  1267. if (ret < 0) {
  1268. spectral_err("target_if_send_vdev_spectral_configure_cmd failed with error=%d",
  1269. ret);
  1270. qdf_spin_unlock_bh(&info->osps_lock);
  1271. return ret;
  1272. }
  1273. qdf_mem_copy(&info->osps_cache.osc_params,
  1274. param, sizeof(info->osps_cache.osc_params));
  1275. /* The cache is now valid */
  1276. info->osps_cache.osc_is_valid = 1;
  1277. qdf_spin_unlock_bh(&info->osps_lock);
  1278. break;
  1279. default:
  1280. spectral_err("Unknown target_if_spectral_info specifier");
  1281. return -EINVAL;
  1282. }
  1283. return 0;
  1284. }
  1285. /**
  1286. * target_if_spectral_get_tsf64() - Function to get the TSF value
  1287. * @arg: Pointer to handle for Spectral target_if internal private data
  1288. *
  1289. * Get the last TSF received in WMI buffer
  1290. *
  1291. * Return: TSF value
  1292. */
  1293. static uint64_t
  1294. target_if_spectral_get_tsf64(void *arg)
  1295. {
  1296. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1297. return spectral->tsf64;
  1298. }
  1299. /**
  1300. * target_if_spectral_get_capability() - Function to get whether a
  1301. * given Spectral hardware capability is available
  1302. * @arg: Pointer to handle for Spectral target_if internal private data
  1303. * @type: Spectral hardware capability type
  1304. *
  1305. * Get whether a given Spectral hardware capability is available
  1306. *
  1307. * Return: True if the capability is available, false if the capability is not
  1308. * available
  1309. */
  1310. uint32_t
  1311. target_if_spectral_get_capability(void *arg, enum spectral_capability_type type)
  1312. {
  1313. int status = STATUS_FAIL;
  1314. switch (type) {
  1315. case SPECTRAL_CAP_PHYDIAG:
  1316. case SPECTRAL_CAP_RADAR:
  1317. case SPECTRAL_CAP_SPECTRAL_SCAN:
  1318. case SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN:
  1319. status = STATUS_PASS;
  1320. break;
  1321. default:
  1322. status = STATUS_FAIL;
  1323. }
  1324. return status;
  1325. }
  1326. /**
  1327. * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
  1328. * @arg: Pointer to handle for Spectral target_if internal private data
  1329. * @rxfilter: Rx filter to be used
  1330. *
  1331. * Note: This is only a placeholder function. It is not currently required since
  1332. * FW should be taking care of setting the required filters.
  1333. *
  1334. * Return: 0
  1335. */
  1336. uint32_t
  1337. target_if_spectral_set_rxfilter(void *arg, int rxfilter)
  1338. {
  1339. /*
  1340. * Will not be required since enabling of spectral in firmware
  1341. * will take care of this
  1342. */
  1343. return 0;
  1344. }
  1345. /**
  1346. * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
  1347. * @arg: Pointer to handle for Spectral target_if internal private data
  1348. *
  1349. * Note: This is only a placeholder function. It is not currently required since
  1350. * FW should be taking care of setting the required filters.
  1351. *
  1352. * Return: 0
  1353. */
  1354. uint32_t
  1355. target_if_spectral_get_rxfilter(void *arg)
  1356. {
  1357. /*
  1358. * Will not be required since enabling of spectral in firmware
  1359. * will take care of this
  1360. */
  1361. return 0;
  1362. }
  1363. /**
  1364. * target_if_sops_is_spectral_active() - Get whether Spectral is active
  1365. * @arg: Pointer to handle for Spectral target_if internal private data
  1366. * @smode: Spectral scan mode
  1367. *
  1368. * Function to check whether Spectral is active
  1369. *
  1370. * Return: True if Spectral is active, false if Spectral is not active
  1371. */
  1372. uint32_t
  1373. target_if_sops_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  1374. {
  1375. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1376. uint8_t val = 0;
  1377. int ret;
  1378. ret = target_if_spectral_info_read(
  1379. spectral,
  1380. smode,
  1381. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  1382. &val, sizeof(val));
  1383. if (ret != 0) {
  1384. /*
  1385. * Could not determine if Spectral is active.
  1386. * Return false as a safe value.
  1387. * XXX: Consider changing the function prototype
  1388. * to be able to indicate failure to fetch value.
  1389. */
  1390. return 0;
  1391. }
  1392. return val;
  1393. }
  1394. /**
  1395. * target_if_sops_is_spectral_enabled() - Get whether Spectral is enabled
  1396. * @arg: Pointer to handle for Spectral target_if internal private data
  1397. * @smode: Spectral scan mode
  1398. *
  1399. * Function to check whether Spectral is enabled
  1400. *
  1401. * Return: True if Spectral is enabled, false if Spectral is not enabled
  1402. */
  1403. uint32_t
  1404. target_if_sops_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  1405. {
  1406. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1407. uint8_t val = 0;
  1408. int ret;
  1409. ret = target_if_spectral_info_read(
  1410. spectral,
  1411. smode,
  1412. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1413. &val, sizeof(val));
  1414. if (ret != 0) {
  1415. /*
  1416. * Could not determine if Spectral is enabled.
  1417. * Return false as a safe value.
  1418. * XXX: Consider changing the function prototype
  1419. * to be able to indicate failure to fetch value.
  1420. */
  1421. return 0;
  1422. }
  1423. return val;
  1424. }
  1425. /**
  1426. * target_if_sops_start_spectral_scan() - Start Spectral scan
  1427. * @arg: Pointer to handle for Spectral target_if internal private data
  1428. * @smode: Spectral scan mode
  1429. * @err: Spectral error code
  1430. *
  1431. * Function to start spectral scan
  1432. *
  1433. * Return: 0 on success else failure
  1434. */
  1435. uint32_t
  1436. target_if_sops_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  1437. enum spectral_cp_error_code *err)
  1438. {
  1439. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1440. uint8_t val = 1;
  1441. uint8_t enabled = 0;
  1442. int ret;
  1443. ret = target_if_spectral_info_read(
  1444. spectral,
  1445. smode,
  1446. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1447. &enabled, sizeof(enabled));
  1448. if (ret != 0) {
  1449. /*
  1450. * Could not determine if Spectral is enabled. Assume we need
  1451. * to enable it
  1452. */
  1453. enabled = 0;
  1454. }
  1455. if (!enabled) {
  1456. ret = target_if_spectral_info_write(
  1457. spectral,
  1458. smode,
  1459. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1460. &val, sizeof(val));
  1461. if (ret != 0)
  1462. return ret;
  1463. }
  1464. ret = target_if_spectral_info_write(
  1465. spectral,
  1466. smode,
  1467. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  1468. &val, sizeof(val));
  1469. if (ret != 0)
  1470. return ret;
  1471. return 0;
  1472. }
  1473. /**
  1474. * target_if_sops_stop_spectral_scan() - Stop Spectral scan
  1475. * @arg: Pointer to handle for Spectral target_if internal private data
  1476. * @smode: Spectral scan mode
  1477. *
  1478. * Function to stop spectral scan
  1479. *
  1480. * Return: 0 on success else failure
  1481. */
  1482. uint32_t
  1483. target_if_sops_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  1484. {
  1485. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1486. uint8_t val = 0;
  1487. int tempret, ret = 0;
  1488. uint8_t enabled = 0;
  1489. tempret = target_if_spectral_info_read(
  1490. spectral,
  1491. smode,
  1492. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1493. &enabled, sizeof(enabled));
  1494. if (tempret)
  1495. /*
  1496. * Could not determine if Spectral is enabled. Assume scan is
  1497. * not in progress
  1498. */
  1499. enabled = 0;
  1500. /* if scan is not enabled, no need to send stop to FW */
  1501. if (!enabled)
  1502. return -EPERM;
  1503. tempret = target_if_spectral_info_write(
  1504. spectral,
  1505. smode,
  1506. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  1507. &val, sizeof(val));
  1508. if (tempret != 0)
  1509. ret = tempret;
  1510. tempret = target_if_spectral_info_write(
  1511. spectral,
  1512. smode,
  1513. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1514. &val, sizeof(val));
  1515. if (tempret != 0)
  1516. ret = tempret;
  1517. if (ret == 0 && smode == SPECTRAL_SCAN_MODE_AGILE) {
  1518. struct target_if_spectral_ops *p_sops;
  1519. struct spectral_config *sparams;
  1520. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1521. sparams = &spectral->params[smode];
  1522. sparams->ss_frequency.cfreq1 = 0;
  1523. sparams->ss_frequency.cfreq2 = 0;
  1524. p_sops->configure_spectral(spectral, sparams, smode);
  1525. }
  1526. return ret;
  1527. }
  1528. /**
  1529. * target_if_spectral_get_extension_channel() - Get the Extension channel
  1530. * @arg: Pointer to handle for Spectral target_if internal private data
  1531. * @smode: Spectral scan mode
  1532. *
  1533. * Function to get the current Extension channel (in MHz)
  1534. *
  1535. * Return: Current Extension channel (in MHz) on success, 0 on failure or if
  1536. * extension channel is not present.
  1537. */
  1538. uint32_t
  1539. target_if_spectral_get_extension_channel(void *arg,
  1540. enum spectral_scan_mode smode)
  1541. {
  1542. /*
  1543. * XXX: Once we expand to use cases where Spectral could be activated
  1544. * without a channel being set to VDEV, we need to consider returning a
  1545. * negative value in case of failure and having all callers handle this.
  1546. */
  1547. struct target_if_spectral *spectral = NULL;
  1548. struct wlan_objmgr_vdev *vdev = NULL;
  1549. uint16_t sec20chan_freq = 0;
  1550. qdf_assert_always(arg);
  1551. spectral = (struct target_if_spectral *)arg;
  1552. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1553. spectral_err("Invalid Spectral mode %u", smode);
  1554. return 0;
  1555. }
  1556. vdev = target_if_spectral_get_vdev(spectral, smode);
  1557. if (!vdev)
  1558. return 0;
  1559. if (target_if_vdev_get_sec20chan_freq_mhz(vdev, &sec20chan_freq) < 0) {
  1560. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1561. return 0;
  1562. }
  1563. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1564. return sec20chan_freq;
  1565. }
  1566. /**
  1567. * target_if_spectral_get_current_channel() - Get the current channel
  1568. * @arg: Pointer to handle for Spectral target_if internal private data
  1569. * @smode: Spectral scan mode
  1570. *
  1571. * Function to get the current channel (in MHz)
  1572. *
  1573. * Return: Current channel (in MHz) on success, 0 on failure
  1574. */
  1575. uint32_t
  1576. target_if_spectral_get_current_channel(void *arg, enum spectral_scan_mode smode)
  1577. {
  1578. /*
  1579. * XXX: Once we expand to use cases where Spectral could be activated
  1580. * without a channel being set to VDEV, we need to consider returning a
  1581. * negative value in case of failure and having all callers handle this.
  1582. */
  1583. struct target_if_spectral *spectral = NULL;
  1584. int16_t chan_freq = 0;
  1585. struct wlan_objmgr_vdev *vdev = NULL;
  1586. qdf_assert_always(arg);
  1587. spectral = (struct target_if_spectral *)arg;
  1588. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1589. spectral_err("Invalid Spectral mode %u", smode);
  1590. return 0;
  1591. }
  1592. vdev = target_if_spectral_get_vdev(spectral, smode);
  1593. if (!vdev)
  1594. return 0;
  1595. chan_freq = target_if_vdev_get_chan_freq(vdev);
  1596. if (chan_freq < 0) {
  1597. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1598. return 0;
  1599. }
  1600. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1601. return chan_freq;
  1602. }
  1603. /**
  1604. * target_if_spectral_reset_hw() - Reset the hardware
  1605. * @arg: Pointer to handle for Spectral target_if internal private data
  1606. *
  1607. * This is only a placeholder since it is not currently required in the offload
  1608. * case.
  1609. *
  1610. * Return: 0
  1611. */
  1612. uint32_t
  1613. target_if_spectral_reset_hw(void *arg)
  1614. {
  1615. not_yet_implemented();
  1616. return 0;
  1617. }
  1618. /**
  1619. * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
  1620. * Noisefloor history buffer
  1621. * @arg: Pointer to handle for Spectral target_if internal private data
  1622. * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
  1623. *
  1624. * This is only a placeholder since it is not currently required in the offload
  1625. * case.
  1626. *
  1627. * Return: 0
  1628. */
  1629. uint32_t
  1630. target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1631. {
  1632. not_yet_implemented();
  1633. return 0;
  1634. }
  1635. /**
  1636. * target_if_spectral_get_ext_noisefloor() - Get the extension channel
  1637. * noisefloor
  1638. * @arg: Pointer to handle for Spectral target_if internal private data
  1639. *
  1640. * This is only a placeholder since it is not currently required in the offload
  1641. * case.
  1642. *
  1643. * Return: 0
  1644. */
  1645. int8_t
  1646. target_if_spectral_get_ext_noisefloor(void *arg)
  1647. {
  1648. not_yet_implemented();
  1649. return 0;
  1650. }
  1651. /**
  1652. * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
  1653. * @arg: Pointer to handle for Spectral target_if internal private data
  1654. *
  1655. * This is only a placeholder since it is not currently required in the offload
  1656. * case.
  1657. *
  1658. * Return: 0
  1659. */
  1660. int8_t
  1661. target_if_spectral_get_ctl_noisefloor(void *arg)
  1662. {
  1663. not_yet_implemented();
  1664. return 0;
  1665. }
  1666. /**
  1667. * target_if_spectral_sops_configure_params() - Configure user supplied Spectral
  1668. * parameters
  1669. * @arg: Pointer to handle for Spectral target_if internal private data
  1670. * @params: Spectral parameters
  1671. * @smode: Spectral scan mode
  1672. *
  1673. * Function to configure spectral parameters
  1674. *
  1675. * Return: 0 on success else failure
  1676. */
  1677. uint32_t
  1678. target_if_spectral_sops_configure_params(
  1679. void *arg, struct spectral_config *params,
  1680. enum spectral_scan_mode smode)
  1681. {
  1682. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1683. return target_if_spectral_info_write(
  1684. spectral,
  1685. smode,
  1686. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1687. params, sizeof(*params));
  1688. }
  1689. /**
  1690. * target_if_spectral_sops_get_params() - Get user configured Spectral
  1691. * parameters
  1692. * @arg: Pointer to handle for Spectral target_if internal private data
  1693. * @params: Pointer to buffer into which Spectral parameters should be copied
  1694. * @smode: Spectral scan mode
  1695. *
  1696. * Function to get the configured spectral parameters
  1697. *
  1698. * Return: 0 on success else failure
  1699. */
  1700. uint32_t
  1701. target_if_spectral_sops_get_params(void *arg, struct spectral_config *params,
  1702. enum spectral_scan_mode smode)
  1703. {
  1704. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1705. return target_if_spectral_info_read(
  1706. spectral,
  1707. smode,
  1708. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1709. params, sizeof(*params));
  1710. }
  1711. /**
  1712. * target_if_spectral_get_ent_mask() - Get enterprise mask
  1713. * @arg: Pointer to handle for Spectral target_if internal private data
  1714. *
  1715. * This is only a placeholder since it is not currently required in the offload
  1716. * case.
  1717. *
  1718. * Return: 0
  1719. */
  1720. static uint32_t
  1721. target_if_spectral_get_ent_mask(void *arg)
  1722. {
  1723. not_yet_implemented();
  1724. return 0;
  1725. }
  1726. /**
  1727. * target_if_spectral_get_macaddr() - Get radio MAC address
  1728. * @arg: Pointer to handle for Spectral target_if internal private data
  1729. * @addr: Pointer to buffer into which MAC address should be copied
  1730. *
  1731. * Function to get the MAC address of the pdev
  1732. *
  1733. * Return: 0 on success, -1 on failure
  1734. */
  1735. static uint32_t
  1736. target_if_spectral_get_macaddr(void *arg, char *addr)
  1737. {
  1738. uint8_t *myaddr = NULL;
  1739. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1740. struct wlan_objmgr_pdev *pdev = NULL;
  1741. pdev = spectral->pdev_obj;
  1742. wlan_pdev_obj_lock(pdev);
  1743. myaddr = wlan_pdev_get_hw_macaddr(pdev);
  1744. wlan_pdev_obj_unlock(pdev);
  1745. qdf_mem_copy(addr, myaddr, QDF_MAC_ADDR_SIZE);
  1746. return 0;
  1747. }
  1748. /**
  1749. * target_if_init_spectral_param_min_max_be() - Initialize Spectral parameter
  1750. * min and max values for beryllium chipsets
  1751. *
  1752. * @spectral: Spectral LMAC object
  1753. *
  1754. * Return: QDF_STATUS of operation
  1755. */
  1756. static QDF_STATUS
  1757. target_if_init_spectral_param_min_max_be(struct target_if_spectral *spectral)
  1758. {
  1759. struct spectral_param_min_max *param_min_max;
  1760. enum phy_ch_width op_bw;
  1761. QDF_STATUS status;
  1762. param_min_max = &spectral->param_min_max;
  1763. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3_BE;
  1764. for (op_bw = CH_WIDTH_20MHZ; op_bw < CH_WIDTH_MAX; op_bw++) {
  1765. bool is_supported;
  1766. status = wlan_reg_is_chwidth_supported(spectral->pdev_obj,
  1767. op_bw, &is_supported);
  1768. if (QDF_IS_STATUS_ERROR(status)) {
  1769. spectral_err("Unable to check if ch_width(%d) is supported",
  1770. op_bw);
  1771. return QDF_STATUS_E_FAILURE;
  1772. }
  1773. if (!is_supported) {
  1774. param_min_max->fft_size_max[op_bw] = INVALID_FFT_SIZE;
  1775. continue;
  1776. }
  1777. switch (op_bw) {
  1778. case CH_WIDTH_20MHZ:
  1779. param_min_max->fft_size_max[op_bw] =
  1780. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_BE_20MHZ;
  1781. break;
  1782. case CH_WIDTH_40MHZ:
  1783. param_min_max->fft_size_max[op_bw] =
  1784. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_BE_40MHZ;
  1785. break;
  1786. default:
  1787. param_min_max->fft_size_max[op_bw] =
  1788. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_BE;
  1789. }
  1790. }
  1791. return QDF_STATUS_SUCCESS;
  1792. }
  1793. /**
  1794. * target_if_init_spectral_param_min_max() - Initialize Spectral parameter
  1795. * min and max values
  1796. *
  1797. * @spectral: Spectral LMAC object
  1798. * @gen: Spectral HW generation
  1799. * @target_type: Target type
  1800. *
  1801. * Initialize Spectral parameter min and max values
  1802. *
  1803. * Return: QDF_STATUS
  1804. */
  1805. static QDF_STATUS
  1806. target_if_init_spectral_param_min_max(
  1807. struct target_if_spectral *spectral,
  1808. enum spectral_gen gen, uint32_t target_type)
  1809. {
  1810. struct spectral_param_min_max *param_min_max;
  1811. if (!spectral) {
  1812. spectral_err("Spectral LMAC object is null");
  1813. return QDF_STATUS_E_NULL_VALUE;
  1814. }
  1815. if (is_spectral_arch_beryllium(target_type))
  1816. return target_if_init_spectral_param_min_max_be(spectral);
  1817. param_min_max = &spectral->param_min_max;
  1818. switch (gen) {
  1819. case SPECTRAL_GEN3:
  1820. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3;
  1821. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1822. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1823. if (target_type == TARGET_TYPE_QCN9000 ||
  1824. target_type == TARGET_TYPE_QCN6122 ||
  1825. target_type == TARGET_TYPE_QCA5018 ||
  1826. target_type == TARGET_TYPE_QCA6490 ||
  1827. target_type == TARGET_TYPE_KIWI ||
  1828. target_type == TARGET_TYPE_MANGO) {
  1829. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1830. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1831. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1832. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1833. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1834. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1835. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1836. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1837. } else {
  1838. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1839. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1840. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1841. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1842. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1843. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1844. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1845. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1846. }
  1847. break;
  1848. case SPECTRAL_GEN2:
  1849. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1850. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1851. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1852. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1853. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1854. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1855. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1856. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1857. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1858. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1859. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1860. break;
  1861. default:
  1862. spectral_err("Invalid spectral generation %d", gen);
  1863. return QDF_STATUS_E_INVAL;
  1864. }
  1865. return QDF_STATUS_SUCCESS;
  1866. }
  1867. /**
  1868. * target_if_init_spectral_param_properties() - Initialize Spectral parameter
  1869. * properties
  1870. * @spectral: Pointer to Spectral target_if internal private data
  1871. *
  1872. * Initialize Spectral parameter properties
  1873. *
  1874. * Return: QDF_STATUS
  1875. */
  1876. static QDF_STATUS
  1877. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1878. {
  1879. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1880. int param;
  1881. /* Initialize default values for properties.
  1882. * Default values are supported for all the parameters for all modes
  1883. * and allows different values for each mode for all the parameters .
  1884. */
  1885. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1886. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1887. spectral->properties[smode][param].supported = true;
  1888. spectral->properties[smode][param].common_all_modes =
  1889. false;
  1890. }
  1891. }
  1892. /* Once FW advertisement is in place remove this hard coding */
  1893. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1894. spectral->properties[SPECTRAL_SCAN_MODE_NORMAL]
  1895. [SPECTRAL_PARAM_FREQUENCY].supported = false;
  1896. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1897. spectral->properties[smode]
  1898. [SPECTRAL_PARAM_SPECT_PRI].common_all_modes = true;
  1899. spectral->properties[smode]
  1900. [SPECTRAL_PARAM_SCAN_PERIOD].common_all_modes = true;
  1901. spectral->properties[smode]
  1902. [SPECTRAL_PARAM_INIT_DELAY].common_all_modes = true;
  1903. }
  1904. return QDF_STATUS_SUCCESS;
  1905. }
  1906. /* Bandwidth to half bandwidth mapping */
  1907. static const enum phy_ch_width half_bw_map[] = {
  1908. #ifdef WLAN_FEATURE_11BE
  1909. [CH_WIDTH_320MHZ] = CH_WIDTH_160MHZ,
  1910. #endif
  1911. [CH_WIDTH_80P80MHZ] = CH_WIDTH_80MHZ,
  1912. [CH_WIDTH_160MHZ] = CH_WIDTH_80MHZ,
  1913. [CH_WIDTH_80MHZ] = CH_WIDTH_40MHZ,
  1914. [CH_WIDTH_40MHZ] = CH_WIDTH_20MHZ,
  1915. [CH_WIDTH_20MHZ] = CH_WIDTH_10MHZ,
  1916. [CH_WIDTH_10MHZ] = CH_WIDTH_5MHZ,
  1917. [CH_WIDTH_5MHZ] = CH_WIDTH_INVALID
  1918. };
  1919. /**
  1920. * target_if_get_half_bandwidth() - Get half bandwidth for a given bandwidth
  1921. * @bw: bandwidth
  1922. *
  1923. * Return: Half bandwidth of @bw
  1924. */
  1925. static enum phy_ch_width target_if_get_half_bandwidth(enum phy_ch_width bw)
  1926. {
  1927. if (bw >= CH_WIDTH_INVALID)
  1928. return CH_WIDTH_INVALID;
  1929. return half_bw_map[bw];
  1930. }
  1931. /**
  1932. * target_if_populate_supported_sscan_bws_be() - Populate supported spectral
  1933. * scan bandwidths for beryllium chipsets
  1934. * @spectral: Spectral LMAC object
  1935. *
  1936. * Return: QDF_STATUS of operation
  1937. */
  1938. static QDF_STATUS
  1939. target_if_populate_supported_sscan_bws_be(struct target_if_spectral *spectral)
  1940. {
  1941. enum phy_ch_width op_bw;
  1942. struct spectral_supported_bws *supported_bws;
  1943. QDF_STATUS status;
  1944. qdf_assert_always(spectral);
  1945. /* 20MHz */
  1946. op_bw = CH_WIDTH_20MHZ;
  1947. supported_bws = &spectral->supported_bws
  1948. [SPECTRAL_SCAN_MODE_NORMAL][op_bw];
  1949. supported_bws->bandwidths |= 1 << get_supported_sscan_bw_pos(op_bw);
  1950. spectral->supported_sscan_bw_list
  1951. [SPECTRAL_SCAN_MODE_NORMAL][op_bw] = true;
  1952. supported_bws = &spectral->supported_bws
  1953. [SPECTRAL_SCAN_MODE_AGILE][op_bw];
  1954. supported_bws->bandwidths |= 1 << get_supported_sscan_bw_pos(op_bw);
  1955. spectral->supported_sscan_bw_list
  1956. [SPECTRAL_SCAN_MODE_AGILE][op_bw] = true;
  1957. for (op_bw = CH_WIDTH_40MHZ; op_bw < CH_WIDTH_MAX; op_bw++) {
  1958. bool is_supported;
  1959. enum phy_ch_width half_op_bw;
  1960. status = wlan_reg_is_chwidth_supported(spectral->pdev_obj,
  1961. op_bw, &is_supported);
  1962. if (QDF_IS_STATUS_ERROR(status)) {
  1963. spectral_err("Unable to check if ch_width(%d) is supported",
  1964. op_bw);
  1965. return QDF_STATUS_E_FAILURE;
  1966. }
  1967. if (!is_supported)
  1968. continue;
  1969. spectral_debug("Updating supported bw for op_bw: %d", op_bw);
  1970. /* Normal mode */
  1971. supported_bws = &spectral->supported_bws
  1972. [SPECTRAL_SCAN_MODE_NORMAL][op_bw];
  1973. supported_bws->bandwidths |=
  1974. 1 << get_supported_sscan_bw_pos(op_bw);
  1975. spectral->supported_sscan_bw_list
  1976. [SPECTRAL_SCAN_MODE_NORMAL][op_bw] = true;
  1977. /* Agile mode */
  1978. supported_bws = &spectral->supported_bws
  1979. [SPECTRAL_SCAN_MODE_AGILE][op_bw];
  1980. supported_bws->bandwidths |=
  1981. 1 << get_supported_sscan_bw_pos(op_bw);
  1982. spectral->supported_sscan_bw_list
  1983. [SPECTRAL_SCAN_MODE_AGILE][op_bw] = true;
  1984. half_op_bw = target_if_get_half_bandwidth(op_bw);
  1985. if (half_op_bw != CH_WIDTH_INVALID) {
  1986. supported_bws->bandwidths |=
  1987. 1 << get_supported_sscan_bw_pos(half_op_bw);
  1988. spectral->supported_sscan_bw_list
  1989. [SPECTRAL_SCAN_MODE_AGILE][half_op_bw] = true;
  1990. }
  1991. }
  1992. return QDF_STATUS_SUCCESS;
  1993. }
  1994. /**
  1995. * target_if_populate_supported_sscan_bws() - Populate supported spectral
  1996. * scan bandwidths
  1997. * @spectral: Spectral LMAC object
  1998. * @target_type: Target type
  1999. *
  2000. * Return: QDF_STATUS of operation
  2001. */
  2002. static QDF_STATUS
  2003. target_if_populate_supported_sscan_bws(struct target_if_spectral *spectral,
  2004. uint32_t target_type)
  2005. {
  2006. enum spectral_scan_mode smode;
  2007. enum phy_ch_width op_bw;
  2008. struct spectral_supported_bws *supported_bws;
  2009. struct wlan_objmgr_psoc *psoc;
  2010. QDF_STATUS status;
  2011. qdf_assert_always(spectral);
  2012. if (is_spectral_arch_beryllium(target_type))
  2013. return target_if_populate_supported_sscan_bws_be(spectral);
  2014. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  2015. if (!psoc) {
  2016. spectral_err("psoc is null");
  2017. return QDF_STATUS_E_NULL_VALUE;
  2018. }
  2019. for (op_bw = CH_WIDTH_20MHZ; op_bw < CH_WIDTH_MAX; op_bw++) {
  2020. bool is_supported;
  2021. status = wlan_reg_is_chwidth_supported(spectral->pdev_obj,
  2022. op_bw, &is_supported);
  2023. if (QDF_IS_STATUS_ERROR(status)) {
  2024. spectral_err("Unable to check if ch_width(%d) is supported",
  2025. op_bw);
  2026. return QDF_STATUS_E_FAILURE;
  2027. }
  2028. if (!is_supported)
  2029. continue;
  2030. spectral_debug("Updating supported bw for op_bw: %d", op_bw);
  2031. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2032. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2033. supported_bws = &spectral->supported_bws[smode][op_bw];
  2034. if (is_ch_width_160_or_80p80(op_bw) &&
  2035. smode == SPECTRAL_SCAN_MODE_AGILE) {
  2036. /**
  2037. * If fragmentation is supported, then only 80Hz
  2038. * agile width is supported
  2039. */
  2040. if (spectral->rparams.
  2041. fragmentation_160[smode]) {
  2042. supported_bws->bandwidths |=
  2043. 1 << get_supported_sscan_bw_pos(
  2044. CH_WIDTH_80MHZ);
  2045. spectral->supported_sscan_bw_list
  2046. [smode][CH_WIDTH_80MHZ] = true;
  2047. }
  2048. /**
  2049. * If restricted 80p80 is supported, then both
  2050. * 160 and 80p80 agile widths are supported for
  2051. * 160MHz, and only 160MHz agile width is
  2052. * supported for 80p80
  2053. */
  2054. if (wlan_psoc_nif_fw_ext_cap_get(
  2055. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  2056. supported_bws->bandwidths |=
  2057. 1 << get_supported_sscan_bw_pos(
  2058. CH_WIDTH_160MHZ);
  2059. spectral->supported_sscan_bw_list
  2060. [smode][CH_WIDTH_160MHZ] = true;
  2061. if (op_bw == CH_WIDTH_160MHZ) {
  2062. supported_bws->bandwidths |=
  2063. 1 << get_supported_sscan_bw_pos(
  2064. CH_WIDTH_80P80MHZ);
  2065. spectral->supported_sscan_bw_list
  2066. [smode][CH_WIDTH_80P80MHZ] = true;
  2067. }
  2068. }
  2069. } else {
  2070. supported_bws->bandwidths |=
  2071. 1 << get_supported_sscan_bw_pos(
  2072. op_bw);
  2073. spectral->supported_sscan_bw_list
  2074. [smode][op_bw] = true;
  2075. }
  2076. }
  2077. }
  2078. return QDF_STATUS_SUCCESS;
  2079. }
  2080. QDF_STATUS
  2081. target_if_init_spectral_capability(struct target_if_spectral *spectral,
  2082. uint32_t target_type)
  2083. {
  2084. struct wlan_objmgr_psoc *psoc;
  2085. struct wlan_objmgr_pdev *pdev;
  2086. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  2087. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  2088. struct target_psoc_info *tgt_psoc_info;
  2089. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  2090. struct spectral_caps *pcap = &spectral->capability;
  2091. QDF_STATUS status;
  2092. pdev = spectral->pdev_obj;
  2093. psoc = wlan_pdev_get_psoc(pdev);
  2094. if (!psoc) {
  2095. spectral_err("psoc is null");
  2096. return QDF_STATUS_E_FAILURE;
  2097. }
  2098. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  2099. if (!tgt_psoc_info) {
  2100. spectral_err("target_psoc_info is null");
  2101. return QDF_STATUS_E_FAILURE;
  2102. }
  2103. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  2104. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  2105. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  2106. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  2107. /* XXX : Workaround: Set Spectral capability */
  2108. pcap = &spectral->capability;
  2109. pcap->phydiag_cap = 1;
  2110. pcap->radar_cap = 1;
  2111. pcap->spectral_cap = wlan_pdev_nif_feat_ext_cap_get(
  2112. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  2113. pcap->advncd_spectral_cap = pcap->spectral_cap;
  2114. pcap->hw_gen = spectral->spectral_gen;
  2115. pcap->agile_spectral_cap = !wlan_pdev_nif_feat_ext_cap_get(
  2116. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  2117. pcap->agile_spectral_cap_160 = !wlan_pdev_nif_feat_ext_cap_get(
  2118. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  2119. pcap->agile_spectral_cap_80p80 = !wlan_pdev_nif_feat_ext_cap_get(
  2120. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  2121. pcap->agile_spectral_cap_320 = !wlan_pdev_nif_feat_ext_cap_get(
  2122. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  2123. if (scaling_params) {
  2124. for (param_idx = 0; param_idx < num_bin_scaling_params;
  2125. param_idx++) {
  2126. if (scaling_params[param_idx].pdev_id == pdev_id) {
  2127. pcap->is_scaling_params_populated = true;
  2128. pcap->formula_id =
  2129. scaling_params[param_idx].formula_id;
  2130. pcap->low_level_offset =
  2131. scaling_params[param_idx].low_level_offset;
  2132. pcap->high_level_offset =
  2133. scaling_params[param_idx].high_level_offset;
  2134. pcap->rssi_thr =
  2135. scaling_params[param_idx].rssi_thr;
  2136. pcap->default_agc_max_gain =
  2137. scaling_params[param_idx].default_agc_max_gain;
  2138. break;
  2139. }
  2140. }
  2141. }
  2142. pcap->num_detectors_20mhz = 1;
  2143. pcap->num_detectors_40mhz = 1;
  2144. pcap->num_detectors_80mhz = 1;
  2145. if (target_type == TARGET_TYPE_QCN9000 ||
  2146. target_type == TARGET_TYPE_QCN6122 ||
  2147. target_type == TARGET_TYPE_QCA6490 ||
  2148. target_type == TARGET_TYPE_KIWI ||
  2149. target_type == TARGET_TYPE_MANGO) {
  2150. pcap->num_detectors_160mhz = 1;
  2151. pcap->num_detectors_80p80mhz = 1;
  2152. pcap->num_detectors_320mhz = 0;
  2153. } else if (is_spectral_arch_beryllium(target_type)) {
  2154. pcap->num_detectors_160mhz = 1;
  2155. pcap->num_detectors_80p80mhz = 0;
  2156. pcap->num_detectors_320mhz = 1;
  2157. } else {
  2158. pcap->num_detectors_160mhz = 2;
  2159. pcap->num_detectors_80p80mhz = 2;
  2160. pcap->num_detectors_320mhz = 0;
  2161. }
  2162. status = target_if_populate_supported_sscan_bws(spectral, target_type);
  2163. if (QDF_IS_STATUS_ERROR(status)) {
  2164. spectral_err("Unable to populate supported sscan BWs");
  2165. return QDF_STATUS_E_FAILURE;
  2166. }
  2167. return QDF_STATUS_SUCCESS;
  2168. }
  2169. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2170. /**
  2171. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  2172. * internal operations with functions related to spectral simulation
  2173. * @p_sops: spectral low level ops table
  2174. *
  2175. * Initialize spectral target_if internal operations with functions
  2176. * related to spectral simulation
  2177. *
  2178. * Return: None
  2179. */
  2180. static void
  2181. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  2182. {
  2183. /*
  2184. * Spectral simulation is currently intended for platform transitions
  2185. * where underlying HW support may not be available for some time.
  2186. * Hence, we do not currently provide a runtime switch to turn the
  2187. * simulation on or off.
  2188. * In case of future requirements where runtime switches are required,
  2189. * this can be added. But it is suggested to use application layer
  2190. * simulation as far as possible in such cases, since the main
  2191. * use of record and replay of samples would concern higher
  2192. * level sample processing rather than lower level delivery.
  2193. */
  2194. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  2195. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  2196. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  2197. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  2198. p_sops->configure_spectral =
  2199. target_if_spectral_sops_sim_configure_params;
  2200. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  2201. }
  2202. #else
  2203. /**
  2204. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  2205. * internal operations
  2206. * @p_sops: spectral low level ops table
  2207. *
  2208. * Return: None
  2209. */
  2210. static void
  2211. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  2212. {
  2213. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  2214. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  2215. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  2216. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  2217. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  2218. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  2219. }
  2220. #endif
  2221. /**
  2222. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  2223. * operations common to all Spectral chipset generations
  2224. *
  2225. * Initializes target_if_spectral_ops common to all chipset generations
  2226. *
  2227. * Return: None
  2228. */
  2229. static void
  2230. target_if_init_spectral_ops_common(void)
  2231. {
  2232. struct target_if_spectral_ops *p_sops = &spectral_ops;
  2233. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  2234. p_sops->get_capability = target_if_spectral_get_capability;
  2235. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  2236. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  2237. target_if_init_spectral_simulation_ops(p_sops);
  2238. p_sops->get_extension_channel =
  2239. target_if_spectral_get_extension_channel;
  2240. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  2241. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  2242. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  2243. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  2244. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  2245. p_sops->reset_hw = target_if_spectral_reset_hw;
  2246. p_sops->get_chain_noise_floor =
  2247. target_if_spectral_get_chain_noise_floor;
  2248. }
  2249. /**
  2250. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  2251. * operations specific to Spectral chipset generation 2.
  2252. *
  2253. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  2254. *
  2255. * Return: None
  2256. */
  2257. static void
  2258. target_if_init_spectral_ops_gen2(void)
  2259. {
  2260. struct target_if_spectral_ops *p_sops = &spectral_ops;
  2261. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  2262. }
  2263. #ifdef BIG_ENDIAN_HOST
  2264. /**
  2265. * spectral_is_host_byte_swap_required() - Check if byte swap has to be done
  2266. * on the Host
  2267. * @pdev: pdev pointer
  2268. * @is_swap_required: Pointer to caller variable
  2269. *
  2270. * Return: QDF_STATUS of operation
  2271. */
  2272. static QDF_STATUS
  2273. spectral_is_host_byte_swap_required(struct wlan_objmgr_pdev *pdev,
  2274. bool *is_swap_required)
  2275. {
  2276. struct wlan_objmgr_psoc *psoc;
  2277. struct wmi_unified *wmi_handle;
  2278. if (!pdev) {
  2279. spectral_err("pdev is null");
  2280. return QDF_STATUS_E_INVAL;
  2281. }
  2282. psoc = wlan_pdev_get_psoc(pdev);
  2283. if (!psoc) {
  2284. spectral_err("psoc is null");
  2285. return QDF_STATUS_E_INVAL;
  2286. }
  2287. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  2288. if (!wmi_handle) {
  2289. spectral_err("wmi handle is null");
  2290. return QDF_STATUS_E_INVAL;
  2291. }
  2292. /**
  2293. * If a chipset supports byte-swap inside the target itself, then no
  2294. * need to apply byte swap on the Host.
  2295. */
  2296. *is_swap_required = !target_if_spectral_wmi_service_enabled(
  2297. psoc, wmi_handle,
  2298. wmi_service_phy_dma_byte_swap_support);
  2299. return QDF_STATUS_SUCCESS;
  2300. }
  2301. /**
  2302. * target_if_spectral_init_byte_swap_funcs_gen3() - Initialize byte-swap
  2303. * operations for Spectral chipset generation 3.
  2304. * @spectral: Spectral LMAC object
  2305. * @p_sops: Spectral function pointer table
  2306. *
  2307. * Return: None
  2308. */
  2309. static void
  2310. target_if_spectral_init_byte_swap_funcs_gen3(
  2311. struct target_if_spectral *spectral,
  2312. struct target_if_spectral_ops *p_sops)
  2313. {
  2314. bool is_swap_required;
  2315. QDF_STATUS status;
  2316. qdf_assert_always(spectral);
  2317. qdf_assert_always(p_sops);
  2318. status = spectral_is_host_byte_swap_required(spectral->pdev_obj,
  2319. &is_swap_required);
  2320. if (QDF_IS_STATUS_ERROR(status)) {
  2321. spectral_err("Failed to check whether byte swap is required");
  2322. return;
  2323. }
  2324. if (is_swap_required) {
  2325. p_sops->byte_swap_headers =
  2326. target_if_byte_swap_spectral_headers_gen3;
  2327. p_sops->byte_swap_fft_bins =
  2328. target_if_byte_swap_spectral_fft_bins_gen3;
  2329. } else {
  2330. p_sops->byte_swap_headers = NULL;
  2331. p_sops->byte_swap_fft_bins = NULL;
  2332. }
  2333. }
  2334. #else
  2335. static void
  2336. target_if_spectral_init_byte_swap_funcs_gen3(
  2337. struct target_if_spectral *spectral,
  2338. struct target_if_spectral_ops *p_sops)
  2339. {
  2340. qdf_assert_always(p_sops);
  2341. /* Byte-swap is not required for little-endian Hosts */
  2342. p_sops->byte_swap_headers = NULL;
  2343. p_sops->byte_swap_fft_bins = NULL;
  2344. }
  2345. #endif /* BIG_ENDIAN_HOST */
  2346. /**
  2347. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  2348. * operations specific to Spectral chipset generation 3.
  2349. * @spectral: Spectral LMAC object
  2350. *
  2351. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  2352. *
  2353. * Return: None
  2354. */
  2355. static void
  2356. target_if_init_spectral_ops_gen3(struct target_if_spectral *spectral)
  2357. {
  2358. struct target_if_spectral_ops *p_sops = &spectral_ops;
  2359. p_sops->process_spectral_report =
  2360. target_if_spectral_process_report_gen3;
  2361. target_if_spectral_init_byte_swap_funcs_gen3(spectral, p_sops);
  2362. }
  2363. /**
  2364. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  2365. * operations.
  2366. * @spectral: Pointer to Spectral target_if internal private data
  2367. *
  2368. * Initializes all function pointers in target_if_spectral_ops for
  2369. * all generations
  2370. *
  2371. * Return: None
  2372. */
  2373. static void
  2374. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  2375. {
  2376. target_if_init_spectral_ops_common();
  2377. if (spectral->spectral_gen == SPECTRAL_GEN2)
  2378. target_if_init_spectral_ops_gen2();
  2379. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  2380. target_if_init_spectral_ops_gen3(spectral);
  2381. else
  2382. spectral_err("Invalid Spectral generation");
  2383. }
  2384. /*
  2385. * Dummy Functions:
  2386. * These functions are initially registered to avoid any crashes due to
  2387. * invocation of spectral functions before they are registered.
  2388. */
  2389. static uint64_t
  2390. null_get_tsf64(void *arg)
  2391. {
  2392. spectral_ops_not_registered("get_tsf64");
  2393. return 0;
  2394. }
  2395. static uint32_t
  2396. null_get_capability(void *arg, enum spectral_capability_type type)
  2397. {
  2398. /*
  2399. * TODO : We should have conditional compilation to get the capability
  2400. * : We have not yet attahced ATH layer here, so there is no
  2401. * : way to check the HAL capbalities
  2402. */
  2403. spectral_ops_not_registered("get_capability");
  2404. /* TODO : For the time being, we are returning TRUE */
  2405. return true;
  2406. }
  2407. static uint32_t
  2408. null_set_rxfilter(void *arg, int rxfilter)
  2409. {
  2410. spectral_ops_not_registered("set_rxfilter");
  2411. return 1;
  2412. }
  2413. static uint32_t
  2414. null_get_rxfilter(void *arg)
  2415. {
  2416. spectral_ops_not_registered("get_rxfilter");
  2417. return 0;
  2418. }
  2419. static uint32_t
  2420. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  2421. {
  2422. spectral_ops_not_registered("is_spectral_active");
  2423. return 1;
  2424. }
  2425. static uint32_t
  2426. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  2427. {
  2428. spectral_ops_not_registered("is_spectral_enabled");
  2429. return 1;
  2430. }
  2431. static uint32_t
  2432. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  2433. enum spectral_cp_error_code *err)
  2434. {
  2435. spectral_ops_not_registered("start_spectral_scan");
  2436. return 1;
  2437. }
  2438. static uint32_t
  2439. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  2440. {
  2441. spectral_ops_not_registered("stop_spectral_scan");
  2442. return 1;
  2443. }
  2444. static uint32_t
  2445. null_get_extension_channel(void *arg, enum spectral_scan_mode smode)
  2446. {
  2447. spectral_ops_not_registered("get_extension_channel");
  2448. return 1;
  2449. }
  2450. static int8_t
  2451. null_get_ctl_noisefloor(void *arg)
  2452. {
  2453. spectral_ops_not_registered("get_ctl_noisefloor");
  2454. return 1;
  2455. }
  2456. static int8_t
  2457. null_get_ext_noisefloor(void *arg)
  2458. {
  2459. spectral_ops_not_registered("get_ext_noisefloor");
  2460. return 0;
  2461. }
  2462. static uint32_t
  2463. null_configure_spectral(void *arg, struct spectral_config *params,
  2464. enum spectral_scan_mode smode)
  2465. {
  2466. spectral_ops_not_registered("configure_spectral");
  2467. return 0;
  2468. }
  2469. static uint32_t
  2470. null_get_spectral_config(void *arg, struct spectral_config *params,
  2471. enum spectral_scan_mode smode)
  2472. {
  2473. spectral_ops_not_registered("get_spectral_config");
  2474. return 0;
  2475. }
  2476. static uint32_t
  2477. null_get_ent_spectral_mask(void *arg)
  2478. {
  2479. spectral_ops_not_registered("get_ent_spectral_mask");
  2480. return 0;
  2481. }
  2482. static uint32_t
  2483. null_get_mac_address(void *arg, char *addr)
  2484. {
  2485. spectral_ops_not_registered("get_mac_address");
  2486. return 0;
  2487. }
  2488. static uint32_t
  2489. null_get_current_channel(void *arg, enum spectral_scan_mode smode)
  2490. {
  2491. spectral_ops_not_registered("get_current_channel");
  2492. return 0;
  2493. }
  2494. static uint32_t
  2495. null_reset_hw(void *arg)
  2496. {
  2497. spectral_ops_not_registered("get_current_channel");
  2498. return 0;
  2499. }
  2500. static uint32_t
  2501. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  2502. {
  2503. spectral_ops_not_registered("get_chain_noise_floor");
  2504. return 0;
  2505. }
  2506. static int
  2507. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  2508. uint8_t *data,
  2509. uint32_t datalen,
  2510. struct target_if_spectral_rfqual_info *p_rfqual,
  2511. struct target_if_spectral_chan_info *p_chaninfo,
  2512. uint64_t tsf64,
  2513. struct target_if_spectral_acs_stats *acs_stats)
  2514. {
  2515. spectral_ops_not_registered("spectral_process_phyerr");
  2516. return 0;
  2517. }
  2518. static int
  2519. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  2520. void *payload)
  2521. {
  2522. spectral_ops_not_registered("process_spectral_report");
  2523. return 0;
  2524. }
  2525. /**
  2526. * target_if_spectral_init_dummy_function_table() -
  2527. * Initialize target_if internal
  2528. * Spectral operations to dummy functions
  2529. * @ps: Pointer to Spectral target_if internal private data
  2530. *
  2531. * Initialize all the function pointers in target_if_spectral_ops with
  2532. * dummy functions.
  2533. *
  2534. * Return: None
  2535. */
  2536. static void
  2537. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  2538. {
  2539. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  2540. p_sops->get_tsf64 = null_get_tsf64;
  2541. p_sops->get_capability = null_get_capability;
  2542. p_sops->set_rxfilter = null_set_rxfilter;
  2543. p_sops->get_rxfilter = null_get_rxfilter;
  2544. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  2545. p_sops->is_spectral_active = null_is_spectral_active;
  2546. p_sops->start_spectral_scan = null_start_spectral_scan;
  2547. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  2548. p_sops->get_extension_channel = null_get_extension_channel;
  2549. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  2550. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  2551. p_sops->configure_spectral = null_configure_spectral;
  2552. p_sops->get_spectral_config = null_get_spectral_config;
  2553. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  2554. p_sops->get_mac_address = null_get_mac_address;
  2555. p_sops->get_current_channel = null_get_current_channel;
  2556. p_sops->reset_hw = null_reset_hw;
  2557. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  2558. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  2559. p_sops->process_spectral_report = null_process_spectral_report;
  2560. }
  2561. /**
  2562. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  2563. * operations
  2564. * @spectral: Pointer to Spectral target_if internal private data
  2565. * @p: Pointer to Spectral function table
  2566. *
  2567. * Return: None
  2568. */
  2569. static void
  2570. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  2571. struct target_if_spectral_ops *p)
  2572. {
  2573. struct target_if_spectral_ops *p_sops =
  2574. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2575. *p_sops = *p;
  2576. }
  2577. /**
  2578. * target_if_spectral_clear_stats() - Clear Spectral stats
  2579. * @spectral: Pointer to Spectral target_if internal private data
  2580. *
  2581. * Function to clear spectral stats
  2582. *
  2583. * Return: None
  2584. */
  2585. static void
  2586. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  2587. {
  2588. struct target_if_spectral_ops *p_sops =
  2589. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2590. qdf_mem_zero(&spectral->spectral_stats,
  2591. sizeof(struct target_if_spectral_stats));
  2592. spectral->spectral_stats.last_reset_tstamp =
  2593. p_sops->get_tsf64(spectral);
  2594. }
  2595. /**
  2596. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  2597. * @spectral: Pointer to Spectral target_if internal private data
  2598. *
  2599. * Function to check whether hardware supports spectral
  2600. *
  2601. * Return: True if HW supports Spectral, false if HW does not support Spectral
  2602. */
  2603. static int
  2604. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  2605. {
  2606. struct target_if_spectral_ops *p_sops = NULL;
  2607. struct spectral_caps *pcap = NULL;
  2608. int is_spectral_supported = true;
  2609. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2610. pcap = &spectral->capability;
  2611. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  2612. is_spectral_supported = false;
  2613. spectral_info("SPECTRAL : No PHYDIAG support");
  2614. return is_spectral_supported;
  2615. }
  2616. pcap->phydiag_cap = 1;
  2617. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  2618. is_spectral_supported = false;
  2619. spectral_info("SPECTRAL : No RADAR support");
  2620. return is_spectral_supported;
  2621. }
  2622. pcap->radar_cap = 1;
  2623. if (p_sops->get_capability(spectral,
  2624. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  2625. is_spectral_supported = false;
  2626. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  2627. return is_spectral_supported;
  2628. }
  2629. pcap->spectral_cap = 1;
  2630. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  2631. == false) {
  2632. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  2633. } else {
  2634. pcap->advncd_spectral_cap = 1;
  2635. }
  2636. return is_spectral_supported;
  2637. }
  2638. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2639. /**
  2640. * target_if_spectral_detach_simulation() - De-initialize Spectral
  2641. * Simulation functionality
  2642. * @spectral: Pointer to Spectral target_if internal private data
  2643. *
  2644. * Function to de-initialize Spectral Simulation functionality
  2645. *
  2646. * Return: None
  2647. */
  2648. static void
  2649. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  2650. {
  2651. target_if_spectral_sim_detach(spectral);
  2652. }
  2653. #else
  2654. static void
  2655. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  2656. {
  2657. }
  2658. #endif
  2659. /**
  2660. * target_if_spectral_detach() - De-initialize target_if Spectral
  2661. * @pdev: Pointer to pdev object
  2662. *
  2663. * Function to detach target_if spectral
  2664. *
  2665. * Return: None
  2666. */
  2667. static void
  2668. target_if_spectral_detach(struct target_if_spectral *spectral)
  2669. {
  2670. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  2671. spectral_info("spectral detach");
  2672. if (spectral) {
  2673. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2674. qdf_spinlock_destroy
  2675. (&spectral->param_info[smode].osps_lock);
  2676. target_if_spectral_detach_simulation(spectral);
  2677. qdf_spinlock_destroy(&spectral->spectral_lock);
  2678. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  2679. qdf_spinlock_destroy(&spectral->detector_list_lock);
  2680. qdf_spinlock_destroy(&spectral->session_report_info_lock);
  2681. qdf_spinlock_destroy(&spectral->session_det_map_lock);
  2682. qdf_mem_free(spectral);
  2683. spectral = NULL;
  2684. }
  2685. }
  2686. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2687. /**
  2688. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  2689. * functionality
  2690. * @spectral: Pointer to Spectral target_if internal private data
  2691. *
  2692. * Function to initialize spectral simulation functionality
  2693. *
  2694. * Return: 0 on success, negative error code on failure
  2695. */
  2696. static int
  2697. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  2698. {
  2699. if (target_if_spectral_sim_attach(spectral)) {
  2700. qdf_mem_free(spectral);
  2701. return -EPERM;
  2702. }
  2703. return 0;
  2704. }
  2705. #else
  2706. static int
  2707. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  2708. {
  2709. return 0;
  2710. }
  2711. #endif
  2712. /**
  2713. * target_if_spectral_len_adj_swar_init() - Initialize FFT bin length adjustment
  2714. * related info
  2715. * @swar: Pointer to Spectral FFT bin length adjustment SWAR params
  2716. * @rparams: Pointer to Spectral report parameter object
  2717. * @target_type: Target type
  2718. *
  2719. * Function to Initialize parameters related to Spectral FFT bin
  2720. * length adjustment SWARs.
  2721. *
  2722. * Return: void
  2723. */
  2724. static void
  2725. target_if_spectral_len_adj_swar_init(struct spectral_fft_bin_len_adj_swar *swar,
  2726. struct spectral_report_params *rparams,
  2727. uint32_t target_type)
  2728. {
  2729. if (target_type == TARGET_TYPE_QCA8074V2 ||
  2730. target_type == TARGET_TYPE_QCA9574 ||
  2731. target_type == TARGET_TYPE_QCN9000 ||
  2732. target_type == TARGET_TYPE_QCN6122 ||
  2733. target_type == TARGET_TYPE_QCA5018 ||
  2734. target_type == TARGET_TYPE_QCA6750 ||
  2735. target_type == TARGET_TYPE_QCA6490 ||
  2736. target_type == TARGET_TYPE_KIWI ||
  2737. target_type == TARGET_TYPE_MANGO) {
  2738. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  2739. rparams->hw_fft_bin_width = 2;
  2740. } else if (target_type == TARGET_TYPE_QCA8074 ||
  2741. target_type == TARGET_TYPE_QCA6018 ||
  2742. target_type == TARGET_TYPE_QCA6390) {
  2743. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  2744. rparams->hw_fft_bin_width = 4;
  2745. } else {
  2746. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  2747. rparams->hw_fft_bin_width = 1;
  2748. }
  2749. if (target_type == TARGET_TYPE_QCA8074 ||
  2750. target_type == TARGET_TYPE_QCA8074V2 ||
  2751. target_type == TARGET_TYPE_QCA9574 ||
  2752. target_type == TARGET_TYPE_QCA6018 ||
  2753. target_type == TARGET_TYPE_QCN6122 ||
  2754. target_type == TARGET_TYPE_QCA5018 ||
  2755. target_type == TARGET_TYPE_QCN9000 ||
  2756. target_type == TARGET_TYPE_QCA6490 ||
  2757. target_type == TARGET_TYPE_QCN9224 ||
  2758. target_type == TARGET_TYPE_KIWI ||
  2759. target_type == TARGET_TYPE_MANGO) {
  2760. swar->inband_fftbin_size_adj = 1;
  2761. swar->null_fftbin_adj = 1;
  2762. } else {
  2763. swar->inband_fftbin_size_adj = 0;
  2764. swar->null_fftbin_adj = 0;
  2765. }
  2766. if (target_type == TARGET_TYPE_QCA8074V2)
  2767. swar->packmode_fftbin_size_adj = 1;
  2768. else
  2769. swar->packmode_fftbin_size_adj = 0;
  2770. }
  2771. /**
  2772. * target_if_spectral_report_params_init() - Initialize parameters which
  2773. * describes the structure of Spectral reports
  2774. *
  2775. * @rparams: Pointer to Spectral report parameter object
  2776. * @target_type: target type
  2777. *
  2778. * Function to Initialize parameters related to the structure of Spectral
  2779. * reports.
  2780. *
  2781. * Return: void
  2782. */
  2783. static void
  2784. target_if_spectral_report_params_init(
  2785. struct spectral_report_params *rparams,
  2786. uint32_t target_type)
  2787. {
  2788. enum spectral_scan_mode smode;
  2789. /* This entries are currently used by gen3 chipsets only. Hence
  2790. * initialization is done for gen3 alone. In future if other generations
  2791. * needs to use them they have to add proper initial values.
  2792. */
  2793. if (target_type == TARGET_TYPE_QCN9000 ||
  2794. target_type == TARGET_TYPE_QCN6122 ||
  2795. target_type == TARGET_TYPE_QCA5018 ||
  2796. target_type == TARGET_TYPE_QCA6750 ||
  2797. target_type == TARGET_TYPE_QCA6490 ||
  2798. target_type == TARGET_TYPE_QCN9224 ||
  2799. target_type == TARGET_TYPE_KIWI ||
  2800. target_type == TARGET_TYPE_MANGO) {
  2801. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_2;
  2802. rparams->num_spectral_detectors =
  2803. NUM_SPECTRAL_DETECTORS_GEN3_V2;
  2804. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2805. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2806. rparams->fragmentation_160[smode] = false;
  2807. } else {
  2808. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_1;
  2809. rparams->num_spectral_detectors =
  2810. NUM_SPECTRAL_DETECTORS_GEN3_V1;
  2811. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2812. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2813. rparams->fragmentation_160[smode] = true;
  2814. }
  2815. switch (rparams->version) {
  2816. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  2817. rparams->ssumaary_padding_bytes =
  2818. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1;
  2819. rparams->fft_report_hdr_len =
  2820. FFT_REPORT_HEADER_LENGTH_GEN3_V1;
  2821. break;
  2822. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  2823. rparams->ssumaary_padding_bytes =
  2824. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2;
  2825. rparams->fft_report_hdr_len =
  2826. FFT_REPORT_HEADER_LENGTH_GEN3_V2;
  2827. break;
  2828. default:
  2829. qdf_assert_always(0);
  2830. }
  2831. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_0] =
  2832. SPECTRAL_SCAN_MODE_NORMAL;
  2833. if (target_type == TARGET_TYPE_QCN9000 ||
  2834. target_type == TARGET_TYPE_QCN6122 ||
  2835. target_type == TARGET_TYPE_QCN9224 ||
  2836. target_type == TARGET_TYPE_QCA6490 ||
  2837. target_type == TARGET_TYPE_KIWI ||
  2838. target_type == TARGET_TYPE_MANGO) {
  2839. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2840. SPECTRAL_SCAN_MODE_AGILE;
  2841. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2842. SPECTRAL_SCAN_MODE_INVALID;
  2843. } else {
  2844. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2845. SPECTRAL_SCAN_MODE_NORMAL;
  2846. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2847. SPECTRAL_SCAN_MODE_AGILE;
  2848. }
  2849. }
  2850. /**
  2851. * target_if_spectral_timestamp_war_init() - Initialize Spectral timestamp WAR
  2852. * related info
  2853. * @twar: Pointer to Spectral timstamp WAR related info
  2854. *
  2855. * Function to Initialize parameters related to Spectral timestamp WAR
  2856. *
  2857. * Return: void
  2858. */
  2859. static void
  2860. target_if_spectral_timestamp_war_init(struct spectral_timestamp_war *twar)
  2861. {
  2862. enum spectral_scan_mode smode;
  2863. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2864. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2865. twar->last_fft_timestamp[smode] = 0;
  2866. twar->timestamp_war_offset[smode] = 0;
  2867. }
  2868. twar->target_reset_count = 0;
  2869. }
  2870. #ifdef OPTIMIZED_SAMP_MESSAGE
  2871. /**
  2872. * target_if_spectral_is_hw_mode_sbs() - Check if the given pdev is in SBS mode
  2873. * @pdev: pdev pointer
  2874. * @is_hw_mode_sbs: Pointer to the variable where this function should write
  2875. * whether the given pdev is in SBS mode
  2876. *
  2877. * Return: QDF_STATUS of operation
  2878. */
  2879. static QDF_STATUS
  2880. target_if_spectral_is_hw_mode_sbs(struct wlan_objmgr_pdev *pdev,
  2881. bool *is_hw_mode_sbs)
  2882. {
  2883. struct wlan_objmgr_psoc *psoc;
  2884. struct target_psoc_info *tgt_hdl;
  2885. enum wmi_host_hw_mode_config_type mode;
  2886. qdf_assert_always(is_hw_mode_sbs);
  2887. psoc = wlan_pdev_get_psoc(pdev);
  2888. if (!psoc) {
  2889. spectral_err("psoc is null");
  2890. return QDF_STATUS_E_NULL_VALUE;
  2891. }
  2892. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  2893. if (!tgt_hdl) {
  2894. spectral_err("target_psoc_info is null");
  2895. return QDF_STATUS_E_NULL_VALUE;
  2896. }
  2897. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  2898. switch (mode) {
  2899. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  2900. case WMI_HOST_HW_MODE_SBS:
  2901. case WMI_HOST_HW_MODE_DBS_SBS:
  2902. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  2903. *is_hw_mode_sbs = true;
  2904. break;
  2905. default:
  2906. *is_hw_mode_sbs = false;
  2907. break;
  2908. }
  2909. return QDF_STATUS_SUCCESS;
  2910. }
  2911. /**
  2912. * target_if_get_pdev_mac_phy_caps() - Get the MAC_PHY capabilities of a pdev
  2913. * @pdev: pdev pointer
  2914. *
  2915. * Return: On success, pointer to MAC_PHY capabilities of @pdev.
  2916. * On failure, NULL
  2917. */
  2918. static struct wlan_psoc_host_mac_phy_caps *
  2919. target_if_get_pdev_mac_phy_caps(struct wlan_objmgr_pdev *pdev)
  2920. {
  2921. struct wlan_objmgr_psoc *psoc;
  2922. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr;
  2923. struct target_psoc_info *tgt_psoc_info;
  2924. uint8_t pdev_id;
  2925. if (!pdev) {
  2926. spectral_err("pdev is NULL");
  2927. return NULL;
  2928. }
  2929. psoc = wlan_pdev_get_psoc(pdev);
  2930. if (!psoc) {
  2931. spectral_err("psoc is null");
  2932. return NULL;
  2933. }
  2934. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  2935. if (!tgt_psoc_info) {
  2936. spectral_err("target_psoc_info is null");
  2937. return NULL;
  2938. }
  2939. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  2940. if (!mac_phy_cap_arr) {
  2941. spectral_err("mac phy cap array is null");
  2942. return NULL;
  2943. }
  2944. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  2945. return &mac_phy_cap_arr[pdev_id];
  2946. }
  2947. /**
  2948. * struct target_if_sscan_pdev_phy_info - PHY information of the pdev on
  2949. * which sscan is done. A pointer to an instance of this structure is passed
  2950. * as an argument to the iterator function target_if_find_sscan_pdev_phya1()
  2951. * @phy_id: PHY ID of this pdev
  2952. * @is_using_phya1: Pointer to the variable where the iterator function should
  2953. * populate whether the given pdev is using PHYA1
  2954. */
  2955. struct target_if_sscan_pdev_phy_info {
  2956. uint8_t phy_id;
  2957. bool *is_using_phya1;
  2958. };
  2959. /**
  2960. * target_if_find_sscan_pdev_phya1() - This is an iterator function to
  2961. * wlan_objmgr_iterate_obj_list(). It checks whether a given sscan_pdev (pdev on
  2962. * which sscan is currenly issued) is using PHYA1 by comparing against the pdev
  2963. * argument given by the wlan_objmgr_iterate_obj_list()
  2964. * @psoc: Pointer to psoc
  2965. * @object: Pointer to pdev
  2966. * @arg: Pointer to target_if_sscan_pdev_phy_info of the sscan_pdev for which
  2967. * we want to check if it uses PHYA1
  2968. *
  2969. * Return: None
  2970. */
  2971. static void
  2972. target_if_find_sscan_pdev_phya1(struct wlan_objmgr_psoc *psoc,
  2973. void *object, void *arg)
  2974. {
  2975. struct target_if_sscan_pdev_phy_info *sscan_pdev_phy_info = arg;
  2976. struct wlan_objmgr_pdev *cur_pdev = object;
  2977. struct wlan_psoc_host_mac_phy_caps *cur_mac_phy_caps;
  2978. cur_mac_phy_caps = target_if_get_pdev_mac_phy_caps(cur_pdev);
  2979. if (!cur_mac_phy_caps) {
  2980. spectral_err("Failed to get MAC PHY Capabilities of"
  2981. "pdev %pK", cur_pdev);
  2982. return;
  2983. }
  2984. spectral_debug("supported_bands: %0x phy_id: %d",
  2985. cur_mac_phy_caps->supported_bands,
  2986. cur_mac_phy_caps->phy_id);
  2987. /* No need to do anything if the current pdev is same as sscan_pdev */
  2988. if (sscan_pdev_phy_info->phy_id == cur_mac_phy_caps->phy_id)
  2989. return;
  2990. /**
  2991. * Compare the phy_id of both the SBS pdevs to figure out if
  2992. * the sscan_pdev using PHYA1
  2993. */
  2994. if (sscan_pdev_phy_info->phy_id > cur_mac_phy_caps->phy_id)
  2995. *sscan_pdev_phy_info->is_using_phya1 = true;
  2996. else
  2997. *sscan_pdev_phy_info->is_using_phya1 = false;
  2998. }
  2999. /**
  3000. * target_if_spectral_detector_list_init() - Initialize Spectral detector list
  3001. * based on target type
  3002. * @spectral: Pointer to Spectral target_if
  3003. *
  3004. * Function to initialize Spectral detector list for possible combinations of
  3005. * Spectral scan mode and channel width, based on target type.
  3006. *
  3007. * Return: Success/Failure
  3008. */
  3009. static QDF_STATUS
  3010. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  3011. {
  3012. struct sscan_detector_list *det_list;
  3013. enum spectral_scan_mode smode;
  3014. enum phy_ch_width ch_width;
  3015. QDF_STATUS ret;
  3016. bool is_hw_mode_sbs = false, is_using_phya1 = false;
  3017. if (!spectral) {
  3018. spectral_err_rl("Spectral LMAC object is null");
  3019. return QDF_STATUS_E_NULL_VALUE;
  3020. }
  3021. /**
  3022. * Special handling is required for SBS mode where the detector
  3023. * list should be the following.
  3024. * For the pdev that use PHYA0:
  3025. * detector 0 for normal mode
  3026. * detector 2 for agile mode
  3027. * For the pdev that use PHYA1:
  3028. * detector 1 for normal mode
  3029. * detector 2 for agile mode
  3030. *
  3031. * There is no direct way of knowing which pdevs are using PHYA0 or
  3032. * PHYA1. We need to look at the phy_id of a given pdev and compare
  3033. * against other pdevs on the same psoc to figure out whether the given
  3034. * pdev is operating using PHYA1.
  3035. */
  3036. /* First check whether this pdev is in SBS mode */
  3037. ret = target_if_spectral_is_hw_mode_sbs(spectral->pdev_obj,
  3038. &is_hw_mode_sbs);
  3039. if (QDF_IS_STATUS_ERROR(ret)) {
  3040. spectral_err("Failed to check whether hw mode is SBS");
  3041. return ret;
  3042. }
  3043. if (is_hw_mode_sbs) {
  3044. struct wlan_psoc_host_mac_phy_caps *mac_phy_caps;
  3045. struct target_if_sscan_pdev_phy_info pdev_phy_info;
  3046. mac_phy_caps =
  3047. target_if_get_pdev_mac_phy_caps(spectral->pdev_obj);
  3048. if (!mac_phy_caps) {
  3049. spectral_err("Failed to get MAC PHY Capabilities of"
  3050. "pdev %pK", spectral->pdev_obj);
  3051. return QDF_STATUS_E_FAILURE;
  3052. }
  3053. spectral_debug("bands: %0x phy_id: %d",
  3054. mac_phy_caps->supported_bands,
  3055. mac_phy_caps->phy_id);
  3056. pdev_phy_info.phy_id = mac_phy_caps->phy_id;
  3057. pdev_phy_info.is_using_phya1 = &is_using_phya1;
  3058. /* Iterate over all pdevs on this psoc */
  3059. wlan_objmgr_iterate_obj_list
  3060. (wlan_pdev_get_psoc(spectral->pdev_obj),
  3061. WLAN_PDEV_OP,
  3062. target_if_find_sscan_pdev_phya1,
  3063. &pdev_phy_info, 0,
  3064. WLAN_SPECTRAL_ID);
  3065. }
  3066. /**
  3067. * We assume there are 2 detectors. The Detector ID coming first will
  3068. * always be pri80 detector, and second detector for sec80.
  3069. */
  3070. ch_width = CH_WIDTH_20MHZ;
  3071. for (; ch_width < CH_WIDTH_MAX; ch_width++) {
  3072. /* Normal spectral scan */
  3073. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3074. spectral_debug("is_hw_mode_sbs: %d is_using_phya1:%d",
  3075. is_hw_mode_sbs, is_using_phya1);
  3076. qdf_spin_lock_bh(&spectral->detector_list_lock);
  3077. if (!spectral->supported_sscan_bw_list[smode][ch_width])
  3078. goto agile_handling;
  3079. det_list = &spectral->detector_list[smode][ch_width];
  3080. det_list->num_detectors = 1;
  3081. if (is_hw_mode_sbs && is_using_phya1)
  3082. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_1;
  3083. else
  3084. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_0;
  3085. if (is_ch_width_160_or_80p80(ch_width) &&
  3086. spectral->rparams.fragmentation_160[smode]) {
  3087. det_list->num_detectors += 1;
  3088. det_list->detectors[1] = SPECTRAL_DETECTOR_ID_1;
  3089. }
  3090. agile_handling:
  3091. /* Agile spectral scan */
  3092. smode = SPECTRAL_SCAN_MODE_AGILE;
  3093. if (!spectral->supported_sscan_bw_list[smode][ch_width]) {
  3094. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  3095. continue;
  3096. }
  3097. det_list = &spectral->detector_list[smode][ch_width];
  3098. det_list->num_detectors = 1;
  3099. if (spectral->rparams.fragmentation_160[smode])
  3100. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_2;
  3101. else
  3102. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_1;
  3103. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  3104. }
  3105. return QDF_STATUS_SUCCESS;
  3106. }
  3107. #else
  3108. static QDF_STATUS
  3109. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  3110. {
  3111. return QDF_STATUS_SUCCESS;
  3112. }
  3113. #endif /* OPTIMIZED_SAMP_MESSAGE */
  3114. /**
  3115. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  3116. * functionality for the given pdev
  3117. * @pdev: Pointer to pdev object
  3118. *
  3119. * Function to initialize pointer to spectral target_if internal private data
  3120. *
  3121. * Return: On success, pointer to Spectral target_if internal private data, on
  3122. * failure, NULL
  3123. */
  3124. void *
  3125. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  3126. {
  3127. struct target_if_spectral_ops *p_sops = NULL;
  3128. struct target_if_spectral *spectral = NULL;
  3129. uint32_t target_type;
  3130. uint32_t target_revision;
  3131. struct wlan_objmgr_psoc *psoc;
  3132. struct wlan_lmac_if_target_tx_ops *tgt_tx_ops;
  3133. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  3134. QDF_STATUS status;
  3135. struct wlan_lmac_if_tx_ops *tx_ops;
  3136. if (!pdev) {
  3137. spectral_err("SPECTRAL: pdev is NULL!");
  3138. return NULL;
  3139. }
  3140. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  3141. sizeof(struct target_if_spectral));
  3142. if (!spectral)
  3143. return spectral;
  3144. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  3145. /* Store pdev in Spectral */
  3146. spectral->pdev_obj = pdev;
  3147. spectral->vdev_id[SPECTRAL_SCAN_MODE_NORMAL] = WLAN_INVALID_VDEV_ID;
  3148. spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE] = WLAN_INVALID_VDEV_ID;
  3149. psoc = wlan_pdev_get_psoc(pdev);
  3150. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  3151. if (!tx_ops) {
  3152. spectral_err("tx_ops is NULL");
  3153. qdf_mem_free(spectral);
  3154. return NULL;
  3155. }
  3156. tgt_tx_ops = &tx_ops->target_tx_ops;
  3157. if (tgt_tx_ops->tgt_get_tgt_type) {
  3158. target_type = tgt_tx_ops->tgt_get_tgt_type(psoc);
  3159. } else {
  3160. qdf_mem_free(spectral);
  3161. return NULL;
  3162. }
  3163. if (tgt_tx_ops->tgt_get_tgt_revision) {
  3164. target_revision = tgt_tx_ops->tgt_get_tgt_revision(psoc);
  3165. } else {
  3166. qdf_mem_free(spectral);
  3167. return NULL;
  3168. }
  3169. /* init the function ptr table */
  3170. target_if_spectral_init_dummy_function_table(spectral);
  3171. /* get spectral function table */
  3172. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3173. /* TODO : Should this be called here of after ath_attach ? */
  3174. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  3175. spectral_info("HAL_CAP_PHYDIAG : Capable");
  3176. /* TODO: Need to fix the capablity check for RADAR */
  3177. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  3178. spectral_info("HAL_CAP_RADAR : Capable");
  3179. /* TODO : Need to fix the capablity check for SPECTRAL */
  3180. /* TODO : Should this be called here of after ath_attach ? */
  3181. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  3182. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  3183. qdf_spinlock_create(&spectral->spectral_lock);
  3184. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  3185. target_if_spectral_clear_stats(spectral);
  3186. if (target_type == TARGET_TYPE_QCA8074 ||
  3187. target_type == TARGET_TYPE_QCA8074V2 ||
  3188. target_type == TARGET_TYPE_QCA9574 ||
  3189. target_type == TARGET_TYPE_QCA6018 ||
  3190. target_type == TARGET_TYPE_QCA5018 ||
  3191. target_type == TARGET_TYPE_QCA6390 ||
  3192. target_type == TARGET_TYPE_QCN6122 ||
  3193. target_type == TARGET_TYPE_QCA6490 ||
  3194. target_type == TARGET_TYPE_QCN9000 ||
  3195. target_type == TARGET_TYPE_QCA6750 ||
  3196. target_type == TARGET_TYPE_QCN9224 ||
  3197. target_type == TARGET_TYPE_KIWI ||
  3198. target_type == TARGET_TYPE_MANGO)
  3199. spectral->direct_dma_support = true;
  3200. target_if_spectral_report_params_init(&spectral->rparams,
  3201. target_type);
  3202. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  3203. &spectral->rparams,
  3204. target_type);
  3205. if ((target_type == TARGET_TYPE_QCA8074) ||
  3206. (target_type == TARGET_TYPE_QCA8074V2) ||
  3207. (target_type == TARGET_TYPE_QCA9574) ||
  3208. (target_type == TARGET_TYPE_QCA6018) ||
  3209. (target_type == TARGET_TYPE_QCA5018) ||
  3210. (target_type == TARGET_TYPE_QCN6122) ||
  3211. (target_type == TARGET_TYPE_QCN9000) ||
  3212. (target_type == TARGET_TYPE_QCA6290) ||
  3213. (target_type == TARGET_TYPE_QCA6390) ||
  3214. (target_type == TARGET_TYPE_QCA6490) ||
  3215. (target_type == TARGET_TYPE_QCN9224) ||
  3216. (target_type == TARGET_TYPE_QCA6750) ||
  3217. (target_type == TARGET_TYPE_KIWI) ||
  3218. (target_type == TARGET_TYPE_MANGO)) {
  3219. spectral->spectral_gen = SPECTRAL_GEN3;
  3220. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  3221. spectral->tag_sscan_summary_exp =
  3222. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  3223. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  3224. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  3225. } else {
  3226. spectral->spectral_gen = SPECTRAL_GEN2;
  3227. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  3228. spectral->tag_sscan_summary_exp =
  3229. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  3230. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  3231. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  3232. }
  3233. status = target_if_init_spectral_param_min_max(
  3234. spectral,
  3235. spectral->spectral_gen, target_type);
  3236. if (QDF_IS_STATUS_ERROR(status)) {
  3237. spectral_err("Failed to initialize parameter min max values");
  3238. goto fail;
  3239. }
  3240. target_if_init_spectral_param_properties(spectral);
  3241. /* Init spectral capability */
  3242. if (target_if_init_spectral_capability(spectral, target_type) !=
  3243. QDF_STATUS_SUCCESS) {
  3244. qdf_mem_free(spectral);
  3245. return NULL;
  3246. }
  3247. if (target_if_spectral_attach_simulation(spectral) < 0)
  3248. return NULL;
  3249. target_if_init_spectral_ops(spectral);
  3250. target_if_spectral_timestamp_war_init(&spectral->timestamp_war);
  3251. /* Spectral mode specific init */
  3252. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  3253. spectral->params_valid[smode] = false;
  3254. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  3255. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  3256. }
  3257. target_if_spectral_register_funcs(spectral, &spectral_ops);
  3258. if (target_if_spectral_check_hw_capability(spectral) == false) {
  3259. goto fail;
  3260. } else {
  3261. /*
  3262. * TODO: Once the driver architecture transitions to chipset
  3263. * versioning based checks, reflect this here.
  3264. */
  3265. spectral->is_160_format = false;
  3266. spectral->is_lb_edge_extrabins_format = false;
  3267. spectral->is_rb_edge_extrabins_format = false;
  3268. if (target_type == TARGET_TYPE_QCA9984 ||
  3269. target_type == TARGET_TYPE_QCA9888) {
  3270. spectral->is_160_format = true;
  3271. spectral->is_lb_edge_extrabins_format = true;
  3272. spectral->is_rb_edge_extrabins_format = true;
  3273. } else if ((target_type == TARGET_TYPE_AR900B) &&
  3274. (target_revision == AR900B_REV_2)) {
  3275. spectral->is_rb_edge_extrabins_format = true;
  3276. }
  3277. if (target_type == TARGET_TYPE_QCA9984 ||
  3278. target_type == TARGET_TYPE_QCA9888)
  3279. spectral->is_sec80_rssi_war_required = true;
  3280. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  3281. if (spectral->spectral_gen == SPECTRAL_GEN3)
  3282. init_160mhz_delivery_state_machine(spectral);
  3283. }
  3284. qdf_spinlock_create(&spectral->detector_list_lock);
  3285. qdf_spinlock_create(&spectral->session_report_info_lock);
  3286. qdf_spinlock_create(&spectral->session_det_map_lock);
  3287. return spectral;
  3288. fail:
  3289. target_if_spectral_detach(spectral);
  3290. return NULL;
  3291. }
  3292. /**
  3293. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  3294. * functionality for the given pdev
  3295. * @pdev: Pointer to pdev object
  3296. *
  3297. * Function to de-initialize pointer to spectral target_if internal private data
  3298. *
  3299. * Return: None
  3300. */
  3301. void
  3302. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  3303. {
  3304. struct target_if_spectral *spectral = NULL;
  3305. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3306. if (!spectral) {
  3307. spectral_err("SPECTRAL : Module doesn't exist");
  3308. return;
  3309. }
  3310. target_if_spectral_detach(spectral);
  3311. return;
  3312. }
  3313. /**
  3314. * target_if_psoc_spectral_deinit() - De-initialize target_if Spectral
  3315. * functionality for the given psoc
  3316. * @psoc: Pointer to psoc object
  3317. *
  3318. * Function to de-initialize pointer to psoc spectral target_if internal
  3319. * private data
  3320. *
  3321. * Return: None
  3322. */
  3323. static void
  3324. target_if_psoc_spectral_deinit(struct wlan_objmgr_psoc *psoc)
  3325. {
  3326. struct target_if_psoc_spectral *psoc_spectral;
  3327. if (!psoc) {
  3328. spectral_err("psoc is null");
  3329. return;
  3330. }
  3331. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  3332. if (!psoc_spectral) {
  3333. spectral_err("Spectral target_if psoc object is null");
  3334. return;
  3335. }
  3336. qdf_mem_free(psoc_spectral);
  3337. }
  3338. /**
  3339. * target_if_psoc_spectral_init() - Initialize target_if Spectral
  3340. * functionality for the given psoc
  3341. * @psoc: Pointer to psoc object
  3342. *
  3343. * Function to initialize pointer to psoc spectral target_if internal
  3344. * private data
  3345. *
  3346. * Return: On success, pointer to Spectral psoc target_if internal
  3347. * private data, on failure, NULL
  3348. */
  3349. static void *
  3350. target_if_psoc_spectral_init(struct wlan_objmgr_psoc *psoc)
  3351. {
  3352. struct target_if_psoc_spectral *psoc_spectral = NULL;
  3353. if (!psoc) {
  3354. spectral_err("psoc is null");
  3355. goto fail;
  3356. }
  3357. psoc_spectral = (struct target_if_psoc_spectral *)qdf_mem_malloc(
  3358. sizeof(struct target_if_psoc_spectral));
  3359. if (!psoc_spectral) {
  3360. spectral_err("Spectral lmac psoc object allocation failed");
  3361. goto fail;
  3362. }
  3363. psoc_spectral->psoc_obj = psoc;
  3364. return psoc_spectral;
  3365. fail:
  3366. if (psoc_spectral)
  3367. target_if_psoc_spectral_deinit(psoc);
  3368. return psoc_spectral;
  3369. }
  3370. /**
  3371. * target_if_calculate_center_freq() - Helper routine to
  3372. * check whether given frequency is center frequency of a
  3373. * WLAN channel
  3374. *
  3375. * @spectral: Pointer to Spectral object
  3376. * @chan_freq: Center frequency of a WLAN channel
  3377. * @is_valid: Indicates whether given frequency is valid
  3378. *
  3379. * Return: QDF_STATUS
  3380. */
  3381. static QDF_STATUS
  3382. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  3383. uint32_t chan_freq,
  3384. bool *is_valid)
  3385. {
  3386. struct regulatory_channel *cur_chan_list;
  3387. int i;
  3388. if (!pdev) {
  3389. spectral_err("pdev object is null");
  3390. return QDF_STATUS_E_FAILURE;
  3391. }
  3392. if (!is_valid) {
  3393. spectral_err("is valid argument is null");
  3394. return QDF_STATUS_E_FAILURE;
  3395. }
  3396. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  3397. if (!cur_chan_list)
  3398. return QDF_STATUS_E_FAILURE;
  3399. if (wlan_reg_get_current_chan_list(
  3400. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  3401. spectral_err("Failed to get cur_chan list");
  3402. qdf_mem_free(cur_chan_list);
  3403. return QDF_STATUS_E_FAILURE;
  3404. }
  3405. *is_valid = false;
  3406. for (i = 0; i < NUM_CHANNELS; i++) {
  3407. uint32_t flags;
  3408. uint32_t center_freq;
  3409. flags = cur_chan_list[i].chan_flags;
  3410. center_freq = cur_chan_list[i].center_freq;
  3411. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  3412. (center_freq == chan_freq)) {
  3413. *is_valid = true;
  3414. break;
  3415. }
  3416. }
  3417. qdf_mem_free(cur_chan_list);
  3418. return QDF_STATUS_SUCCESS;
  3419. }
  3420. /**
  3421. * target_if_calculate_center_freq() - Helper routine to
  3422. * find the center frequency of the agile span from a
  3423. * WLAN channel center frequency
  3424. *
  3425. * @spectral: Pointer to Spectral object
  3426. * @ch_width: Channel width array
  3427. * @chan_freq: Center frequency of a WLAN channel
  3428. * @center_freq: Pointer to center frequency
  3429. *
  3430. * Return: QDF_STATUS
  3431. */
  3432. static QDF_STATUS
  3433. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  3434. enum phy_ch_width *ch_width,
  3435. uint16_t chan_freq,
  3436. uint16_t *center_freq)
  3437. {
  3438. enum phy_ch_width agile_ch_width;
  3439. if (!spectral) {
  3440. spectral_err("spectral target if object is null");
  3441. return QDF_STATUS_E_FAILURE;
  3442. }
  3443. if (!ch_width) {
  3444. spectral_err("Channel width array is null");
  3445. return QDF_STATUS_E_INVAL;
  3446. }
  3447. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3448. if (!center_freq) {
  3449. spectral_err("center_freq argument is null");
  3450. return QDF_STATUS_E_FAILURE;
  3451. }
  3452. if (agile_ch_width == CH_WIDTH_20MHZ) {
  3453. *center_freq = chan_freq;
  3454. } else {
  3455. uint16_t start_freq;
  3456. uint16_t end_freq;
  3457. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3458. enum channel_state state;
  3459. state = wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3460. (spectral->pdev_obj, chan_freq, agile_ch_width,
  3461. &bonded_chan_ptr, REG_CURRENT_PWR_MODE);
  3462. if (state == CHANNEL_STATE_DISABLE ||
  3463. state == CHANNEL_STATE_INVALID) {
  3464. spectral_err("Channel state is disable or invalid");
  3465. return QDF_STATUS_E_FAILURE;
  3466. }
  3467. if (!bonded_chan_ptr) {
  3468. spectral_err("Bonded channel is not found");
  3469. return QDF_STATUS_E_FAILURE;
  3470. }
  3471. start_freq = bonded_chan_ptr->start_freq;
  3472. end_freq = bonded_chan_ptr->end_freq;
  3473. *center_freq = (start_freq + end_freq) >> 1;
  3474. }
  3475. return QDF_STATUS_SUCCESS;
  3476. }
  3477. /**
  3478. * target_if_validate_center_freq() - Helper routine to
  3479. * validate user provided agile center frequency
  3480. *
  3481. * @spectral: Pointer to Spectral object
  3482. * @ch_width: Channel width array
  3483. * @center_freq: User provided agile span center frequency
  3484. * @is_valid: Indicates whether agile span center frequency is valid
  3485. *
  3486. * Return: QDF_STATUS
  3487. */
  3488. static QDF_STATUS
  3489. target_if_validate_center_freq(struct target_if_spectral *spectral,
  3490. enum phy_ch_width *ch_width,
  3491. uint16_t center_freq,
  3492. bool *is_valid)
  3493. {
  3494. enum phy_ch_width agile_ch_width;
  3495. struct wlan_objmgr_pdev *pdev;
  3496. QDF_STATUS status;
  3497. if (!spectral) {
  3498. spectral_err("spectral target if object is null");
  3499. return QDF_STATUS_E_FAILURE;
  3500. }
  3501. if (!ch_width) {
  3502. spectral_err("channel width array is null");
  3503. return QDF_STATUS_E_INVAL;
  3504. }
  3505. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3506. if (!is_valid) {
  3507. spectral_err("is_valid argument is null");
  3508. return QDF_STATUS_E_FAILURE;
  3509. }
  3510. pdev = spectral->pdev_obj;
  3511. if (agile_ch_width == CH_WIDTH_20MHZ) {
  3512. status = target_if_is_center_freq_of_any_chan
  3513. (pdev, center_freq, is_valid);
  3514. if (QDF_IS_STATUS_ERROR(status))
  3515. return QDF_STATUS_E_FAILURE;
  3516. } else {
  3517. uint16_t start_freq;
  3518. uint16_t end_freq;
  3519. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3520. bool is_chan;
  3521. status = target_if_is_center_freq_of_any_chan
  3522. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  3523. &is_chan);
  3524. if (QDF_IS_STATUS_ERROR(status))
  3525. return QDF_STATUS_E_FAILURE;
  3526. if (is_chan) {
  3527. uint32_t calulated_center_freq;
  3528. enum channel_state st;
  3529. st =
  3530. wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3531. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  3532. agile_ch_width,
  3533. &bonded_chan_ptr,
  3534. REG_CURRENT_PWR_MODE);
  3535. if (st == CHANNEL_STATE_DISABLE ||
  3536. st == CHANNEL_STATE_INVALID) {
  3537. spectral_err("Channel state disable/invalid");
  3538. return QDF_STATUS_E_FAILURE;
  3539. }
  3540. if (!bonded_chan_ptr) {
  3541. spectral_err("Bonded channel is not found");
  3542. return QDF_STATUS_E_FAILURE;
  3543. }
  3544. start_freq = bonded_chan_ptr->start_freq;
  3545. end_freq = bonded_chan_ptr->end_freq;
  3546. calulated_center_freq = (start_freq + end_freq) >> 1;
  3547. *is_valid = (center_freq == calulated_center_freq);
  3548. } else {
  3549. *is_valid = false;
  3550. }
  3551. }
  3552. return QDF_STATUS_SUCCESS;
  3553. }
  3554. /**
  3555. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  3556. * check whether agile span overlaps with current operating band.
  3557. *
  3558. * @spectral: Pointer to Spectral object
  3559. * @ch_width: Channel width array
  3560. * @center_freq: Agile span center frequency
  3561. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  3562. *
  3563. * Helper routine to check whether agile span overlaps with current
  3564. * operating band.
  3565. *
  3566. * Return: QDF_STATUS
  3567. */
  3568. static QDF_STATUS
  3569. target_if_is_agile_span_overlap_with_operating_span
  3570. (struct target_if_spectral *spectral,
  3571. enum phy_ch_width *ch_width,
  3572. struct spectral_config_frequency *center_freq,
  3573. bool *is_overlapping)
  3574. {
  3575. enum phy_ch_width op_ch_width;
  3576. enum phy_ch_width agile_ch_width;
  3577. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3578. struct wlan_objmgr_vdev *vdev;
  3579. struct wlan_objmgr_pdev *pdev;
  3580. int16_t chan_freq;
  3581. uint32_t op_start_freq;
  3582. uint32_t op_end_freq;
  3583. uint32_t agile_start_freq;
  3584. uint32_t agile_end_freq;
  3585. uint32_t cfreq2;
  3586. if (!spectral) {
  3587. spectral_err("Spectral object is NULL");
  3588. return QDF_STATUS_E_FAILURE;
  3589. }
  3590. pdev = spectral->pdev_obj;
  3591. if (!pdev) {
  3592. spectral_err("pdev object is NULL");
  3593. return QDF_STATUS_E_FAILURE;
  3594. }
  3595. if (!ch_width) {
  3596. spectral_err("channel width array is null");
  3597. return QDF_STATUS_E_FAILURE;
  3598. }
  3599. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  3600. if (op_ch_width == CH_WIDTH_INVALID) {
  3601. spectral_err("Invalid channel width");
  3602. return QDF_STATUS_E_INVAL;
  3603. }
  3604. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3605. if (agile_ch_width == CH_WIDTH_INVALID) {
  3606. spectral_err("Invalid channel width");
  3607. return QDF_STATUS_E_INVAL;
  3608. }
  3609. if (!is_overlapping) {
  3610. spectral_err("Argument(is_overlapping) is NULL");
  3611. return QDF_STATUS_E_FAILURE;
  3612. }
  3613. *is_overlapping = false;
  3614. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  3615. if (!vdev) {
  3616. spectral_err("vdev is NULL");
  3617. return QDF_STATUS_E_FAILURE;
  3618. }
  3619. chan_freq = target_if_vdev_get_chan_freq(vdev);
  3620. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  3621. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3622. if (cfreq2 < 0) {
  3623. spectral_err("cfreq2 is invalid");
  3624. return QDF_STATUS_E_FAILURE;
  3625. }
  3626. if (op_ch_width == CH_WIDTH_20MHZ) {
  3627. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  3628. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  3629. } else {
  3630. enum channel_state state;
  3631. state = wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3632. (pdev, chan_freq, op_ch_width, &bonded_chan_ptr,
  3633. REG_CURRENT_PWR_MODE);
  3634. if (state == CHANNEL_STATE_DISABLE ||
  3635. state == CHANNEL_STATE_INVALID) {
  3636. spectral_err("Channel state is disable or invalid");
  3637. return QDF_STATUS_E_FAILURE;
  3638. }
  3639. if (!bonded_chan_ptr) {
  3640. spectral_err("Bonded channel is not found");
  3641. return QDF_STATUS_E_FAILURE;
  3642. }
  3643. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  3644. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  3645. }
  3646. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3647. agile_start_freq = center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3648. agile_end_freq = center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3649. if (agile_end_freq > op_start_freq &&
  3650. op_end_freq > agile_start_freq)
  3651. *is_overlapping = true;
  3652. agile_start_freq = center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3653. agile_end_freq = center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3654. if (agile_end_freq > op_start_freq &&
  3655. op_end_freq > agile_start_freq)
  3656. *is_overlapping = true;
  3657. } else {
  3658. agile_start_freq = center_freq->cfreq1 -
  3659. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3660. agile_end_freq = center_freq->cfreq1 +
  3661. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3662. if (agile_end_freq > op_start_freq &&
  3663. op_end_freq > agile_start_freq)
  3664. *is_overlapping = true;
  3665. }
  3666. if (op_ch_width == CH_WIDTH_80P80MHZ) {
  3667. uint32_t sec80_start_feq;
  3668. uint32_t sec80_end_freq;
  3669. sec80_start_feq = cfreq2 - FREQ_OFFSET_40MHZ;
  3670. sec80_end_freq = cfreq2 + FREQ_OFFSET_40MHZ;
  3671. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3672. agile_start_freq =
  3673. center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3674. agile_end_freq =
  3675. center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3676. if (agile_end_freq > sec80_start_feq &&
  3677. sec80_end_freq > agile_start_freq)
  3678. *is_overlapping = true;
  3679. agile_start_freq =
  3680. center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3681. agile_end_freq =
  3682. center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3683. if (agile_end_freq > sec80_start_feq &&
  3684. sec80_end_freq > agile_start_freq)
  3685. *is_overlapping = true;
  3686. } else {
  3687. agile_start_freq = center_freq->cfreq1 -
  3688. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3689. agile_end_freq = center_freq->cfreq1 +
  3690. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3691. if (agile_end_freq > sec80_start_feq &&
  3692. sec80_end_freq > agile_start_freq)
  3693. *is_overlapping = true;
  3694. }
  3695. }
  3696. return QDF_STATUS_SUCCESS;
  3697. }
  3698. /**
  3699. * target_if_spectral_populate_chwidth() - Helper routine to
  3700. * populate channel width for different Spectral modes
  3701. *
  3702. * @spectral: Pointer to Spectral object
  3703. * @ch_width: Channel width array
  3704. * @is_80_80_agile: Indicates whether 80+80 agile scan is requested
  3705. *
  3706. * Helper routine to populate channel width for different Spectral modes
  3707. *
  3708. * Return: QDF_STATUS
  3709. */
  3710. static QDF_STATUS
  3711. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral,
  3712. enum phy_ch_width *ch_width,
  3713. bool is_80_80_agile)
  3714. {
  3715. enum spectral_scan_mode smode;
  3716. qdf_assert_always(spectral);
  3717. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3718. for (; smode < SPECTRAL_SCAN_MODE_MAX; ++smode) {
  3719. /* If user has configured sscan bandwidth, use it */
  3720. if (spectral->sscan_width_configured[smode]) {
  3721. ch_width[smode] = spectral->params[smode].ss_bandwidth;
  3722. } else {
  3723. /* Otherwise, derive the default sscan bandwidth */
  3724. ch_width[smode] = get_default_sscan_bw(spectral, smode,
  3725. is_80_80_agile);
  3726. if (ch_width[smode] >= CH_WIDTH_INVALID) {
  3727. spectral_err("Invalid sscan BW %u",
  3728. ch_width[smode]);
  3729. return QDF_STATUS_E_FAILURE;
  3730. }
  3731. spectral->params[smode].ss_bandwidth = ch_width[smode];
  3732. }
  3733. }
  3734. return QDF_STATUS_SUCCESS;
  3735. }
  3736. /**
  3737. * target_if_spectral_is_valid_80p80_freq() - API to check whether given
  3738. * (cfreq1, cfreq2) pair forms a valid 80+80 combination
  3739. * @pdev: pointer to pdev
  3740. * @cfreq1: center frequency 1
  3741. * @cfreq2: center frequency 2
  3742. *
  3743. * API to check whether given (cfreq1, cfreq2) pair forms a valid 80+80
  3744. * combination
  3745. *
  3746. * Return: true or false
  3747. */
  3748. static bool
  3749. target_if_spectral_is_valid_80p80_freq(struct wlan_objmgr_pdev *pdev,
  3750. uint32_t cfreq1, uint32_t cfreq2)
  3751. {
  3752. struct ch_params ch_params = {0};
  3753. enum channel_state chan_state1;
  3754. enum channel_state chan_state2;
  3755. struct wlan_objmgr_psoc *psoc;
  3756. struct ch_params temp_params = {0};
  3757. qdf_assert_always(pdev);
  3758. psoc = wlan_pdev_get_psoc(pdev);
  3759. qdf_assert_always(psoc);
  3760. /* In restricted 80P80 MHz enabled, only one 80+80 MHz
  3761. * channel is supported with cfreq=5690 and cfreq=5775.
  3762. */
  3763. if (wlan_psoc_nif_fw_ext_cap_get(
  3764. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  3765. return CHAN_WITHIN_RESTRICTED_80P80(cfreq1, cfreq2);
  3766. ch_params.center_freq_seg1 = wlan_reg_freq_to_chan(pdev, cfreq2);
  3767. ch_params.mhz_freq_seg1 = cfreq2;
  3768. ch_params.ch_width = CH_WIDTH_80P80MHZ;
  3769. wlan_reg_set_channel_params_for_pwrmode(
  3770. pdev,
  3771. cfreq1 - FREQ_OFFSET_10MHZ,
  3772. 0,
  3773. &ch_params,
  3774. REG_CURRENT_PWR_MODE);
  3775. if (ch_params.ch_width != CH_WIDTH_80P80MHZ)
  3776. return false;
  3777. if (ch_params.mhz_freq_seg0 != cfreq1 ||
  3778. ch_params.mhz_freq_seg1 != cfreq2)
  3779. return false;
  3780. temp_params.ch_width = CH_WIDTH_80MHZ;
  3781. chan_state1 = wlan_reg_get_5g_bonded_channel_state_for_pwrmode(
  3782. pdev,
  3783. ch_params.mhz_freq_seg0 - FREQ_OFFSET_10MHZ,
  3784. &temp_params,
  3785. REG_CURRENT_PWR_MODE);
  3786. if ((chan_state1 == CHANNEL_STATE_DISABLE) ||
  3787. (chan_state1 == CHANNEL_STATE_INVALID))
  3788. return false;
  3789. temp_params.ch_width = CH_WIDTH_80MHZ;
  3790. chan_state2 = wlan_reg_get_5g_bonded_channel_state_for_pwrmode(
  3791. pdev,
  3792. ch_params.mhz_freq_seg1 - FREQ_OFFSET_10MHZ,
  3793. &temp_params,
  3794. REG_CURRENT_PWR_MODE);
  3795. if ((chan_state2 == CHANNEL_STATE_DISABLE) ||
  3796. (chan_state2 == CHANNEL_STATE_INVALID))
  3797. return false;
  3798. if (abs(ch_params.mhz_freq_seg0 - ch_params.mhz_freq_seg1) <=
  3799. FREQ_OFFSET_80MHZ)
  3800. return false;
  3801. return true;
  3802. }
  3803. /**
  3804. * _target_if_set_spectral_config() - Set spectral config
  3805. * @spectral: Pointer to spectral object
  3806. * @param: Spectral parameter id and value
  3807. * @smode: Spectral scan mode
  3808. * @err: Spectral error code
  3809. *
  3810. * API to set spectral configurations
  3811. *
  3812. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3813. */
  3814. static QDF_STATUS
  3815. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  3816. const struct spectral_cp_param *param,
  3817. const enum spectral_scan_mode smode,
  3818. enum spectral_cp_error_code *err)
  3819. {
  3820. struct spectral_config params;
  3821. struct target_if_spectral_ops *p_sops;
  3822. struct spectral_config *sparams;
  3823. QDF_STATUS status;
  3824. bool is_overlapping;
  3825. uint16_t agile_cfreq;
  3826. bool is_valid_chan;
  3827. struct spectral_param_min_max *param_min_max;
  3828. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  3829. enum spectral_scan_mode m;
  3830. struct spectral_config_frequency center_freq = {0};
  3831. bool is_bw_supported;
  3832. struct wlan_objmgr_vdev *vdev;
  3833. enum phy_ch_width op_bw;
  3834. if (!err) {
  3835. spectral_err("Error code argument is null");
  3836. QDF_ASSERT(0);
  3837. return QDF_STATUS_E_FAILURE;
  3838. }
  3839. *err = SPECTRAL_SCAN_ERR_INVALID;
  3840. if (!param) {
  3841. spectral_err("Parameter object is null");
  3842. return QDF_STATUS_E_FAILURE;
  3843. }
  3844. if (!spectral) {
  3845. spectral_err("spectral object is NULL");
  3846. return QDF_STATUS_E_FAILURE;
  3847. }
  3848. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3849. param_min_max = &spectral->param_min_max;
  3850. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3851. spectral_err("Invalid Spectral mode %u", smode);
  3852. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3853. return QDF_STATUS_E_FAILURE;
  3854. }
  3855. sparams = &spectral->params[smode];
  3856. m = SPECTRAL_SCAN_MODE_NORMAL;
  3857. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  3858. ch_width[m] = CH_WIDTH_INVALID;
  3859. if (!spectral->params_valid[smode]) {
  3860. target_if_spectral_info_read(spectral,
  3861. smode,
  3862. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3863. &spectral->params[smode],
  3864. sizeof(spectral->params[smode]));
  3865. spectral->params_valid[smode] = true;
  3866. }
  3867. switch (param->id) {
  3868. case SPECTRAL_PARAM_FFT_PERIOD:
  3869. sparams->ss_fft_period = param->value;
  3870. break;
  3871. case SPECTRAL_PARAM_SCAN_PERIOD:
  3872. sparams->ss_period = param->value;
  3873. if (sparams->ss_recapture && ((sparams->ss_period <
  3874. SPECTRAL_RECAPTURE_SCAN_PERIOD_THRESHOLD) ||
  3875. (smode == SPECTRAL_SCAN_MODE_AGILE))) {
  3876. sparams->ss_recapture = false;
  3877. spectral_err("FFT recapture cannot be enabled due to scan period: %d us or spectral scan mode: %d",
  3878. sparams->ss_period, smode);
  3879. }
  3880. break;
  3881. case SPECTRAL_PARAM_FFT_RECAPTURE:
  3882. if (param->value) {
  3883. if (sparams->ss_period >=
  3884. SPECTRAL_RECAPTURE_SCAN_PERIOD_THRESHOLD &&
  3885. smode == SPECTRAL_SCAN_MODE_NORMAL) {
  3886. sparams->ss_recapture = true;
  3887. } else {
  3888. spectral_err("FFT recapture cannot be enabled due to scan period: %d us or spectral scan mode: %d",
  3889. sparams->ss_period, smode);
  3890. sparams->ss_recapture = false;
  3891. }
  3892. } else {
  3893. sparams->ss_recapture = false;
  3894. }
  3895. break;
  3896. case SPECTRAL_PARAM_SCAN_COUNT:
  3897. sparams->ss_count = param->value;
  3898. break;
  3899. case SPECTRAL_PARAM_SHORT_REPORT:
  3900. sparams->ss_short_report = (!!param->value) ? true : false;
  3901. break;
  3902. case SPECTRAL_PARAM_SPECT_PRI:
  3903. sparams->ss_spectral_pri = (!!param->value) ? true : false;
  3904. break;
  3905. case SPECTRAL_PARAM_FFT_SIZE:
  3906. status = target_if_spectral_populate_chwidth
  3907. (spectral, ch_width, spectral->params
  3908. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  3909. if (QDF_IS_STATUS_ERROR(status))
  3910. return QDF_STATUS_E_FAILURE;
  3911. if ((param->value < param_min_max->fft_size_min) ||
  3912. (param->value > param_min_max->fft_size_max
  3913. [ch_width[smode]])) {
  3914. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3915. return QDF_STATUS_E_FAILURE;
  3916. }
  3917. sparams->ss_fft_size = param->value;
  3918. break;
  3919. case SPECTRAL_PARAM_GC_ENA:
  3920. sparams->ss_gc_ena = !!param->value;
  3921. break;
  3922. case SPECTRAL_PARAM_RESTART_ENA:
  3923. sparams->ss_restart_ena = !!param->value;
  3924. break;
  3925. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  3926. sparams->ss_noise_floor_ref = param->value;
  3927. break;
  3928. case SPECTRAL_PARAM_INIT_DELAY:
  3929. sparams->ss_init_delay = param->value;
  3930. break;
  3931. case SPECTRAL_PARAM_NB_TONE_THR:
  3932. sparams->ss_nb_tone_thr = param->value;
  3933. break;
  3934. case SPECTRAL_PARAM_STR_BIN_THR:
  3935. sparams->ss_str_bin_thr = param->value;
  3936. break;
  3937. case SPECTRAL_PARAM_WB_RPT_MODE:
  3938. sparams->ss_wb_rpt_mode = !!param->value;
  3939. break;
  3940. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  3941. sparams->ss_rssi_rpt_mode = !!param->value;
  3942. break;
  3943. case SPECTRAL_PARAM_RSSI_THR:
  3944. sparams->ss_rssi_thr = param->value;
  3945. break;
  3946. case SPECTRAL_PARAM_PWR_FORMAT:
  3947. sparams->ss_pwr_format = !!param->value;
  3948. break;
  3949. case SPECTRAL_PARAM_RPT_MODE:
  3950. if ((param->value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  3951. (param->value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  3952. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3953. return QDF_STATUS_E_FAILURE;
  3954. }
  3955. sparams->ss_rpt_mode = param->value;
  3956. break;
  3957. case SPECTRAL_PARAM_BIN_SCALE:
  3958. sparams->ss_bin_scale = param->value;
  3959. break;
  3960. case SPECTRAL_PARAM_DBM_ADJ:
  3961. sparams->ss_dbm_adj = !!param->value;
  3962. break;
  3963. case SPECTRAL_PARAM_CHN_MASK:
  3964. sparams->ss_chn_mask = param->value;
  3965. break;
  3966. case SPECTRAL_PARAM_FREQUENCY:
  3967. status = target_if_spectral_populate_chwidth(
  3968. spectral, ch_width, param->freq.cfreq2 > 0);
  3969. if (QDF_IS_STATUS_ERROR(status)) {
  3970. spectral_err("Failed to populate channel width");
  3971. return QDF_STATUS_E_FAILURE;
  3972. }
  3973. if (ch_width[smode] != CH_WIDTH_80P80MHZ &&
  3974. param->freq.cfreq2) {
  3975. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3976. spectral_err("Non zero cfreq2 expected for 80p80 only");
  3977. return QDF_STATUS_E_INVAL;
  3978. }
  3979. if (ch_width[smode] == CH_WIDTH_80P80MHZ &&
  3980. !param->freq.cfreq2) {
  3981. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3982. spectral_err("Non zero cfreq2 expected for 80p80");
  3983. return QDF_STATUS_E_INVAL;
  3984. }
  3985. status = target_if_is_center_freq_of_any_chan
  3986. (spectral->pdev_obj, param->freq.cfreq1,
  3987. &is_valid_chan);
  3988. if (QDF_IS_STATUS_ERROR(status))
  3989. return QDF_STATUS_E_FAILURE;
  3990. if (is_valid_chan) {
  3991. status = target_if_calculate_center_freq(
  3992. spectral, ch_width,
  3993. param->freq.cfreq1,
  3994. &agile_cfreq);
  3995. if (QDF_IS_STATUS_ERROR(status)) {
  3996. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3997. return QDF_STATUS_E_FAILURE;
  3998. }
  3999. } else {
  4000. bool is_valid_agile_cfreq;
  4001. status = target_if_validate_center_freq
  4002. (spectral, ch_width, param->freq.cfreq1,
  4003. &is_valid_agile_cfreq);
  4004. if (QDF_IS_STATUS_ERROR(status))
  4005. return QDF_STATUS_E_FAILURE;
  4006. if (!is_valid_agile_cfreq) {
  4007. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4008. spectral_err("Invalid agile center frequency");
  4009. return QDF_STATUS_E_FAILURE;
  4010. }
  4011. agile_cfreq = param->freq.cfreq1;
  4012. }
  4013. center_freq.cfreq1 = agile_cfreq;
  4014. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  4015. status = target_if_is_center_freq_of_any_chan
  4016. (spectral->pdev_obj, param->freq.cfreq2,
  4017. &is_valid_chan);
  4018. if (QDF_IS_STATUS_ERROR(status))
  4019. return QDF_STATUS_E_FAILURE;
  4020. if (is_valid_chan) {
  4021. status = target_if_calculate_center_freq(
  4022. spectral, ch_width,
  4023. param->freq.cfreq2,
  4024. &agile_cfreq);
  4025. if (QDF_IS_STATUS_ERROR(status)) {
  4026. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4027. return QDF_STATUS_E_FAILURE;
  4028. }
  4029. } else {
  4030. bool is_valid_agile_cfreq;
  4031. status = target_if_validate_center_freq
  4032. (spectral, ch_width, param->freq.cfreq2,
  4033. &is_valid_agile_cfreq);
  4034. if (QDF_IS_STATUS_ERROR(status))
  4035. return QDF_STATUS_E_FAILURE;
  4036. if (!is_valid_agile_cfreq) {
  4037. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4038. spectral_err("Invalid agile center frequency");
  4039. return QDF_STATUS_E_FAILURE;
  4040. }
  4041. agile_cfreq = param->freq.cfreq2;
  4042. }
  4043. center_freq.cfreq2 = agile_cfreq;
  4044. }
  4045. status = target_if_is_agile_span_overlap_with_operating_span
  4046. (spectral, ch_width,
  4047. &center_freq, &is_overlapping);
  4048. if (QDF_IS_STATUS_ERROR(status))
  4049. return QDF_STATUS_E_FAILURE;
  4050. if (is_overlapping) {
  4051. spectral_err("Agile freq %u, %u overlaps with operating span",
  4052. center_freq.cfreq1, center_freq.cfreq2);
  4053. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4054. return QDF_STATUS_E_FAILURE;
  4055. }
  4056. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  4057. bool is_valid_80p80;
  4058. is_valid_80p80 = target_if_spectral_is_valid_80p80_freq(
  4059. spectral->pdev_obj,
  4060. center_freq.cfreq1,
  4061. center_freq.cfreq2);
  4062. if (!is_valid_80p80) {
  4063. spectral_err("Agile freq %u, %u is invalid 80+80 combination",
  4064. center_freq.cfreq1,
  4065. center_freq.cfreq2);
  4066. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4067. return QDF_STATUS_E_FAILURE;
  4068. }
  4069. }
  4070. sparams->ss_frequency.cfreq1 = center_freq.cfreq1;
  4071. sparams->ss_frequency.cfreq2 = center_freq.cfreq2;
  4072. break;
  4073. case SPECTRAL_PARAM_CHAN_WIDTH:
  4074. if (param->value >= CH_WIDTH_INVALID) {
  4075. spectral_err("invalid sscan width: %u", param->value);
  4076. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4077. return QDF_STATUS_E_FAILURE;
  4078. }
  4079. vdev = target_if_spectral_get_vdev(spectral, smode);
  4080. if (!vdev) {
  4081. spectral_err("vdev is null");
  4082. return QDF_STATUS_E_NULL_VALUE;
  4083. }
  4084. op_bw = target_if_vdev_get_ch_width(vdev);
  4085. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4086. /* Validate the bandwidth */
  4087. status = target_if_is_sscan_bw_supported(
  4088. spectral, smode,
  4089. param->value, op_bw, &is_bw_supported,
  4090. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  4091. ss_frequency.cfreq2 > 0);
  4092. if (QDF_IS_STATUS_ERROR(status)) {
  4093. spectral_err("Unable to check if given sscan_bw is supported");
  4094. return QDF_STATUS_E_FAILURE;
  4095. }
  4096. if (!is_bw_supported) {
  4097. spectral_err("sscan bw(%u) is not supported for the current operating width(%u) and sscan mode(%u)",
  4098. param->value, op_bw, smode);
  4099. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4100. return QDF_STATUS_E_FAILURE;
  4101. }
  4102. sparams->ss_bandwidth = param->value;
  4103. spectral->sscan_width_configured[smode] = true;
  4104. break;
  4105. }
  4106. p_sops->configure_spectral(spectral, sparams, smode);
  4107. /* only to validate the writes */
  4108. p_sops->get_spectral_config(spectral, &params, smode);
  4109. return QDF_STATUS_SUCCESS;
  4110. }
  4111. QDF_STATUS
  4112. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  4113. const struct spectral_cp_param *param,
  4114. const enum spectral_scan_mode smode,
  4115. enum spectral_cp_error_code *err)
  4116. {
  4117. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  4118. struct target_if_spectral *spectral;
  4119. QDF_STATUS status;
  4120. if (!err) {
  4121. spectral_err("Error code argument is null");
  4122. QDF_ASSERT(0);
  4123. return QDF_STATUS_E_FAILURE;
  4124. }
  4125. *err = SPECTRAL_SCAN_ERR_INVALID;
  4126. if (!pdev) {
  4127. spectral_err("pdev object is NULL");
  4128. return QDF_STATUS_E_FAILURE;
  4129. }
  4130. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4131. if (!spectral) {
  4132. spectral_err("spectral object is NULL");
  4133. return QDF_STATUS_E_FAILURE;
  4134. }
  4135. if (!param) {
  4136. spectral_err("parameter object is NULL");
  4137. return QDF_STATUS_E_FAILURE;
  4138. }
  4139. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4140. spectral_err("Invalid Spectral mode %u", smode);
  4141. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4142. return QDF_STATUS_E_FAILURE;
  4143. }
  4144. if (!spectral->properties[smode][param->id].supported) {
  4145. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  4146. param->id, smode);
  4147. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  4148. return QDF_STATUS_E_FAILURE;
  4149. }
  4150. if (spectral->properties[smode][param->id].common_all_modes) {
  4151. spectral_warn("Setting Spectral parameter %u for all modes",
  4152. param->id);
  4153. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  4154. status = _target_if_set_spectral_config
  4155. (spectral, param, mode, err);
  4156. if (QDF_IS_STATUS_ERROR(status))
  4157. return QDF_STATUS_E_FAILURE;
  4158. }
  4159. return QDF_STATUS_SUCCESS;
  4160. }
  4161. return _target_if_set_spectral_config(spectral, param, smode, err);
  4162. }
  4163. /**
  4164. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  4165. * @fft_len: FFT length
  4166. * @pdev: Pointer to pdev object
  4167. *
  4168. * API to get fft bin count for a given fft length
  4169. *
  4170. * Return: FFt bin count
  4171. */
  4172. static int
  4173. target_if_get_fft_bin_count(int fft_len)
  4174. {
  4175. int bin_count = 0;
  4176. switch (fft_len) {
  4177. case 5:
  4178. bin_count = 16;
  4179. break;
  4180. case 6:
  4181. bin_count = 32;
  4182. break;
  4183. case 7:
  4184. bin_count = 64;
  4185. break;
  4186. case 8:
  4187. bin_count = 128;
  4188. break;
  4189. case 9:
  4190. bin_count = 256;
  4191. break;
  4192. default:
  4193. break;
  4194. }
  4195. return bin_count;
  4196. }
  4197. /**
  4198. * target_if_init_upper_lower_flags() - Initializes control and extension
  4199. * segment flags
  4200. * @spectral: pointer to target if spectral object
  4201. * @smode: Spectral scan mode
  4202. *
  4203. * API to initialize the control and extension flags with the lower/upper
  4204. * segment based on the HT mode
  4205. *
  4206. * Return: FFt bin count
  4207. */
  4208. static void
  4209. target_if_init_upper_lower_flags(struct target_if_spectral *spectral,
  4210. enum spectral_scan_mode smode)
  4211. {
  4212. int current_channel = 0;
  4213. int ext_channel = 0;
  4214. struct target_if_spectral_ops *p_sops =
  4215. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4216. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4217. spectral_err("Invalid Spectral mode %u", smode);
  4218. return;
  4219. }
  4220. current_channel = p_sops->get_current_channel(spectral, smode);
  4221. ext_channel = p_sops->get_extension_channel(spectral, smode);
  4222. if ((current_channel == 0) || (ext_channel == 0))
  4223. return;
  4224. if (spectral->sc_spectral_20_40_mode) {
  4225. /* HT40 mode */
  4226. if (ext_channel < current_channel) {
  4227. spectral->lower_is_extension = 1;
  4228. spectral->upper_is_control = 1;
  4229. spectral->lower_is_control = 0;
  4230. spectral->upper_is_extension = 0;
  4231. } else {
  4232. spectral->lower_is_extension = 0;
  4233. spectral->upper_is_control = 0;
  4234. spectral->lower_is_control = 1;
  4235. spectral->upper_is_extension = 1;
  4236. }
  4237. } else {
  4238. /* HT20 mode, lower is always control */
  4239. spectral->lower_is_extension = 0;
  4240. spectral->upper_is_control = 0;
  4241. spectral->lower_is_control = 1;
  4242. spectral->upper_is_extension = 0;
  4243. }
  4244. }
  4245. /**
  4246. * target_if_get_spectral_config() - Get spectral configuration
  4247. * @pdev: Pointer to pdev object
  4248. * @param: Pointer to spectral_config structure in which the configuration
  4249. * should be returned
  4250. * @smode: Spectral scan mode
  4251. *
  4252. * API to get the current spectral configuration
  4253. *
  4254. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4255. */
  4256. QDF_STATUS
  4257. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  4258. struct spectral_config *param,
  4259. enum spectral_scan_mode smode)
  4260. {
  4261. struct target_if_spectral_ops *p_sops = NULL;
  4262. struct target_if_spectral *spectral = NULL;
  4263. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4264. if (!spectral) {
  4265. spectral_err("SPECTRAL : Module doesn't exist");
  4266. return QDF_STATUS_E_FAILURE;
  4267. }
  4268. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4269. if (!p_sops) {
  4270. spectral_err("p_sops is null");
  4271. return QDF_STATUS_E_FAILURE;
  4272. }
  4273. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4274. spectral_err("Invalid Spectral mode %u", smode);
  4275. return QDF_STATUS_E_FAILURE;
  4276. }
  4277. qdf_mem_zero(param, sizeof(struct spectral_config));
  4278. p_sops->get_spectral_config(spectral, param, smode);
  4279. return QDF_STATUS_SUCCESS;
  4280. }
  4281. #ifdef WLAN_FEATURE_11BE
  4282. /**
  4283. * target_if_spectral_get_num_detectors_for_higher_bws() - Get number of
  4284. * Spectral detectors for higher bandwidths
  4285. * @spectral: Pointer to target if Spectral object
  4286. * @ch_width: channel width
  4287. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  4288. *
  4289. * API to get number of Spectral detectors used for scan in the given channel
  4290. * width.
  4291. *
  4292. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  4293. */
  4294. static QDF_STATUS
  4295. target_if_spectral_get_num_detectors_for_higher_bws(
  4296. struct target_if_spectral *spectral,
  4297. enum phy_ch_width ch_width,
  4298. uint32_t *num_detectors)
  4299. {
  4300. switch (ch_width) {
  4301. case CH_WIDTH_320MHZ:
  4302. *num_detectors = spectral->capability.num_detectors_320mhz;
  4303. break;
  4304. default:
  4305. spectral_err("Unsupported channel width %d", ch_width);
  4306. return QDF_STATUS_E_INVAL;
  4307. }
  4308. return QDF_STATUS_SUCCESS;
  4309. }
  4310. #else
  4311. static QDF_STATUS
  4312. target_if_spectral_get_num_detectors_for_higher_bws(
  4313. struct target_if_spectral *spectral,
  4314. enum phy_ch_width ch_width,
  4315. uint32_t *num_detectors)
  4316. {
  4317. spectral_err("Unsupported channel width %d", ch_width);
  4318. return QDF_STATUS_E_INVAL;
  4319. }
  4320. #endif
  4321. /**
  4322. * target_if_spectral_get_num_detectors() - Get number of Spectral detectors
  4323. * @spectral: Pointer to target if Spectral object
  4324. * @ch_width: channel width
  4325. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  4326. *
  4327. * API to get number of Spectral detectors used for scan in the given channel
  4328. * width.
  4329. *
  4330. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  4331. */
  4332. static QDF_STATUS
  4333. target_if_spectral_get_num_detectors(struct target_if_spectral *spectral,
  4334. enum phy_ch_width ch_width,
  4335. uint32_t *num_detectors)
  4336. {
  4337. if (!spectral) {
  4338. spectral_err("target if spectral object is null");
  4339. return QDF_STATUS_E_INVAL;
  4340. }
  4341. if (ch_width >= CH_WIDTH_INVALID) {
  4342. spectral_err("Invalid channel width %d", ch_width);
  4343. return QDF_STATUS_E_INVAL;
  4344. }
  4345. if (!num_detectors) {
  4346. spectral_err("Invalid argument, number of detectors");
  4347. return QDF_STATUS_E_INVAL;
  4348. }
  4349. switch (ch_width) {
  4350. case CH_WIDTH_20MHZ:
  4351. *num_detectors = spectral->capability.num_detectors_20mhz;
  4352. break;
  4353. case CH_WIDTH_40MHZ:
  4354. *num_detectors = spectral->capability.num_detectors_40mhz;
  4355. break;
  4356. case CH_WIDTH_80MHZ:
  4357. *num_detectors = spectral->capability.num_detectors_80mhz;
  4358. break;
  4359. case CH_WIDTH_160MHZ:
  4360. *num_detectors = spectral->capability.num_detectors_160mhz;
  4361. break;
  4362. case CH_WIDTH_80P80MHZ:
  4363. *num_detectors = spectral->capability.num_detectors_80p80mhz;
  4364. break;
  4365. default:
  4366. return target_if_spectral_get_num_detectors_for_higher_bws(
  4367. spectral, ch_width, num_detectors);
  4368. }
  4369. return QDF_STATUS_SUCCESS;
  4370. }
  4371. /**
  4372. * target_if_spectral_finite_scan_init() - Initializations required for finite
  4373. * Spectral scan
  4374. * @spectral: Pointer to target of Spctral object
  4375. * @smode: Spectral scan mode
  4376. *
  4377. * This routine initializes the finite Spectral scan. Finite Spectral scan is
  4378. * triggered by configuring a non zero scan count.
  4379. *
  4380. * Return: QDF_STATUS_SUCCESS on success
  4381. */
  4382. static QDF_STATUS
  4383. target_if_spectral_finite_scan_init(struct target_if_spectral *spectral,
  4384. enum spectral_scan_mode smode)
  4385. {
  4386. struct target_if_finite_spectral_scan_params *finite_scan;
  4387. enum phy_ch_width ch_width;
  4388. uint32_t num_detectors;
  4389. QDF_STATUS status;
  4390. uint16_t sscan_count;
  4391. if (!spectral) {
  4392. spectral_err("target if spectral object is null");
  4393. return QDF_STATUS_E_INVAL;
  4394. }
  4395. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4396. spectral_err("Invalid Spectral mode");
  4397. return QDF_STATUS_E_INVAL;
  4398. }
  4399. ch_width = spectral->ch_width[smode];
  4400. status = target_if_spectral_get_num_detectors(spectral, ch_width,
  4401. &num_detectors);
  4402. if (QDF_IS_STATUS_ERROR(status)) {
  4403. spectral_err("Failed to get number of detectors");
  4404. return QDF_STATUS_E_FAILURE;
  4405. }
  4406. finite_scan = &spectral->finite_scan[smode];
  4407. sscan_count = spectral->params[smode].ss_count;
  4408. finite_scan->finite_spectral_scan = true;
  4409. finite_scan->num_reports_expected = num_detectors * sscan_count;
  4410. return QDF_STATUS_SUCCESS;
  4411. }
  4412. /**
  4413. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  4414. * parameters
  4415. * @spectral: Pointer to Spectral target_if internal private data
  4416. * @spectral_params: Pointer to Spectral parameters
  4417. * @smode: Spectral scan mode
  4418. * @err: Spectral error code
  4419. *
  4420. * Enable use of desired Spectral parameters by configuring them into HW, and
  4421. * starting Spectral scan
  4422. *
  4423. * Return: 0 on success, 1 on failure
  4424. */
  4425. int
  4426. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  4427. struct spectral_config *spectral_params,
  4428. enum spectral_scan_mode smode,
  4429. enum spectral_cp_error_code *err)
  4430. {
  4431. int extension_channel = 0;
  4432. int current_channel = 0;
  4433. struct target_if_spectral_ops *p_sops = NULL;
  4434. QDF_STATUS status;
  4435. struct wlan_objmgr_pdev *pdev;
  4436. struct wlan_objmgr_psoc *psoc;
  4437. if (!spectral) {
  4438. spectral_err("Spectral LMAC object is NULL");
  4439. return 1;
  4440. }
  4441. pdev = spectral->pdev_obj;
  4442. if (!pdev) {
  4443. spectral_err("pdev is null");
  4444. return QDF_STATUS_E_INVAL;
  4445. }
  4446. psoc = wlan_pdev_get_psoc(pdev);
  4447. if (!psoc) {
  4448. spectral_err("psoc is null");
  4449. return QDF_STATUS_E_INVAL;
  4450. }
  4451. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4452. spectral_err("Invalid Spectral mode %u", smode);
  4453. return 1;
  4454. }
  4455. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4456. if (!p_sops) {
  4457. spectral_err("p_sops is NULL");
  4458. return 1;
  4459. }
  4460. spectral->sc_spectral_noise_pwr_cal =
  4461. spectral_params->ss_spectral_pri ? 1 : 0;
  4462. /* check if extension channel is present */
  4463. extension_channel = p_sops->get_extension_channel(spectral, smode);
  4464. current_channel = p_sops->get_current_channel(spectral, smode);
  4465. if (spectral->capability.advncd_spectral_cap) {
  4466. spectral->lb_edge_extrabins = 0;
  4467. spectral->rb_edge_extrabins = 0;
  4468. if (spectral->is_lb_edge_extrabins_format &&
  4469. spectral->params[smode].ss_rpt_mode == 2) {
  4470. spectral->lb_edge_extrabins = 4;
  4471. }
  4472. if (spectral->is_rb_edge_extrabins_format &&
  4473. spectral->params[smode].ss_rpt_mode == 2) {
  4474. spectral->rb_edge_extrabins = 4;
  4475. }
  4476. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  4477. spectral->sc_spectral_20_40_mode = 0;
  4478. spectral->spectral_numbins =
  4479. target_if_get_fft_bin_count(
  4480. spectral->params[smode].ss_fft_size);
  4481. spectral->spectral_fft_len =
  4482. target_if_get_fft_bin_count(
  4483. spectral->params[smode].ss_fft_size);
  4484. spectral->spectral_data_len =
  4485. target_if_get_fft_bin_count(
  4486. spectral->params[smode].ss_fft_size);
  4487. /*
  4488. * Initialize classifier params to be sent to user
  4489. * space classifier
  4490. */
  4491. spectral->classifier_params.lower_chan_in_mhz =
  4492. current_channel;
  4493. spectral->classifier_params.upper_chan_in_mhz = 0;
  4494. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  4495. /* TODO : Remove this variable */
  4496. spectral->sc_spectral_20_40_mode = 1;
  4497. spectral->spectral_numbins =
  4498. target_if_get_fft_bin_count(
  4499. spectral->params[smode].ss_fft_size);
  4500. spectral->spectral_fft_len =
  4501. target_if_get_fft_bin_count(
  4502. spectral->params[smode].ss_fft_size);
  4503. spectral->spectral_data_len =
  4504. target_if_get_fft_bin_count(
  4505. spectral->params[smode].ss_fft_size);
  4506. /*
  4507. * Initialize classifier params to be sent to user
  4508. * space classifier
  4509. */
  4510. if (extension_channel < current_channel) {
  4511. spectral->classifier_params.lower_chan_in_mhz =
  4512. extension_channel;
  4513. spectral->classifier_params.upper_chan_in_mhz =
  4514. current_channel;
  4515. } else {
  4516. spectral->classifier_params.lower_chan_in_mhz =
  4517. current_channel;
  4518. spectral->classifier_params.upper_chan_in_mhz =
  4519. extension_channel;
  4520. }
  4521. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  4522. /* Set the FFT Size */
  4523. /* TODO : Remove this variable */
  4524. spectral->sc_spectral_20_40_mode = 0;
  4525. spectral->spectral_numbins =
  4526. target_if_get_fft_bin_count(
  4527. spectral->params[smode].ss_fft_size);
  4528. spectral->spectral_fft_len =
  4529. target_if_get_fft_bin_count(
  4530. spectral->params[smode].ss_fft_size);
  4531. spectral->spectral_data_len =
  4532. target_if_get_fft_bin_count(
  4533. spectral->params[smode].ss_fft_size);
  4534. /*
  4535. * Initialize classifier params to be sent to user
  4536. * space classifier
  4537. */
  4538. spectral->classifier_params.lower_chan_in_mhz =
  4539. current_channel;
  4540. spectral->classifier_params.upper_chan_in_mhz = 0;
  4541. /*
  4542. * Initialize classifier params to be sent to user
  4543. * space classifier
  4544. */
  4545. if (extension_channel < current_channel) {
  4546. spectral->classifier_params.lower_chan_in_mhz =
  4547. extension_channel;
  4548. spectral->classifier_params.upper_chan_in_mhz =
  4549. current_channel;
  4550. } else {
  4551. spectral->classifier_params.lower_chan_in_mhz =
  4552. current_channel;
  4553. spectral->classifier_params.upper_chan_in_mhz =
  4554. extension_channel;
  4555. }
  4556. } else if (is_ch_width_160_or_80p80(
  4557. spectral->ch_width[smode])) {
  4558. /* Set the FFT Size */
  4559. /* The below applies to both 160 and 80+80 cases */
  4560. /* TODO : Remove this variable */
  4561. spectral->sc_spectral_20_40_mode = 0;
  4562. spectral->spectral_numbins =
  4563. target_if_get_fft_bin_count(
  4564. spectral->params[smode].ss_fft_size);
  4565. spectral->spectral_fft_len =
  4566. target_if_get_fft_bin_count(
  4567. spectral->params[smode].ss_fft_size);
  4568. spectral->spectral_data_len =
  4569. target_if_get_fft_bin_count(
  4570. spectral->params[smode].ss_fft_size);
  4571. /*
  4572. * Initialize classifier params to be sent to user
  4573. * space classifier
  4574. */
  4575. spectral->classifier_params.lower_chan_in_mhz =
  4576. current_channel;
  4577. spectral->classifier_params.upper_chan_in_mhz = 0;
  4578. /*
  4579. * Initialize classifier params to be sent to user
  4580. * space classifier
  4581. */
  4582. if (extension_channel < current_channel) {
  4583. spectral->classifier_params.lower_chan_in_mhz =
  4584. extension_channel;
  4585. spectral->classifier_params.upper_chan_in_mhz =
  4586. current_channel;
  4587. } else {
  4588. spectral->classifier_params.lower_chan_in_mhz =
  4589. current_channel;
  4590. spectral->classifier_params.upper_chan_in_mhz =
  4591. extension_channel;
  4592. }
  4593. }
  4594. if (spectral->spectral_numbins) {
  4595. spectral->spectral_numbins +=
  4596. spectral->lb_edge_extrabins;
  4597. spectral->spectral_numbins +=
  4598. spectral->rb_edge_extrabins;
  4599. }
  4600. if (spectral->spectral_fft_len) {
  4601. spectral->spectral_fft_len +=
  4602. spectral->lb_edge_extrabins;
  4603. spectral->spectral_fft_len +=
  4604. spectral->rb_edge_extrabins;
  4605. }
  4606. if (spectral->spectral_data_len) {
  4607. spectral->spectral_data_len +=
  4608. spectral->lb_edge_extrabins;
  4609. spectral->spectral_data_len +=
  4610. spectral->rb_edge_extrabins;
  4611. }
  4612. } else {
  4613. /*
  4614. * The decision to find 20/40 mode is found based on the
  4615. * presence of extension channel
  4616. * instead of channel width, as the channel width can
  4617. * dynamically change
  4618. */
  4619. if (extension_channel == 0) {
  4620. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  4621. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  4622. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  4623. spectral->spectral_data_len =
  4624. SPECTRAL_HT20_TOTAL_DATA_LEN;
  4625. /* only valid in 20-40 mode */
  4626. spectral->spectral_lower_max_index_offset = -1;
  4627. /* only valid in 20-40 mode */
  4628. spectral->spectral_upper_max_index_offset = -1;
  4629. spectral->spectral_max_index_offset =
  4630. spectral->spectral_fft_len + 2;
  4631. spectral->sc_spectral_20_40_mode = 0;
  4632. /*
  4633. * Initialize classifier params to be sent to user
  4634. * space classifier
  4635. */
  4636. spectral->classifier_params.lower_chan_in_mhz =
  4637. current_channel;
  4638. spectral->classifier_params.upper_chan_in_mhz = 0;
  4639. } else {
  4640. spectral->spectral_numbins =
  4641. SPECTRAL_HT40_TOTAL_NUM_BINS;
  4642. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  4643. spectral->spectral_data_len =
  4644. SPECTRAL_HT40_TOTAL_DATA_LEN;
  4645. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  4646. /* only valid in 20 mode */
  4647. spectral->spectral_max_index_offset = -1;
  4648. spectral->spectral_lower_max_index_offset =
  4649. spectral->spectral_fft_len + 2;
  4650. spectral->spectral_upper_max_index_offset =
  4651. spectral->spectral_fft_len + 5;
  4652. spectral->sc_spectral_20_40_mode = 1;
  4653. /*
  4654. * Initialize classifier params to be sent to user
  4655. * space classifier
  4656. */
  4657. if (extension_channel < current_channel) {
  4658. spectral->classifier_params.lower_chan_in_mhz =
  4659. extension_channel;
  4660. spectral->classifier_params.upper_chan_in_mhz =
  4661. current_channel;
  4662. } else {
  4663. spectral->classifier_params.lower_chan_in_mhz =
  4664. current_channel;
  4665. spectral->classifier_params.upper_chan_in_mhz =
  4666. extension_channel;
  4667. }
  4668. }
  4669. }
  4670. spectral->send_single_packet = 0;
  4671. spectral->classifier_params.spectral_20_40_mode =
  4672. spectral->sc_spectral_20_40_mode;
  4673. spectral->classifier_params.spectral_dc_index =
  4674. spectral->spectral_dc_index;
  4675. spectral->spectral_sent_msg = 0;
  4676. spectral->classify_scan = 0;
  4677. spectral->num_spectral_data = 0;
  4678. if (!p_sops->is_spectral_active(spectral, smode)) {
  4679. p_sops->configure_spectral(spectral, spectral_params, smode);
  4680. spectral->rparams.marker[smode].is_valid = false;
  4681. if (spectral->params[smode].ss_count) {
  4682. status = target_if_spectral_finite_scan_init(spectral,
  4683. smode);
  4684. if (QDF_IS_STATUS_ERROR(status)) {
  4685. spectral_err("Failed to init finite scan");
  4686. return 1;
  4687. }
  4688. }
  4689. p_sops->start_spectral_scan(spectral, smode, err);
  4690. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  4691. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  4692. }
  4693. /* get current spectral configuration */
  4694. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  4695. target_if_init_upper_lower_flags(spectral, smode);
  4696. return 0;
  4697. }
  4698. /**
  4699. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  4700. * Agile DFS
  4701. * @psoc: Pointer to psoc
  4702. * @object: Pointer to pdev
  4703. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  4704. *
  4705. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  4706. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  4707. *
  4708. * Return: void
  4709. */
  4710. static void
  4711. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  4712. void *object, void *arg)
  4713. {
  4714. bool *is_aspectral_prohibited = arg;
  4715. struct wlan_objmgr_pdev *cur_pdev = object;
  4716. bool is_agile_precac_enabled_cur_pdev = false;
  4717. bool is_agile_rcac_enabled_cur_pdev = false;
  4718. QDF_STATUS status;
  4719. qdf_assert_always(is_aspectral_prohibited);
  4720. if (*is_aspectral_prohibited)
  4721. return;
  4722. qdf_assert_always(psoc);
  4723. qdf_assert_always(cur_pdev);
  4724. status = ucfg_dfs_get_agile_precac_enable
  4725. (cur_pdev,
  4726. &is_agile_precac_enabled_cur_pdev);
  4727. if (QDF_IS_STATUS_ERROR(status)) {
  4728. spectral_err("Get agile precac failed, prohibiting aSpectral");
  4729. *is_aspectral_prohibited = true;
  4730. return;
  4731. }
  4732. status = ucfg_dfs_get_rcac_enable(cur_pdev,
  4733. &is_agile_rcac_enabled_cur_pdev);
  4734. if (QDF_IS_STATUS_ERROR(status)) {
  4735. spectral_err("Get agile RCAC failed, prohibiting aSpectral");
  4736. *is_aspectral_prohibited = true;
  4737. return;
  4738. }
  4739. if (is_agile_precac_enabled_cur_pdev) {
  4740. spectral_err("aDFS preCAC is in progress on one of the pdevs");
  4741. *is_aspectral_prohibited = true;
  4742. } else if (is_agile_rcac_enabled_cur_pdev) {
  4743. spectral_err("aDFS RCAC is in progress on one of the pdevs");
  4744. *is_aspectral_prohibited = true;
  4745. }
  4746. }
  4747. /**
  4748. * target_if_get_curr_band() - Get current operating band of pdev
  4749. *
  4750. * @pdev: pointer to pdev object
  4751. *
  4752. * API to get current operating band of a given pdev.
  4753. *
  4754. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  4755. */
  4756. static enum reg_wifi_band
  4757. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id)
  4758. {
  4759. struct wlan_objmgr_vdev *vdev;
  4760. int16_t chan_freq;
  4761. enum reg_wifi_band cur_band;
  4762. if (!pdev) {
  4763. spectral_err("pdev is NULL");
  4764. return REG_BAND_UNKNOWN;
  4765. }
  4766. if (vdev_id == WLAN_INVALID_VDEV_ID)
  4767. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  4768. else
  4769. vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, vdev_id,
  4770. WLAN_SPECTRAL_ID);
  4771. if (!vdev) {
  4772. spectral_debug("vdev is NULL");
  4773. return REG_BAND_UNKNOWN;
  4774. }
  4775. chan_freq = target_if_vdev_get_chan_freq(vdev);
  4776. cur_band = wlan_reg_freq_to_band(chan_freq);
  4777. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4778. return cur_band;
  4779. }
  4780. /**
  4781. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  4782. * any of the 5G pdevs
  4783. * @psoc: Pointer to psoc
  4784. * @object: Pointer to pdev
  4785. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  4786. * progress in any 5G pdevs
  4787. *
  4788. * Return: void
  4789. */
  4790. static void
  4791. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  4792. void *object, void *arg)
  4793. {
  4794. enum reg_wifi_band band;
  4795. bool *is_agile_scan_inprog_5g_pdev = arg;
  4796. struct target_if_spectral *spectral;
  4797. struct wlan_objmgr_pdev *cur_pdev = object;
  4798. struct target_if_spectral_ops *p_sops;
  4799. if (*is_agile_scan_inprog_5g_pdev)
  4800. return;
  4801. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  4802. if (!spectral) {
  4803. spectral_err("target if spectral handle is NULL");
  4804. return;
  4805. }
  4806. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4807. band = target_if_get_curr_band(
  4808. cur_pdev, spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE]);
  4809. if (band == REG_BAND_UNKNOWN) {
  4810. spectral_debug("Failed to get current band");
  4811. return;
  4812. }
  4813. if (band == REG_BAND_5G &&
  4814. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  4815. *is_agile_scan_inprog_5g_pdev = true;
  4816. }
  4817. /**
  4818. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  4819. * for current vdev rx chainmask.
  4820. *
  4821. * @spectral: Pointer to Spectral object
  4822. * @is_supported: Pointer to is_supported
  4823. *
  4824. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4825. */
  4826. static QDF_STATUS
  4827. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  4828. bool *is_supported)
  4829. {
  4830. struct wlan_objmgr_vdev *vdev;
  4831. uint8_t vdev_rxchainmask;
  4832. struct wlan_objmgr_psoc *psoc;
  4833. struct wlan_objmgr_pdev *pdev;
  4834. struct target_psoc_info *tgt_psoc_info;
  4835. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  4836. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  4837. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  4838. struct wlan_psoc_host_chainmask_table *table;
  4839. int j;
  4840. uint32_t table_id;
  4841. enum phy_ch_width ch_width;
  4842. uint8_t pdev_id;
  4843. if (!spectral) {
  4844. spectral_err("spectral target if object is null");
  4845. return QDF_STATUS_E_FAILURE;
  4846. }
  4847. if (!is_supported) {
  4848. spectral_err("is supported argument is null");
  4849. return QDF_STATUS_E_FAILURE;
  4850. }
  4851. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  4852. spectral_err("HW Agile mode is not supported up to gen 2");
  4853. return QDF_STATUS_E_FAILURE;
  4854. }
  4855. pdev = spectral->pdev_obj;
  4856. if (!pdev) {
  4857. spectral_err("pdev is null");
  4858. return QDF_STATUS_E_FAILURE;
  4859. }
  4860. psoc = wlan_pdev_get_psoc(pdev);
  4861. if (!psoc) {
  4862. spectral_err("psoc is null");
  4863. return QDF_STATUS_E_FAILURE;
  4864. }
  4865. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  4866. if (!vdev) {
  4867. spectral_err("First vdev is NULL");
  4868. return QDF_STATUS_E_FAILURE;
  4869. }
  4870. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  4871. if (!vdev_rxchainmask) {
  4872. spectral_err("vdev rx chainmask is zero");
  4873. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4874. return QDF_STATUS_E_FAILURE;
  4875. }
  4876. ch_width = target_if_vdev_get_ch_width(vdev);
  4877. if (ch_width == CH_WIDTH_INVALID) {
  4878. spectral_err("Invalid channel width");
  4879. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4880. return QDF_STATUS_E_FAILURE;
  4881. }
  4882. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4883. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  4884. if (!tgt_psoc_info) {
  4885. spectral_err("target_psoc_info is null");
  4886. return QDF_STATUS_E_FAILURE;
  4887. }
  4888. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  4889. if (!ext_svc_param) {
  4890. spectral_err("Extended service ready param null");
  4891. return QDF_STATUS_E_FAILURE;
  4892. }
  4893. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  4894. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  4895. if (!mac_phy_cap_arr) {
  4896. spectral_err("mac phy cap array is null");
  4897. return QDF_STATUS_E_FAILURE;
  4898. }
  4899. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  4900. if (!mac_phy_cap) {
  4901. spectral_err("mac phy cap is null");
  4902. return QDF_STATUS_E_FAILURE;
  4903. }
  4904. table_id = mac_phy_cap->chainmask_table_id;
  4905. table = &ext_svc_param->chainmask_table[table_id];
  4906. if (!table) {
  4907. spectral_err("chainmask table not found");
  4908. return QDF_STATUS_E_FAILURE;
  4909. }
  4910. for (j = 0; j < table->num_valid_chainmasks; j++) {
  4911. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  4912. if (ch_width <= CH_WIDTH_80MHZ)
  4913. *is_supported =
  4914. table->cap_list[j].supports_aSpectral;
  4915. else
  4916. *is_supported =
  4917. table->cap_list[j].supports_aSpectral_160;
  4918. break;
  4919. }
  4920. }
  4921. if (j == table->num_valid_chainmasks) {
  4922. spectral_err("vdev rx chainmask %u not found in table id = %u",
  4923. vdev_rxchainmask, table_id);
  4924. return QDF_STATUS_E_FAILURE;
  4925. }
  4926. return QDF_STATUS_SUCCESS;
  4927. }
  4928. #define INVALID_SPAN_NUM (-1)
  4929. /**
  4930. * target_if_spectral_get_num_spans() - Get number of spans for a given sscan_bw
  4931. * @pdev: Pointer to pdev object
  4932. * @sscan_bw: Spectral scan bandwidth
  4933. *
  4934. * Return: Number of spans on success, INVALID_SPAN_NUM on failure
  4935. */
  4936. static int
  4937. target_if_spectral_get_num_spans(
  4938. struct wlan_objmgr_pdev *pdev,
  4939. enum phy_ch_width sscan_bw)
  4940. {
  4941. struct wlan_objmgr_psoc *psoc;
  4942. int num_spans;
  4943. if (!pdev) {
  4944. spectral_err_rl("pdev is null");
  4945. return INVALID_SPAN_NUM;
  4946. }
  4947. psoc = wlan_pdev_get_psoc(pdev);
  4948. if (!psoc) {
  4949. spectral_err_rl("psoc is null");
  4950. return INVALID_SPAN_NUM;
  4951. }
  4952. if (sscan_bw == CH_WIDTH_80P80MHZ) {
  4953. num_spans = 2;
  4954. if (wlan_psoc_nif_fw_ext_cap_get(
  4955. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  4956. /* 5 MHz frequency span in restricted 80p80 case */
  4957. num_spans += 1;
  4958. } else {
  4959. num_spans = 1;
  4960. }
  4961. return num_spans;
  4962. }
  4963. #ifdef OPTIMIZED_SAMP_MESSAGE
  4964. /**
  4965. * target_if_spectral_populate_session_report_info() - Populate per-session
  4966. * report level information.
  4967. *
  4968. * @spectral: Pointer to Spectral object
  4969. * @smode: Spectral scan mode
  4970. *
  4971. * Return: Success/Failure
  4972. */
  4973. static QDF_STATUS
  4974. target_if_spectral_populate_session_report_info(
  4975. struct target_if_spectral *spectral,
  4976. enum spectral_scan_mode smode)
  4977. {
  4978. struct per_session_report_info *rpt_info;
  4979. if (!spectral) {
  4980. spectral_err_rl("Spectral LMAC object is null");
  4981. return QDF_STATUS_E_NULL_VALUE;
  4982. }
  4983. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  4984. spectral_err_rl("Invalid Spectral scan mode");
  4985. return QDF_STATUS_E_FAILURE;
  4986. }
  4987. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  4988. /* Fill per-session report information, based on the spectral mode */
  4989. rpt_info = &spectral->report_info[smode];
  4990. rpt_info->operating_bw = spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  4991. rpt_info->sscan_bw = spectral->ch_width[smode];
  4992. rpt_info->sscan_cfreq1 = spectral->params[smode].ss_frequency.cfreq1;
  4993. rpt_info->sscan_cfreq2 = spectral->params[smode].ss_frequency.cfreq2;
  4994. rpt_info->num_spans = target_if_spectral_get_num_spans(
  4995. spectral->pdev_obj,
  4996. rpt_info->sscan_bw);
  4997. qdf_assert_always(rpt_info->num_spans != INVALID_SPAN_NUM);
  4998. rpt_info->valid = true;
  4999. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5000. return QDF_STATUS_SUCCESS;
  5001. }
  5002. /**
  5003. * target_if_spectral_populate_session_det_host_info() - Populate per-session
  5004. * detector level information that is known to the Host
  5005. *
  5006. * @spectral: Pointer to Spectral object
  5007. * @smode: Spectral scan mode
  5008. *
  5009. * Return: Success/Failure
  5010. */
  5011. static QDF_STATUS
  5012. target_if_spectral_populate_session_det_host_info(
  5013. struct target_if_spectral *spectral,
  5014. enum spectral_scan_mode smode)
  5015. {
  5016. struct per_session_report_info *rpt_info;
  5017. struct sscan_detector_list *detector_list;
  5018. struct wlan_objmgr_psoc *psoc;
  5019. uint16_t dest_det_idx = 0;
  5020. uint16_t dest_span_idx = 0;
  5021. bool is_sec80 = false;
  5022. uint8_t det, dest_det;
  5023. if (!spectral) {
  5024. spectral_err_rl("Spectral LMAC object is null");
  5025. return QDF_STATUS_E_NULL_VALUE;
  5026. }
  5027. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  5028. spectral_err_rl("Invalid Spectral scan mode");
  5029. return QDF_STATUS_E_FAILURE;
  5030. }
  5031. if (!spectral->pdev_obj) {
  5032. spectral_err_rl("Spectral PDEV is null");
  5033. return QDF_STATUS_E_NULL_VALUE;
  5034. }
  5035. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  5036. if (!psoc) {
  5037. spectral_err_rl("psoc is null");
  5038. return QDF_STATUS_E_NULL_VALUE;
  5039. }
  5040. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5041. rpt_info = &spectral->report_info[smode];
  5042. qdf_spin_lock_bh(&spectral->detector_list_lock);
  5043. /* Fill per-sesion detector-level information */
  5044. detector_list = &spectral->detector_list[smode][rpt_info->sscan_bw];
  5045. for (det = 0; det < detector_list->num_detectors; det++) {
  5046. struct per_session_det_map *det_map;
  5047. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  5048. det_map = &spectral->det_map[detector_list->detectors[det]];
  5049. if (detector_list->num_detectors > 1) {
  5050. if (det == 0) {
  5051. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  5052. det_map->send_to_upper_layers = false;
  5053. } else if (det == detector_list->num_detectors - 1) {
  5054. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  5055. det_map->send_to_upper_layers = true;
  5056. } else {
  5057. /* middle fragments */
  5058. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  5059. det_map->send_to_upper_layers = false;
  5060. }
  5061. } else {
  5062. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  5063. det_map->send_to_upper_layers = true;
  5064. }
  5065. det_map->num_dest_det_info = 1;
  5066. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ &&
  5067. wlan_psoc_nif_fw_ext_cap_get(
  5068. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  5069. /**
  5070. * In 165MHz case, 1 Spectral HW detector maps to 3
  5071. * detectors in SAMP msg.
  5072. */
  5073. det_map->num_dest_det_info += 2;
  5074. }
  5075. for (dest_det = 0; dest_det < det_map->num_dest_det_info;
  5076. dest_det++) {
  5077. struct per_session_dest_det_info *map_det_info;
  5078. map_det_info = &det_map->dest_det_info[dest_det];
  5079. map_det_info->freq_span_id = dest_span_idx;
  5080. map_det_info->det_id = dest_det_idx;
  5081. map_det_info->is_sec80 = is_sec80;
  5082. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ) {
  5083. /* Increment span ID for non-contiguous modes */
  5084. dest_det_idx = 0;
  5085. dest_span_idx++;
  5086. } else {
  5087. /* Increment detector ID for contiguous modes */
  5088. dest_det_idx++;
  5089. }
  5090. is_sec80 = !is_sec80;
  5091. }
  5092. det_map->det_map_valid[smode] = true;
  5093. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  5094. }
  5095. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  5096. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5097. return QDF_STATUS_SUCCESS;
  5098. }
  5099. #else
  5100. static QDF_STATUS
  5101. target_if_spectral_populate_session_report_info(
  5102. struct target_if_spectral *spectral,
  5103. enum spectral_scan_mode smode)
  5104. {
  5105. return QDF_STATUS_SUCCESS;
  5106. }
  5107. static QDF_STATUS
  5108. target_if_spectral_populate_session_det_host_info(
  5109. struct target_if_spectral *spectral,
  5110. enum spectral_scan_mode smode)
  5111. {
  5112. return QDF_STATUS_SUCCESS;
  5113. }
  5114. #endif /* OPTIMIZED_SAMP_MESSAGE */
  5115. QDF_STATUS
  5116. spectral_is_session_info_expected_from_target(struct wlan_objmgr_pdev *pdev,
  5117. bool *is_session_info_expected)
  5118. {
  5119. struct wlan_objmgr_psoc *psoc;
  5120. struct wmi_unified *wmi_handle;
  5121. if (!pdev) {
  5122. spectral_err("pdev is null");
  5123. return QDF_STATUS_E_NULL_VALUE;
  5124. }
  5125. psoc = wlan_pdev_get_psoc(pdev);
  5126. if (!psoc) {
  5127. spectral_err("psoc is null");
  5128. return QDF_STATUS_E_NULL_VALUE;
  5129. }
  5130. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  5131. if (!wmi_handle) {
  5132. spectral_err("wmi handle is null");
  5133. return QDF_STATUS_E_NULL_VALUE;
  5134. }
  5135. *is_session_info_expected = target_if_spectral_wmi_service_enabled(
  5136. psoc, wmi_handle,
  5137. wmi_service_spectral_session_info_support);
  5138. return QDF_STATUS_SUCCESS;
  5139. }
  5140. QDF_STATUS
  5141. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  5142. uint8_t vdev_id,
  5143. const enum spectral_scan_mode smode,
  5144. enum spectral_cp_error_code *err)
  5145. {
  5146. struct target_if_spectral_ops *p_sops;
  5147. struct target_if_spectral *spectral;
  5148. struct wlan_objmgr_psoc *psoc;
  5149. enum reg_wifi_band band;
  5150. QDF_STATUS ret;
  5151. bool is_session_info_expected;
  5152. if (!err) {
  5153. spectral_err("Error code argument is null");
  5154. QDF_ASSERT(0);
  5155. return QDF_STATUS_E_FAILURE;
  5156. }
  5157. *err = SPECTRAL_SCAN_ERR_INVALID;
  5158. if (!pdev) {
  5159. spectral_err("pdev object is NUll");
  5160. return QDF_STATUS_E_FAILURE;
  5161. }
  5162. psoc = wlan_pdev_get_psoc(pdev);
  5163. if (!psoc) {
  5164. spectral_err("psoc is null");
  5165. return QDF_STATUS_E_FAILURE;
  5166. }
  5167. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5168. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5169. spectral_err("Invalid Spectral mode %u", smode);
  5170. return QDF_STATUS_E_FAILURE;
  5171. }
  5172. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5173. if (!spectral) {
  5174. spectral_err("Spectral LMAC object is NUll");
  5175. return QDF_STATUS_E_FAILURE;
  5176. }
  5177. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5178. if (!p_sops) {
  5179. spectral_err("p_sops is null");
  5180. return QDF_STATUS_E_FAILURE;
  5181. }
  5182. if (p_sops->is_spectral_active(spectral, smode)) {
  5183. spectral_err("spectral in progress in current pdev, mode %d",
  5184. smode);
  5185. return QDF_STATUS_E_FAILURE;
  5186. }
  5187. spectral->vdev_id[smode] = vdev_id;
  5188. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5189. QDF_STATUS status;
  5190. bool is_supported = false;
  5191. status = target_if_is_agile_supported_cur_chmask(spectral,
  5192. &is_supported);
  5193. if (QDF_IS_STATUS_ERROR(status)) {
  5194. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5195. return QDF_STATUS_E_FAILURE;
  5196. }
  5197. if (!is_supported) {
  5198. spectral_err("aSpectral unsupported for cur chainmask");
  5199. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5200. return QDF_STATUS_E_FAILURE;
  5201. }
  5202. }
  5203. band = target_if_get_curr_band(spectral->pdev_obj, vdev_id);
  5204. if (band == REG_BAND_UNKNOWN) {
  5205. spectral_err("Failed to get current band");
  5206. return QDF_STATUS_E_FAILURE;
  5207. }
  5208. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  5209. struct target_psoc_info *tgt_hdl;
  5210. enum wmi_host_hw_mode_config_type mode;
  5211. bool is_agile_scan_inprog_5g_pdev;
  5212. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  5213. if (!tgt_hdl) {
  5214. target_if_err("target_psoc_info is null");
  5215. return QDF_STATUS_E_FAILURE;
  5216. }
  5217. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  5218. switch (mode) {
  5219. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  5220. case WMI_HOST_HW_MODE_SBS:
  5221. case WMI_HOST_HW_MODE_DBS_SBS:
  5222. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  5223. is_agile_scan_inprog_5g_pdev = false;
  5224. wlan_objmgr_iterate_obj_list
  5225. (psoc, WLAN_PDEV_OP,
  5226. target_if_is_agile_scan_active_in_5g,
  5227. &is_agile_scan_inprog_5g_pdev, 0,
  5228. WLAN_SPECTRAL_ID);
  5229. break;
  5230. default:
  5231. is_agile_scan_inprog_5g_pdev = false;
  5232. break;
  5233. }
  5234. if (is_agile_scan_inprog_5g_pdev) {
  5235. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  5236. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5237. return QDF_STATUS_E_FAILURE;
  5238. }
  5239. }
  5240. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5241. bool is_aspectral_prohibited = false;
  5242. QDF_STATUS status;
  5243. status = wlan_objmgr_iterate_obj_list
  5244. (psoc, WLAN_PDEV_OP,
  5245. target_if_is_aspectral_prohibited_by_adfs,
  5246. &is_aspectral_prohibited, 0,
  5247. WLAN_SPECTRAL_ID);
  5248. if (QDF_IS_STATUS_ERROR(status)) {
  5249. spectral_err("Failed to iterate over pdevs");
  5250. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5251. return QDF_STATUS_E_FAILURE;
  5252. }
  5253. if (is_aspectral_prohibited) {
  5254. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5255. return QDF_STATUS_E_FAILURE;
  5256. }
  5257. }
  5258. if (!spectral->params_valid[smode]) {
  5259. target_if_spectral_info_read(spectral,
  5260. smode,
  5261. TARGET_IF_SPECTRAL_INFO_PARAMS,
  5262. &spectral->params[smode],
  5263. sizeof(spectral->params[smode]));
  5264. spectral->params_valid[smode] = true;
  5265. }
  5266. qdf_spin_lock_bh(&spectral->spectral_lock);
  5267. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5268. QDF_STATUS status;
  5269. bool is_overlapping;
  5270. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  5271. enum spectral_scan_mode m;
  5272. enum phy_ch_width agile_ch_width;
  5273. m = SPECTRAL_SCAN_MODE_NORMAL;
  5274. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  5275. ch_width[m] = CH_WIDTH_INVALID;
  5276. status = target_if_spectral_populate_chwidth
  5277. (spectral, ch_width, spectral->params
  5278. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  5279. if (QDF_IS_STATUS_ERROR(status)) {
  5280. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5281. spectral_err("Failed to populate channel width");
  5282. return QDF_STATUS_E_FAILURE;
  5283. }
  5284. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  5285. if (!spectral->params[smode].ss_frequency.cfreq1) {
  5286. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  5287. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5288. spectral_err("Agile Spectral cfreq1 is 0");
  5289. return QDF_STATUS_E_FAILURE;
  5290. } else if (agile_ch_width == CH_WIDTH_80P80MHZ &&
  5291. !spectral->params[smode].ss_frequency.cfreq2) {
  5292. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  5293. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5294. spectral_err("Agile Spectral cfreq2 is 0");
  5295. return QDF_STATUS_E_FAILURE;
  5296. }
  5297. status = target_if_is_agile_span_overlap_with_operating_span
  5298. (spectral, ch_width,
  5299. &spectral->params[smode].ss_frequency,
  5300. &is_overlapping);
  5301. if (QDF_IS_STATUS_ERROR(status)) {
  5302. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5303. return QDF_STATUS_E_FAILURE;
  5304. }
  5305. if (is_overlapping) {
  5306. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  5307. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5308. return QDF_STATUS_E_FAILURE;
  5309. }
  5310. }
  5311. /* Populate detectot list first */
  5312. ret = target_if_spectral_detector_list_init(spectral);
  5313. if (QDF_IS_STATUS_ERROR(ret)) {
  5314. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5315. spectral_err("Failed to initialize detector list");
  5316. return ret;
  5317. }
  5318. ret = target_if_spectral_populate_chwidth(
  5319. spectral, spectral->ch_width,
  5320. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  5321. ss_frequency.cfreq2 > 0);
  5322. if (QDF_IS_STATUS_ERROR(ret)) {
  5323. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5324. spectral_err("Failed to get channel widths");
  5325. return ret;
  5326. }
  5327. ret = spectral_is_session_info_expected_from_target(
  5328. spectral->pdev_obj,
  5329. &is_session_info_expected);
  5330. if (QDF_IS_STATUS_ERROR(ret)) {
  5331. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5332. spectral_err("Failed to check if session info is expected");
  5333. return ret;
  5334. }
  5335. /* If FW doesn't send session info, populate it */
  5336. if (!is_session_info_expected) {
  5337. ret = target_if_spectral_populate_session_report_info(spectral,
  5338. smode);
  5339. if (QDF_IS_STATUS_ERROR(ret)) {
  5340. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5341. spectral_err("Failed to populate per-session report info");
  5342. return QDF_STATUS_E_FAILURE;
  5343. }
  5344. ret = target_if_spectral_populate_session_det_host_info(
  5345. spectral, smode);
  5346. if (QDF_IS_STATUS_ERROR(ret)) {
  5347. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5348. spectral_err("Failed to populate per-session detector info");
  5349. return QDF_STATUS_E_FAILURE;
  5350. }
  5351. }
  5352. target_if_spectral_scan_enable_params(spectral,
  5353. &spectral->params[smode], smode,
  5354. err);
  5355. spectral->sscan_width_configured[smode] = false;
  5356. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5357. return QDF_STATUS_SUCCESS;
  5358. }
  5359. QDF_STATUS
  5360. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  5361. const enum spectral_scan_mode smode,
  5362. enum spectral_cp_error_code *err)
  5363. {
  5364. struct target_if_spectral_ops *p_sops;
  5365. struct target_if_spectral *spectral;
  5366. uint8_t det;
  5367. if (!pdev) {
  5368. spectral_err("pdev object is NULL");
  5369. return QDF_STATUS_E_INVAL;
  5370. }
  5371. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  5372. spectral_info("Spectral feature is disabled");
  5373. return QDF_STATUS_COMP_DISABLED;
  5374. }
  5375. if (!err) {
  5376. spectral_err("Error code argument is null");
  5377. QDF_ASSERT(0);
  5378. return QDF_STATUS_E_FAILURE;
  5379. }
  5380. *err = SPECTRAL_SCAN_ERR_INVALID;
  5381. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5382. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5383. spectral_err("Invalid Spectral mode %u", smode);
  5384. return QDF_STATUS_E_FAILURE;
  5385. }
  5386. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5387. if (!spectral) {
  5388. spectral_err("Spectral LMAC object is NUll ");
  5389. return QDF_STATUS_E_FAILURE;
  5390. }
  5391. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5392. qdf_spin_lock_bh(&spectral->spectral_lock);
  5393. p_sops->stop_spectral_scan(spectral, smode);
  5394. if (spectral->classify_scan) {
  5395. /* TODO : Check if this logic is necessary */
  5396. spectral->detects_control_channel = 0;
  5397. spectral->detects_extension_channel = 0;
  5398. spectral->detects_above_dc = 0;
  5399. spectral->detects_below_dc = 0;
  5400. spectral->classify_scan = 0;
  5401. }
  5402. spectral->send_single_packet = 0;
  5403. spectral->sc_spectral_scan = 0;
  5404. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  5405. for (det = 0; det < MAX_DETECTORS_PER_PDEV; det++)
  5406. spectral->det_map[det].det_map_valid[smode] = false;
  5407. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  5408. /* Mark report info as invalid */
  5409. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5410. spectral->report_info[smode].valid = false;
  5411. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5412. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5413. return QDF_STATUS_SUCCESS;
  5414. }
  5415. /**
  5416. * target_if_is_spectral_active() - Get whether Spectral is active
  5417. * @pdev: Pointer to pdev object
  5418. * @smode: Spectral scan mode
  5419. *
  5420. * API to get whether Spectral is active
  5421. *
  5422. * Return: True if Spectral is active, false if Spectral is not active
  5423. */
  5424. bool
  5425. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  5426. const enum spectral_scan_mode smode)
  5427. {
  5428. struct target_if_spectral *spectral = NULL;
  5429. struct target_if_spectral_ops *p_sops = NULL;
  5430. if (!pdev) {
  5431. spectral_err("pdev is null");
  5432. return false;
  5433. }
  5434. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  5435. spectral_info("Spectral feature is disabled");
  5436. return false;
  5437. }
  5438. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5439. if (!spectral) {
  5440. spectral_err("SPECTRAL : Module doesn't exist");
  5441. return false;
  5442. }
  5443. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5444. if (!p_sops) {
  5445. spectral_err("p_sops is null");
  5446. return false;
  5447. }
  5448. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5449. spectral_err("Invalid Spectral mode %u", smode);
  5450. return false;
  5451. }
  5452. return p_sops->is_spectral_active(spectral, smode);
  5453. }
  5454. /**
  5455. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  5456. * @pdev: Pointer to pdev object
  5457. * @smode: Spectral scan mode
  5458. *
  5459. * API to get whether Spectral is enabled
  5460. *
  5461. * Return: True if Spectral is enabled, false if Spectral is not enabled
  5462. */
  5463. bool
  5464. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  5465. enum spectral_scan_mode smode)
  5466. {
  5467. struct target_if_spectral *spectral = NULL;
  5468. struct target_if_spectral_ops *p_sops = NULL;
  5469. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5470. if (!spectral) {
  5471. spectral_err("SPECTRAL : Module doesn't exist");
  5472. return false;
  5473. }
  5474. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5475. if (!p_sops) {
  5476. spectral_err("p_sops is null");
  5477. return false;
  5478. }
  5479. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5480. spectral_err("Invalid Spectral mode %u", smode);
  5481. return false;
  5482. }
  5483. return p_sops->is_spectral_enabled(spectral, smode);
  5484. }
  5485. #ifdef DIRECT_BUF_RX_DEBUG
  5486. /**
  5487. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  5488. * @pdev: Pointer to pdev object
  5489. * @enable: Enable/Disable Spectral DMA ring debug
  5490. *
  5491. * Start/stop Spectral DMA ring debug based on @enable.
  5492. * Also save the state for future use.
  5493. *
  5494. * Return: QDF_STATUS of operation
  5495. */
  5496. static QDF_STATUS
  5497. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  5498. {
  5499. struct target_if_spectral *spectral;
  5500. struct wlan_lmac_if_tx_ops *tx_ops;
  5501. struct wlan_objmgr_psoc *psoc;
  5502. if (!pdev)
  5503. return QDF_STATUS_E_FAILURE;
  5504. psoc = wlan_pdev_get_psoc(pdev);
  5505. if (!psoc) {
  5506. spectral_err("psoc is null");
  5507. return QDF_STATUS_E_INVAL;
  5508. }
  5509. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5510. if (!tx_ops) {
  5511. spectral_err("tx_ops is NULL");
  5512. return QDF_STATUS_E_INVAL;
  5513. }
  5514. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5515. if (!spectral) {
  5516. spectral_err("Spectal LMAC object is NULL");
  5517. return QDF_STATUS_E_INVAL;
  5518. }
  5519. /* Save the state */
  5520. spectral->dbr_ring_debug = enable;
  5521. if (enable)
  5522. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  5523. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  5524. else
  5525. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  5526. pdev, 0);
  5527. return QDF_STATUS_SUCCESS;
  5528. }
  5529. /**
  5530. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  5531. * @pdev: Pointer to pdev object
  5532. * @enable: Enable/Disable Spectral DMA buffer debug
  5533. *
  5534. * Start/stop Spectral DMA buffer debug based on @enable.
  5535. * Also save the state for future use.
  5536. *
  5537. * Return: QDF_STATUS of operation
  5538. */
  5539. static QDF_STATUS
  5540. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  5541. {
  5542. struct target_if_spectral *spectral;
  5543. struct wlan_lmac_if_tx_ops *tx_ops;
  5544. struct wlan_objmgr_psoc *psoc;
  5545. if (!pdev)
  5546. return QDF_STATUS_E_FAILURE;
  5547. psoc = wlan_pdev_get_psoc(pdev);
  5548. if (!psoc) {
  5549. spectral_err("psoc is null");
  5550. return QDF_STATUS_E_INVAL;
  5551. }
  5552. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5553. if (!tx_ops) {
  5554. spectral_err("tx_ops is NULL");
  5555. return QDF_STATUS_E_INVAL;
  5556. }
  5557. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5558. if (!spectral) {
  5559. spectral_err("Spectal LMAC object is NULL");
  5560. return QDF_STATUS_E_INVAL;
  5561. }
  5562. /* Save the state */
  5563. spectral->dbr_buff_debug = enable;
  5564. if (enable)
  5565. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  5566. pdev, 0, MEM_POISON_SIGNATURE);
  5567. else
  5568. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  5569. pdev, 0);
  5570. }
  5571. /**
  5572. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  5573. * debug based on the previous state
  5574. * @pdev: Pointer to pdev object
  5575. *
  5576. * Return: QDF_STATUS of operation
  5577. */
  5578. static QDF_STATUS
  5579. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  5580. {
  5581. struct target_if_spectral *spectral;
  5582. if (!pdev) {
  5583. spectral_err("pdev is NULL!");
  5584. return QDF_STATUS_E_FAILURE;
  5585. }
  5586. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5587. if (!spectral) {
  5588. spectral_err("Spectal LMAC object is NULL");
  5589. return QDF_STATUS_E_INVAL;
  5590. }
  5591. if (spectral->dbr_buff_debug)
  5592. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  5593. else
  5594. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  5595. }
  5596. /**
  5597. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  5598. * debug based on the previous state
  5599. * @pdev: Pointer to pdev object
  5600. *
  5601. * Return: QDF_STATUS of operation
  5602. */
  5603. static QDF_STATUS
  5604. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  5605. {
  5606. struct target_if_spectral *spectral;
  5607. if (!pdev) {
  5608. spectral_err("pdev is NULL!");
  5609. return QDF_STATUS_E_FAILURE;
  5610. }
  5611. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5612. if (!spectral) {
  5613. spectral_err("Spectal LMAC object is NULL");
  5614. return QDF_STATUS_E_INVAL;
  5615. }
  5616. if (spectral->dbr_ring_debug)
  5617. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  5618. else
  5619. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  5620. }
  5621. /**
  5622. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  5623. * @pdev: Pointer to pdev object
  5624. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  5625. * @debug_value: Value to be set for @dma_debug_type
  5626. *
  5627. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  5628. * based on @debug_value
  5629. *
  5630. * Return: QDF_STATUS of operation
  5631. */
  5632. static QDF_STATUS
  5633. target_if_spectral_set_dma_debug(
  5634. struct wlan_objmgr_pdev *pdev,
  5635. enum spectral_dma_debug dma_debug_type,
  5636. bool debug_value)
  5637. {
  5638. struct target_if_spectral_ops *p_sops;
  5639. struct wlan_objmgr_psoc *psoc;
  5640. struct wlan_lmac_if_tx_ops *tx_ops;
  5641. struct target_if_spectral *spectral;
  5642. if (!pdev)
  5643. return QDF_STATUS_E_FAILURE;
  5644. psoc = wlan_pdev_get_psoc(pdev);
  5645. if (!psoc) {
  5646. spectral_err("psoc is null");
  5647. return QDF_STATUS_E_INVAL;
  5648. }
  5649. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5650. if (!tx_ops) {
  5651. spectral_err("tx_ops is NULL");
  5652. return QDF_STATUS_E_FAILURE;
  5653. }
  5654. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  5655. spectral_err("Unable to fetch target type");
  5656. return QDF_STATUS_E_FAILURE;
  5657. }
  5658. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5659. if (!spectral) {
  5660. spectral_err("Spectal LMAC object is NULL");
  5661. return QDF_STATUS_E_INVAL;
  5662. }
  5663. if (spectral->direct_dma_support) {
  5664. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5665. if (p_sops->is_spectral_active(spectral,
  5666. SPECTRAL_SCAN_MODE_NORMAL) ||
  5667. p_sops->is_spectral_active(spectral,
  5668. SPECTRAL_SCAN_MODE_AGILE)) {
  5669. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  5670. return QDF_STATUS_E_FAILURE;
  5671. }
  5672. switch (dma_debug_type) {
  5673. case SPECTRAL_DMA_RING_DEBUG:
  5674. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  5675. break;
  5676. case SPECTRAL_DMA_BUFFER_DEBUG:
  5677. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  5678. break;
  5679. default:
  5680. spectral_err("Unsupported DMA debug type : %d",
  5681. dma_debug_type);
  5682. return QDF_STATUS_E_FAILURE;
  5683. }
  5684. }
  5685. return QDF_STATUS_SUCCESS;
  5686. }
  5687. #endif /* DIRECT_BUF_RX_DEBUG */
  5688. /**
  5689. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  5690. * @pdev: Pointer to pdev object
  5691. *
  5692. * Return: Whether Direct-DMA is supported on this radio
  5693. */
  5694. static bool
  5695. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  5696. {
  5697. struct target_if_spectral *spectral;
  5698. if (!pdev) {
  5699. spectral_err("pdev is NULL!");
  5700. return false;
  5701. }
  5702. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5703. if (!spectral) {
  5704. spectral_err("Spectral LMAC object is NULL");
  5705. return false;
  5706. }
  5707. return spectral->direct_dma_support;
  5708. }
  5709. /**
  5710. * target_if_set_debug_level() - Set debug level for Spectral
  5711. * @pdev: Pointer to pdev object
  5712. * @debug_level: Debug level
  5713. *
  5714. * API to set the debug level for Spectral
  5715. *
  5716. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5717. */
  5718. QDF_STATUS
  5719. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  5720. {
  5721. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  5722. return QDF_STATUS_SUCCESS;
  5723. }
  5724. /**
  5725. * target_if_get_debug_level() - Get debug level for Spectral
  5726. * @pdev: Pointer to pdev object
  5727. *
  5728. * API to get the debug level for Spectral
  5729. *
  5730. * Return: Current debug level
  5731. */
  5732. uint32_t
  5733. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  5734. {
  5735. return spectral_debug_level;
  5736. }
  5737. /**
  5738. * target_if_get_spectral_capinfo() - Get Spectral capability information
  5739. * @pdev: Pointer to pdev object
  5740. * @scaps: Buffer into which data should be copied
  5741. *
  5742. * API to get the spectral capability information
  5743. *
  5744. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5745. */
  5746. QDF_STATUS
  5747. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  5748. struct spectral_caps *scaps)
  5749. {
  5750. struct target_if_spectral *spectral = NULL;
  5751. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5752. if (!spectral) {
  5753. spectral_err("SPECTRAL : Module doesn't exist");
  5754. return QDF_STATUS_E_FAILURE;
  5755. }
  5756. qdf_mem_copy(scaps, &spectral->capability,
  5757. sizeof(struct spectral_caps));
  5758. return QDF_STATUS_SUCCESS;
  5759. }
  5760. /**
  5761. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  5762. * @pdev: Pointer to pdev object
  5763. * @stats: Buffer into which data should be copied
  5764. *
  5765. * API to get the spectral diagnostic statistics
  5766. *
  5767. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5768. */
  5769. QDF_STATUS
  5770. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  5771. struct spectral_diag_stats *stats)
  5772. {
  5773. struct target_if_spectral *spectral = NULL;
  5774. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5775. if (!spectral) {
  5776. spectral_err("SPECTRAL : Module doesn't exist");
  5777. return QDF_STATUS_E_FAILURE;
  5778. }
  5779. qdf_mem_copy(stats, &spectral->diag_stats,
  5780. sizeof(struct spectral_diag_stats));
  5781. return QDF_STATUS_SUCCESS;
  5782. }
  5783. /**
  5784. * target_if_register_spectral_wmi_ops() - Register Spectral WMI operations
  5785. * @psoc: Pointer to psoc object
  5786. * @wmi_ops: Pointer to the structure having Spectral WMI operations
  5787. *
  5788. * API for registering Spectral WMI operations in
  5789. * spectral internal data structure
  5790. *
  5791. * Return: QDF_STATUS
  5792. */
  5793. static QDF_STATUS
  5794. target_if_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
  5795. struct spectral_wmi_ops *wmi_ops)
  5796. {
  5797. struct target_if_psoc_spectral *psoc_spectral;
  5798. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5799. if (!psoc_spectral) {
  5800. spectral_err("Spectral LMAC object is null");
  5801. return QDF_STATUS_E_INVAL;
  5802. }
  5803. psoc_spectral->wmi_ops = *wmi_ops;
  5804. return QDF_STATUS_SUCCESS;
  5805. }
  5806. /**
  5807. * target_if_register_spectral_tgt_ops() - Register Spectral target operations
  5808. * @psoc: Pointer to psoc object
  5809. * @tgt_ops: Pointer to the structure having Spectral target operations
  5810. *
  5811. * API for registering Spectral target operations in
  5812. * spectral internal data structure
  5813. *
  5814. * Return: QDF_STATUS
  5815. */
  5816. static QDF_STATUS
  5817. target_if_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
  5818. struct spectral_tgt_ops *tgt_ops)
  5819. {
  5820. if (!psoc) {
  5821. spectral_err("psoc is null");
  5822. return QDF_STATUS_E_INVAL;
  5823. }
  5824. ops_tgt = *tgt_ops;
  5825. return QDF_STATUS_SUCCESS;
  5826. }
  5827. /**
  5828. * target_if_register_netlink_cb() - Register Netlink callbacks
  5829. * @pdev: Pointer to pdev object
  5830. * @nl_cb: Netlink callbacks to register
  5831. *
  5832. * Return: void
  5833. */
  5834. static void
  5835. target_if_register_netlink_cb(
  5836. struct wlan_objmgr_pdev *pdev,
  5837. struct spectral_nl_cb *nl_cb)
  5838. {
  5839. struct target_if_spectral *spectral = NULL;
  5840. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5841. if (!spectral) {
  5842. spectral_err("SPECTRAL : Module doesn't exist");
  5843. return;
  5844. }
  5845. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  5846. if (spectral->use_nl_bcast)
  5847. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  5848. else
  5849. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  5850. }
  5851. /**
  5852. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  5853. * Netlink messages to the application layer
  5854. * @pdev: Pointer to pdev object
  5855. *
  5856. * Return: true for broadcast, false for unicast
  5857. */
  5858. static bool
  5859. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  5860. {
  5861. struct target_if_spectral *spectral = NULL;
  5862. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5863. if (!spectral) {
  5864. spectral_err("SPECTRAL : Module doesn't exist");
  5865. return false;
  5866. }
  5867. return spectral->use_nl_bcast;
  5868. }
  5869. /**
  5870. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  5871. * @pdev: Pointer to pdev object
  5872. *
  5873. * Return: void
  5874. */
  5875. static void
  5876. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  5877. {
  5878. struct target_if_spectral *spectral = NULL;
  5879. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5880. if (!spectral) {
  5881. spectral_err("SPECTRAL : Module doesn't exist");
  5882. return;
  5883. }
  5884. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  5885. }
  5886. static int
  5887. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  5888. void *payload)
  5889. {
  5890. struct target_if_spectral *spectral = NULL;
  5891. struct target_if_spectral_ops *p_sops = NULL;
  5892. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5893. if (!spectral) {
  5894. spectral_err("SPECTRAL : Module doesn't exist");
  5895. return -EPERM;
  5896. }
  5897. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5898. if (!p_sops) {
  5899. spectral_err("p_sops is null");
  5900. return -EPERM;
  5901. }
  5902. return p_sops->process_spectral_report(pdev, payload);
  5903. }
  5904. #ifdef DIRECT_BUF_RX_DEBUG
  5905. static inline void
  5906. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5907. {
  5908. if (!tx_ops) {
  5909. spectral_err("tx_ops is NULL");
  5910. return;
  5911. }
  5912. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  5913. target_if_spectral_set_dma_debug;
  5914. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  5915. target_if_spectral_check_and_do_dbr_ring_debug;
  5916. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  5917. target_if_spectral_check_and_do_dbr_buff_debug;
  5918. }
  5919. #else
  5920. static inline void
  5921. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5922. {
  5923. }
  5924. #endif
  5925. #if defined(WLAN_CONV_SPECTRAL_ENABLE) && defined(SPECTRAL_MODULIZED_ENABLE)
  5926. /**
  5927. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  5928. * register WMI event handler
  5929. * @psoc: Pointer to psoc object
  5930. * @event_id: Event id
  5931. * @handler_func: Handler function
  5932. * @rx_ctx: Context of WMI event processing
  5933. *
  5934. * Wrapper function to register WMI event handler
  5935. *
  5936. * Return: 0 for success else failure
  5937. */
  5938. static int
  5939. target_if_spectral_wmi_unified_register_event_handler(
  5940. struct wlan_objmgr_psoc *psoc,
  5941. wmi_conv_event_id event_id,
  5942. wmi_unified_event_handler handler_func,
  5943. uint8_t rx_ctx)
  5944. {
  5945. wmi_unified_t wmi_handle;
  5946. struct target_if_psoc_spectral *psoc_spectral;
  5947. QDF_STATUS ret;
  5948. if (!psoc) {
  5949. spectral_err("psoc is null");
  5950. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5951. }
  5952. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5953. if (!wmi_handle) {
  5954. spectral_err("WMI handle is null");
  5955. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5956. }
  5957. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5958. if (!psoc_spectral) {
  5959. spectral_err("spectral object is null");
  5960. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5961. }
  5962. ret = psoc_spectral->wmi_ops.wmi_unified_register_event_handler(
  5963. wmi_handle, event_id, handler_func, rx_ctx);
  5964. return qdf_status_to_os_return(ret);
  5965. }
  5966. /**
  5967. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  5968. * to unregister WMI event handler
  5969. * @psoc: Pointer to psoc object
  5970. * @event_id: Event id
  5971. *
  5972. * Wrapper function to unregister WMI event handler
  5973. *
  5974. * Return: 0 for success else failure
  5975. */
  5976. static int
  5977. target_if_spectral_wmi_unified_unregister_event_handler(
  5978. struct wlan_objmgr_psoc *psoc,
  5979. wmi_conv_event_id event_id)
  5980. {
  5981. wmi_unified_t wmi_handle;
  5982. struct target_if_psoc_spectral *psoc_spectral;
  5983. QDF_STATUS ret;
  5984. if (!psoc) {
  5985. spectral_err("psoc is null");
  5986. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5987. }
  5988. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5989. if (!wmi_handle) {
  5990. spectral_err("WMI handle is null");
  5991. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5992. }
  5993. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5994. if (!psoc_spectral) {
  5995. spectral_err("spectral object is null");
  5996. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5997. }
  5998. ret = psoc_spectral->wmi_ops.wmi_unified_unregister_event_handler(
  5999. wmi_handle, event_id);
  6000. return qdf_status_to_os_return(ret);
  6001. }
  6002. /**
  6003. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  6004. * function to extract fixed parameters from start scan response event
  6005. * @psoc: Pointer to psoc object
  6006. * @evt_buf: Event buffer
  6007. * @param: Start scan response parameters
  6008. *
  6009. * Wrapper function to extract fixed parameters from start scan response event
  6010. *
  6011. * Return: QDF_STATUS
  6012. */
  6013. static QDF_STATUS
  6014. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6015. struct wlan_objmgr_psoc *psoc,
  6016. uint8_t *evt_buf,
  6017. struct spectral_startscan_resp_params *param)
  6018. {
  6019. wmi_unified_t wmi_handle;
  6020. struct target_if_psoc_spectral *psoc_spectral;
  6021. if (!psoc) {
  6022. spectral_err("psoc is null");
  6023. return QDF_STATUS_E_INVAL;
  6024. }
  6025. if (!evt_buf) {
  6026. spectral_err("WMI event buffer is null");
  6027. return QDF_STATUS_E_INVAL;
  6028. }
  6029. if (!param) {
  6030. spectral_err("Spectral startscan response parameters is null");
  6031. return QDF_STATUS_E_INVAL;
  6032. }
  6033. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6034. if (!wmi_handle) {
  6035. spectral_err("WMI handle is null");
  6036. return QDF_STATUS_E_INVAL;
  6037. }
  6038. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6039. if (!psoc_spectral) {
  6040. spectral_err("spectral object is null");
  6041. return QDF_STATUS_E_FAILURE;
  6042. }
  6043. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6044. wmi_handle, evt_buf, param);
  6045. }
  6046. /**
  6047. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  6048. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  6049. * secondary 80 MHz FFT bins
  6050. * @psoc: Pointer to psoc object
  6051. * @evt_buf: Event buffer
  6052. * @param: FFT bin start and end indices
  6053. *
  6054. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  6055. * and secondary 80 MHz FFT bins
  6056. *
  6057. * Return: QDF_STATUS
  6058. */
  6059. static QDF_STATUS
  6060. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6061. struct wlan_objmgr_psoc *psoc,
  6062. uint8_t *evt_buf,
  6063. struct spectral_fft_bin_markers_160_165mhz *param)
  6064. {
  6065. wmi_unified_t wmi_handle;
  6066. struct target_if_psoc_spectral *psoc_spectral;
  6067. if (!psoc) {
  6068. spectral_err("psoc is null");
  6069. return QDF_STATUS_E_INVAL;
  6070. }
  6071. if (!evt_buf) {
  6072. spectral_err("WMI event buffer is null");
  6073. return QDF_STATUS_E_INVAL;
  6074. }
  6075. if (!param) {
  6076. spectral_err("Spectral FFT bin markers is null");
  6077. return QDF_STATUS_E_INVAL;
  6078. }
  6079. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6080. if (!wmi_handle) {
  6081. spectral_err("WMI handle is null");
  6082. return QDF_STATUS_E_INVAL;
  6083. }
  6084. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6085. if (!psoc_spectral) {
  6086. spectral_err("spectral object is null");
  6087. return QDF_STATUS_E_FAILURE;
  6088. }
  6089. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fft_bin_index(
  6090. wmi_handle, evt_buf, param);
  6091. }
  6092. /**
  6093. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  6094. * object from scn handle
  6095. * @scn: scn handle
  6096. *
  6097. * Wrapper function to get psoc object from scn handle
  6098. *
  6099. * Return: Pointer to psoc object
  6100. */
  6101. static struct wlan_objmgr_psoc *
  6102. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  6103. {
  6104. if (!scn) {
  6105. spectral_err("scn is null");
  6106. return NULL;
  6107. }
  6108. return ops_tgt.tgt_get_psoc_from_scn_hdl(scn);
  6109. }
  6110. /**
  6111. * target_if_extract_pdev_spectral_session_chan_info() - Wrapper
  6112. * function to extract channel information for a spectral scan session
  6113. * @psoc: Pointer to psoc object
  6114. * @evt_buf: Event buffer
  6115. * @chan_info: Spectral session channel information data structure to be filled
  6116. * by this API
  6117. *
  6118. * Return: QDF_STATUS of operation
  6119. */
  6120. static QDF_STATUS
  6121. target_if_extract_pdev_spectral_session_chan_info(
  6122. struct wlan_objmgr_psoc *psoc,
  6123. void *evt_buf,
  6124. struct spectral_session_chan_info *chan_info)
  6125. {
  6126. wmi_unified_t wmi_handle;
  6127. struct target_if_psoc_spectral *psoc_spectral;
  6128. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6129. if (!wmi_handle) {
  6130. spectral_err("WMI handle is null");
  6131. return QDF_STATUS_E_NULL_VALUE;
  6132. }
  6133. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6134. if (!psoc_spectral) {
  6135. spectral_err("spectral object is null");
  6136. return QDF_STATUS_E_NULL_VALUE;
  6137. }
  6138. return psoc_spectral->wmi_ops.extract_pdev_spectral_session_chan_info(
  6139. wmi_handle, evt_buf, chan_info);
  6140. }
  6141. /**
  6142. * target_if_extract_pdev_spectral_session_detector_info() - Wrapper
  6143. * function to extract detector information for a spectral scan session
  6144. * @psoc: Pointer to psoc object
  6145. * @evt_buf: Event buffer
  6146. * @det_info: Spectral session detector information data structure to be filled
  6147. * by this API
  6148. * @det_info_idx: index in the array of spectral scan detector info TLVs
  6149. *
  6150. * Return: QDF_STATUS of operation
  6151. */
  6152. static QDF_STATUS
  6153. target_if_extract_pdev_spectral_session_detector_info(
  6154. struct wlan_objmgr_psoc *psoc, void *evt_buf,
  6155. struct spectral_session_det_info *det_info,
  6156. uint8_t det_info_idx)
  6157. {
  6158. wmi_unified_t wmi_handle;
  6159. struct target_if_psoc_spectral *psoc_spectral;
  6160. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6161. if (!wmi_handle) {
  6162. spectral_err("WMI handle is null");
  6163. return QDF_STATUS_E_NULL_VALUE;
  6164. }
  6165. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6166. if (!psoc_spectral) {
  6167. spectral_err("spectral object is null");
  6168. return QDF_STATUS_E_NULL_VALUE;
  6169. }
  6170. return psoc_spectral->wmi_ops.
  6171. extract_pdev_spectral_session_detector_info(
  6172. wmi_handle, evt_buf, det_info, det_info_idx);
  6173. }
  6174. /**
  6175. * target_if_wmi_extract_spectral_caps_fixed_param() - Wrapper function to
  6176. * extract fixed params from Spectral capabilities WMI event
  6177. * @psoc: Pointer to psoc object
  6178. * @evt_buf: Event buffer
  6179. * @param: Spectral capabilities event parameters data structure to be filled
  6180. * by this API
  6181. *
  6182. * Return: QDF_STATUS of operation
  6183. */
  6184. QDF_STATUS
  6185. target_if_wmi_extract_spectral_caps_fixed_param(
  6186. struct wlan_objmgr_psoc *psoc,
  6187. uint8_t *evt_buf,
  6188. struct spectral_capabilities_event_params *param)
  6189. {
  6190. struct target_if_psoc_spectral *psoc_spectral;
  6191. wmi_unified_t wmi_handle;
  6192. if (!psoc) {
  6193. spectral_err("psoc is null");
  6194. return QDF_STATUS_E_NULL_VALUE;
  6195. }
  6196. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6197. if (!wmi_handle) {
  6198. spectral_err("WMI handle is null");
  6199. return QDF_STATUS_E_NULL_VALUE;
  6200. }
  6201. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6202. if (!psoc_spectral) {
  6203. spectral_err("spectral object is null");
  6204. return QDF_STATUS_E_FAILURE;
  6205. }
  6206. return psoc_spectral->wmi_ops.extract_spectral_caps_fixed_param(
  6207. wmi_handle, evt_buf, param);
  6208. }
  6209. /**
  6210. * target_if_wmi_extract_spectral_scan_bw_caps() - Wrapper function to
  6211. * extract bandwidth capabilities from Spectral capabilities WMI event
  6212. * @psoc: Pointer to psoc object
  6213. * @evt_buf: Event buffer
  6214. * @bw_caps: Data structure to be filled by this API after extraction
  6215. *
  6216. * Return: QDF_STATUS of operation
  6217. */
  6218. QDF_STATUS
  6219. target_if_wmi_extract_spectral_scan_bw_caps(
  6220. struct wlan_objmgr_psoc *psoc,
  6221. uint8_t *evt_buf,
  6222. struct spectral_scan_bw_capabilities *bw_caps)
  6223. {
  6224. struct target_if_psoc_spectral *psoc_spectral;
  6225. wmi_unified_t wmi_handle;
  6226. if (!psoc) {
  6227. spectral_err("psoc is null");
  6228. return QDF_STATUS_E_INVAL;
  6229. }
  6230. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6231. if (!wmi_handle) {
  6232. spectral_err("WMI handle is null");
  6233. return QDF_STATUS_E_INVAL;
  6234. }
  6235. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6236. if (!psoc_spectral) {
  6237. spectral_err("spectral object is null");
  6238. return QDF_STATUS_E_FAILURE;
  6239. }
  6240. return psoc_spectral->wmi_ops.extract_spectral_scan_bw_caps(
  6241. wmi_handle, evt_buf, bw_caps);
  6242. }
  6243. /**
  6244. * target_if_wmi_extract_spectral_fft_size_caps() - Wrapper function to
  6245. * extract fft size capabilities from Spectral capabilities WMI event
  6246. * @psoc: Pointer to psoc object
  6247. * @evt_buf: Event buffer
  6248. * @fft_size_caps: Data structure to be filled by this API after extraction
  6249. *
  6250. * Return: QDF_STATUS of operation
  6251. */
  6252. QDF_STATUS
  6253. target_if_wmi_extract_spectral_fft_size_caps(
  6254. struct wlan_objmgr_psoc *psoc,
  6255. uint8_t *evt_buf,
  6256. struct spectral_fft_size_capabilities *fft_size_caps)
  6257. {
  6258. struct target_if_psoc_spectral *psoc_spectral;
  6259. wmi_unified_t wmi_handle;
  6260. if (!psoc) {
  6261. spectral_err("psoc is null");
  6262. return QDF_STATUS_E_INVAL;
  6263. }
  6264. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6265. if (!wmi_handle) {
  6266. spectral_err("WMI handle is null");
  6267. return QDF_STATUS_E_INVAL;
  6268. }
  6269. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6270. if (!psoc_spectral) {
  6271. spectral_err("spectral object is null");
  6272. return QDF_STATUS_E_FAILURE;
  6273. }
  6274. return psoc_spectral->wmi_ops.extract_spectral_fft_size_caps(
  6275. wmi_handle, evt_buf, fft_size_caps);
  6276. }
  6277. #else
  6278. /**
  6279. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  6280. * register WMI event handler
  6281. * @psoc: Pointer to psoc object
  6282. * @event_id: Event id
  6283. * @handler_func: Handler function
  6284. * @rx_ctx: Context of WMI event processing
  6285. *
  6286. * Wrapper function to register WMI event handler
  6287. *
  6288. * Return: 0 for success else failure
  6289. */
  6290. static int
  6291. target_if_spectral_wmi_unified_register_event_handler(
  6292. struct wlan_objmgr_psoc *psoc,
  6293. wmi_conv_event_id event_id,
  6294. wmi_unified_event_handler handler_func,
  6295. uint8_t rx_ctx)
  6296. {
  6297. wmi_unified_t wmi_handle;
  6298. QDF_STATUS ret;
  6299. if (!psoc) {
  6300. spectral_err("psoc is null");
  6301. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6302. }
  6303. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6304. if (!wmi_handle) {
  6305. spectral_err("WMI handle is null");
  6306. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6307. }
  6308. ret = wmi_unified_register_event_handler(wmi_handle, event_id,
  6309. handler_func, rx_ctx);
  6310. return qdf_status_to_os_return(ret);
  6311. }
  6312. /**
  6313. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  6314. * to unregister WMI event handler
  6315. * @psoc: Pointer to psoc object
  6316. * @event_id: Event id
  6317. *
  6318. * Wrapper function to unregister WMI event handler
  6319. *
  6320. * Return: 0 for success else failure
  6321. */
  6322. static int
  6323. target_if_spectral_wmi_unified_unregister_event_handler(
  6324. struct wlan_objmgr_psoc *psoc,
  6325. wmi_conv_event_id event_id)
  6326. {
  6327. wmi_unified_t wmi_handle;
  6328. QDF_STATUS ret;
  6329. if (!psoc) {
  6330. spectral_err("psoc is null");
  6331. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6332. }
  6333. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6334. if (!wmi_handle) {
  6335. spectral_err("WMI handle is null");
  6336. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6337. }
  6338. ret = wmi_unified_unregister_event_handler(wmi_handle, event_id);
  6339. return qdf_status_to_os_return(ret);
  6340. }
  6341. /**
  6342. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  6343. * function to extract fixed parameters from start scan response event
  6344. * @psoc: Pointer to psoc object
  6345. * @evt_buf: Event buffer
  6346. * @param: Start scan response parameters
  6347. *
  6348. * Wrapper function to extract fixed parameters from start scan response event
  6349. *
  6350. * Return: QDF_STATUS
  6351. */
  6352. static QDF_STATUS
  6353. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6354. struct wlan_objmgr_psoc *psoc,
  6355. uint8_t *evt_buf,
  6356. struct spectral_startscan_resp_params *param)
  6357. {
  6358. wmi_unified_t wmi_handle;
  6359. if (!psoc) {
  6360. spectral_err("psoc is null");
  6361. return QDF_STATUS_E_INVAL;
  6362. }
  6363. if (!evt_buf) {
  6364. spectral_err("WMI event buffer is null");
  6365. return QDF_STATUS_E_INVAL;
  6366. }
  6367. if (!param) {
  6368. spectral_err("Spectral startscan response parameters is null");
  6369. return QDF_STATUS_E_INVAL;
  6370. }
  6371. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6372. if (!wmi_handle) {
  6373. spectral_err("WMI handle is null");
  6374. return QDF_STATUS_E_INVAL;
  6375. }
  6376. return wmi_extract_pdev_sscan_fw_cmd_fixed_param(wmi_handle, evt_buf,
  6377. param);
  6378. }
  6379. /**
  6380. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  6381. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  6382. * secondary 80 MHz FFT bins
  6383. * @psoc: Pointer to psoc object
  6384. * @evt_buf: Event buffer
  6385. * @param: FFT bin start and end indices
  6386. *
  6387. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  6388. * and secondary 80 MHz FFT bins
  6389. *
  6390. * Return: QDF_STATUS
  6391. */
  6392. static QDF_STATUS
  6393. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6394. struct wlan_objmgr_psoc *psoc,
  6395. uint8_t *evt_buf,
  6396. struct spectral_fft_bin_markers_160_165mhz *param)
  6397. {
  6398. wmi_unified_t wmi_handle;
  6399. if (!psoc) {
  6400. spectral_err("psoc is null");
  6401. return QDF_STATUS_E_INVAL;
  6402. }
  6403. if (!evt_buf) {
  6404. spectral_err("WMI event buffer is null");
  6405. return QDF_STATUS_E_INVAL;
  6406. }
  6407. if (!param) {
  6408. spectral_err("Spectral FFT bin markers is null");
  6409. return QDF_STATUS_E_INVAL;
  6410. }
  6411. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6412. if (!wmi_handle) {
  6413. spectral_err("WMI handle is null");
  6414. return QDF_STATUS_E_INVAL;
  6415. }
  6416. return wmi_extract_pdev_sscan_fft_bin_index(wmi_handle, evt_buf, param);
  6417. }
  6418. /**
  6419. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  6420. * object from scn handle
  6421. * @scn: scn handle
  6422. *
  6423. * Wrapper function to get psoc object from scn handle
  6424. *
  6425. * Return: Pointer to psoc object
  6426. */
  6427. static struct wlan_objmgr_psoc *
  6428. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  6429. {
  6430. if (!scn) {
  6431. spectral_err("scn is null");
  6432. return NULL;
  6433. }
  6434. return target_if_get_psoc_from_scn_hdl(scn);
  6435. }
  6436. /**
  6437. * target_if_extract_pdev_spectral_session_chan_info() - Wrapper
  6438. * function to extract channel information for a spectral scan session
  6439. * @psoc: Pointer to psoc object
  6440. * @evt_buf: Event buffer
  6441. * @chan_info: Spectral session channel information data structure to be fille
  6442. * by this API
  6443. *
  6444. * Return: QDF_STATUS of operation
  6445. */
  6446. static QDF_STATUS
  6447. target_if_extract_pdev_spectral_session_chan_info(
  6448. struct wlan_objmgr_psoc *psoc,
  6449. void *evt_buf,
  6450. struct spectral_session_chan_info *chan_info)
  6451. {
  6452. wmi_unified_t wmi_handle;
  6453. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6454. if (!wmi_handle) {
  6455. spectral_err("WMI handle is null");
  6456. return QDF_STATUS_E_NULL_VALUE;
  6457. }
  6458. return wmi_extract_pdev_spectral_session_chan_info(
  6459. wmi_handle, evt_buf, chan_info);
  6460. }
  6461. /**
  6462. * target_if_extract_pdev_spectral_session_detector_info() - Wrapper
  6463. * function to extract detector information for a spectral scan session
  6464. * @psoc: Pointer to psoc object
  6465. * @evt_buf: Event buffer
  6466. * @det_info: Spectral session detector information data structure to be filled
  6467. * by this API
  6468. * @det_info_idx: index in the array of spectral scan detector info TLVs
  6469. *
  6470. * Return: QDF_STATUS of operation
  6471. */
  6472. static QDF_STATUS
  6473. target_if_extract_pdev_spectral_session_detector_info(
  6474. struct wlan_objmgr_psoc *psoc, void *evt_buf,
  6475. struct spectral_session_det_info *det_info,
  6476. uint8_t det_info_idx)
  6477. {
  6478. wmi_unified_t wmi_handle;
  6479. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6480. if (!wmi_handle) {
  6481. spectral_err("WMI handle is null");
  6482. return QDF_STATUS_E_NULL_VALUE;
  6483. }
  6484. return wmi_extract_pdev_spectral_session_detector_info(
  6485. wmi_handle, evt_buf, det_info, det_info_idx);
  6486. }
  6487. QDF_STATUS
  6488. target_if_wmi_extract_spectral_caps_fixed_param(
  6489. struct wlan_objmgr_psoc *psoc,
  6490. uint8_t *evt_buf,
  6491. struct spectral_capabilities_event_params *param)
  6492. {
  6493. wmi_unified_t wmi_handle;
  6494. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6495. if (!wmi_handle) {
  6496. spectral_err("WMI handle is null");
  6497. return QDF_STATUS_E_INVAL;
  6498. }
  6499. return wmi_extract_spectral_caps_fixed_param(wmi_handle, evt_buf,
  6500. param);
  6501. }
  6502. QDF_STATUS
  6503. target_if_wmi_extract_spectral_scan_bw_caps(
  6504. struct wlan_objmgr_psoc *psoc,
  6505. uint8_t *evt_buf,
  6506. struct spectral_scan_bw_capabilities *bw_caps)
  6507. {
  6508. wmi_unified_t wmi_handle;
  6509. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6510. if (!wmi_handle) {
  6511. spectral_err("WMI handle is null");
  6512. return QDF_STATUS_E_INVAL;
  6513. }
  6514. return wmi_extract_spectral_scan_bw_caps(wmi_handle, evt_buf, bw_caps);
  6515. }
  6516. QDF_STATUS
  6517. target_if_wmi_extract_spectral_fft_size_caps(
  6518. struct wlan_objmgr_psoc *psoc,
  6519. uint8_t *evt_buf,
  6520. struct spectral_fft_size_capabilities *fft_size_caps)
  6521. {
  6522. wmi_unified_t wmi_handle;
  6523. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6524. if (!wmi_handle) {
  6525. spectral_err("WMI handle is null");
  6526. return QDF_STATUS_E_INVAL;
  6527. }
  6528. return wmi_extract_spectral_fft_size_caps(wmi_handle, evt_buf,
  6529. fft_size_caps);
  6530. }
  6531. #endif
  6532. /**
  6533. * target_if_update_det_info_in_spectral_session() - Update detector
  6534. * information in spectral scan session
  6535. * @spectral: Spectral LMAC object
  6536. * @det_info: Pointer to spectral session detector information
  6537. * @smode: Spectral scan mode
  6538. *
  6539. * Return: QDF_STATUS of operation
  6540. */
  6541. static QDF_STATUS
  6542. target_if_update_det_info_in_spectral_session(
  6543. struct target_if_spectral *spectral,
  6544. const struct spectral_session_det_info *det_info,
  6545. enum spectral_scan_mode smode)
  6546. {
  6547. struct per_session_det_map *det_map;
  6548. struct per_session_dest_det_info *dest_det_info;
  6549. if (!spectral) {
  6550. spectral_err_rl("Spectral LMAC object is null");
  6551. return QDF_STATUS_E_NULL_VALUE;
  6552. }
  6553. qdf_assert_always(det_info->det_id < MAX_DETECTORS_PER_PDEV);
  6554. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  6555. det_map = &spectral->det_map[det_info->det_id];
  6556. dest_det_info = &det_map->dest_det_info[0];
  6557. dest_det_info->start_freq = det_info->start_freq;
  6558. dest_det_info->end_freq = det_info->end_freq;
  6559. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  6560. /* This detector will be used for this smode throughout this session */
  6561. spectral->rparams.detid_mode_table[det_info->det_id] = smode;
  6562. return QDF_STATUS_SUCCESS;
  6563. }
  6564. /**
  6565. * target_if_update_chan_info_in_spectral_session() - Update channel information
  6566. * in spectral scan session
  6567. * @spectral: Spectral LMAC object
  6568. * @chan_info: Pointer to spectral session channel information
  6569. * @smode: Spectral scan mode
  6570. *
  6571. * Return: QDF_STATUS of operation
  6572. */
  6573. static QDF_STATUS
  6574. target_if_update_chan_info_in_spectral_session(
  6575. struct target_if_spectral *spectral,
  6576. const struct spectral_session_chan_info *chan_info,
  6577. enum spectral_scan_mode smode)
  6578. {
  6579. struct per_session_report_info *rpt_info;
  6580. if (!spectral) {
  6581. spectral_err_rl("Spectral LMAC object is null");
  6582. return QDF_STATUS_E_NULL_VALUE;
  6583. }
  6584. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6585. spectral_err_rl("Invalid Spectral scan mode :%u", smode);
  6586. return QDF_STATUS_E_FAILURE;
  6587. }
  6588. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  6589. rpt_info = &spectral->report_info[smode];
  6590. /* Update per-session report info */
  6591. rpt_info->pri20_freq = chan_info->operating_pri20_freq;
  6592. rpt_info->cfreq1 = chan_info->operating_cfreq1;
  6593. rpt_info->cfreq2 = chan_info->operating_cfreq2;
  6594. rpt_info->operating_bw = chan_info->operating_bw;
  6595. rpt_info->sscan_cfreq1 = chan_info->sscan_cfreq1;
  6596. rpt_info->sscan_cfreq2 = chan_info->sscan_cfreq2;
  6597. rpt_info->sscan_bw = chan_info->sscan_bw;
  6598. /* num_spans depends on sscan_bw, update it */
  6599. rpt_info->num_spans = target_if_spectral_get_num_spans(
  6600. spectral->pdev_obj,
  6601. rpt_info->sscan_bw);
  6602. qdf_assert_always(rpt_info->num_spans != INVALID_SPAN_NUM);
  6603. rpt_info->valid = true;
  6604. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  6605. return QDF_STATUS_SUCCESS;
  6606. }
  6607. /**
  6608. * target_if_spectral_fw_param_event_handler() - WMI event handler to
  6609. * process start scan response event
  6610. * @scn: Pointer to scn object
  6611. * @data_buf: Pointer to event buffer
  6612. * @data_len: Length of event buffer
  6613. *
  6614. * Return: 0 for success, else failure
  6615. */
  6616. static int
  6617. target_if_spectral_fw_param_event_handler(ol_scn_t scn, uint8_t *data_buf,
  6618. uint32_t data_len)
  6619. {
  6620. QDF_STATUS status;
  6621. struct wlan_objmgr_psoc *psoc;
  6622. struct wlan_objmgr_pdev *pdev;
  6623. struct wmi_unified *wmi_handle;
  6624. struct spectral_startscan_resp_params event_params = {0};
  6625. struct target_if_psoc_spectral *psoc_spectral;
  6626. struct target_if_spectral *spectral;
  6627. bool is_session_info_expected;
  6628. if (!scn) {
  6629. spectral_err("scn handle is null");
  6630. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6631. }
  6632. if (!data_buf) {
  6633. spectral_err("WMI event buffer null");
  6634. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6635. }
  6636. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  6637. if (!psoc) {
  6638. spectral_err("psoc is null");
  6639. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6640. }
  6641. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6642. if (!psoc_spectral) {
  6643. spectral_err("spectral object is null");
  6644. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6645. }
  6646. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6647. if (!wmi_handle) {
  6648. spectral_err("WMI handle is null");
  6649. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6650. }
  6651. status = target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6652. psoc, data_buf, &event_params);
  6653. if (QDF_IS_STATUS_ERROR(status)) {
  6654. spectral_err("unable to extract sscan fw fixed params");
  6655. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6656. }
  6657. if (event_params.smode >= SPECTRAL_SCAN_MODE_MAX ||
  6658. event_params.smode < SPECTRAL_SCAN_MODE_NORMAL) {
  6659. spectral_err("Invalid smode %d", event_params.smode);
  6660. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6661. }
  6662. pdev = wlan_objmgr_get_pdev_by_id(psoc, event_params.pdev_id,
  6663. WLAN_SPECTRAL_ID);
  6664. if (!pdev) {
  6665. spectral_err("pdev is null");
  6666. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6667. }
  6668. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  6669. if (!spectral) {
  6670. spectral_err("spectral object is null");
  6671. status = QDF_STATUS_E_FAILURE;
  6672. goto release_pdev_ref;
  6673. }
  6674. if (event_params.num_fft_bin_index == 1) {
  6675. status =
  6676. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6677. psoc, data_buf,
  6678. &spectral->rparams.marker[event_params.smode]);
  6679. if (QDF_IS_STATUS_ERROR(status)) {
  6680. spectral_err("unable to extract sscan fw fixed params");
  6681. goto release_pdev_ref;
  6682. }
  6683. } else {
  6684. spectral->rparams.marker[event_params.smode].is_valid = false;
  6685. }
  6686. status = spectral_is_session_info_expected_from_target(
  6687. pdev, &is_session_info_expected);
  6688. if (QDF_IS_STATUS_ERROR(status)) {
  6689. spectral_err("Failed to check if session info is expected");
  6690. goto release_pdev_ref;
  6691. }
  6692. if (is_session_info_expected) {
  6693. struct spectral_session_chan_info chan_info;
  6694. uint8_t det_info_idx = 0;
  6695. status = target_if_extract_pdev_spectral_session_chan_info(
  6696. psoc, data_buf, &chan_info);
  6697. if (QDF_IS_STATUS_ERROR(status)) {
  6698. spectral_err("Unable to extract spectral session channel info");
  6699. goto release_pdev_ref;
  6700. }
  6701. status = target_if_update_chan_info_in_spectral_session(
  6702. spectral, &chan_info, event_params.smode);
  6703. if (QDF_IS_STATUS_ERROR(status)) {
  6704. spectral_err("Unable to update channel info");
  6705. goto release_pdev_ref;
  6706. }
  6707. /* FFT bins info depends upon sscan_bw, update it */
  6708. status = target_if_populate_fft_bins_info(spectral,
  6709. event_params.smode);
  6710. if (QDF_IS_STATUS_ERROR(status)) {
  6711. spectral_err("Failed to populate FFT bins info");
  6712. goto release_pdev_ref;
  6713. }
  6714. /**
  6715. * per-session det info that depends on sscan_bw needs to be
  6716. * updated here
  6717. */
  6718. status = target_if_spectral_populate_session_det_host_info(
  6719. spectral, event_params.smode);
  6720. if (QDF_IS_STATUS_ERROR(status)) {
  6721. spectral_err("Failed to populate per-session det info");
  6722. goto release_pdev_ref;
  6723. }
  6724. for (; det_info_idx < event_params.num_det_info;
  6725. ++det_info_idx) {
  6726. struct spectral_session_det_info det_info;
  6727. status =
  6728. target_if_extract_pdev_spectral_session_detector_info
  6729. (psoc, data_buf, &det_info, det_info_idx);
  6730. if (QDF_IS_STATUS_ERROR(status)) {
  6731. spectral_err("Unable to extract spectral session detector info for %u",
  6732. det_info_idx);
  6733. goto release_pdev_ref;
  6734. }
  6735. status = target_if_update_det_info_in_spectral_session(
  6736. spectral, &det_info,
  6737. event_params.smode);
  6738. if (QDF_IS_STATUS_ERROR(status)) {
  6739. spectral_err("Unable to update detector info");
  6740. goto release_pdev_ref;
  6741. }
  6742. }
  6743. }
  6744. status = QDF_STATUS_SUCCESS;
  6745. release_pdev_ref:
  6746. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  6747. return qdf_status_to_os_return(status);
  6748. }
  6749. /**
  6750. * target_if_spectral_capabilities_event_handler() - Handler for the Spectral
  6751. * Capabilities event
  6752. * @scn: Pointer to scn object
  6753. * @data_buf: Pointer to event buffer
  6754. * @data_len: Length of event buffer
  6755. *
  6756. * Return: 0 for success, else failure
  6757. */
  6758. static int
  6759. target_if_spectral_capabilities_event_handler(ol_scn_t scn, uint8_t *data_buf,
  6760. uint32_t data_len)
  6761. {
  6762. QDF_STATUS status;
  6763. struct wlan_objmgr_psoc *psoc;
  6764. struct wmi_unified *wmi_handle;
  6765. struct spectral_capabilities_event_params event_params = {0};
  6766. struct spectral_scan_bw_capabilities *bw_caps;
  6767. struct spectral_fft_size_capabilities *fft_size_caps;
  6768. if (!scn) {
  6769. spectral_err("scn handle is null");
  6770. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6771. }
  6772. if (!data_buf) {
  6773. spectral_err("WMI event buffer null");
  6774. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6775. }
  6776. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  6777. if (!psoc) {
  6778. spectral_err("psoc is null");
  6779. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6780. }
  6781. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6782. if (!wmi_handle) {
  6783. spectral_err("WMI handle is null");
  6784. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6785. }
  6786. status = target_if_wmi_extract_spectral_caps_fixed_param(
  6787. psoc, data_buf, &event_params);
  6788. if (QDF_IS_STATUS_ERROR(status)) {
  6789. spectral_err("Failed to extract fixed parameters");
  6790. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6791. }
  6792. /* There should be atleast one capability */
  6793. qdf_assert(event_params.num_sscan_bw_caps > 0);
  6794. qdf_assert(event_params.num_fft_size_caps > 0);
  6795. bw_caps = qdf_mem_malloc(
  6796. sizeof(*bw_caps) * event_params.num_sscan_bw_caps);
  6797. if (!bw_caps) {
  6798. spectral_err("memory allocation failed");
  6799. return qdf_status_to_os_return(QDF_STATUS_E_NOMEM);
  6800. }
  6801. status = target_if_wmi_extract_spectral_scan_bw_caps(psoc, data_buf,
  6802. bw_caps);
  6803. if (QDF_IS_STATUS_ERROR(status)) {
  6804. spectral_err("Failed to extract BW caps");
  6805. status = QDF_STATUS_E_FAILURE;
  6806. goto free_bw_caps;
  6807. }
  6808. fft_size_caps = qdf_mem_malloc(
  6809. sizeof(*fft_size_caps) * event_params.num_fft_size_caps);
  6810. if (!fft_size_caps) {
  6811. spectral_err("memory allocation failed");
  6812. status = QDF_STATUS_E_NOMEM;
  6813. goto free_bw_caps;
  6814. }
  6815. status = target_if_wmi_extract_spectral_fft_size_caps(psoc, data_buf,
  6816. fft_size_caps);
  6817. if (QDF_IS_STATUS_ERROR(status)) {
  6818. spectral_err("Failed to extract fft size caps");
  6819. status = QDF_STATUS_E_FAILURE;
  6820. goto free_fft_size_caps;
  6821. }
  6822. status = QDF_STATUS_SUCCESS;
  6823. free_fft_size_caps:
  6824. qdf_mem_free(fft_size_caps);
  6825. free_bw_caps:
  6826. qdf_mem_free(bw_caps);
  6827. return qdf_status_to_os_return(status);
  6828. }
  6829. static QDF_STATUS
  6830. target_if_spectral_register_events(struct wlan_objmgr_psoc *psoc)
  6831. {
  6832. int ret;
  6833. if (!psoc) {
  6834. spectral_err("psoc is null");
  6835. return QDF_STATUS_E_INVAL;
  6836. }
  6837. ret = target_if_spectral_wmi_unified_register_event_handler(
  6838. psoc,
  6839. wmi_pdev_sscan_fw_param_eventid,
  6840. target_if_spectral_fw_param_event_handler,
  6841. WMI_RX_UMAC_CTX);
  6842. if (ret)
  6843. spectral_debug("event handler not supported, ret=%d", ret);
  6844. ret = target_if_spectral_wmi_unified_register_event_handler(
  6845. psoc,
  6846. wmi_spectral_capabilities_eventid,
  6847. target_if_spectral_capabilities_event_handler,
  6848. WMI_RX_UMAC_CTX);
  6849. if (ret)
  6850. spectral_debug("event handler not supported, ret=%d", ret);
  6851. return QDF_STATUS_SUCCESS;
  6852. }
  6853. static QDF_STATUS
  6854. target_if_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
  6855. {
  6856. int ret;
  6857. if (!psoc) {
  6858. spectral_err("psoc is null");
  6859. return QDF_STATUS_E_INVAL;
  6860. }
  6861. target_if_spectral_wmi_unified_unregister_event_handler(
  6862. psoc, wmi_spectral_capabilities_eventid);
  6863. ret = target_if_spectral_wmi_unified_unregister_event_handler(
  6864. psoc, wmi_pdev_sscan_fw_param_eventid);
  6865. if (ret)
  6866. spectral_debug("Unregister WMI event handler failed, ret = %d",
  6867. ret);
  6868. return QDF_STATUS_SUCCESS;
  6869. }
  6870. void
  6871. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  6872. {
  6873. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  6874. target_if_pdev_spectral_init;
  6875. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  6876. target_if_pdev_spectral_deinit;
  6877. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init =
  6878. target_if_psoc_spectral_init;
  6879. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit =
  6880. target_if_psoc_spectral_deinit;
  6881. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  6882. target_if_set_spectral_config;
  6883. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  6884. target_if_get_spectral_config;
  6885. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  6886. target_if_start_spectral_scan;
  6887. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  6888. target_if_stop_spectral_scan;
  6889. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  6890. target_if_is_spectral_active;
  6891. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  6892. target_if_is_spectral_enabled;
  6893. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  6894. target_if_set_debug_level;
  6895. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  6896. target_if_get_debug_level;
  6897. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  6898. target_if_get_spectral_capinfo;
  6899. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  6900. target_if_get_spectral_diagstats;
  6901. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_wmi_ops =
  6902. target_if_register_spectral_wmi_ops;
  6903. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_tgt_ops =
  6904. target_if_register_spectral_tgt_ops;
  6905. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  6906. target_if_register_netlink_cb;
  6907. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  6908. target_if_use_nl_bcast;
  6909. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  6910. target_if_deregister_netlink_cb;
  6911. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  6912. target_if_process_spectral_report;
  6913. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  6914. target_if_spectral_direct_dma_support;
  6915. tx_ops->sptrl_tx_ops.sptrlto_register_events =
  6916. target_if_spectral_register_events;
  6917. tx_ops->sptrl_tx_ops.sptrlto_unregister_events =
  6918. target_if_spectral_unregister_events;
  6919. tx_ops->sptrl_tx_ops.sptrlto_init_pdev_feature_caps =
  6920. target_if_spectral_init_pdev_feature_caps;
  6921. target_if_sptrl_debug_register_tx_ops(tx_ops);
  6922. }
  6923. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  6924. void
  6925. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  6926. uint16_t cw_int, uint32_t dcs_enabled)
  6927. {
  6928. struct spectral_samp_msg *msg = NULL;
  6929. struct target_if_spectral_ops *p_sops = NULL;
  6930. struct target_if_spectral *spectral = NULL;
  6931. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  6932. if (!spectral) {
  6933. spectral_err("SPECTRAL : Module doesn't exist");
  6934. return;
  6935. }
  6936. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  6937. if (!p_sops) {
  6938. spectral_err("p_sops is null");
  6939. return;
  6940. }
  6941. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  6942. spectral->pdev_obj,
  6943. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  6944. SPECTRAL_MSG_BUF_NEW);
  6945. if (msg) {
  6946. msg->int_type = cw_int ?
  6947. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  6948. msg->dcs_enabled = dcs_enabled;
  6949. msg->signature = SPECTRAL_SIGNATURE;
  6950. p_sops->get_mac_address(spectral, msg->macaddr);
  6951. if (spectral->send_phy_data
  6952. (pdev,
  6953. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  6954. spectral->spectral_sent_msg++;
  6955. }
  6956. }
  6957. qdf_export_symbol(target_if_spectral_send_intf_found_msg);
  6958. QDF_STATUS
  6959. target_if_spectral_is_finite_scan(struct target_if_spectral *spectral,
  6960. enum spectral_scan_mode smode,
  6961. bool *finite_spectral_scan)
  6962. {
  6963. struct target_if_finite_spectral_scan_params *finite_scan;
  6964. if (!spectral) {
  6965. spectral_err_rl("target if spectral object is null");
  6966. return QDF_STATUS_E_INVAL;
  6967. }
  6968. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6969. spectral_err_rl("invalid spectral mode %d", smode);
  6970. return QDF_STATUS_E_INVAL;
  6971. }
  6972. if (!finite_spectral_scan) {
  6973. spectral_err_rl("Invalid pointer");
  6974. return QDF_STATUS_E_INVAL;
  6975. }
  6976. finite_scan = &spectral->finite_scan[smode];
  6977. *finite_spectral_scan = finite_scan->finite_spectral_scan;
  6978. return QDF_STATUS_SUCCESS;
  6979. }
  6980. QDF_STATUS
  6981. target_if_spectral_finite_scan_update(struct target_if_spectral *spectral,
  6982. enum spectral_scan_mode smode)
  6983. {
  6984. struct target_if_finite_spectral_scan_params *finite_scan;
  6985. if (!spectral) {
  6986. spectral_err_rl("target if spectral object is null");
  6987. return QDF_STATUS_E_INVAL;
  6988. }
  6989. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6990. spectral_err_rl("Invalid Spectral mode");
  6991. return QDF_STATUS_E_INVAL;
  6992. }
  6993. finite_scan = &spectral->finite_scan[smode];
  6994. if (!finite_scan->num_reports_expected) {
  6995. spectral_err_rl("Error, No reports expected");
  6996. return QDF_STATUS_E_FAILURE;
  6997. }
  6998. finite_scan->num_reports_expected--;
  6999. if (!finite_scan->num_reports_expected) {
  7000. QDF_STATUS status;
  7001. enum spectral_cp_error_code err;
  7002. /* received expected number of reports from target, stop scan */
  7003. status = target_if_stop_spectral_scan(spectral->pdev_obj, smode,
  7004. &err);
  7005. if (QDF_IS_STATUS_ERROR(status)) {
  7006. spectral_err_rl("Failed to stop finite Spectral scan");
  7007. return QDF_STATUS_E_FAILURE;
  7008. }
  7009. finite_scan->finite_spectral_scan = false;
  7010. }
  7011. return QDF_STATUS_SUCCESS;
  7012. }