target_if_spectral.c 222 KB

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