target_if_spectral.c 215 KB

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