target_if_spectral.c 215 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911
  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_pwrmode
  3449. (spectral->pdev_obj, chan_freq, agile_ch_width,
  3450. &bonded_chan_ptr, REG_CURRENT_PWR_MODE);
  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 =
  3519. wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3520. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  3521. agile_ch_width,
  3522. &bonded_chan_ptr,
  3523. REG_CURRENT_PWR_MODE);
  3524. if (st == CHANNEL_STATE_DISABLE ||
  3525. st == CHANNEL_STATE_INVALID) {
  3526. spectral_err("Channel state disable/invalid");
  3527. return QDF_STATUS_E_FAILURE;
  3528. }
  3529. if (!bonded_chan_ptr) {
  3530. spectral_err("Bonded channel is not found");
  3531. return QDF_STATUS_E_FAILURE;
  3532. }
  3533. start_freq = bonded_chan_ptr->start_freq;
  3534. end_freq = bonded_chan_ptr->end_freq;
  3535. calulated_center_freq = (start_freq + end_freq) >> 1;
  3536. *is_valid = (center_freq == calulated_center_freq);
  3537. } else {
  3538. *is_valid = false;
  3539. }
  3540. }
  3541. return QDF_STATUS_SUCCESS;
  3542. }
  3543. /**
  3544. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  3545. * check whether agile span overlaps with current operating band.
  3546. *
  3547. * @spectral: Pointer to Spectral object
  3548. * @ch_width: Channel width array
  3549. * @center_freq: Agile span center frequency
  3550. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  3551. *
  3552. * Helper routine to check whether agile span overlaps with current
  3553. * operating band.
  3554. *
  3555. * Return: QDF_STATUS
  3556. */
  3557. static QDF_STATUS
  3558. target_if_is_agile_span_overlap_with_operating_span
  3559. (struct target_if_spectral *spectral,
  3560. enum phy_ch_width *ch_width,
  3561. struct spectral_config_frequency *center_freq,
  3562. bool *is_overlapping)
  3563. {
  3564. enum phy_ch_width op_ch_width;
  3565. enum phy_ch_width agile_ch_width;
  3566. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3567. struct wlan_objmgr_vdev *vdev;
  3568. struct wlan_objmgr_pdev *pdev;
  3569. int16_t chan_freq;
  3570. uint32_t op_start_freq;
  3571. uint32_t op_end_freq;
  3572. uint32_t agile_start_freq;
  3573. uint32_t agile_end_freq;
  3574. uint32_t cfreq2;
  3575. if (!spectral) {
  3576. spectral_err("Spectral object is NULL");
  3577. return QDF_STATUS_E_FAILURE;
  3578. }
  3579. pdev = spectral->pdev_obj;
  3580. if (!pdev) {
  3581. spectral_err("pdev object is NULL");
  3582. return QDF_STATUS_E_FAILURE;
  3583. }
  3584. if (!ch_width) {
  3585. spectral_err("channel width array is null");
  3586. return QDF_STATUS_E_FAILURE;
  3587. }
  3588. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  3589. if (op_ch_width == CH_WIDTH_INVALID) {
  3590. spectral_err("Invalid channel width");
  3591. return QDF_STATUS_E_INVAL;
  3592. }
  3593. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3594. if (agile_ch_width == CH_WIDTH_INVALID) {
  3595. spectral_err("Invalid channel width");
  3596. return QDF_STATUS_E_INVAL;
  3597. }
  3598. if (!is_overlapping) {
  3599. spectral_err("Argument(is_overlapping) is NULL");
  3600. return QDF_STATUS_E_FAILURE;
  3601. }
  3602. *is_overlapping = false;
  3603. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  3604. if (!vdev) {
  3605. spectral_err("vdev is NULL");
  3606. return QDF_STATUS_E_FAILURE;
  3607. }
  3608. chan_freq = target_if_vdev_get_chan_freq(vdev);
  3609. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  3610. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3611. if (cfreq2 < 0) {
  3612. spectral_err("cfreq2 is invalid");
  3613. return QDF_STATUS_E_FAILURE;
  3614. }
  3615. if (op_ch_width == CH_WIDTH_20MHZ) {
  3616. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  3617. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  3618. } else {
  3619. enum channel_state state;
  3620. state = wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3621. (pdev, chan_freq, op_ch_width, &bonded_chan_ptr,
  3622. REG_CURRENT_PWR_MODE);
  3623. if (state == CHANNEL_STATE_DISABLE ||
  3624. state == CHANNEL_STATE_INVALID) {
  3625. spectral_err("Channel state is disable or invalid");
  3626. return QDF_STATUS_E_FAILURE;
  3627. }
  3628. if (!bonded_chan_ptr) {
  3629. spectral_err("Bonded channel is not found");
  3630. return QDF_STATUS_E_FAILURE;
  3631. }
  3632. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  3633. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  3634. }
  3635. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3636. agile_start_freq = center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3637. agile_end_freq = center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3638. if (agile_end_freq > op_start_freq &&
  3639. op_end_freq > agile_start_freq)
  3640. *is_overlapping = true;
  3641. agile_start_freq = center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3642. agile_end_freq = center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3643. if (agile_end_freq > op_start_freq &&
  3644. op_end_freq > agile_start_freq)
  3645. *is_overlapping = true;
  3646. } else {
  3647. agile_start_freq = center_freq->cfreq1 -
  3648. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3649. agile_end_freq = center_freq->cfreq1 +
  3650. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3651. if (agile_end_freq > op_start_freq &&
  3652. op_end_freq > agile_start_freq)
  3653. *is_overlapping = true;
  3654. }
  3655. if (op_ch_width == CH_WIDTH_80P80MHZ) {
  3656. uint32_t sec80_start_feq;
  3657. uint32_t sec80_end_freq;
  3658. sec80_start_feq = cfreq2 - FREQ_OFFSET_40MHZ;
  3659. sec80_end_freq = cfreq2 + FREQ_OFFSET_40MHZ;
  3660. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3661. agile_start_freq =
  3662. center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3663. agile_end_freq =
  3664. center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3665. if (agile_end_freq > sec80_start_feq &&
  3666. sec80_end_freq > agile_start_freq)
  3667. *is_overlapping = true;
  3668. agile_start_freq =
  3669. center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3670. agile_end_freq =
  3671. center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3672. if (agile_end_freq > sec80_start_feq &&
  3673. sec80_end_freq > agile_start_freq)
  3674. *is_overlapping = true;
  3675. } else {
  3676. agile_start_freq = center_freq->cfreq1 -
  3677. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3678. agile_end_freq = center_freq->cfreq1 +
  3679. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3680. if (agile_end_freq > sec80_start_feq &&
  3681. sec80_end_freq > agile_start_freq)
  3682. *is_overlapping = true;
  3683. }
  3684. }
  3685. return QDF_STATUS_SUCCESS;
  3686. }
  3687. /**
  3688. * target_if_spectral_populate_chwidth() - Helper routine to
  3689. * populate channel width for different Spectral modes
  3690. *
  3691. * @spectral: Pointer to Spectral object
  3692. * @ch_width: Channel width array
  3693. * @is_80_80_agile: Indicates whether 80+80 agile scan is requested
  3694. *
  3695. * Helper routine to populate channel width for different Spectral modes
  3696. *
  3697. * Return: QDF_STATUS
  3698. */
  3699. static QDF_STATUS
  3700. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral,
  3701. enum phy_ch_width *ch_width,
  3702. bool is_80_80_agile)
  3703. {
  3704. enum spectral_scan_mode smode;
  3705. qdf_assert_always(spectral);
  3706. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3707. for (; smode < SPECTRAL_SCAN_MODE_MAX; ++smode) {
  3708. /* If user has configured sscan bandwidth, use it */
  3709. if (spectral->sscan_width_configured[smode]) {
  3710. ch_width[smode] = spectral->params[smode].ss_bandwidth;
  3711. } else {
  3712. /* Otherwise, derive the default sscan bandwidth */
  3713. ch_width[smode] = get_default_sscan_bw(spectral, smode,
  3714. is_80_80_agile);
  3715. if (ch_width[smode] >= CH_WIDTH_INVALID) {
  3716. spectral_err("Invalid sscan BW %u",
  3717. ch_width[smode]);
  3718. return QDF_STATUS_E_FAILURE;
  3719. }
  3720. spectral->params[smode].ss_bandwidth = ch_width[smode];
  3721. }
  3722. }
  3723. return QDF_STATUS_SUCCESS;
  3724. }
  3725. /**
  3726. * target_if_spectral_is_valid_80p80_freq() - API to check whether given
  3727. * (cfreq1, cfreq2) pair forms a valid 80+80 combination
  3728. * @pdev: pointer to pdev
  3729. * @cfreq1: center frequency 1
  3730. * @cfreq2: center frequency 2
  3731. *
  3732. * API to check whether given (cfreq1, cfreq2) pair forms a valid 80+80
  3733. * combination
  3734. *
  3735. * Return: true or false
  3736. */
  3737. static bool
  3738. target_if_spectral_is_valid_80p80_freq(struct wlan_objmgr_pdev *pdev,
  3739. uint32_t cfreq1, uint32_t cfreq2)
  3740. {
  3741. struct ch_params ch_params;
  3742. enum channel_state chan_state1;
  3743. enum channel_state chan_state2;
  3744. struct wlan_objmgr_psoc *psoc;
  3745. qdf_assert_always(pdev);
  3746. psoc = wlan_pdev_get_psoc(pdev);
  3747. qdf_assert_always(psoc);
  3748. /* In restricted 80P80 MHz enabled, only one 80+80 MHz
  3749. * channel is supported with cfreq=5690 and cfreq=5775.
  3750. */
  3751. if (wlan_psoc_nif_fw_ext_cap_get(
  3752. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  3753. return CHAN_WITHIN_RESTRICTED_80P80(cfreq1, cfreq2);
  3754. ch_params.center_freq_seg1 = wlan_reg_freq_to_chan(pdev, cfreq2);
  3755. ch_params.mhz_freq_seg1 = cfreq2;
  3756. ch_params.ch_width = CH_WIDTH_80P80MHZ;
  3757. wlan_reg_set_channel_params_for_pwrmode(
  3758. pdev,
  3759. cfreq1 - FREQ_OFFSET_10MHZ,
  3760. 0,
  3761. &ch_params,
  3762. REG_CURRENT_PWR_MODE);
  3763. if (ch_params.ch_width != CH_WIDTH_80P80MHZ)
  3764. return false;
  3765. if (ch_params.mhz_freq_seg0 != cfreq1 ||
  3766. ch_params.mhz_freq_seg1 != cfreq2)
  3767. return false;
  3768. chan_state1 = wlan_reg_get_5g_bonded_channel_state_for_pwrmode(
  3769. pdev,
  3770. ch_params.mhz_freq_seg0 - FREQ_OFFSET_10MHZ,
  3771. CH_WIDTH_80MHZ,
  3772. REG_CURRENT_PWR_MODE);
  3773. if ((chan_state1 == CHANNEL_STATE_DISABLE) ||
  3774. (chan_state1 == CHANNEL_STATE_INVALID))
  3775. return false;
  3776. chan_state2 = wlan_reg_get_5g_bonded_channel_state_for_pwrmode(
  3777. pdev,
  3778. ch_params.mhz_freq_seg1 - FREQ_OFFSET_10MHZ,
  3779. CH_WIDTH_80MHZ,
  3780. REG_CURRENT_PWR_MODE);
  3781. if ((chan_state2 == CHANNEL_STATE_DISABLE) ||
  3782. (chan_state2 == CHANNEL_STATE_INVALID))
  3783. return false;
  3784. if (abs(ch_params.mhz_freq_seg0 - ch_params.mhz_freq_seg1) <=
  3785. FREQ_OFFSET_80MHZ)
  3786. return false;
  3787. return true;
  3788. }
  3789. /**
  3790. * _target_if_set_spectral_config() - Set spectral config
  3791. * @spectral: Pointer to spectral object
  3792. * @param: Spectral parameter id and value
  3793. * @smode: Spectral scan mode
  3794. * @err: Spectral error code
  3795. *
  3796. * API to set spectral configurations
  3797. *
  3798. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3799. */
  3800. static QDF_STATUS
  3801. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  3802. const struct spectral_cp_param *param,
  3803. const enum spectral_scan_mode smode,
  3804. enum spectral_cp_error_code *err)
  3805. {
  3806. struct spectral_config params;
  3807. struct target_if_spectral_ops *p_sops;
  3808. struct spectral_config *sparams;
  3809. QDF_STATUS status;
  3810. bool is_overlapping;
  3811. uint16_t agile_cfreq;
  3812. bool is_valid_chan;
  3813. struct spectral_param_min_max *param_min_max;
  3814. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  3815. enum spectral_scan_mode m;
  3816. struct spectral_config_frequency center_freq = {0};
  3817. bool is_bw_supported;
  3818. struct wlan_objmgr_vdev *vdev;
  3819. enum phy_ch_width op_bw;
  3820. if (!err) {
  3821. spectral_err("Error code argument is null");
  3822. QDF_ASSERT(0);
  3823. return QDF_STATUS_E_FAILURE;
  3824. }
  3825. *err = SPECTRAL_SCAN_ERR_INVALID;
  3826. if (!param) {
  3827. spectral_err("Parameter object is null");
  3828. return QDF_STATUS_E_FAILURE;
  3829. }
  3830. if (!spectral) {
  3831. spectral_err("spectral object is NULL");
  3832. return QDF_STATUS_E_FAILURE;
  3833. }
  3834. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3835. param_min_max = &spectral->param_min_max;
  3836. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3837. spectral_err("Invalid Spectral mode %u", smode);
  3838. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3839. return QDF_STATUS_E_FAILURE;
  3840. }
  3841. sparams = &spectral->params[smode];
  3842. m = SPECTRAL_SCAN_MODE_NORMAL;
  3843. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  3844. ch_width[m] = CH_WIDTH_INVALID;
  3845. if (!spectral->params_valid[smode]) {
  3846. target_if_spectral_info_read(spectral,
  3847. smode,
  3848. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3849. &spectral->params[smode],
  3850. sizeof(spectral->params[smode]));
  3851. spectral->params_valid[smode] = true;
  3852. }
  3853. switch (param->id) {
  3854. case SPECTRAL_PARAM_FFT_PERIOD:
  3855. sparams->ss_fft_period = param->value;
  3856. break;
  3857. case SPECTRAL_PARAM_SCAN_PERIOD:
  3858. sparams->ss_period = param->value;
  3859. break;
  3860. case SPECTRAL_PARAM_SCAN_COUNT:
  3861. sparams->ss_count = param->value;
  3862. break;
  3863. case SPECTRAL_PARAM_SHORT_REPORT:
  3864. sparams->ss_short_report = (!!param->value) ? true : false;
  3865. break;
  3866. case SPECTRAL_PARAM_SPECT_PRI:
  3867. sparams->ss_spectral_pri = (!!param->value) ? true : false;
  3868. break;
  3869. case SPECTRAL_PARAM_FFT_SIZE:
  3870. status = target_if_spectral_populate_chwidth
  3871. (spectral, ch_width, spectral->params
  3872. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  3873. if (QDF_IS_STATUS_ERROR(status))
  3874. return QDF_STATUS_E_FAILURE;
  3875. if ((param->value < param_min_max->fft_size_min) ||
  3876. (param->value > param_min_max->fft_size_max
  3877. [ch_width[smode]])) {
  3878. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3879. return QDF_STATUS_E_FAILURE;
  3880. }
  3881. sparams->ss_fft_size = param->value;
  3882. break;
  3883. case SPECTRAL_PARAM_GC_ENA:
  3884. sparams->ss_gc_ena = !!param->value;
  3885. break;
  3886. case SPECTRAL_PARAM_RESTART_ENA:
  3887. sparams->ss_restart_ena = !!param->value;
  3888. break;
  3889. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  3890. sparams->ss_noise_floor_ref = param->value;
  3891. break;
  3892. case SPECTRAL_PARAM_INIT_DELAY:
  3893. sparams->ss_init_delay = param->value;
  3894. break;
  3895. case SPECTRAL_PARAM_NB_TONE_THR:
  3896. sparams->ss_nb_tone_thr = param->value;
  3897. break;
  3898. case SPECTRAL_PARAM_STR_BIN_THR:
  3899. sparams->ss_str_bin_thr = param->value;
  3900. break;
  3901. case SPECTRAL_PARAM_WB_RPT_MODE:
  3902. sparams->ss_wb_rpt_mode = !!param->value;
  3903. break;
  3904. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  3905. sparams->ss_rssi_rpt_mode = !!param->value;
  3906. break;
  3907. case SPECTRAL_PARAM_RSSI_THR:
  3908. sparams->ss_rssi_thr = param->value;
  3909. break;
  3910. case SPECTRAL_PARAM_PWR_FORMAT:
  3911. sparams->ss_pwr_format = !!param->value;
  3912. break;
  3913. case SPECTRAL_PARAM_RPT_MODE:
  3914. if ((param->value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  3915. (param->value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  3916. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3917. return QDF_STATUS_E_FAILURE;
  3918. }
  3919. sparams->ss_rpt_mode = param->value;
  3920. break;
  3921. case SPECTRAL_PARAM_BIN_SCALE:
  3922. sparams->ss_bin_scale = param->value;
  3923. break;
  3924. case SPECTRAL_PARAM_DBM_ADJ:
  3925. sparams->ss_dbm_adj = !!param->value;
  3926. break;
  3927. case SPECTRAL_PARAM_CHN_MASK:
  3928. sparams->ss_chn_mask = param->value;
  3929. break;
  3930. case SPECTRAL_PARAM_FREQUENCY:
  3931. status = target_if_spectral_populate_chwidth(
  3932. spectral, ch_width, param->freq.cfreq2 > 0);
  3933. if (QDF_IS_STATUS_ERROR(status)) {
  3934. spectral_err("Failed to populate channel width");
  3935. return QDF_STATUS_E_FAILURE;
  3936. }
  3937. if (ch_width[smode] != CH_WIDTH_80P80MHZ &&
  3938. param->freq.cfreq2) {
  3939. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3940. spectral_err("Non zero cfreq2 expected for 80p80 only");
  3941. return QDF_STATUS_E_INVAL;
  3942. }
  3943. if (ch_width[smode] == CH_WIDTH_80P80MHZ &&
  3944. !param->freq.cfreq2) {
  3945. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3946. spectral_err("Non zero cfreq2 expected for 80p80");
  3947. return QDF_STATUS_E_INVAL;
  3948. }
  3949. status = target_if_is_center_freq_of_any_chan
  3950. (spectral->pdev_obj, param->freq.cfreq1,
  3951. &is_valid_chan);
  3952. if (QDF_IS_STATUS_ERROR(status))
  3953. return QDF_STATUS_E_FAILURE;
  3954. if (is_valid_chan) {
  3955. status = target_if_calculate_center_freq(
  3956. spectral, ch_width,
  3957. param->freq.cfreq1,
  3958. &agile_cfreq);
  3959. if (QDF_IS_STATUS_ERROR(status)) {
  3960. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3961. return QDF_STATUS_E_FAILURE;
  3962. }
  3963. } else {
  3964. bool is_valid_agile_cfreq;
  3965. status = target_if_validate_center_freq
  3966. (spectral, ch_width, param->freq.cfreq1,
  3967. &is_valid_agile_cfreq);
  3968. if (QDF_IS_STATUS_ERROR(status))
  3969. return QDF_STATUS_E_FAILURE;
  3970. if (!is_valid_agile_cfreq) {
  3971. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3972. spectral_err("Invalid agile center frequency");
  3973. return QDF_STATUS_E_FAILURE;
  3974. }
  3975. agile_cfreq = param->freq.cfreq1;
  3976. }
  3977. center_freq.cfreq1 = agile_cfreq;
  3978. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  3979. status = target_if_is_center_freq_of_any_chan
  3980. (spectral->pdev_obj, param->freq.cfreq2,
  3981. &is_valid_chan);
  3982. if (QDF_IS_STATUS_ERROR(status))
  3983. return QDF_STATUS_E_FAILURE;
  3984. if (is_valid_chan) {
  3985. status = target_if_calculate_center_freq(
  3986. spectral, ch_width,
  3987. param->freq.cfreq2,
  3988. &agile_cfreq);
  3989. if (QDF_IS_STATUS_ERROR(status)) {
  3990. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3991. return QDF_STATUS_E_FAILURE;
  3992. }
  3993. } else {
  3994. bool is_valid_agile_cfreq;
  3995. status = target_if_validate_center_freq
  3996. (spectral, ch_width, param->freq.cfreq2,
  3997. &is_valid_agile_cfreq);
  3998. if (QDF_IS_STATUS_ERROR(status))
  3999. return QDF_STATUS_E_FAILURE;
  4000. if (!is_valid_agile_cfreq) {
  4001. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4002. spectral_err("Invalid agile center frequency");
  4003. return QDF_STATUS_E_FAILURE;
  4004. }
  4005. agile_cfreq = param->freq.cfreq2;
  4006. }
  4007. center_freq.cfreq2 = agile_cfreq;
  4008. }
  4009. status = target_if_is_agile_span_overlap_with_operating_span
  4010. (spectral, ch_width,
  4011. &center_freq, &is_overlapping);
  4012. if (QDF_IS_STATUS_ERROR(status))
  4013. return QDF_STATUS_E_FAILURE;
  4014. if (is_overlapping) {
  4015. spectral_err("Agile freq %u, %u overlaps with operating span",
  4016. center_freq.cfreq1, center_freq.cfreq2);
  4017. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4018. return QDF_STATUS_E_FAILURE;
  4019. }
  4020. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  4021. bool is_valid_80p80;
  4022. is_valid_80p80 = target_if_spectral_is_valid_80p80_freq(
  4023. spectral->pdev_obj,
  4024. center_freq.cfreq1,
  4025. center_freq.cfreq2);
  4026. if (!is_valid_80p80) {
  4027. spectral_err("Agile freq %u, %u is invalid 80+80 combination",
  4028. center_freq.cfreq1,
  4029. center_freq.cfreq2);
  4030. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4031. return QDF_STATUS_E_FAILURE;
  4032. }
  4033. }
  4034. sparams->ss_frequency.cfreq1 = center_freq.cfreq1;
  4035. sparams->ss_frequency.cfreq2 = center_freq.cfreq2;
  4036. break;
  4037. case SPECTRAL_PARAM_CHAN_WIDTH:
  4038. if (param->value >= CH_WIDTH_INVALID) {
  4039. spectral_err("invalid sscan width: %u", param->value);
  4040. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4041. return QDF_STATUS_E_FAILURE;
  4042. }
  4043. vdev = target_if_spectral_get_vdev(spectral, smode);
  4044. if (!vdev) {
  4045. spectral_err("vdev is null");
  4046. return QDF_STATUS_E_NULL_VALUE;
  4047. }
  4048. op_bw = target_if_vdev_get_ch_width(vdev);
  4049. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4050. /* Validate the bandwidth */
  4051. status = target_if_is_sscan_bw_supported(
  4052. spectral, smode,
  4053. param->value, op_bw, &is_bw_supported,
  4054. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  4055. ss_frequency.cfreq2 > 0);
  4056. if (QDF_IS_STATUS_ERROR(status)) {
  4057. spectral_err("Unable to check if given sscan_bw is supported");
  4058. return QDF_STATUS_E_FAILURE;
  4059. }
  4060. if (!is_bw_supported) {
  4061. spectral_err("sscan bw(%u) is not supported for the current operating width(%u) and sscan mode(%u)",
  4062. param->value, op_bw, smode);
  4063. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4064. return QDF_STATUS_E_FAILURE;
  4065. }
  4066. sparams->ss_bandwidth = param->value;
  4067. spectral->sscan_width_configured[smode] = true;
  4068. break;
  4069. }
  4070. p_sops->configure_spectral(spectral, sparams, smode);
  4071. /* only to validate the writes */
  4072. p_sops->get_spectral_config(spectral, &params, smode);
  4073. return QDF_STATUS_SUCCESS;
  4074. }
  4075. QDF_STATUS
  4076. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  4077. const struct spectral_cp_param *param,
  4078. const enum spectral_scan_mode smode,
  4079. enum spectral_cp_error_code *err)
  4080. {
  4081. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  4082. struct target_if_spectral *spectral;
  4083. QDF_STATUS status;
  4084. if (!err) {
  4085. spectral_err("Error code argument is null");
  4086. QDF_ASSERT(0);
  4087. return QDF_STATUS_E_FAILURE;
  4088. }
  4089. *err = SPECTRAL_SCAN_ERR_INVALID;
  4090. if (!pdev) {
  4091. spectral_err("pdev object is NULL");
  4092. return QDF_STATUS_E_FAILURE;
  4093. }
  4094. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4095. if (!spectral) {
  4096. spectral_err("spectral object is NULL");
  4097. return QDF_STATUS_E_FAILURE;
  4098. }
  4099. if (!param) {
  4100. spectral_err("parameter object is NULL");
  4101. return QDF_STATUS_E_FAILURE;
  4102. }
  4103. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4104. spectral_err("Invalid Spectral mode %u", smode);
  4105. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4106. return QDF_STATUS_E_FAILURE;
  4107. }
  4108. if (!spectral->properties[smode][param->id].supported) {
  4109. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  4110. param->id, smode);
  4111. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  4112. return QDF_STATUS_E_FAILURE;
  4113. }
  4114. if (spectral->properties[smode][param->id].common_all_modes) {
  4115. spectral_warn("Setting Spectral parameter %u for all modes",
  4116. param->id);
  4117. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  4118. status = _target_if_set_spectral_config
  4119. (spectral, param, mode, err);
  4120. if (QDF_IS_STATUS_ERROR(status))
  4121. return QDF_STATUS_E_FAILURE;
  4122. }
  4123. return QDF_STATUS_SUCCESS;
  4124. }
  4125. return _target_if_set_spectral_config(spectral, param, smode, err);
  4126. }
  4127. /**
  4128. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  4129. * @fft_len: FFT length
  4130. * @pdev: Pointer to pdev object
  4131. *
  4132. * API to get fft bin count for a given fft length
  4133. *
  4134. * Return: FFt bin count
  4135. */
  4136. static int
  4137. target_if_get_fft_bin_count(int fft_len)
  4138. {
  4139. int bin_count = 0;
  4140. switch (fft_len) {
  4141. case 5:
  4142. bin_count = 16;
  4143. break;
  4144. case 6:
  4145. bin_count = 32;
  4146. break;
  4147. case 7:
  4148. bin_count = 64;
  4149. break;
  4150. case 8:
  4151. bin_count = 128;
  4152. break;
  4153. case 9:
  4154. bin_count = 256;
  4155. break;
  4156. default:
  4157. break;
  4158. }
  4159. return bin_count;
  4160. }
  4161. /**
  4162. * target_if_init_upper_lower_flags() - Initializes control and extension
  4163. * segment flags
  4164. * @spectral: pointer to target if spectral object
  4165. * @smode: Spectral scan mode
  4166. *
  4167. * API to initialize the control and extension flags with the lower/upper
  4168. * segment based on the HT mode
  4169. *
  4170. * Return: FFt bin count
  4171. */
  4172. static void
  4173. target_if_init_upper_lower_flags(struct target_if_spectral *spectral,
  4174. enum spectral_scan_mode smode)
  4175. {
  4176. int current_channel = 0;
  4177. int ext_channel = 0;
  4178. struct target_if_spectral_ops *p_sops =
  4179. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4180. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4181. spectral_err("Invalid Spectral mode %u", smode);
  4182. return;
  4183. }
  4184. current_channel = p_sops->get_current_channel(spectral, smode);
  4185. ext_channel = p_sops->get_extension_channel(spectral, smode);
  4186. if ((current_channel == 0) || (ext_channel == 0))
  4187. return;
  4188. if (spectral->sc_spectral_20_40_mode) {
  4189. /* HT40 mode */
  4190. if (ext_channel < current_channel) {
  4191. spectral->lower_is_extension = 1;
  4192. spectral->upper_is_control = 1;
  4193. spectral->lower_is_control = 0;
  4194. spectral->upper_is_extension = 0;
  4195. } else {
  4196. spectral->lower_is_extension = 0;
  4197. spectral->upper_is_control = 0;
  4198. spectral->lower_is_control = 1;
  4199. spectral->upper_is_extension = 1;
  4200. }
  4201. } else {
  4202. /* HT20 mode, lower is always control */
  4203. spectral->lower_is_extension = 0;
  4204. spectral->upper_is_control = 0;
  4205. spectral->lower_is_control = 1;
  4206. spectral->upper_is_extension = 0;
  4207. }
  4208. }
  4209. /**
  4210. * target_if_get_spectral_config() - Get spectral configuration
  4211. * @pdev: Pointer to pdev object
  4212. * @param: Pointer to spectral_config structure in which the configuration
  4213. * should be returned
  4214. * @smode: Spectral scan mode
  4215. *
  4216. * API to get the current spectral configuration
  4217. *
  4218. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4219. */
  4220. QDF_STATUS
  4221. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  4222. struct spectral_config *param,
  4223. enum spectral_scan_mode smode)
  4224. {
  4225. struct target_if_spectral_ops *p_sops = NULL;
  4226. struct target_if_spectral *spectral = NULL;
  4227. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4228. if (!spectral) {
  4229. spectral_err("SPECTRAL : Module doesn't exist");
  4230. return QDF_STATUS_E_FAILURE;
  4231. }
  4232. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4233. if (!p_sops) {
  4234. spectral_err("p_sops is null");
  4235. return QDF_STATUS_E_FAILURE;
  4236. }
  4237. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4238. spectral_err("Invalid Spectral mode %u", smode);
  4239. return QDF_STATUS_E_FAILURE;
  4240. }
  4241. qdf_mem_zero(param, sizeof(struct spectral_config));
  4242. p_sops->get_spectral_config(spectral, param, smode);
  4243. return QDF_STATUS_SUCCESS;
  4244. }
  4245. #ifdef WLAN_FEATURE_11BE
  4246. /**
  4247. * target_if_spectral_get_num_detectors_for_higher_bws() - Get number of
  4248. * Spectral detectors for higher bandwidths
  4249. * @spectral: Pointer to target if Spectral object
  4250. * @ch_width: channel width
  4251. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  4252. *
  4253. * API to get number of Spectral detectors used for scan in the given channel
  4254. * width.
  4255. *
  4256. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  4257. */
  4258. static QDF_STATUS
  4259. target_if_spectral_get_num_detectors_for_higher_bws(
  4260. struct target_if_spectral *spectral,
  4261. enum phy_ch_width ch_width,
  4262. uint32_t *num_detectors)
  4263. {
  4264. switch (ch_width) {
  4265. case CH_WIDTH_320MHZ:
  4266. *num_detectors = spectral->capability.num_detectors_320mhz;
  4267. break;
  4268. default:
  4269. spectral_err("Unsupported channel width %d", ch_width);
  4270. return QDF_STATUS_E_INVAL;
  4271. }
  4272. return QDF_STATUS_SUCCESS;
  4273. }
  4274. #else
  4275. static QDF_STATUS
  4276. target_if_spectral_get_num_detectors_for_higher_bws(
  4277. struct target_if_spectral *spectral,
  4278. enum phy_ch_width ch_width,
  4279. uint32_t *num_detectors)
  4280. {
  4281. spectral_err("Unsupported channel width %d", ch_width);
  4282. return QDF_STATUS_E_INVAL;
  4283. }
  4284. #endif
  4285. /**
  4286. * target_if_spectral_get_num_detectors() - Get number of Spectral detectors
  4287. * @spectral: Pointer to target if Spectral object
  4288. * @ch_width: channel width
  4289. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  4290. *
  4291. * API to get number of Spectral detectors used for scan in the given channel
  4292. * width.
  4293. *
  4294. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  4295. */
  4296. static QDF_STATUS
  4297. target_if_spectral_get_num_detectors(struct target_if_spectral *spectral,
  4298. enum phy_ch_width ch_width,
  4299. uint32_t *num_detectors)
  4300. {
  4301. if (!spectral) {
  4302. spectral_err("target if spectral object is null");
  4303. return QDF_STATUS_E_INVAL;
  4304. }
  4305. if (ch_width >= CH_WIDTH_INVALID) {
  4306. spectral_err("Invalid channel width %d", ch_width);
  4307. return QDF_STATUS_E_INVAL;
  4308. }
  4309. if (!num_detectors) {
  4310. spectral_err("Invalid argument, number of detectors");
  4311. return QDF_STATUS_E_INVAL;
  4312. }
  4313. switch (ch_width) {
  4314. case CH_WIDTH_20MHZ:
  4315. *num_detectors = spectral->capability.num_detectors_20mhz;
  4316. break;
  4317. case CH_WIDTH_40MHZ:
  4318. *num_detectors = spectral->capability.num_detectors_40mhz;
  4319. break;
  4320. case CH_WIDTH_80MHZ:
  4321. *num_detectors = spectral->capability.num_detectors_80mhz;
  4322. break;
  4323. case CH_WIDTH_160MHZ:
  4324. *num_detectors = spectral->capability.num_detectors_160mhz;
  4325. break;
  4326. case CH_WIDTH_80P80MHZ:
  4327. *num_detectors = spectral->capability.num_detectors_80p80mhz;
  4328. break;
  4329. default:
  4330. return target_if_spectral_get_num_detectors_for_higher_bws(
  4331. spectral, ch_width, num_detectors);
  4332. }
  4333. return QDF_STATUS_SUCCESS;
  4334. }
  4335. /**
  4336. * target_if_spectral_finite_scan_init() - Initializations required for finite
  4337. * Spectral scan
  4338. * @spectral: Pointer to target of Spctral object
  4339. * @smode: Spectral scan mode
  4340. *
  4341. * This routine initializes the finite Spectral scan. Finite Spectral scan is
  4342. * triggered by configuring a non zero scan count.
  4343. *
  4344. * Return: QDF_STATUS_SUCCESS on success
  4345. */
  4346. static QDF_STATUS
  4347. target_if_spectral_finite_scan_init(struct target_if_spectral *spectral,
  4348. enum spectral_scan_mode smode)
  4349. {
  4350. struct target_if_finite_spectral_scan_params *finite_scan;
  4351. enum phy_ch_width ch_width;
  4352. uint32_t num_detectors;
  4353. QDF_STATUS status;
  4354. uint16_t sscan_count;
  4355. if (!spectral) {
  4356. spectral_err("target if spectral object is null");
  4357. return QDF_STATUS_E_INVAL;
  4358. }
  4359. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4360. spectral_err("Invalid Spectral mode");
  4361. return QDF_STATUS_E_INVAL;
  4362. }
  4363. ch_width = spectral->ch_width[smode];
  4364. status = target_if_spectral_get_num_detectors(spectral, ch_width,
  4365. &num_detectors);
  4366. if (QDF_IS_STATUS_ERROR(status)) {
  4367. spectral_err("Failed to get number of detectors");
  4368. return QDF_STATUS_E_FAILURE;
  4369. }
  4370. finite_scan = &spectral->finite_scan[smode];
  4371. sscan_count = spectral->params[smode].ss_count;
  4372. finite_scan->finite_spectral_scan = true;
  4373. finite_scan->num_reports_expected = num_detectors * sscan_count;
  4374. return QDF_STATUS_SUCCESS;
  4375. }
  4376. /**
  4377. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  4378. * parameters
  4379. * @spectral: Pointer to Spectral target_if internal private data
  4380. * @spectral_params: Pointer to Spectral parameters
  4381. * @smode: Spectral scan mode
  4382. * @err: Spectral error code
  4383. *
  4384. * Enable use of desired Spectral parameters by configuring them into HW, and
  4385. * starting Spectral scan
  4386. *
  4387. * Return: 0 on success, 1 on failure
  4388. */
  4389. int
  4390. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  4391. struct spectral_config *spectral_params,
  4392. enum spectral_scan_mode smode,
  4393. enum spectral_cp_error_code *err)
  4394. {
  4395. int extension_channel = 0;
  4396. int current_channel = 0;
  4397. struct target_if_spectral_ops *p_sops = NULL;
  4398. QDF_STATUS status;
  4399. struct wlan_objmgr_pdev *pdev;
  4400. struct wlan_objmgr_psoc *psoc;
  4401. if (!spectral) {
  4402. spectral_err("Spectral LMAC object is NULL");
  4403. return 1;
  4404. }
  4405. pdev = spectral->pdev_obj;
  4406. if (!pdev) {
  4407. spectral_err("pdev is null");
  4408. return QDF_STATUS_E_INVAL;
  4409. }
  4410. psoc = wlan_pdev_get_psoc(pdev);
  4411. if (!psoc) {
  4412. spectral_err("psoc is null");
  4413. return QDF_STATUS_E_INVAL;
  4414. }
  4415. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4416. spectral_err("Invalid Spectral mode %u", smode);
  4417. return 1;
  4418. }
  4419. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4420. if (!p_sops) {
  4421. spectral_err("p_sops is NULL");
  4422. return 1;
  4423. }
  4424. spectral->sc_spectral_noise_pwr_cal =
  4425. spectral_params->ss_spectral_pri ? 1 : 0;
  4426. /* check if extension channel is present */
  4427. extension_channel = p_sops->get_extension_channel(spectral, smode);
  4428. current_channel = p_sops->get_current_channel(spectral, smode);
  4429. if (spectral->capability.advncd_spectral_cap) {
  4430. spectral->lb_edge_extrabins = 0;
  4431. spectral->rb_edge_extrabins = 0;
  4432. if (spectral->is_lb_edge_extrabins_format &&
  4433. spectral->params[smode].ss_rpt_mode == 2) {
  4434. spectral->lb_edge_extrabins = 4;
  4435. }
  4436. if (spectral->is_rb_edge_extrabins_format &&
  4437. spectral->params[smode].ss_rpt_mode == 2) {
  4438. spectral->rb_edge_extrabins = 4;
  4439. }
  4440. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  4441. spectral->sc_spectral_20_40_mode = 0;
  4442. spectral->spectral_numbins =
  4443. target_if_get_fft_bin_count(
  4444. spectral->params[smode].ss_fft_size);
  4445. spectral->spectral_fft_len =
  4446. target_if_get_fft_bin_count(
  4447. spectral->params[smode].ss_fft_size);
  4448. spectral->spectral_data_len =
  4449. target_if_get_fft_bin_count(
  4450. spectral->params[smode].ss_fft_size);
  4451. /*
  4452. * Initialize classifier params to be sent to user
  4453. * space classifier
  4454. */
  4455. spectral->classifier_params.lower_chan_in_mhz =
  4456. current_channel;
  4457. spectral->classifier_params.upper_chan_in_mhz = 0;
  4458. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  4459. /* TODO : Remove this variable */
  4460. spectral->sc_spectral_20_40_mode = 1;
  4461. spectral->spectral_numbins =
  4462. target_if_get_fft_bin_count(
  4463. spectral->params[smode].ss_fft_size);
  4464. spectral->spectral_fft_len =
  4465. target_if_get_fft_bin_count(
  4466. spectral->params[smode].ss_fft_size);
  4467. spectral->spectral_data_len =
  4468. target_if_get_fft_bin_count(
  4469. spectral->params[smode].ss_fft_size);
  4470. /*
  4471. * Initialize classifier params to be sent to user
  4472. * space classifier
  4473. */
  4474. if (extension_channel < current_channel) {
  4475. spectral->classifier_params.lower_chan_in_mhz =
  4476. extension_channel;
  4477. spectral->classifier_params.upper_chan_in_mhz =
  4478. current_channel;
  4479. } else {
  4480. spectral->classifier_params.lower_chan_in_mhz =
  4481. current_channel;
  4482. spectral->classifier_params.upper_chan_in_mhz =
  4483. extension_channel;
  4484. }
  4485. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  4486. /* Set the FFT Size */
  4487. /* TODO : Remove this variable */
  4488. spectral->sc_spectral_20_40_mode = 0;
  4489. spectral->spectral_numbins =
  4490. target_if_get_fft_bin_count(
  4491. spectral->params[smode].ss_fft_size);
  4492. spectral->spectral_fft_len =
  4493. target_if_get_fft_bin_count(
  4494. spectral->params[smode].ss_fft_size);
  4495. spectral->spectral_data_len =
  4496. target_if_get_fft_bin_count(
  4497. spectral->params[smode].ss_fft_size);
  4498. /*
  4499. * Initialize classifier params to be sent to user
  4500. * space classifier
  4501. */
  4502. spectral->classifier_params.lower_chan_in_mhz =
  4503. current_channel;
  4504. spectral->classifier_params.upper_chan_in_mhz = 0;
  4505. /*
  4506. * Initialize classifier params to be sent to user
  4507. * space classifier
  4508. */
  4509. if (extension_channel < current_channel) {
  4510. spectral->classifier_params.lower_chan_in_mhz =
  4511. extension_channel;
  4512. spectral->classifier_params.upper_chan_in_mhz =
  4513. current_channel;
  4514. } else {
  4515. spectral->classifier_params.lower_chan_in_mhz =
  4516. current_channel;
  4517. spectral->classifier_params.upper_chan_in_mhz =
  4518. extension_channel;
  4519. }
  4520. } else if (is_ch_width_160_or_80p80(
  4521. spectral->ch_width[smode])) {
  4522. /* Set the FFT Size */
  4523. /* The below applies to both 160 and 80+80 cases */
  4524. /* TODO : Remove this variable */
  4525. spectral->sc_spectral_20_40_mode = 0;
  4526. spectral->spectral_numbins =
  4527. target_if_get_fft_bin_count(
  4528. spectral->params[smode].ss_fft_size);
  4529. spectral->spectral_fft_len =
  4530. target_if_get_fft_bin_count(
  4531. spectral->params[smode].ss_fft_size);
  4532. spectral->spectral_data_len =
  4533. target_if_get_fft_bin_count(
  4534. spectral->params[smode].ss_fft_size);
  4535. /*
  4536. * Initialize classifier params to be sent to user
  4537. * space classifier
  4538. */
  4539. spectral->classifier_params.lower_chan_in_mhz =
  4540. current_channel;
  4541. spectral->classifier_params.upper_chan_in_mhz = 0;
  4542. /*
  4543. * Initialize classifier params to be sent to user
  4544. * space classifier
  4545. */
  4546. if (extension_channel < current_channel) {
  4547. spectral->classifier_params.lower_chan_in_mhz =
  4548. extension_channel;
  4549. spectral->classifier_params.upper_chan_in_mhz =
  4550. current_channel;
  4551. } else {
  4552. spectral->classifier_params.lower_chan_in_mhz =
  4553. current_channel;
  4554. spectral->classifier_params.upper_chan_in_mhz =
  4555. extension_channel;
  4556. }
  4557. }
  4558. if (spectral->spectral_numbins) {
  4559. spectral->spectral_numbins +=
  4560. spectral->lb_edge_extrabins;
  4561. spectral->spectral_numbins +=
  4562. spectral->rb_edge_extrabins;
  4563. }
  4564. if (spectral->spectral_fft_len) {
  4565. spectral->spectral_fft_len +=
  4566. spectral->lb_edge_extrabins;
  4567. spectral->spectral_fft_len +=
  4568. spectral->rb_edge_extrabins;
  4569. }
  4570. if (spectral->spectral_data_len) {
  4571. spectral->spectral_data_len +=
  4572. spectral->lb_edge_extrabins;
  4573. spectral->spectral_data_len +=
  4574. spectral->rb_edge_extrabins;
  4575. }
  4576. } else {
  4577. /*
  4578. * The decision to find 20/40 mode is found based on the
  4579. * presence of extension channel
  4580. * instead of channel width, as the channel width can
  4581. * dynamically change
  4582. */
  4583. if (extension_channel == 0) {
  4584. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  4585. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  4586. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  4587. spectral->spectral_data_len =
  4588. SPECTRAL_HT20_TOTAL_DATA_LEN;
  4589. /* only valid in 20-40 mode */
  4590. spectral->spectral_lower_max_index_offset = -1;
  4591. /* only valid in 20-40 mode */
  4592. spectral->spectral_upper_max_index_offset = -1;
  4593. spectral->spectral_max_index_offset =
  4594. spectral->spectral_fft_len + 2;
  4595. spectral->sc_spectral_20_40_mode = 0;
  4596. /*
  4597. * Initialize classifier params to be sent to user
  4598. * space classifier
  4599. */
  4600. spectral->classifier_params.lower_chan_in_mhz =
  4601. current_channel;
  4602. spectral->classifier_params.upper_chan_in_mhz = 0;
  4603. } else {
  4604. spectral->spectral_numbins =
  4605. SPECTRAL_HT40_TOTAL_NUM_BINS;
  4606. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  4607. spectral->spectral_data_len =
  4608. SPECTRAL_HT40_TOTAL_DATA_LEN;
  4609. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  4610. /* only valid in 20 mode */
  4611. spectral->spectral_max_index_offset = -1;
  4612. spectral->spectral_lower_max_index_offset =
  4613. spectral->spectral_fft_len + 2;
  4614. spectral->spectral_upper_max_index_offset =
  4615. spectral->spectral_fft_len + 5;
  4616. spectral->sc_spectral_20_40_mode = 1;
  4617. /*
  4618. * Initialize classifier params to be sent to user
  4619. * space classifier
  4620. */
  4621. if (extension_channel < current_channel) {
  4622. spectral->classifier_params.lower_chan_in_mhz =
  4623. extension_channel;
  4624. spectral->classifier_params.upper_chan_in_mhz =
  4625. current_channel;
  4626. } else {
  4627. spectral->classifier_params.lower_chan_in_mhz =
  4628. current_channel;
  4629. spectral->classifier_params.upper_chan_in_mhz =
  4630. extension_channel;
  4631. }
  4632. }
  4633. }
  4634. spectral->send_single_packet = 0;
  4635. spectral->classifier_params.spectral_20_40_mode =
  4636. spectral->sc_spectral_20_40_mode;
  4637. spectral->classifier_params.spectral_dc_index =
  4638. spectral->spectral_dc_index;
  4639. spectral->spectral_sent_msg = 0;
  4640. spectral->classify_scan = 0;
  4641. spectral->num_spectral_data = 0;
  4642. if (!p_sops->is_spectral_active(spectral, smode)) {
  4643. p_sops->configure_spectral(spectral, spectral_params, smode);
  4644. spectral->rparams.marker[smode].is_valid = false;
  4645. if (spectral->params[smode].ss_count) {
  4646. status = target_if_spectral_finite_scan_init(spectral,
  4647. smode);
  4648. if (QDF_IS_STATUS_ERROR(status)) {
  4649. spectral_err("Failed to init finite scan");
  4650. return 1;
  4651. }
  4652. }
  4653. p_sops->start_spectral_scan(spectral, smode, err);
  4654. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  4655. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  4656. }
  4657. /* get current spectral configuration */
  4658. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  4659. target_if_init_upper_lower_flags(spectral, smode);
  4660. return 0;
  4661. }
  4662. /**
  4663. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  4664. * Agile DFS
  4665. * @psoc: Pointer to psoc
  4666. * @object: Pointer to pdev
  4667. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  4668. *
  4669. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  4670. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  4671. *
  4672. * Return: void
  4673. */
  4674. static void
  4675. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  4676. void *object, void *arg)
  4677. {
  4678. bool *is_aspectral_prohibited = arg;
  4679. struct wlan_objmgr_pdev *cur_pdev = object;
  4680. bool is_agile_precac_enabled_cur_pdev = false;
  4681. bool is_agile_rcac_enabled_cur_pdev = false;
  4682. QDF_STATUS status;
  4683. qdf_assert_always(is_aspectral_prohibited);
  4684. if (*is_aspectral_prohibited)
  4685. return;
  4686. qdf_assert_always(psoc);
  4687. qdf_assert_always(cur_pdev);
  4688. status = ucfg_dfs_get_agile_precac_enable
  4689. (cur_pdev,
  4690. &is_agile_precac_enabled_cur_pdev);
  4691. if (QDF_IS_STATUS_ERROR(status)) {
  4692. spectral_err("Get agile precac failed, prohibiting aSpectral");
  4693. *is_aspectral_prohibited = true;
  4694. return;
  4695. }
  4696. status = ucfg_dfs_get_rcac_enable(cur_pdev,
  4697. &is_agile_rcac_enabled_cur_pdev);
  4698. if (QDF_IS_STATUS_ERROR(status)) {
  4699. spectral_err("Get agile RCAC failed, prohibiting aSpectral");
  4700. *is_aspectral_prohibited = true;
  4701. return;
  4702. }
  4703. if (is_agile_precac_enabled_cur_pdev) {
  4704. spectral_err("aDFS preCAC is in progress on one of the pdevs");
  4705. *is_aspectral_prohibited = true;
  4706. } else if (is_agile_rcac_enabled_cur_pdev) {
  4707. spectral_err("aDFS RCAC is in progress on one of the pdevs");
  4708. *is_aspectral_prohibited = true;
  4709. }
  4710. }
  4711. /**
  4712. * target_if_get_curr_band() - Get current operating band of pdev
  4713. *
  4714. * @pdev: pointer to pdev object
  4715. *
  4716. * API to get current operating band of a given pdev.
  4717. *
  4718. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  4719. */
  4720. static enum reg_wifi_band
  4721. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id)
  4722. {
  4723. struct wlan_objmgr_vdev *vdev;
  4724. int16_t chan_freq;
  4725. enum reg_wifi_band cur_band;
  4726. if (!pdev) {
  4727. spectral_err("pdev is NULL");
  4728. return REG_BAND_UNKNOWN;
  4729. }
  4730. if (vdev_id == WLAN_INVALID_VDEV_ID)
  4731. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  4732. else
  4733. vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, vdev_id,
  4734. WLAN_SPECTRAL_ID);
  4735. if (!vdev) {
  4736. spectral_debug("vdev is NULL");
  4737. return REG_BAND_UNKNOWN;
  4738. }
  4739. chan_freq = target_if_vdev_get_chan_freq(vdev);
  4740. cur_band = wlan_reg_freq_to_band(chan_freq);
  4741. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4742. return cur_band;
  4743. }
  4744. /**
  4745. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  4746. * any of the 5G pdevs
  4747. * @psoc: Pointer to psoc
  4748. * @object: Pointer to pdev
  4749. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  4750. * progress in any 5G pdevs
  4751. *
  4752. * Return: void
  4753. */
  4754. static void
  4755. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  4756. void *object, void *arg)
  4757. {
  4758. enum reg_wifi_band band;
  4759. bool *is_agile_scan_inprog_5g_pdev = arg;
  4760. struct target_if_spectral *spectral;
  4761. struct wlan_objmgr_pdev *cur_pdev = object;
  4762. struct target_if_spectral_ops *p_sops;
  4763. if (*is_agile_scan_inprog_5g_pdev)
  4764. return;
  4765. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  4766. if (!spectral) {
  4767. spectral_err("target if spectral handle is NULL");
  4768. return;
  4769. }
  4770. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4771. band = target_if_get_curr_band(
  4772. cur_pdev, spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE]);
  4773. if (band == REG_BAND_UNKNOWN) {
  4774. spectral_debug("Failed to get current band");
  4775. return;
  4776. }
  4777. if (band == REG_BAND_5G &&
  4778. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  4779. *is_agile_scan_inprog_5g_pdev = true;
  4780. }
  4781. /**
  4782. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  4783. * for current vdev rx chainmask.
  4784. *
  4785. * @spectral: Pointer to Spectral object
  4786. * @is_supported: Pointer to is_supported
  4787. *
  4788. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4789. */
  4790. static QDF_STATUS
  4791. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  4792. bool *is_supported)
  4793. {
  4794. struct wlan_objmgr_vdev *vdev;
  4795. uint8_t vdev_rxchainmask;
  4796. struct wlan_objmgr_psoc *psoc;
  4797. struct wlan_objmgr_pdev *pdev;
  4798. struct target_psoc_info *tgt_psoc_info;
  4799. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  4800. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  4801. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  4802. struct wlan_psoc_host_chainmask_table *table;
  4803. int j;
  4804. uint32_t table_id;
  4805. enum phy_ch_width ch_width;
  4806. uint8_t pdev_id;
  4807. if (!spectral) {
  4808. spectral_err("spectral target if object is null");
  4809. return QDF_STATUS_E_FAILURE;
  4810. }
  4811. if (!is_supported) {
  4812. spectral_err("is supported argument is null");
  4813. return QDF_STATUS_E_FAILURE;
  4814. }
  4815. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  4816. spectral_err("HW Agile mode is not supported up to gen 2");
  4817. return QDF_STATUS_E_FAILURE;
  4818. }
  4819. pdev = spectral->pdev_obj;
  4820. if (!pdev) {
  4821. spectral_err("pdev is null");
  4822. return QDF_STATUS_E_FAILURE;
  4823. }
  4824. psoc = wlan_pdev_get_psoc(pdev);
  4825. if (!psoc) {
  4826. spectral_err("psoc is null");
  4827. return QDF_STATUS_E_FAILURE;
  4828. }
  4829. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  4830. if (!vdev) {
  4831. spectral_err("First vdev is NULL");
  4832. return QDF_STATUS_E_FAILURE;
  4833. }
  4834. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  4835. if (!vdev_rxchainmask) {
  4836. spectral_err("vdev rx chainmask is zero");
  4837. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4838. return QDF_STATUS_E_FAILURE;
  4839. }
  4840. ch_width = target_if_vdev_get_ch_width(vdev);
  4841. if (ch_width == CH_WIDTH_INVALID) {
  4842. spectral_err("Invalid channel width");
  4843. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4844. return QDF_STATUS_E_FAILURE;
  4845. }
  4846. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4847. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  4848. if (!tgt_psoc_info) {
  4849. spectral_err("target_psoc_info is null");
  4850. return QDF_STATUS_E_FAILURE;
  4851. }
  4852. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  4853. if (!ext_svc_param) {
  4854. spectral_err("Extended service ready param null");
  4855. return QDF_STATUS_E_FAILURE;
  4856. }
  4857. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  4858. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  4859. if (!mac_phy_cap_arr) {
  4860. spectral_err("mac phy cap array is null");
  4861. return QDF_STATUS_E_FAILURE;
  4862. }
  4863. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  4864. if (!mac_phy_cap) {
  4865. spectral_err("mac phy cap is null");
  4866. return QDF_STATUS_E_FAILURE;
  4867. }
  4868. table_id = mac_phy_cap->chainmask_table_id;
  4869. table = &ext_svc_param->chainmask_table[table_id];
  4870. if (!table) {
  4871. spectral_err("chainmask table not found");
  4872. return QDF_STATUS_E_FAILURE;
  4873. }
  4874. for (j = 0; j < table->num_valid_chainmasks; j++) {
  4875. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  4876. if (ch_width <= CH_WIDTH_80MHZ)
  4877. *is_supported =
  4878. table->cap_list[j].supports_aSpectral;
  4879. else
  4880. *is_supported =
  4881. table->cap_list[j].supports_aSpectral_160;
  4882. break;
  4883. }
  4884. }
  4885. if (j == table->num_valid_chainmasks) {
  4886. spectral_err("vdev rx chainmask %u not found in table id = %u",
  4887. vdev_rxchainmask, table_id);
  4888. return QDF_STATUS_E_FAILURE;
  4889. }
  4890. return QDF_STATUS_SUCCESS;
  4891. }
  4892. #define INVALID_SPAN_NUM (-1)
  4893. /**
  4894. * target_if_spectral_get_num_spans() - Get number of spans for a given sscan_bw
  4895. * @pdev: Pointer to pdev object
  4896. * @sscan_bw: Spectral scan bandwidth
  4897. *
  4898. * Return: Number of spans on success, INVALID_SPAN_NUM on failure
  4899. */
  4900. static int
  4901. target_if_spectral_get_num_spans(
  4902. struct wlan_objmgr_pdev *pdev,
  4903. enum phy_ch_width sscan_bw)
  4904. {
  4905. struct wlan_objmgr_psoc *psoc;
  4906. int num_spans;
  4907. if (!pdev) {
  4908. spectral_err_rl("pdev is null");
  4909. return INVALID_SPAN_NUM;
  4910. }
  4911. psoc = wlan_pdev_get_psoc(pdev);
  4912. if (!psoc) {
  4913. spectral_err_rl("psoc is null");
  4914. return INVALID_SPAN_NUM;
  4915. }
  4916. if (sscan_bw == CH_WIDTH_80P80MHZ) {
  4917. num_spans = 2;
  4918. if (wlan_psoc_nif_fw_ext_cap_get(
  4919. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  4920. /* 5 MHz frequency span in restricted 80p80 case */
  4921. num_spans += 1;
  4922. } else {
  4923. num_spans = 1;
  4924. }
  4925. return num_spans;
  4926. }
  4927. #ifdef OPTIMIZED_SAMP_MESSAGE
  4928. /**
  4929. * target_if_spectral_populate_session_report_info() - Populate per-session
  4930. * report level information.
  4931. *
  4932. * @spectral: Pointer to Spectral object
  4933. * @smode: Spectral scan mode
  4934. *
  4935. * Return: Success/Failure
  4936. */
  4937. static QDF_STATUS
  4938. target_if_spectral_populate_session_report_info(
  4939. struct target_if_spectral *spectral,
  4940. enum spectral_scan_mode smode)
  4941. {
  4942. struct per_session_report_info *rpt_info;
  4943. if (!spectral) {
  4944. spectral_err_rl("Spectral LMAC object is null");
  4945. return QDF_STATUS_E_NULL_VALUE;
  4946. }
  4947. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  4948. spectral_err_rl("Invalid Spectral scan mode");
  4949. return QDF_STATUS_E_FAILURE;
  4950. }
  4951. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  4952. /* Fill per-session report information, based on the spectral mode */
  4953. rpt_info = &spectral->report_info[smode];
  4954. rpt_info->operating_bw = spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  4955. rpt_info->sscan_bw = spectral->ch_width[smode];
  4956. rpt_info->sscan_cfreq1 = spectral->params[smode].ss_frequency.cfreq1;
  4957. rpt_info->sscan_cfreq2 = spectral->params[smode].ss_frequency.cfreq2;
  4958. rpt_info->num_spans = target_if_spectral_get_num_spans(
  4959. spectral->pdev_obj,
  4960. rpt_info->sscan_bw);
  4961. qdf_assert_always(rpt_info->num_spans != INVALID_SPAN_NUM);
  4962. rpt_info->valid = true;
  4963. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  4964. return QDF_STATUS_SUCCESS;
  4965. }
  4966. /**
  4967. * target_if_spectral_populate_session_det_host_info() - Populate per-session
  4968. * detector level information that is known to the Host
  4969. *
  4970. * @spectral: Pointer to Spectral object
  4971. * @smode: Spectral scan mode
  4972. *
  4973. * Return: Success/Failure
  4974. */
  4975. static QDF_STATUS
  4976. target_if_spectral_populate_session_det_host_info(
  4977. struct target_if_spectral *spectral,
  4978. enum spectral_scan_mode smode)
  4979. {
  4980. struct per_session_report_info *rpt_info;
  4981. struct sscan_detector_list *detector_list;
  4982. struct wlan_objmgr_psoc *psoc;
  4983. uint16_t dest_det_idx = 0;
  4984. uint16_t dest_span_idx = 0;
  4985. bool is_sec80 = false;
  4986. uint8_t det, dest_det;
  4987. if (!spectral) {
  4988. spectral_err_rl("Spectral LMAC object is null");
  4989. return QDF_STATUS_E_NULL_VALUE;
  4990. }
  4991. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  4992. spectral_err_rl("Invalid Spectral scan mode");
  4993. return QDF_STATUS_E_FAILURE;
  4994. }
  4995. if (!spectral->pdev_obj) {
  4996. spectral_err_rl("Spectral PDEV is null");
  4997. return QDF_STATUS_E_NULL_VALUE;
  4998. }
  4999. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  5000. if (!psoc) {
  5001. spectral_err_rl("psoc is null");
  5002. return QDF_STATUS_E_NULL_VALUE;
  5003. }
  5004. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5005. rpt_info = &spectral->report_info[smode];
  5006. qdf_spin_lock_bh(&spectral->detector_list_lock);
  5007. /* Fill per-sesion detector-level information */
  5008. detector_list = &spectral->detector_list[smode][rpt_info->sscan_bw];
  5009. for (det = 0; det < detector_list->num_detectors; det++) {
  5010. struct per_session_det_map *det_map;
  5011. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  5012. det_map = &spectral->det_map[detector_list->detectors[det]];
  5013. if (detector_list->num_detectors > 1) {
  5014. if (det == 0) {
  5015. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  5016. det_map->send_to_upper_layers = false;
  5017. } else if (det == detector_list->num_detectors - 1) {
  5018. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  5019. det_map->send_to_upper_layers = true;
  5020. } else {
  5021. /* middle fragments */
  5022. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  5023. det_map->send_to_upper_layers = false;
  5024. }
  5025. } else {
  5026. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  5027. det_map->send_to_upper_layers = true;
  5028. }
  5029. det_map->num_dest_det_info = 1;
  5030. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ &&
  5031. wlan_psoc_nif_fw_ext_cap_get(
  5032. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  5033. /**
  5034. * In 165MHz case, 1 Spectral HW detector maps to 3
  5035. * detectors in SAMP msg.
  5036. */
  5037. det_map->num_dest_det_info += 2;
  5038. }
  5039. for (dest_det = 0; dest_det < det_map->num_dest_det_info;
  5040. dest_det++) {
  5041. struct per_session_dest_det_info *map_det_info;
  5042. map_det_info = &det_map->dest_det_info[dest_det];
  5043. map_det_info->freq_span_id = dest_span_idx;
  5044. map_det_info->det_id = dest_det_idx;
  5045. map_det_info->is_sec80 = is_sec80;
  5046. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ) {
  5047. /* Increment span ID for non-contiguous modes */
  5048. dest_det_idx = 0;
  5049. dest_span_idx++;
  5050. } else {
  5051. /* Increment detector ID for contiguous modes */
  5052. dest_det_idx++;
  5053. }
  5054. is_sec80 = !is_sec80;
  5055. }
  5056. det_map->det_map_valid[smode] = true;
  5057. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  5058. }
  5059. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  5060. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5061. return QDF_STATUS_SUCCESS;
  5062. }
  5063. #else
  5064. static QDF_STATUS
  5065. target_if_spectral_populate_session_report_info(
  5066. struct target_if_spectral *spectral,
  5067. enum spectral_scan_mode smode)
  5068. {
  5069. return QDF_STATUS_SUCCESS;
  5070. }
  5071. static QDF_STATUS
  5072. target_if_spectral_populate_session_det_host_info(
  5073. struct target_if_spectral *spectral,
  5074. enum spectral_scan_mode smode)
  5075. {
  5076. return QDF_STATUS_SUCCESS;
  5077. }
  5078. #endif /* OPTIMIZED_SAMP_MESSAGE */
  5079. QDF_STATUS
  5080. spectral_is_session_info_expected_from_target(struct wlan_objmgr_pdev *pdev,
  5081. bool *is_session_info_expected)
  5082. {
  5083. struct wlan_objmgr_psoc *psoc;
  5084. struct wmi_unified *wmi_handle;
  5085. if (!pdev) {
  5086. spectral_err("pdev is null");
  5087. return QDF_STATUS_E_NULL_VALUE;
  5088. }
  5089. psoc = wlan_pdev_get_psoc(pdev);
  5090. if (!psoc) {
  5091. spectral_err("psoc is null");
  5092. return QDF_STATUS_E_NULL_VALUE;
  5093. }
  5094. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  5095. if (!wmi_handle) {
  5096. spectral_err("wmi handle is null");
  5097. return QDF_STATUS_E_NULL_VALUE;
  5098. }
  5099. *is_session_info_expected = target_if_spectral_wmi_service_enabled(
  5100. psoc, wmi_handle,
  5101. wmi_service_spectral_session_info_support);
  5102. return QDF_STATUS_SUCCESS;
  5103. }
  5104. QDF_STATUS
  5105. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  5106. uint8_t vdev_id,
  5107. const enum spectral_scan_mode smode,
  5108. enum spectral_cp_error_code *err)
  5109. {
  5110. struct target_if_spectral_ops *p_sops;
  5111. struct target_if_spectral *spectral;
  5112. struct wlan_objmgr_psoc *psoc;
  5113. enum reg_wifi_band band;
  5114. QDF_STATUS ret;
  5115. bool is_session_info_expected;
  5116. if (!err) {
  5117. spectral_err("Error code argument is null");
  5118. QDF_ASSERT(0);
  5119. return QDF_STATUS_E_FAILURE;
  5120. }
  5121. *err = SPECTRAL_SCAN_ERR_INVALID;
  5122. if (!pdev) {
  5123. spectral_err("pdev object is NUll");
  5124. return QDF_STATUS_E_FAILURE;
  5125. }
  5126. psoc = wlan_pdev_get_psoc(pdev);
  5127. if (!psoc) {
  5128. spectral_err("psoc is null");
  5129. return QDF_STATUS_E_FAILURE;
  5130. }
  5131. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5132. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5133. spectral_err("Invalid Spectral mode %u", smode);
  5134. return QDF_STATUS_E_FAILURE;
  5135. }
  5136. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5137. if (!spectral) {
  5138. spectral_err("Spectral LMAC object is NUll");
  5139. return QDF_STATUS_E_FAILURE;
  5140. }
  5141. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5142. if (!p_sops) {
  5143. spectral_err("p_sops is null");
  5144. return QDF_STATUS_E_FAILURE;
  5145. }
  5146. if (p_sops->is_spectral_active(spectral, smode)) {
  5147. spectral_err("spectral in progress in current pdev, mode %d",
  5148. smode);
  5149. return QDF_STATUS_E_FAILURE;
  5150. }
  5151. spectral->vdev_id[smode] = vdev_id;
  5152. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5153. QDF_STATUS status;
  5154. bool is_supported = false;
  5155. status = target_if_is_agile_supported_cur_chmask(spectral,
  5156. &is_supported);
  5157. if (QDF_IS_STATUS_ERROR(status)) {
  5158. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5159. return QDF_STATUS_E_FAILURE;
  5160. }
  5161. if (!is_supported) {
  5162. spectral_err("aSpectral unsupported for cur chainmask");
  5163. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5164. return QDF_STATUS_E_FAILURE;
  5165. }
  5166. }
  5167. band = target_if_get_curr_band(spectral->pdev_obj, vdev_id);
  5168. if (band == REG_BAND_UNKNOWN) {
  5169. spectral_err("Failed to get current band");
  5170. return QDF_STATUS_E_FAILURE;
  5171. }
  5172. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  5173. struct target_psoc_info *tgt_hdl;
  5174. enum wmi_host_hw_mode_config_type mode;
  5175. bool is_agile_scan_inprog_5g_pdev;
  5176. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  5177. if (!tgt_hdl) {
  5178. target_if_err("target_psoc_info is null");
  5179. return QDF_STATUS_E_FAILURE;
  5180. }
  5181. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  5182. switch (mode) {
  5183. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  5184. case WMI_HOST_HW_MODE_SBS:
  5185. case WMI_HOST_HW_MODE_DBS_SBS:
  5186. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  5187. is_agile_scan_inprog_5g_pdev = false;
  5188. wlan_objmgr_iterate_obj_list
  5189. (psoc, WLAN_PDEV_OP,
  5190. target_if_is_agile_scan_active_in_5g,
  5191. &is_agile_scan_inprog_5g_pdev, 0,
  5192. WLAN_SPECTRAL_ID);
  5193. break;
  5194. default:
  5195. is_agile_scan_inprog_5g_pdev = false;
  5196. break;
  5197. }
  5198. if (is_agile_scan_inprog_5g_pdev) {
  5199. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  5200. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5201. return QDF_STATUS_E_FAILURE;
  5202. }
  5203. }
  5204. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5205. bool is_aspectral_prohibited = false;
  5206. QDF_STATUS status;
  5207. status = wlan_objmgr_iterate_obj_list
  5208. (psoc, WLAN_PDEV_OP,
  5209. target_if_is_aspectral_prohibited_by_adfs,
  5210. &is_aspectral_prohibited, 0,
  5211. WLAN_SPECTRAL_ID);
  5212. if (QDF_IS_STATUS_ERROR(status)) {
  5213. spectral_err("Failed to iterate over pdevs");
  5214. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5215. return QDF_STATUS_E_FAILURE;
  5216. }
  5217. if (is_aspectral_prohibited) {
  5218. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5219. return QDF_STATUS_E_FAILURE;
  5220. }
  5221. }
  5222. if (!spectral->params_valid[smode]) {
  5223. target_if_spectral_info_read(spectral,
  5224. smode,
  5225. TARGET_IF_SPECTRAL_INFO_PARAMS,
  5226. &spectral->params[smode],
  5227. sizeof(spectral->params[smode]));
  5228. spectral->params_valid[smode] = true;
  5229. }
  5230. qdf_spin_lock_bh(&spectral->spectral_lock);
  5231. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5232. QDF_STATUS status;
  5233. bool is_overlapping;
  5234. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  5235. enum spectral_scan_mode m;
  5236. enum phy_ch_width op_ch_width;
  5237. enum phy_ch_width agile_ch_width;
  5238. m = SPECTRAL_SCAN_MODE_NORMAL;
  5239. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  5240. ch_width[m] = CH_WIDTH_INVALID;
  5241. status = target_if_spectral_populate_chwidth
  5242. (spectral, ch_width, spectral->params
  5243. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  5244. if (QDF_IS_STATUS_ERROR(status)) {
  5245. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5246. spectral_err("Failed to populate channel width");
  5247. return QDF_STATUS_E_FAILURE;
  5248. }
  5249. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  5250. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  5251. if (!spectral->params[smode].ss_frequency.cfreq1) {
  5252. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  5253. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5254. spectral_err("Agile Spectral cfreq1 is 0");
  5255. return QDF_STATUS_E_FAILURE;
  5256. } else if (agile_ch_width == CH_WIDTH_80P80MHZ &&
  5257. !spectral->params[smode].ss_frequency.cfreq2) {
  5258. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  5259. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5260. spectral_err("Agile Spectral cfreq2 is 0");
  5261. return QDF_STATUS_E_FAILURE;
  5262. }
  5263. status = target_if_is_agile_span_overlap_with_operating_span
  5264. (spectral, ch_width,
  5265. &spectral->params[smode].ss_frequency,
  5266. &is_overlapping);
  5267. if (QDF_IS_STATUS_ERROR(status)) {
  5268. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5269. return QDF_STATUS_E_FAILURE;
  5270. }
  5271. if (is_overlapping) {
  5272. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  5273. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5274. return QDF_STATUS_E_FAILURE;
  5275. }
  5276. }
  5277. /* Populate detectot list first */
  5278. ret = target_if_spectral_detector_list_init(spectral);
  5279. if (QDF_IS_STATUS_ERROR(ret)) {
  5280. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5281. spectral_err("Failed to initialize detector list");
  5282. return ret;
  5283. }
  5284. ret = target_if_spectral_populate_chwidth(
  5285. spectral, spectral->ch_width,
  5286. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  5287. ss_frequency.cfreq2 > 0);
  5288. if (QDF_IS_STATUS_ERROR(ret)) {
  5289. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5290. spectral_err("Failed to get channel widths");
  5291. return ret;
  5292. }
  5293. ret = spectral_is_session_info_expected_from_target(
  5294. spectral->pdev_obj,
  5295. &is_session_info_expected);
  5296. if (QDF_IS_STATUS_ERROR(ret)) {
  5297. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5298. spectral_err("Failed to check if session info is expected");
  5299. return ret;
  5300. }
  5301. /* If FW doesn't send session info, populate it */
  5302. if (!is_session_info_expected) {
  5303. ret = target_if_spectral_populate_session_report_info(spectral,
  5304. smode);
  5305. if (QDF_IS_STATUS_ERROR(ret)) {
  5306. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5307. spectral_err("Failed to populate per-session report info");
  5308. return QDF_STATUS_E_FAILURE;
  5309. }
  5310. ret = target_if_spectral_populate_session_det_host_info(
  5311. spectral, smode);
  5312. if (QDF_IS_STATUS_ERROR(ret)) {
  5313. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5314. spectral_err("Failed to populate per-session detector info");
  5315. return QDF_STATUS_E_FAILURE;
  5316. }
  5317. }
  5318. target_if_spectral_scan_enable_params(spectral,
  5319. &spectral->params[smode], smode,
  5320. err);
  5321. spectral->sscan_width_configured[smode] = false;
  5322. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5323. return QDF_STATUS_SUCCESS;
  5324. }
  5325. QDF_STATUS
  5326. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  5327. const enum spectral_scan_mode smode,
  5328. enum spectral_cp_error_code *err)
  5329. {
  5330. struct target_if_spectral_ops *p_sops;
  5331. struct target_if_spectral *spectral;
  5332. uint8_t det;
  5333. if (!pdev) {
  5334. spectral_err("pdev object is NULL");
  5335. return QDF_STATUS_E_INVAL;
  5336. }
  5337. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  5338. spectral_info("Spectral feature is disabled");
  5339. return QDF_STATUS_COMP_DISABLED;
  5340. }
  5341. if (!err) {
  5342. spectral_err("Error code argument is null");
  5343. QDF_ASSERT(0);
  5344. return QDF_STATUS_E_FAILURE;
  5345. }
  5346. *err = SPECTRAL_SCAN_ERR_INVALID;
  5347. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5348. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5349. spectral_err("Invalid Spectral mode %u", smode);
  5350. return QDF_STATUS_E_FAILURE;
  5351. }
  5352. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5353. if (!spectral) {
  5354. spectral_err("Spectral LMAC object is NUll ");
  5355. return QDF_STATUS_E_FAILURE;
  5356. }
  5357. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5358. qdf_spin_lock_bh(&spectral->spectral_lock);
  5359. p_sops->stop_spectral_scan(spectral, smode);
  5360. if (spectral->classify_scan) {
  5361. /* TODO : Check if this logic is necessary */
  5362. spectral->detects_control_channel = 0;
  5363. spectral->detects_extension_channel = 0;
  5364. spectral->detects_above_dc = 0;
  5365. spectral->detects_below_dc = 0;
  5366. spectral->classify_scan = 0;
  5367. }
  5368. spectral->send_single_packet = 0;
  5369. spectral->sc_spectral_scan = 0;
  5370. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  5371. for (det = 0; det < MAX_DETECTORS_PER_PDEV; det++)
  5372. spectral->det_map[det].det_map_valid[smode] = false;
  5373. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  5374. /* Mark report info as invalid */
  5375. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5376. spectral->report_info[smode].valid = false;
  5377. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5378. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5379. return QDF_STATUS_SUCCESS;
  5380. }
  5381. /**
  5382. * target_if_is_spectral_active() - Get whether Spectral is active
  5383. * @pdev: Pointer to pdev object
  5384. * @smode: Spectral scan mode
  5385. *
  5386. * API to get whether Spectral is active
  5387. *
  5388. * Return: True if Spectral is active, false if Spectral is not active
  5389. */
  5390. bool
  5391. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  5392. const enum spectral_scan_mode smode)
  5393. {
  5394. struct target_if_spectral *spectral = NULL;
  5395. struct target_if_spectral_ops *p_sops = NULL;
  5396. if (!pdev) {
  5397. spectral_err("pdev is null");
  5398. return false;
  5399. }
  5400. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  5401. spectral_info("Spectral feature is disabled");
  5402. return false;
  5403. }
  5404. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5405. if (!spectral) {
  5406. spectral_err("SPECTRAL : Module doesn't exist");
  5407. return false;
  5408. }
  5409. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5410. if (!p_sops) {
  5411. spectral_err("p_sops is null");
  5412. return false;
  5413. }
  5414. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5415. spectral_err("Invalid Spectral mode %u", smode);
  5416. return false;
  5417. }
  5418. return p_sops->is_spectral_active(spectral, smode);
  5419. }
  5420. /**
  5421. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  5422. * @pdev: Pointer to pdev object
  5423. * @smode: Spectral scan mode
  5424. *
  5425. * API to get whether Spectral is enabled
  5426. *
  5427. * Return: True if Spectral is enabled, false if Spectral is not enabled
  5428. */
  5429. bool
  5430. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  5431. enum spectral_scan_mode smode)
  5432. {
  5433. struct target_if_spectral *spectral = NULL;
  5434. struct target_if_spectral_ops *p_sops = NULL;
  5435. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5436. if (!spectral) {
  5437. spectral_err("SPECTRAL : Module doesn't exist");
  5438. return false;
  5439. }
  5440. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5441. if (!p_sops) {
  5442. spectral_err("p_sops is null");
  5443. return false;
  5444. }
  5445. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5446. spectral_err("Invalid Spectral mode %u", smode);
  5447. return false;
  5448. }
  5449. return p_sops->is_spectral_enabled(spectral, smode);
  5450. }
  5451. #ifdef DIRECT_BUF_RX_DEBUG
  5452. /**
  5453. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  5454. * @pdev: Pointer to pdev object
  5455. * @enable: Enable/Disable Spectral DMA ring debug
  5456. *
  5457. * Start/stop Spectral DMA ring debug based on @enable.
  5458. * Also save the state for future use.
  5459. *
  5460. * Return: QDF_STATUS of operation
  5461. */
  5462. static QDF_STATUS
  5463. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  5464. {
  5465. struct target_if_spectral *spectral;
  5466. struct wlan_lmac_if_tx_ops *tx_ops;
  5467. struct wlan_objmgr_psoc *psoc;
  5468. if (!pdev)
  5469. return QDF_STATUS_E_FAILURE;
  5470. psoc = wlan_pdev_get_psoc(pdev);
  5471. if (!psoc) {
  5472. spectral_err("psoc is null");
  5473. return QDF_STATUS_E_INVAL;
  5474. }
  5475. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5476. if (!tx_ops) {
  5477. spectral_err("tx_ops is NULL");
  5478. return QDF_STATUS_E_INVAL;
  5479. }
  5480. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5481. if (!spectral) {
  5482. spectral_err("Spectal LMAC object is NULL");
  5483. return QDF_STATUS_E_INVAL;
  5484. }
  5485. /* Save the state */
  5486. spectral->dbr_ring_debug = enable;
  5487. if (enable)
  5488. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  5489. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  5490. else
  5491. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  5492. pdev, 0);
  5493. return QDF_STATUS_SUCCESS;
  5494. }
  5495. /**
  5496. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  5497. * @pdev: Pointer to pdev object
  5498. * @enable: Enable/Disable Spectral DMA buffer debug
  5499. *
  5500. * Start/stop Spectral DMA buffer debug based on @enable.
  5501. * Also save the state for future use.
  5502. *
  5503. * Return: QDF_STATUS of operation
  5504. */
  5505. static QDF_STATUS
  5506. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  5507. {
  5508. struct target_if_spectral *spectral;
  5509. struct wlan_lmac_if_tx_ops *tx_ops;
  5510. struct wlan_objmgr_psoc *psoc;
  5511. if (!pdev)
  5512. return QDF_STATUS_E_FAILURE;
  5513. psoc = wlan_pdev_get_psoc(pdev);
  5514. if (!psoc) {
  5515. spectral_err("psoc is null");
  5516. return QDF_STATUS_E_INVAL;
  5517. }
  5518. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5519. if (!tx_ops) {
  5520. spectral_err("tx_ops is NULL");
  5521. return QDF_STATUS_E_INVAL;
  5522. }
  5523. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5524. if (!spectral) {
  5525. spectral_err("Spectal LMAC object is NULL");
  5526. return QDF_STATUS_E_INVAL;
  5527. }
  5528. /* Save the state */
  5529. spectral->dbr_buff_debug = enable;
  5530. if (enable)
  5531. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  5532. pdev, 0, MEM_POISON_SIGNATURE);
  5533. else
  5534. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  5535. pdev, 0);
  5536. }
  5537. /**
  5538. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  5539. * debug based on the previous state
  5540. * @pdev: Pointer to pdev object
  5541. *
  5542. * Return: QDF_STATUS of operation
  5543. */
  5544. static QDF_STATUS
  5545. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  5546. {
  5547. struct target_if_spectral *spectral;
  5548. if (!pdev) {
  5549. spectral_err("pdev is NULL!");
  5550. return QDF_STATUS_E_FAILURE;
  5551. }
  5552. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5553. if (!spectral) {
  5554. spectral_err("Spectal LMAC object is NULL");
  5555. return QDF_STATUS_E_INVAL;
  5556. }
  5557. if (spectral->dbr_buff_debug)
  5558. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  5559. else
  5560. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  5561. }
  5562. /**
  5563. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  5564. * debug based on the previous state
  5565. * @pdev: Pointer to pdev object
  5566. *
  5567. * Return: QDF_STATUS of operation
  5568. */
  5569. static QDF_STATUS
  5570. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  5571. {
  5572. struct target_if_spectral *spectral;
  5573. if (!pdev) {
  5574. spectral_err("pdev is NULL!");
  5575. return QDF_STATUS_E_FAILURE;
  5576. }
  5577. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5578. if (!spectral) {
  5579. spectral_err("Spectal LMAC object is NULL");
  5580. return QDF_STATUS_E_INVAL;
  5581. }
  5582. if (spectral->dbr_ring_debug)
  5583. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  5584. else
  5585. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  5586. }
  5587. /**
  5588. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  5589. * @pdev: Pointer to pdev object
  5590. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  5591. * @debug_value: Value to be set for @dma_debug_type
  5592. *
  5593. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  5594. * based on @debug_value
  5595. *
  5596. * Return: QDF_STATUS of operation
  5597. */
  5598. static QDF_STATUS
  5599. target_if_spectral_set_dma_debug(
  5600. struct wlan_objmgr_pdev *pdev,
  5601. enum spectral_dma_debug dma_debug_type,
  5602. bool debug_value)
  5603. {
  5604. struct target_if_spectral_ops *p_sops;
  5605. struct wlan_objmgr_psoc *psoc;
  5606. struct wlan_lmac_if_tx_ops *tx_ops;
  5607. struct target_if_spectral *spectral;
  5608. if (!pdev)
  5609. return QDF_STATUS_E_FAILURE;
  5610. psoc = wlan_pdev_get_psoc(pdev);
  5611. if (!psoc) {
  5612. spectral_err("psoc is null");
  5613. return QDF_STATUS_E_INVAL;
  5614. }
  5615. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5616. if (!tx_ops) {
  5617. spectral_err("tx_ops is NULL");
  5618. return QDF_STATUS_E_FAILURE;
  5619. }
  5620. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  5621. spectral_err("Unable to fetch target type");
  5622. return QDF_STATUS_E_FAILURE;
  5623. }
  5624. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5625. if (!spectral) {
  5626. spectral_err("Spectal LMAC object is NULL");
  5627. return QDF_STATUS_E_INVAL;
  5628. }
  5629. if (spectral->direct_dma_support) {
  5630. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5631. if (p_sops->is_spectral_active(spectral,
  5632. SPECTRAL_SCAN_MODE_NORMAL) ||
  5633. p_sops->is_spectral_active(spectral,
  5634. SPECTRAL_SCAN_MODE_AGILE)) {
  5635. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  5636. return QDF_STATUS_E_FAILURE;
  5637. }
  5638. switch (dma_debug_type) {
  5639. case SPECTRAL_DMA_RING_DEBUG:
  5640. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  5641. break;
  5642. case SPECTRAL_DMA_BUFFER_DEBUG:
  5643. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  5644. break;
  5645. default:
  5646. spectral_err("Unsupported DMA debug type : %d",
  5647. dma_debug_type);
  5648. return QDF_STATUS_E_FAILURE;
  5649. }
  5650. }
  5651. return QDF_STATUS_SUCCESS;
  5652. }
  5653. #endif /* DIRECT_BUF_RX_DEBUG */
  5654. /**
  5655. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  5656. * @pdev: Pointer to pdev object
  5657. *
  5658. * Return: Whether Direct-DMA is supported on this radio
  5659. */
  5660. static bool
  5661. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  5662. {
  5663. struct target_if_spectral *spectral;
  5664. if (!pdev) {
  5665. spectral_err("pdev is NULL!");
  5666. return false;
  5667. }
  5668. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5669. if (!spectral) {
  5670. spectral_err("Spectral LMAC object is NULL");
  5671. return false;
  5672. }
  5673. return spectral->direct_dma_support;
  5674. }
  5675. /**
  5676. * target_if_set_debug_level() - Set debug level for Spectral
  5677. * @pdev: Pointer to pdev object
  5678. * @debug_level: Debug level
  5679. *
  5680. * API to set the debug level for Spectral
  5681. *
  5682. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5683. */
  5684. QDF_STATUS
  5685. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  5686. {
  5687. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  5688. return QDF_STATUS_SUCCESS;
  5689. }
  5690. /**
  5691. * target_if_get_debug_level() - Get debug level for Spectral
  5692. * @pdev: Pointer to pdev object
  5693. *
  5694. * API to get the debug level for Spectral
  5695. *
  5696. * Return: Current debug level
  5697. */
  5698. uint32_t
  5699. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  5700. {
  5701. return spectral_debug_level;
  5702. }
  5703. /**
  5704. * target_if_get_spectral_capinfo() - Get Spectral capability information
  5705. * @pdev: Pointer to pdev object
  5706. * @scaps: Buffer into which data should be copied
  5707. *
  5708. * API to get the spectral capability information
  5709. *
  5710. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5711. */
  5712. QDF_STATUS
  5713. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  5714. struct spectral_caps *scaps)
  5715. {
  5716. struct target_if_spectral *spectral = NULL;
  5717. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5718. if (!spectral) {
  5719. spectral_err("SPECTRAL : Module doesn't exist");
  5720. return QDF_STATUS_E_FAILURE;
  5721. }
  5722. qdf_mem_copy(scaps, &spectral->capability,
  5723. sizeof(struct spectral_caps));
  5724. return QDF_STATUS_SUCCESS;
  5725. }
  5726. /**
  5727. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  5728. * @pdev: Pointer to pdev object
  5729. * @stats: Buffer into which data should be copied
  5730. *
  5731. * API to get the spectral diagnostic statistics
  5732. *
  5733. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5734. */
  5735. QDF_STATUS
  5736. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  5737. struct spectral_diag_stats *stats)
  5738. {
  5739. struct target_if_spectral *spectral = NULL;
  5740. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5741. if (!spectral) {
  5742. spectral_err("SPECTRAL : Module doesn't exist");
  5743. return QDF_STATUS_E_FAILURE;
  5744. }
  5745. qdf_mem_copy(stats, &spectral->diag_stats,
  5746. sizeof(struct spectral_diag_stats));
  5747. return QDF_STATUS_SUCCESS;
  5748. }
  5749. /**
  5750. * target_if_register_spectral_wmi_ops() - Register Spectral WMI operations
  5751. * @psoc: Pointer to psoc object
  5752. * @wmi_ops: Pointer to the structure having Spectral WMI operations
  5753. *
  5754. * API for registering Spectral WMI operations in
  5755. * spectral internal data structure
  5756. *
  5757. * Return: QDF_STATUS
  5758. */
  5759. static QDF_STATUS
  5760. target_if_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
  5761. struct spectral_wmi_ops *wmi_ops)
  5762. {
  5763. struct target_if_psoc_spectral *psoc_spectral;
  5764. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5765. if (!psoc_spectral) {
  5766. spectral_err("Spectral LMAC object is null");
  5767. return QDF_STATUS_E_INVAL;
  5768. }
  5769. psoc_spectral->wmi_ops = *wmi_ops;
  5770. return QDF_STATUS_SUCCESS;
  5771. }
  5772. /**
  5773. * target_if_register_spectral_tgt_ops() - Register Spectral target operations
  5774. * @psoc: Pointer to psoc object
  5775. * @tgt_ops: Pointer to the structure having Spectral target operations
  5776. *
  5777. * API for registering Spectral target operations in
  5778. * spectral internal data structure
  5779. *
  5780. * Return: QDF_STATUS
  5781. */
  5782. static QDF_STATUS
  5783. target_if_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
  5784. struct spectral_tgt_ops *tgt_ops)
  5785. {
  5786. if (!psoc) {
  5787. spectral_err("psoc is null");
  5788. return QDF_STATUS_E_INVAL;
  5789. }
  5790. ops_tgt = *tgt_ops;
  5791. return QDF_STATUS_SUCCESS;
  5792. }
  5793. /**
  5794. * target_if_register_netlink_cb() - Register Netlink callbacks
  5795. * @pdev: Pointer to pdev object
  5796. * @nl_cb: Netlink callbacks to register
  5797. *
  5798. * Return: void
  5799. */
  5800. static void
  5801. target_if_register_netlink_cb(
  5802. struct wlan_objmgr_pdev *pdev,
  5803. struct spectral_nl_cb *nl_cb)
  5804. {
  5805. struct target_if_spectral *spectral = NULL;
  5806. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5807. if (!spectral) {
  5808. spectral_err("SPECTRAL : Module doesn't exist");
  5809. return;
  5810. }
  5811. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  5812. if (spectral->use_nl_bcast)
  5813. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  5814. else
  5815. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  5816. }
  5817. /**
  5818. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  5819. * Netlink messages to the application layer
  5820. * @pdev: Pointer to pdev object
  5821. *
  5822. * Return: true for broadcast, false for unicast
  5823. */
  5824. static bool
  5825. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  5826. {
  5827. struct target_if_spectral *spectral = NULL;
  5828. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5829. if (!spectral) {
  5830. spectral_err("SPECTRAL : Module doesn't exist");
  5831. return false;
  5832. }
  5833. return spectral->use_nl_bcast;
  5834. }
  5835. /**
  5836. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  5837. * @pdev: Pointer to pdev object
  5838. *
  5839. * Return: void
  5840. */
  5841. static void
  5842. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  5843. {
  5844. struct target_if_spectral *spectral = NULL;
  5845. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5846. if (!spectral) {
  5847. spectral_err("SPECTRAL : Module doesn't exist");
  5848. return;
  5849. }
  5850. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  5851. }
  5852. static int
  5853. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  5854. void *payload)
  5855. {
  5856. struct target_if_spectral *spectral = NULL;
  5857. struct target_if_spectral_ops *p_sops = NULL;
  5858. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5859. if (!spectral) {
  5860. spectral_err("SPECTRAL : Module doesn't exist");
  5861. return -EPERM;
  5862. }
  5863. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5864. if (!p_sops) {
  5865. spectral_err("p_sops is null");
  5866. return -EPERM;
  5867. }
  5868. return p_sops->process_spectral_report(pdev, payload);
  5869. }
  5870. #ifdef DIRECT_BUF_RX_DEBUG
  5871. static inline void
  5872. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5873. {
  5874. if (!tx_ops) {
  5875. spectral_err("tx_ops is NULL");
  5876. return;
  5877. }
  5878. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  5879. target_if_spectral_set_dma_debug;
  5880. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  5881. target_if_spectral_check_and_do_dbr_ring_debug;
  5882. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  5883. target_if_spectral_check_and_do_dbr_buff_debug;
  5884. }
  5885. #else
  5886. static inline void
  5887. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5888. {
  5889. }
  5890. #endif
  5891. #if defined(WLAN_CONV_SPECTRAL_ENABLE) && defined(SPECTRAL_MODULIZED_ENABLE)
  5892. /**
  5893. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  5894. * register WMI event handler
  5895. * @psoc: Pointer to psoc object
  5896. * @event_id: Event id
  5897. * @handler_func: Handler function
  5898. * @rx_ctx: Context of WMI event processing
  5899. *
  5900. * Wrapper function to register WMI event handler
  5901. *
  5902. * Return: 0 for success else failure
  5903. */
  5904. static int
  5905. target_if_spectral_wmi_unified_register_event_handler(
  5906. struct wlan_objmgr_psoc *psoc,
  5907. wmi_conv_event_id event_id,
  5908. wmi_unified_event_handler handler_func,
  5909. uint8_t rx_ctx)
  5910. {
  5911. wmi_unified_t wmi_handle;
  5912. struct target_if_psoc_spectral *psoc_spectral;
  5913. QDF_STATUS ret;
  5914. if (!psoc) {
  5915. spectral_err("psoc is null");
  5916. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5917. }
  5918. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5919. if (!wmi_handle) {
  5920. spectral_err("WMI handle is null");
  5921. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5922. }
  5923. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5924. if (!psoc_spectral) {
  5925. spectral_err("spectral object is null");
  5926. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5927. }
  5928. ret = psoc_spectral->wmi_ops.wmi_unified_register_event_handler(
  5929. wmi_handle, event_id, handler_func, rx_ctx);
  5930. return qdf_status_to_os_return(ret);
  5931. }
  5932. /**
  5933. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  5934. * to unregister WMI event handler
  5935. * @psoc: Pointer to psoc object
  5936. * @event_id: Event id
  5937. *
  5938. * Wrapper function to unregister WMI event handler
  5939. *
  5940. * Return: 0 for success else failure
  5941. */
  5942. static int
  5943. target_if_spectral_wmi_unified_unregister_event_handler(
  5944. struct wlan_objmgr_psoc *psoc,
  5945. wmi_conv_event_id event_id)
  5946. {
  5947. wmi_unified_t wmi_handle;
  5948. struct target_if_psoc_spectral *psoc_spectral;
  5949. QDF_STATUS ret;
  5950. if (!psoc) {
  5951. spectral_err("psoc is null");
  5952. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5953. }
  5954. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5955. if (!wmi_handle) {
  5956. spectral_err("WMI handle is null");
  5957. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5958. }
  5959. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5960. if (!psoc_spectral) {
  5961. spectral_err("spectral object is null");
  5962. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5963. }
  5964. ret = psoc_spectral->wmi_ops.wmi_unified_unregister_event_handler(
  5965. wmi_handle, event_id);
  5966. return qdf_status_to_os_return(ret);
  5967. }
  5968. /**
  5969. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  5970. * function to extract fixed parameters from start scan response event
  5971. * @psoc: Pointer to psoc object
  5972. * @evt_buf: Event buffer
  5973. * @param: Start scan response parameters
  5974. *
  5975. * Wrapper function to extract fixed parameters from start scan response event
  5976. *
  5977. * Return: QDF_STATUS
  5978. */
  5979. static QDF_STATUS
  5980. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  5981. struct wlan_objmgr_psoc *psoc,
  5982. uint8_t *evt_buf,
  5983. struct spectral_startscan_resp_params *param)
  5984. {
  5985. wmi_unified_t wmi_handle;
  5986. struct target_if_psoc_spectral *psoc_spectral;
  5987. if (!psoc) {
  5988. spectral_err("psoc is null");
  5989. return QDF_STATUS_E_INVAL;
  5990. }
  5991. if (!evt_buf) {
  5992. spectral_err("WMI event buffer is null");
  5993. return QDF_STATUS_E_INVAL;
  5994. }
  5995. if (!param) {
  5996. spectral_err("Spectral startscan response parameters is null");
  5997. return QDF_STATUS_E_INVAL;
  5998. }
  5999. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6000. if (!wmi_handle) {
  6001. spectral_err("WMI handle is null");
  6002. return QDF_STATUS_E_INVAL;
  6003. }
  6004. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6005. if (!psoc_spectral) {
  6006. spectral_err("spectral object is null");
  6007. return QDF_STATUS_E_FAILURE;
  6008. }
  6009. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6010. wmi_handle, evt_buf, param);
  6011. }
  6012. /**
  6013. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  6014. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  6015. * secondary 80 MHz FFT bins
  6016. * @psoc: Pointer to psoc object
  6017. * @evt_buf: Event buffer
  6018. * @param: FFT bin start and end indices
  6019. *
  6020. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  6021. * and secondary 80 MHz FFT bins
  6022. *
  6023. * Return: QDF_STATUS
  6024. */
  6025. static QDF_STATUS
  6026. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6027. struct wlan_objmgr_psoc *psoc,
  6028. uint8_t *evt_buf,
  6029. struct spectral_fft_bin_markers_160_165mhz *param)
  6030. {
  6031. wmi_unified_t wmi_handle;
  6032. struct target_if_psoc_spectral *psoc_spectral;
  6033. if (!psoc) {
  6034. spectral_err("psoc is null");
  6035. return QDF_STATUS_E_INVAL;
  6036. }
  6037. if (!evt_buf) {
  6038. spectral_err("WMI event buffer is null");
  6039. return QDF_STATUS_E_INVAL;
  6040. }
  6041. if (!param) {
  6042. spectral_err("Spectral FFT bin markers is null");
  6043. return QDF_STATUS_E_INVAL;
  6044. }
  6045. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6046. if (!wmi_handle) {
  6047. spectral_err("WMI handle is null");
  6048. return QDF_STATUS_E_INVAL;
  6049. }
  6050. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6051. if (!psoc_spectral) {
  6052. spectral_err("spectral object is null");
  6053. return QDF_STATUS_E_FAILURE;
  6054. }
  6055. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fft_bin_index(
  6056. wmi_handle, evt_buf, param);
  6057. }
  6058. /**
  6059. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  6060. * object from scn handle
  6061. * @scn: scn handle
  6062. *
  6063. * Wrapper function to get psoc object from scn handle
  6064. *
  6065. * Return: Pointer to psoc object
  6066. */
  6067. static struct wlan_objmgr_psoc *
  6068. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  6069. {
  6070. if (!scn) {
  6071. spectral_err("scn is null");
  6072. return NULL;
  6073. }
  6074. return ops_tgt.tgt_get_psoc_from_scn_hdl(scn);
  6075. }
  6076. /**
  6077. * target_if_extract_pdev_spectral_session_chan_info() - Wrapper
  6078. * function to extract channel information for a spectral scan session
  6079. * @psoc: Pointer to psoc object
  6080. * @evt_buf: Event buffer
  6081. * @chan_info: Spectral session channel information data structure to be filled
  6082. * by this API
  6083. *
  6084. * Return: QDF_STATUS of operation
  6085. */
  6086. static QDF_STATUS
  6087. target_if_extract_pdev_spectral_session_chan_info(
  6088. struct wlan_objmgr_psoc *psoc,
  6089. void *evt_buf,
  6090. struct spectral_session_chan_info *chan_info)
  6091. {
  6092. wmi_unified_t wmi_handle;
  6093. struct target_if_psoc_spectral *psoc_spectral;
  6094. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6095. if (!wmi_handle) {
  6096. spectral_err("WMI handle is null");
  6097. return QDF_STATUS_E_NULL_VALUE;
  6098. }
  6099. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6100. if (!psoc_spectral) {
  6101. spectral_err("spectral object is null");
  6102. return QDF_STATUS_E_NULL_VALUE;
  6103. }
  6104. return psoc_spectral->wmi_ops.extract_pdev_spectral_session_chan_info(
  6105. wmi_handle, evt_buf, chan_info);
  6106. }
  6107. /**
  6108. * target_if_extract_pdev_spectral_session_detector_info() - Wrapper
  6109. * function to extract detector information for a spectral scan session
  6110. * @psoc: Pointer to psoc object
  6111. * @evt_buf: Event buffer
  6112. * @det_info: Spectral session detector information data structure to be filled
  6113. * by this API
  6114. * @det_info_idx: index in the array of spectral scan detector info TLVs
  6115. *
  6116. * Return: QDF_STATUS of operation
  6117. */
  6118. static QDF_STATUS
  6119. target_if_extract_pdev_spectral_session_detector_info(
  6120. struct wlan_objmgr_psoc *psoc, void *evt_buf,
  6121. struct spectral_session_det_info *det_info,
  6122. uint8_t det_info_idx)
  6123. {
  6124. wmi_unified_t wmi_handle;
  6125. struct target_if_psoc_spectral *psoc_spectral;
  6126. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6127. if (!wmi_handle) {
  6128. spectral_err("WMI handle is null");
  6129. return QDF_STATUS_E_NULL_VALUE;
  6130. }
  6131. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6132. if (!psoc_spectral) {
  6133. spectral_err("spectral object is null");
  6134. return QDF_STATUS_E_NULL_VALUE;
  6135. }
  6136. return psoc_spectral->wmi_ops.
  6137. extract_pdev_spectral_session_detector_info(
  6138. wmi_handle, evt_buf, det_info, det_info_idx);
  6139. }
  6140. /**
  6141. * target_if_wmi_extract_spectral_caps_fixed_param() - Wrapper function to
  6142. * extract fixed params from Spectral capabilities WMI event
  6143. * @psoc: Pointer to psoc object
  6144. * @evt_buf: Event buffer
  6145. * @param: Spectral capabilities event parameters data structure to be filled
  6146. * by this API
  6147. *
  6148. * Return: QDF_STATUS of operation
  6149. */
  6150. QDF_STATUS
  6151. target_if_wmi_extract_spectral_caps_fixed_param(
  6152. struct wlan_objmgr_psoc *psoc,
  6153. uint8_t *evt_buf,
  6154. struct spectral_capabilities_event_params *param)
  6155. {
  6156. struct target_if_psoc_spectral *psoc_spectral;
  6157. wmi_unified_t wmi_handle;
  6158. if (!psoc) {
  6159. spectral_err("psoc is null");
  6160. return QDF_STATUS_E_NULL_VALUE;
  6161. }
  6162. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6163. if (!wmi_handle) {
  6164. spectral_err("WMI handle is null");
  6165. return QDF_STATUS_E_NULL_VALUE;
  6166. }
  6167. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6168. if (!psoc_spectral) {
  6169. spectral_err("spectral object is null");
  6170. return QDF_STATUS_E_FAILURE;
  6171. }
  6172. return psoc_spectral->wmi_ops.extract_spectral_caps_fixed_param(
  6173. wmi_handle, evt_buf, param);
  6174. }
  6175. /**
  6176. * target_if_wmi_extract_spectral_scan_bw_caps() - Wrapper function to
  6177. * extract bandwidth capabilities from Spectral capabilities WMI event
  6178. * @psoc: Pointer to psoc object
  6179. * @evt_buf: Event buffer
  6180. * @bw_caps: Data structure to be filled by this API after extraction
  6181. *
  6182. * Return: QDF_STATUS of operation
  6183. */
  6184. QDF_STATUS
  6185. target_if_wmi_extract_spectral_scan_bw_caps(
  6186. struct wlan_objmgr_psoc *psoc,
  6187. uint8_t *evt_buf,
  6188. struct spectral_scan_bw_capabilities *bw_caps)
  6189. {
  6190. struct target_if_psoc_spectral *psoc_spectral;
  6191. wmi_unified_t wmi_handle;
  6192. if (!psoc) {
  6193. spectral_err("psoc is null");
  6194. return QDF_STATUS_E_INVAL;
  6195. }
  6196. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6197. if (!wmi_handle) {
  6198. spectral_err("WMI handle is null");
  6199. return QDF_STATUS_E_INVAL;
  6200. }
  6201. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6202. if (!psoc_spectral) {
  6203. spectral_err("spectral object is null");
  6204. return QDF_STATUS_E_FAILURE;
  6205. }
  6206. return psoc_spectral->wmi_ops.extract_spectral_scan_bw_caps(
  6207. wmi_handle, evt_buf, bw_caps);
  6208. }
  6209. /**
  6210. * target_if_wmi_extract_spectral_fft_size_caps() - Wrapper function to
  6211. * extract fft size capabilities from Spectral capabilities WMI event
  6212. * @psoc: Pointer to psoc object
  6213. * @evt_buf: Event buffer
  6214. * @fft_size_caps: Data structure to be filled by this API after extraction
  6215. *
  6216. * Return: QDF_STATUS of operation
  6217. */
  6218. QDF_STATUS
  6219. target_if_wmi_extract_spectral_fft_size_caps(
  6220. struct wlan_objmgr_psoc *psoc,
  6221. uint8_t *evt_buf,
  6222. struct spectral_fft_size_capabilities *fft_size_caps)
  6223. {
  6224. struct target_if_psoc_spectral *psoc_spectral;
  6225. wmi_unified_t wmi_handle;
  6226. if (!psoc) {
  6227. spectral_err("psoc is null");
  6228. return QDF_STATUS_E_INVAL;
  6229. }
  6230. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6231. if (!wmi_handle) {
  6232. spectral_err("WMI handle is null");
  6233. return QDF_STATUS_E_INVAL;
  6234. }
  6235. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6236. if (!psoc_spectral) {
  6237. spectral_err("spectral object is null");
  6238. return QDF_STATUS_E_FAILURE;
  6239. }
  6240. return psoc_spectral->wmi_ops.extract_spectral_fft_size_caps(
  6241. wmi_handle, evt_buf, fft_size_caps);
  6242. }
  6243. #else
  6244. /**
  6245. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  6246. * register WMI event handler
  6247. * @psoc: Pointer to psoc object
  6248. * @event_id: Event id
  6249. * @handler_func: Handler function
  6250. * @rx_ctx: Context of WMI event processing
  6251. *
  6252. * Wrapper function to register WMI event handler
  6253. *
  6254. * Return: 0 for success else failure
  6255. */
  6256. static int
  6257. target_if_spectral_wmi_unified_register_event_handler(
  6258. struct wlan_objmgr_psoc *psoc,
  6259. wmi_conv_event_id event_id,
  6260. wmi_unified_event_handler handler_func,
  6261. uint8_t rx_ctx)
  6262. {
  6263. wmi_unified_t wmi_handle;
  6264. QDF_STATUS ret;
  6265. if (!psoc) {
  6266. spectral_err("psoc is null");
  6267. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6268. }
  6269. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6270. if (!wmi_handle) {
  6271. spectral_err("WMI handle is null");
  6272. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6273. }
  6274. ret = wmi_unified_register_event_handler(wmi_handle, event_id,
  6275. handler_func, rx_ctx);
  6276. return qdf_status_to_os_return(ret);
  6277. }
  6278. /**
  6279. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  6280. * to unregister WMI event handler
  6281. * @psoc: Pointer to psoc object
  6282. * @event_id: Event id
  6283. *
  6284. * Wrapper function to unregister WMI event handler
  6285. *
  6286. * Return: 0 for success else failure
  6287. */
  6288. static int
  6289. target_if_spectral_wmi_unified_unregister_event_handler(
  6290. struct wlan_objmgr_psoc *psoc,
  6291. wmi_conv_event_id event_id)
  6292. {
  6293. wmi_unified_t wmi_handle;
  6294. QDF_STATUS ret;
  6295. if (!psoc) {
  6296. spectral_err("psoc is null");
  6297. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6298. }
  6299. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6300. if (!wmi_handle) {
  6301. spectral_err("WMI handle is null");
  6302. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6303. }
  6304. ret = wmi_unified_unregister_event_handler(wmi_handle, event_id);
  6305. return qdf_status_to_os_return(ret);
  6306. }
  6307. /**
  6308. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  6309. * function to extract fixed parameters from start scan response event
  6310. * @psoc: Pointer to psoc object
  6311. * @evt_buf: Event buffer
  6312. * @param: Start scan response parameters
  6313. *
  6314. * Wrapper function to extract fixed parameters from start scan response event
  6315. *
  6316. * Return: QDF_STATUS
  6317. */
  6318. static QDF_STATUS
  6319. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6320. struct wlan_objmgr_psoc *psoc,
  6321. uint8_t *evt_buf,
  6322. struct spectral_startscan_resp_params *param)
  6323. {
  6324. wmi_unified_t wmi_handle;
  6325. if (!psoc) {
  6326. spectral_err("psoc is null");
  6327. return QDF_STATUS_E_INVAL;
  6328. }
  6329. if (!evt_buf) {
  6330. spectral_err("WMI event buffer is null");
  6331. return QDF_STATUS_E_INVAL;
  6332. }
  6333. if (!param) {
  6334. spectral_err("Spectral startscan response parameters is null");
  6335. return QDF_STATUS_E_INVAL;
  6336. }
  6337. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6338. if (!wmi_handle) {
  6339. spectral_err("WMI handle is null");
  6340. return QDF_STATUS_E_INVAL;
  6341. }
  6342. return wmi_extract_pdev_sscan_fw_cmd_fixed_param(wmi_handle, evt_buf,
  6343. param);
  6344. }
  6345. /**
  6346. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  6347. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  6348. * secondary 80 MHz FFT bins
  6349. * @psoc: Pointer to psoc object
  6350. * @evt_buf: Event buffer
  6351. * @param: FFT bin start and end indices
  6352. *
  6353. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  6354. * and secondary 80 MHz FFT bins
  6355. *
  6356. * Return: QDF_STATUS
  6357. */
  6358. static QDF_STATUS
  6359. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6360. struct wlan_objmgr_psoc *psoc,
  6361. uint8_t *evt_buf,
  6362. struct spectral_fft_bin_markers_160_165mhz *param)
  6363. {
  6364. wmi_unified_t wmi_handle;
  6365. if (!psoc) {
  6366. spectral_err("psoc is null");
  6367. return QDF_STATUS_E_INVAL;
  6368. }
  6369. if (!evt_buf) {
  6370. spectral_err("WMI event buffer is null");
  6371. return QDF_STATUS_E_INVAL;
  6372. }
  6373. if (!param) {
  6374. spectral_err("Spectral FFT bin markers is null");
  6375. return QDF_STATUS_E_INVAL;
  6376. }
  6377. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6378. if (!wmi_handle) {
  6379. spectral_err("WMI handle is null");
  6380. return QDF_STATUS_E_INVAL;
  6381. }
  6382. return wmi_extract_pdev_sscan_fft_bin_index(wmi_handle, evt_buf, param);
  6383. }
  6384. /**
  6385. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  6386. * object from scn handle
  6387. * @scn: scn handle
  6388. *
  6389. * Wrapper function to get psoc object from scn handle
  6390. *
  6391. * Return: Pointer to psoc object
  6392. */
  6393. static struct wlan_objmgr_psoc *
  6394. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  6395. {
  6396. if (!scn) {
  6397. spectral_err("scn is null");
  6398. return NULL;
  6399. }
  6400. return target_if_get_psoc_from_scn_hdl(scn);
  6401. }
  6402. /**
  6403. * target_if_extract_pdev_spectral_session_chan_info() - Wrapper
  6404. * function to extract channel information for a spectral scan session
  6405. * @psoc: Pointer to psoc object
  6406. * @evt_buf: Event buffer
  6407. * @chan_info: Spectral session channel information data structure to be fille
  6408. * by this API
  6409. *
  6410. * Return: QDF_STATUS of operation
  6411. */
  6412. static QDF_STATUS
  6413. target_if_extract_pdev_spectral_session_chan_info(
  6414. struct wlan_objmgr_psoc *psoc,
  6415. void *evt_buf,
  6416. struct spectral_session_chan_info *chan_info)
  6417. {
  6418. wmi_unified_t wmi_handle;
  6419. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6420. if (!wmi_handle) {
  6421. spectral_err("WMI handle is null");
  6422. return QDF_STATUS_E_NULL_VALUE;
  6423. }
  6424. return wmi_extract_pdev_spectral_session_chan_info(
  6425. wmi_handle, evt_buf, chan_info);
  6426. }
  6427. /**
  6428. * target_if_extract_pdev_spectral_session_detector_info() - Wrapper
  6429. * function to extract detector information for a spectral scan session
  6430. * @psoc: Pointer to psoc object
  6431. * @evt_buf: Event buffer
  6432. * @det_info: Spectral session detector information data structure to be filled
  6433. * by this API
  6434. * @det_info_idx: index in the array of spectral scan detector info TLVs
  6435. *
  6436. * Return: QDF_STATUS of operation
  6437. */
  6438. static QDF_STATUS
  6439. target_if_extract_pdev_spectral_session_detector_info(
  6440. struct wlan_objmgr_psoc *psoc, void *evt_buf,
  6441. struct spectral_session_det_info *det_info,
  6442. uint8_t det_info_idx)
  6443. {
  6444. wmi_unified_t wmi_handle;
  6445. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6446. if (!wmi_handle) {
  6447. spectral_err("WMI handle is null");
  6448. return QDF_STATUS_E_NULL_VALUE;
  6449. }
  6450. return wmi_extract_pdev_spectral_session_detector_info(
  6451. wmi_handle, evt_buf, det_info, det_info_idx);
  6452. }
  6453. QDF_STATUS
  6454. target_if_wmi_extract_spectral_caps_fixed_param(
  6455. struct wlan_objmgr_psoc *psoc,
  6456. uint8_t *evt_buf,
  6457. struct spectral_capabilities_event_params *param)
  6458. {
  6459. wmi_unified_t wmi_handle;
  6460. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6461. if (!wmi_handle) {
  6462. spectral_err("WMI handle is null");
  6463. return QDF_STATUS_E_INVAL;
  6464. }
  6465. return wmi_extract_spectral_caps_fixed_param(wmi_handle, evt_buf,
  6466. param);
  6467. }
  6468. QDF_STATUS
  6469. target_if_wmi_extract_spectral_scan_bw_caps(
  6470. struct wlan_objmgr_psoc *psoc,
  6471. uint8_t *evt_buf,
  6472. struct spectral_scan_bw_capabilities *bw_caps)
  6473. {
  6474. wmi_unified_t wmi_handle;
  6475. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6476. if (!wmi_handle) {
  6477. spectral_err("WMI handle is null");
  6478. return QDF_STATUS_E_INVAL;
  6479. }
  6480. return wmi_extract_spectral_scan_bw_caps(wmi_handle, evt_buf, bw_caps);
  6481. }
  6482. QDF_STATUS
  6483. target_if_wmi_extract_spectral_fft_size_caps(
  6484. struct wlan_objmgr_psoc *psoc,
  6485. uint8_t *evt_buf,
  6486. struct spectral_fft_size_capabilities *fft_size_caps)
  6487. {
  6488. wmi_unified_t wmi_handle;
  6489. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6490. if (!wmi_handle) {
  6491. spectral_err("WMI handle is null");
  6492. return QDF_STATUS_E_INVAL;
  6493. }
  6494. return wmi_extract_spectral_fft_size_caps(wmi_handle, evt_buf,
  6495. fft_size_caps);
  6496. }
  6497. #endif
  6498. /**
  6499. * target_if_update_det_info_in_spectral_session() - Update detector
  6500. * information in spectral scan session
  6501. * @spectral: Spectral LMAC object
  6502. * @det_info: Pointer to spectral session detector information
  6503. *
  6504. * Return: QDF_STATUS of operation
  6505. */
  6506. static QDF_STATUS
  6507. target_if_update_det_info_in_spectral_session(
  6508. struct target_if_spectral *spectral,
  6509. const struct spectral_session_det_info *det_info)
  6510. {
  6511. struct per_session_det_map *det_map;
  6512. struct per_session_dest_det_info *dest_det_info;
  6513. if (!spectral) {
  6514. spectral_err_rl("Spectral LMAC object is null");
  6515. return QDF_STATUS_E_NULL_VALUE;
  6516. }
  6517. qdf_assert_always(det_info->det_id < MAX_DETECTORS_PER_PDEV);
  6518. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  6519. det_map = &spectral->det_map[det_info->det_id];
  6520. dest_det_info = &det_map->dest_det_info[0];
  6521. dest_det_info->start_freq = det_info->start_freq;
  6522. dest_det_info->end_freq = det_info->end_freq;
  6523. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  6524. return QDF_STATUS_SUCCESS;
  6525. }
  6526. /**
  6527. * target_if_update_chan_info_in_spectral_session() - Update channel information
  6528. * in spectral scan session
  6529. * @spectral: Spectral LMAC object
  6530. * @chan_info: Pointer to spectral session channel information
  6531. * @smode: Spectral scan mode
  6532. *
  6533. * Return: QDF_STATUS of operation
  6534. */
  6535. static QDF_STATUS
  6536. target_if_update_chan_info_in_spectral_session(
  6537. struct target_if_spectral *spectral,
  6538. const struct spectral_session_chan_info *chan_info,
  6539. enum spectral_scan_mode smode)
  6540. {
  6541. struct per_session_report_info *rpt_info;
  6542. if (!spectral) {
  6543. spectral_err_rl("Spectral LMAC object is null");
  6544. return QDF_STATUS_E_NULL_VALUE;
  6545. }
  6546. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6547. spectral_err_rl("Invalid Spectral scan mode :%u", smode);
  6548. return QDF_STATUS_E_FAILURE;
  6549. }
  6550. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  6551. rpt_info = &spectral->report_info[smode];
  6552. /* Update per-session report info */
  6553. rpt_info->pri20_freq = chan_info->operating_pri20_freq;
  6554. rpt_info->cfreq1 = chan_info->operating_cfreq1;
  6555. rpt_info->cfreq2 = chan_info->operating_cfreq2;
  6556. rpt_info->operating_bw = chan_info->operating_bw;
  6557. rpt_info->sscan_cfreq1 = chan_info->sscan_cfreq1;
  6558. rpt_info->sscan_cfreq2 = chan_info->sscan_cfreq2;
  6559. rpt_info->sscan_bw = chan_info->sscan_bw;
  6560. /* num_spans depends on sscan_bw, update it */
  6561. rpt_info->num_spans = target_if_spectral_get_num_spans(
  6562. spectral->pdev_obj,
  6563. rpt_info->sscan_bw);
  6564. qdf_assert_always(rpt_info->num_spans != INVALID_SPAN_NUM);
  6565. rpt_info->valid = true;
  6566. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  6567. return QDF_STATUS_SUCCESS;
  6568. }
  6569. /**
  6570. * target_if_spectral_fw_param_event_handler() - WMI event handler to
  6571. * process start scan response event
  6572. * @scn: Pointer to scn object
  6573. * @data_buf: Pointer to event buffer
  6574. * @data_len: Length of event buffer
  6575. *
  6576. * Return: 0 for success, else failure
  6577. */
  6578. static int
  6579. target_if_spectral_fw_param_event_handler(ol_scn_t scn, uint8_t *data_buf,
  6580. uint32_t data_len)
  6581. {
  6582. QDF_STATUS status;
  6583. struct wlan_objmgr_psoc *psoc;
  6584. struct wlan_objmgr_pdev *pdev;
  6585. struct wmi_unified *wmi_handle;
  6586. struct spectral_startscan_resp_params event_params = {0};
  6587. struct target_if_psoc_spectral *psoc_spectral;
  6588. struct target_if_spectral *spectral;
  6589. bool is_session_info_expected;
  6590. if (!scn) {
  6591. spectral_err("scn handle is null");
  6592. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6593. }
  6594. if (!data_buf) {
  6595. spectral_err("WMI event buffer null");
  6596. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6597. }
  6598. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  6599. if (!psoc) {
  6600. spectral_err("psoc is null");
  6601. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6602. }
  6603. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6604. if (!psoc_spectral) {
  6605. spectral_err("spectral object is null");
  6606. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6607. }
  6608. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6609. if (!wmi_handle) {
  6610. spectral_err("WMI handle is null");
  6611. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6612. }
  6613. status = target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6614. psoc, data_buf, &event_params);
  6615. if (QDF_IS_STATUS_ERROR(status)) {
  6616. spectral_err("unable to extract sscan fw fixed params");
  6617. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6618. }
  6619. if (event_params.smode >= SPECTRAL_SCAN_MODE_MAX ||
  6620. event_params.smode < SPECTRAL_SCAN_MODE_NORMAL) {
  6621. spectral_err("Invalid smode %d", event_params.smode);
  6622. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6623. }
  6624. pdev = wlan_objmgr_get_pdev_by_id(psoc, event_params.pdev_id,
  6625. WLAN_SPECTRAL_ID);
  6626. if (!pdev) {
  6627. spectral_err("pdev is null");
  6628. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6629. }
  6630. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  6631. if (!spectral) {
  6632. spectral_err("spectral object is null");
  6633. status = QDF_STATUS_E_FAILURE;
  6634. goto release_pdev_ref;
  6635. }
  6636. if (event_params.num_fft_bin_index == 1) {
  6637. status =
  6638. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6639. psoc, data_buf,
  6640. &spectral->rparams.marker[event_params.smode]);
  6641. if (QDF_IS_STATUS_ERROR(status)) {
  6642. spectral_err("unable to extract sscan fw fixed params");
  6643. goto release_pdev_ref;
  6644. }
  6645. } else {
  6646. spectral->rparams.marker[event_params.smode].is_valid = false;
  6647. }
  6648. status = spectral_is_session_info_expected_from_target(
  6649. pdev, &is_session_info_expected);
  6650. if (QDF_IS_STATUS_ERROR(status)) {
  6651. spectral_err("Failed to check if session info is expected");
  6652. goto release_pdev_ref;
  6653. }
  6654. if (is_session_info_expected) {
  6655. struct spectral_session_chan_info chan_info;
  6656. uint8_t det_info_idx = 0;
  6657. status = target_if_extract_pdev_spectral_session_chan_info(
  6658. psoc, data_buf, &chan_info);
  6659. if (QDF_IS_STATUS_ERROR(status)) {
  6660. spectral_err("Unable to extract spectral session channel info");
  6661. goto release_pdev_ref;
  6662. }
  6663. status = target_if_update_chan_info_in_spectral_session(
  6664. spectral, &chan_info, event_params.smode);
  6665. if (QDF_IS_STATUS_ERROR(status)) {
  6666. spectral_err("Unable to update channel info");
  6667. goto release_pdev_ref;
  6668. }
  6669. /* FFT bins info depends upon sscan_bw, update it */
  6670. status = target_if_populate_fft_bins_info(spectral,
  6671. event_params.smode);
  6672. if (QDF_IS_STATUS_ERROR(status)) {
  6673. spectral_err("Failed to populate FFT bins info");
  6674. goto release_pdev_ref;
  6675. }
  6676. /**
  6677. * per-session det info that depends on sscan_bw needs to be
  6678. * updated here
  6679. */
  6680. status = target_if_spectral_populate_session_det_host_info(
  6681. spectral, event_params.smode);
  6682. if (QDF_IS_STATUS_ERROR(status)) {
  6683. spectral_err("Failed to populate per-session det info");
  6684. goto release_pdev_ref;
  6685. }
  6686. for (; det_info_idx < event_params.num_det_info;
  6687. ++det_info_idx) {
  6688. struct spectral_session_det_info det_info;
  6689. status =
  6690. target_if_extract_pdev_spectral_session_detector_info
  6691. (psoc, data_buf, &det_info, det_info_idx);
  6692. if (QDF_IS_STATUS_ERROR(status)) {
  6693. spectral_err("Unable to extract spectral session detector info for %u",
  6694. det_info_idx);
  6695. goto release_pdev_ref;
  6696. }
  6697. status = target_if_update_det_info_in_spectral_session(
  6698. spectral, &det_info);
  6699. if (QDF_IS_STATUS_ERROR(status)) {
  6700. spectral_err("Unable to update detector info");
  6701. goto release_pdev_ref;
  6702. }
  6703. }
  6704. }
  6705. status = QDF_STATUS_SUCCESS;
  6706. release_pdev_ref:
  6707. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  6708. return qdf_status_to_os_return(status);
  6709. }
  6710. static QDF_STATUS
  6711. target_if_spectral_register_events(struct wlan_objmgr_psoc *psoc)
  6712. {
  6713. int ret;
  6714. if (!psoc) {
  6715. spectral_err("psoc is null");
  6716. return QDF_STATUS_E_INVAL;
  6717. }
  6718. ret = target_if_spectral_wmi_unified_register_event_handler(
  6719. psoc,
  6720. wmi_pdev_sscan_fw_param_eventid,
  6721. target_if_spectral_fw_param_event_handler,
  6722. WMI_RX_UMAC_CTX);
  6723. if (ret)
  6724. spectral_debug("event handler not supported, ret=%d", ret);
  6725. return QDF_STATUS_SUCCESS;
  6726. }
  6727. static QDF_STATUS
  6728. target_if_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
  6729. {
  6730. int ret;
  6731. if (!psoc) {
  6732. spectral_err("psoc is null");
  6733. return QDF_STATUS_E_INVAL;
  6734. }
  6735. ret = target_if_spectral_wmi_unified_unregister_event_handler(
  6736. psoc, wmi_pdev_sscan_fw_param_eventid);
  6737. if (ret)
  6738. spectral_debug("Unregister WMI event handler failed, ret = %d",
  6739. ret);
  6740. return QDF_STATUS_SUCCESS;
  6741. }
  6742. void
  6743. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  6744. {
  6745. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  6746. target_if_pdev_spectral_init;
  6747. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  6748. target_if_pdev_spectral_deinit;
  6749. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init =
  6750. target_if_psoc_spectral_init;
  6751. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit =
  6752. target_if_psoc_spectral_deinit;
  6753. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  6754. target_if_set_spectral_config;
  6755. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  6756. target_if_get_spectral_config;
  6757. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  6758. target_if_start_spectral_scan;
  6759. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  6760. target_if_stop_spectral_scan;
  6761. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  6762. target_if_is_spectral_active;
  6763. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  6764. target_if_is_spectral_enabled;
  6765. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  6766. target_if_set_debug_level;
  6767. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  6768. target_if_get_debug_level;
  6769. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  6770. target_if_get_spectral_capinfo;
  6771. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  6772. target_if_get_spectral_diagstats;
  6773. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_wmi_ops =
  6774. target_if_register_spectral_wmi_ops;
  6775. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_tgt_ops =
  6776. target_if_register_spectral_tgt_ops;
  6777. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  6778. target_if_register_netlink_cb;
  6779. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  6780. target_if_use_nl_bcast;
  6781. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  6782. target_if_deregister_netlink_cb;
  6783. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  6784. target_if_process_spectral_report;
  6785. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  6786. target_if_spectral_direct_dma_support;
  6787. tx_ops->sptrl_tx_ops.sptrlto_register_events =
  6788. target_if_spectral_register_events;
  6789. tx_ops->sptrl_tx_ops.sptrlto_unregister_events =
  6790. target_if_spectral_unregister_events;
  6791. tx_ops->sptrl_tx_ops.sptrlto_init_pdev_feature_caps =
  6792. target_if_spectral_init_pdev_feature_caps;
  6793. target_if_sptrl_debug_register_tx_ops(tx_ops);
  6794. }
  6795. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  6796. void
  6797. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  6798. uint16_t cw_int, uint32_t dcs_enabled)
  6799. {
  6800. struct spectral_samp_msg *msg = NULL;
  6801. struct target_if_spectral_ops *p_sops = NULL;
  6802. struct target_if_spectral *spectral = NULL;
  6803. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  6804. if (!spectral) {
  6805. spectral_err("SPECTRAL : Module doesn't exist");
  6806. return;
  6807. }
  6808. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  6809. if (!p_sops) {
  6810. spectral_err("p_sops is null");
  6811. return;
  6812. }
  6813. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  6814. spectral->pdev_obj,
  6815. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  6816. SPECTRAL_MSG_BUF_NEW);
  6817. if (msg) {
  6818. msg->int_type = cw_int ?
  6819. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  6820. msg->dcs_enabled = dcs_enabled;
  6821. msg->signature = SPECTRAL_SIGNATURE;
  6822. p_sops->get_mac_address(spectral, msg->macaddr);
  6823. if (spectral->send_phy_data
  6824. (pdev,
  6825. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  6826. spectral->spectral_sent_msg++;
  6827. }
  6828. }
  6829. qdf_export_symbol(target_if_spectral_send_intf_found_msg);
  6830. QDF_STATUS
  6831. target_if_spectral_is_finite_scan(struct target_if_spectral *spectral,
  6832. enum spectral_scan_mode smode,
  6833. bool *finite_spectral_scan)
  6834. {
  6835. struct target_if_finite_spectral_scan_params *finite_scan;
  6836. if (!spectral) {
  6837. spectral_err_rl("target if spectral object is null");
  6838. return QDF_STATUS_E_INVAL;
  6839. }
  6840. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6841. spectral_err_rl("invalid spectral mode %d", smode);
  6842. return QDF_STATUS_E_INVAL;
  6843. }
  6844. if (!finite_spectral_scan) {
  6845. spectral_err_rl("Invalid pointer");
  6846. return QDF_STATUS_E_INVAL;
  6847. }
  6848. finite_scan = &spectral->finite_scan[smode];
  6849. *finite_spectral_scan = finite_scan->finite_spectral_scan;
  6850. return QDF_STATUS_SUCCESS;
  6851. }
  6852. QDF_STATUS
  6853. target_if_spectral_finite_scan_update(struct target_if_spectral *spectral,
  6854. enum spectral_scan_mode smode)
  6855. {
  6856. struct target_if_finite_spectral_scan_params *finite_scan;
  6857. if (!spectral) {
  6858. spectral_err_rl("target if spectral object is null");
  6859. return QDF_STATUS_E_INVAL;
  6860. }
  6861. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6862. spectral_err_rl("Invalid Spectral mode");
  6863. return QDF_STATUS_E_INVAL;
  6864. }
  6865. finite_scan = &spectral->finite_scan[smode];
  6866. if (!finite_scan->num_reports_expected) {
  6867. spectral_err_rl("Error, No reports expected");
  6868. return QDF_STATUS_E_FAILURE;
  6869. }
  6870. finite_scan->num_reports_expected--;
  6871. if (!finite_scan->num_reports_expected) {
  6872. QDF_STATUS status;
  6873. enum spectral_cp_error_code err;
  6874. /* received expected number of reports from target, stop scan */
  6875. status = target_if_stop_spectral_scan(spectral->pdev_obj, smode,
  6876. &err);
  6877. if (QDF_IS_STATUS_ERROR(status)) {
  6878. spectral_err_rl("Failed to stop finite Spectral scan");
  6879. return QDF_STATUS_E_FAILURE;
  6880. }
  6881. finite_scan->finite_spectral_scan = false;
  6882. }
  6883. return QDF_STATUS_SUCCESS;
  6884. }