target_if_spectral.c 221 KB

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