target_if_spectral.c 220 KB

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