target_if_spectral.c 176 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501
  1. /*
  2. * Copyright (c) 2011,2017-2021 The Linux Foundation. All rights reserved.
  3. *
  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. return QDF_STATUS_SUCCESS;
  206. }
  207. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  208. if (!tgt_psoc_info) {
  209. spectral_err("target_psoc_info is null");
  210. return QDF_STATUS_E_FAILURE;
  211. }
  212. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  213. if (!mac_phy_cap_arr) {
  214. spectral_err("mac phy cap array is null");
  215. return QDF_STATUS_E_FAILURE;
  216. }
  217. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  218. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  219. table_id = mac_phy_cap->chainmask_table_id;
  220. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  221. if (!ext_svc_param) {
  222. spectral_err("Extended service ready params null");
  223. return QDF_STATUS_E_FAILURE;
  224. }
  225. table = &ext_svc_param->chainmask_table[table_id];
  226. for (i = 0; i < table->num_valid_chainmasks; i++) {
  227. agile_cap->agile_spectral_cap |=
  228. table->cap_list[i].supports_aSpectral;
  229. agile_cap->agile_spectral_cap_160 |=
  230. table->cap_list[i].supports_aSpectral_160;
  231. }
  232. agile_cap->agile_spectral_cap_80p80 = agile_cap->agile_spectral_cap_160;
  233. return QDF_STATUS_SUCCESS;
  234. }
  235. /**
  236. * target_if_spectral_init_pdev_feature_cap_per_mode() - API to initialize
  237. * Spectral scan pdev feature caps for a given Spectral mode
  238. * @pdev: pdev handle
  239. * @smode: Spectral scan mode
  240. *
  241. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE/
  242. * QDF_STATUS_E_INVAL on failure
  243. */
  244. static QDF_STATUS
  245. target_if_spectral_init_pdev_feature_cap_per_mode(struct wlan_objmgr_pdev *pdev,
  246. enum spectral_scan_mode smode)
  247. {
  248. struct wlan_objmgr_psoc *psoc;
  249. bool normal_mode_disable;
  250. struct target_if_spectral_agile_mode_cap agile_cap = { 0 };
  251. QDF_STATUS status;
  252. if (!pdev) {
  253. spectral_err("pdev is null");
  254. return QDF_STATUS_E_INVAL;
  255. }
  256. psoc = wlan_pdev_get_psoc(pdev);
  257. if (!psoc) {
  258. spectral_err("psoc is null");
  259. return QDF_STATUS_E_INVAL;
  260. }
  261. switch (smode) {
  262. case SPECTRAL_SCAN_MODE_NORMAL:
  263. if (target_if_spectral_is_feature_disabled_psoc(psoc)) {
  264. wlan_pdev_nif_feat_ext_cap_set(
  265. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  266. return QDF_STATUS_SUCCESS;
  267. }
  268. status = target_if_spectral_get_normal_mode_cap(
  269. pdev, &normal_mode_disable);
  270. if (QDF_IS_STATUS_ERROR(status)) {
  271. spectral_err("Failed to get normal spectral scan caps");
  272. return QDF_STATUS_E_FAILURE;
  273. }
  274. if (normal_mode_disable)
  275. wlan_pdev_nif_feat_ext_cap_set(
  276. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  277. else
  278. wlan_pdev_nif_feat_ext_cap_clear(
  279. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  280. break;
  281. case SPECTRAL_SCAN_MODE_AGILE:
  282. if (target_if_spectral_is_feature_disabled_psoc(psoc)) {
  283. wlan_pdev_nif_feat_ext_cap_set(
  284. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  285. wlan_pdev_nif_feat_ext_cap_set(
  286. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  287. wlan_pdev_nif_feat_ext_cap_set(
  288. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  289. return QDF_STATUS_SUCCESS;
  290. }
  291. status = target_if_spectral_get_agile_mode_cap(
  292. pdev, &agile_cap);
  293. if (QDF_IS_STATUS_ERROR(status)) {
  294. spectral_err("Failed to get agile Spectral capability");
  295. return QDF_STATUS_E_FAILURE;
  296. }
  297. if (!agile_cap.agile_spectral_cap)
  298. wlan_pdev_nif_feat_ext_cap_set(
  299. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  300. else
  301. wlan_pdev_nif_feat_ext_cap_clear(
  302. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  303. if (!agile_cap.agile_spectral_cap_160)
  304. wlan_pdev_nif_feat_ext_cap_set(
  305. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  306. else
  307. wlan_pdev_nif_feat_ext_cap_clear(
  308. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  309. if (!agile_cap.agile_spectral_cap_80p80)
  310. wlan_pdev_nif_feat_ext_cap_set(
  311. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  312. else
  313. wlan_pdev_nif_feat_ext_cap_clear(
  314. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  315. break;
  316. default:
  317. spectral_err("Invalid Spectral scan mode %d", smode);
  318. return QDF_STATUS_E_INVAL;
  319. }
  320. return QDF_STATUS_SUCCESS;
  321. }
  322. /**
  323. * target_if_spectral_init_pdev_feature_caps() - API to initialize
  324. * Spectral scan pdev feature caps for a given pdev
  325. * @pdev: pdev handle
  326. *
  327. * API initialize normal and agile Spectral scan pdev
  328. * feature caps for a given pdev.
  329. *
  330. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  331. */
  332. static QDF_STATUS
  333. target_if_spectral_init_pdev_feature_caps(struct wlan_objmgr_pdev *pdev)
  334. {
  335. enum spectral_scan_mode smode;
  336. if (!pdev) {
  337. spectral_err("pdev is NULL!");
  338. return QDF_STATUS_E_INVAL;
  339. }
  340. smode = SPECTRAL_SCAN_MODE_NORMAL;
  341. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  342. QDF_STATUS status;
  343. status = target_if_spectral_init_pdev_feature_cap_per_mode(
  344. pdev, smode);
  345. if (QDF_IS_STATUS_ERROR(status))
  346. return QDF_STATUS_E_INVAL;
  347. }
  348. return QDF_STATUS_SUCCESS;
  349. }
  350. static void target_if_spectral_get_firstvdev_pdev(struct wlan_objmgr_pdev *pdev,
  351. void *obj, void *arg)
  352. {
  353. struct wlan_objmgr_vdev *vdev = obj;
  354. struct wlan_objmgr_vdev **first_vdev = arg;
  355. if (!(*first_vdev))
  356. *first_vdev = vdev;
  357. }
  358. struct wlan_objmgr_vdev *
  359. target_if_spectral_get_vdev(struct target_if_spectral *spectral,
  360. enum spectral_scan_mode smode)
  361. {
  362. struct wlan_objmgr_pdev *pdev = NULL;
  363. struct wlan_objmgr_vdev *first_vdev = NULL;
  364. qdf_assert_always(spectral);
  365. pdev = spectral->pdev_obj;
  366. qdf_assert_always(pdev);
  367. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  368. spectral_err("Invalid Spectral mode %u", smode);
  369. return NULL;
  370. }
  371. if (spectral->vdev_id[smode] != WLAN_INVALID_VDEV_ID) {
  372. first_vdev = wlan_objmgr_get_vdev_by_id_from_pdev(
  373. pdev, spectral->vdev_id[smode],
  374. WLAN_SPECTRAL_ID);
  375. return first_vdev;
  376. }
  377. if (wlan_objmgr_pdev_try_get_ref(pdev, WLAN_SPECTRAL_ID) !=
  378. QDF_STATUS_SUCCESS) {
  379. spectral_err("Unable to get pdev reference.");
  380. return NULL;
  381. }
  382. wlan_objmgr_pdev_iterate_obj_list(pdev, WLAN_VDEV_OP,
  383. target_if_spectral_get_firstvdev_pdev,
  384. &first_vdev, 0, WLAN_SPECTRAL_ID);
  385. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  386. if (!first_vdev)
  387. return NULL;
  388. if (wlan_objmgr_vdev_try_get_ref(first_vdev, WLAN_SPECTRAL_ID) !=
  389. QDF_STATUS_SUCCESS)
  390. first_vdev = NULL;
  391. return first_vdev;
  392. }
  393. /**
  394. * target_if_send_vdev_spectral_configure_cmd() - Send WMI command to configure
  395. * spectral parameters
  396. * @spectral: Pointer to Spectral target_if internal private data
  397. * @smode: Spectral scan mode
  398. * @param: Pointer to spectral_config giving the Spectral configuration
  399. *
  400. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  401. */
  402. static int
  403. target_if_send_vdev_spectral_configure_cmd(struct target_if_spectral *spectral,
  404. enum spectral_scan_mode smode,
  405. struct spectral_config *param)
  406. {
  407. struct vdev_spectral_configure_params sparam;
  408. struct wlan_objmgr_psoc *psoc;
  409. struct wlan_objmgr_pdev *pdev = NULL;
  410. struct wlan_objmgr_vdev *vdev = NULL;
  411. struct target_if_psoc_spectral *psoc_spectral;
  412. qdf_assert_always(spectral && param);
  413. pdev = spectral->pdev_obj;
  414. qdf_assert_always(pdev);
  415. psoc = wlan_pdev_get_psoc(pdev);
  416. if (!psoc) {
  417. spectral_err("psoc is null");
  418. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  419. }
  420. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  421. if (!psoc_spectral) {
  422. spectral_err("psoc spectral object is null");
  423. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  424. }
  425. vdev = target_if_spectral_get_vdev(spectral, smode);
  426. if (!vdev)
  427. return QDF_STATUS_E_NOENT;
  428. qdf_mem_zero(&sparam, sizeof(sparam));
  429. sparam.vdev_id = wlan_vdev_get_id(vdev);
  430. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  431. sparam.count = param->ss_count;
  432. sparam.period = param->ss_period;
  433. sparam.spectral_pri = param->ss_spectral_pri;
  434. sparam.fft_size = param->ss_fft_size;
  435. sparam.gc_enable = param->ss_gc_ena;
  436. sparam.restart_enable = param->ss_restart_ena;
  437. sparam.noise_floor_ref = param->ss_noise_floor_ref;
  438. sparam.init_delay = param->ss_init_delay;
  439. sparam.nb_tone_thr = param->ss_nb_tone_thr;
  440. sparam.str_bin_thr = param->ss_str_bin_thr;
  441. sparam.wb_rpt_mode = param->ss_wb_rpt_mode;
  442. sparam.rssi_rpt_mode = param->ss_rssi_rpt_mode;
  443. sparam.rssi_thr = param->ss_rssi_thr;
  444. sparam.pwr_format = param->ss_pwr_format;
  445. sparam.rpt_mode = param->ss_rpt_mode;
  446. sparam.bin_scale = param->ss_bin_scale;
  447. sparam.dbm_adj = param->ss_dbm_adj;
  448. sparam.chn_mask = param->ss_chn_mask;
  449. sparam.mode = smode;
  450. sparam.center_freq1 = param->ss_frequency.cfreq1;
  451. sparam.center_freq2 = param->ss_frequency.cfreq2;
  452. sparam.chan_width = spectral->ch_width[smode];
  453. return psoc_spectral->wmi_ops.wmi_spectral_configure_cmd_send(
  454. GET_WMI_HDL_FROM_PDEV(pdev), &sparam);
  455. }
  456. /**
  457. * target_if_send_vdev_spectral_enable_cmd() - Send WMI command to
  458. * enable/disable Spectral
  459. * @spectral: Pointer to Spectral target_if internal private data
  460. * @smode: Spectral scan mode
  461. * @is_spectral_active_valid: Flag to indicate if spectral activate (trigger) is
  462. * valid
  463. * @is_spectral_active: Value of spectral activate
  464. * @is_spectral_enabled_valid: Flag to indicate if spectral enable is valid
  465. * @is_spectral_enabled: Value of spectral enable
  466. *
  467. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  468. */
  469. static int
  470. target_if_send_vdev_spectral_enable_cmd(struct target_if_spectral *spectral,
  471. enum spectral_scan_mode smode,
  472. uint8_t is_spectral_active_valid,
  473. uint8_t is_spectral_active,
  474. uint8_t is_spectral_enabled_valid,
  475. uint8_t is_spectral_enabled)
  476. {
  477. struct vdev_spectral_enable_params param;
  478. struct wlan_objmgr_psoc *psoc;
  479. struct wlan_objmgr_pdev *pdev = NULL;
  480. struct wlan_objmgr_vdev *vdev = NULL;
  481. struct target_if_psoc_spectral *psoc_spectral;
  482. qdf_assert_always(spectral);
  483. pdev = spectral->pdev_obj;
  484. qdf_assert_always(pdev);
  485. psoc = wlan_pdev_get_psoc(pdev);
  486. if (!psoc) {
  487. spectral_err("psoc is null");
  488. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  489. }
  490. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  491. if (!psoc_spectral) {
  492. spectral_err("psoc spectral object is null");
  493. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  494. }
  495. vdev = target_if_spectral_get_vdev(spectral, smode);
  496. if (!vdev)
  497. return QDF_STATUS_E_NOENT;
  498. qdf_mem_zero(&param, sizeof(param));
  499. param.vdev_id = wlan_vdev_get_id(vdev);
  500. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  501. param.active_valid = is_spectral_active_valid;
  502. param.enabled_valid = is_spectral_enabled_valid;
  503. param.active = is_spectral_active;
  504. param.enabled = is_spectral_enabled;
  505. param.mode = smode;
  506. return psoc_spectral->wmi_ops.wmi_spectral_enable_cmd_send(
  507. GET_WMI_HDL_FROM_PDEV(pdev), &param);
  508. }
  509. /**
  510. * target_if_spectral_info_init_defaults() - Helper function to load defaults
  511. * for Spectral information (parameters and state) into cache.
  512. * @spectral: Pointer to Spectral target_if internal private data
  513. * @smode: Spectral scan mode
  514. *
  515. * It is assumed that the caller has obtained the requisite lock if applicable.
  516. * Note that this is currently treated as a temporary function. Ideally, we
  517. * would like to get defaults from the firmware.
  518. *
  519. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  520. */
  521. static QDF_STATUS
  522. target_if_spectral_info_init_defaults(struct target_if_spectral *spectral,
  523. enum spectral_scan_mode smode)
  524. {
  525. struct target_if_spectral_param_state_info *info;
  526. struct wlan_objmgr_vdev *vdev = NULL;
  527. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  528. spectral_err("Invalid Spectral mode %u", smode);
  529. return QDF_STATUS_E_FAILURE;
  530. }
  531. info = &spectral->param_info[smode];
  532. /* State */
  533. info->osps_cache.osc_spectral_active = SPECTRAL_SCAN_ACTIVE_DEFAULT;
  534. info->osps_cache.osc_spectral_enabled = SPECTRAL_SCAN_ENABLE_DEFAULT;
  535. /* Parameters */
  536. info->osps_cache.osc_params.ss_count = SPECTRAL_SCAN_COUNT_DEFAULT;
  537. if (spectral->spectral_gen == SPECTRAL_GEN3)
  538. info->osps_cache.osc_params.ss_period =
  539. SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT;
  540. else
  541. info->osps_cache.osc_params.ss_period =
  542. SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT;
  543. info->osps_cache.osc_params.ss_spectral_pri =
  544. SPECTRAL_SCAN_PRIORITY_DEFAULT;
  545. info->osps_cache.osc_params.ss_fft_size =
  546. SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  547. info->osps_cache.osc_params.ss_gc_ena = SPECTRAL_SCAN_GC_ENA_DEFAULT;
  548. info->osps_cache.osc_params.ss_restart_ena =
  549. SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  550. info->osps_cache.osc_params.ss_noise_floor_ref =
  551. SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  552. info->osps_cache.osc_params.ss_init_delay =
  553. SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  554. info->osps_cache.osc_params.ss_nb_tone_thr =
  555. SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  556. info->osps_cache.osc_params.ss_str_bin_thr =
  557. SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  558. info->osps_cache.osc_params.ss_wb_rpt_mode =
  559. SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  560. info->osps_cache.osc_params.ss_rssi_rpt_mode =
  561. SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  562. info->osps_cache.osc_params.ss_rssi_thr =
  563. SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  564. info->osps_cache.osc_params.ss_pwr_format =
  565. SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  566. info->osps_cache.osc_params.ss_rpt_mode =
  567. SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  568. info->osps_cache.osc_params.ss_bin_scale =
  569. SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  570. info->osps_cache.osc_params.ss_dbm_adj = SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  571. vdev = target_if_spectral_get_vdev(spectral, smode);
  572. if (!vdev)
  573. return QDF_STATUS_E_NOENT;
  574. info->osps_cache.osc_params.ss_chn_mask =
  575. wlan_vdev_mlme_get_rxchainmask(vdev);
  576. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  577. info->osps_cache.osc_params.ss_short_report =
  578. SPECTRAL_SCAN_SHORT_REPORT_DEFAULT;
  579. info->osps_cache.osc_params.ss_fft_period =
  580. SPECTRAL_SCAN_FFT_PERIOD_DEFAULT;
  581. info->osps_cache.osc_params.ss_frequency.cfreq1 =
  582. SPECTRAL_SCAN_FREQUENCY_DEFAULT;
  583. info->osps_cache.osc_params.ss_frequency.cfreq2 =
  584. SPECTRAL_SCAN_FREQUENCY_DEFAULT;
  585. /* The cache is now valid */
  586. info->osps_cache.osc_is_valid = 1;
  587. return QDF_STATUS_SUCCESS;
  588. }
  589. /**
  590. * target_if_log_read_spectral_active() - Helper function to log whether
  591. * spectral is active after reading cache
  592. * @function_name: Function name
  593. * @output: whether spectral is active or not
  594. *
  595. * Helper function to log whether spectral is active after reading cache
  596. *
  597. * Return: none
  598. */
  599. static void
  600. target_if_log_read_spectral_active(
  601. const char *function_name,
  602. unsigned char output)
  603. {
  604. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE. Returning val=%u",
  605. function_name, output);
  606. }
  607. /**
  608. * target_if_log_read_spectral_enabled() - Helper function to log whether
  609. * spectral is enabled after reading cache
  610. * @function_name: Function name
  611. * @output: whether spectral is enabled or not
  612. *
  613. * Helper function to log whether spectral is enabled after reading cache
  614. *
  615. * Return: none
  616. */
  617. static void
  618. target_if_log_read_spectral_enabled(
  619. const char *function_name,
  620. unsigned char output)
  621. {
  622. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED. Returning val=%u",
  623. function_name, output);
  624. }
  625. /**
  626. * target_if_log_read_spectral_enabled() - Helper function to log spectral
  627. * parameters after reading cache
  628. * @function_name: Function name
  629. * @pparam: Spectral parameters
  630. *
  631. * Helper function to log spectral parameters after reading cache
  632. *
  633. * Return: none
  634. */
  635. static void
  636. target_if_log_read_spectral_params(
  637. const char *function_name,
  638. struct spectral_config *pparam)
  639. {
  640. 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",
  641. function_name,
  642. pparam->ss_count,
  643. pparam->ss_period,
  644. pparam->ss_spectral_pri,
  645. pparam->ss_fft_size,
  646. pparam->ss_gc_ena,
  647. pparam->ss_restart_ena,
  648. (int8_t)pparam->ss_noise_floor_ref,
  649. pparam->ss_init_delay,
  650. pparam->ss_nb_tone_thr,
  651. pparam->ss_str_bin_thr,
  652. pparam->ss_wb_rpt_mode,
  653. pparam->ss_rssi_rpt_mode,
  654. (int8_t)pparam->ss_rssi_thr,
  655. pparam->ss_pwr_format,
  656. pparam->ss_rpt_mode,
  657. pparam->ss_bin_scale,
  658. pparam->ss_dbm_adj,
  659. pparam->ss_chn_mask,
  660. pparam->ss_frequency.cfreq1,
  661. pparam->ss_frequency.cfreq2);
  662. }
  663. /**
  664. * target_if_log_read_spectral_active_catch_validate() - Helper function to
  665. * log whether spectral is active after intializing the cache
  666. * @function_name: Function name
  667. * @output: whether spectral is active or not
  668. *
  669. * Helper function to log whether spectral is active after intializing cache
  670. *
  671. * Return: none
  672. */
  673. static void
  674. target_if_log_read_spectral_active_catch_validate(
  675. const char *function_name,
  676. unsigned char output)
  677. {
  678. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE on initial cache validation\nReturning val=%u",
  679. function_name, output);
  680. }
  681. /**
  682. * target_if_log_read_spectral_enabled_catch_validate() - Helper function to
  683. * log whether spectral is enabled after intializing the cache
  684. * @function_name: Function name
  685. * @output: whether spectral is enabled or not
  686. *
  687. * Helper function to log whether spectral is enabled after intializing cache
  688. *
  689. * Return: none
  690. */
  691. static void
  692. target_if_log_read_spectral_enabled_catch_validate(
  693. const char *function_name,
  694. unsigned char output)
  695. {
  696. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED on initial cache validation\nReturning val=%u\n",
  697. function_name, output);
  698. }
  699. /**
  700. * target_if_log_read_spectral_params_catch_validate() - Helper function to
  701. * log spectral parameters after intializing the cache
  702. * @function_name: Function name
  703. * @pparam: Spectral parameters
  704. *
  705. * Helper function to log spectral parameters after intializing the cache
  706. *
  707. * Return: none
  708. */
  709. static void
  710. target_if_log_read_spectral_params_catch_validate(
  711. const char *function_name,
  712. struct spectral_config *pparam)
  713. {
  714. 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",
  715. function_name,
  716. pparam->ss_count,
  717. pparam->ss_period,
  718. pparam->ss_spectral_pri,
  719. pparam->ss_fft_size,
  720. pparam->ss_gc_ena,
  721. pparam->ss_restart_ena,
  722. (int8_t)pparam->ss_noise_floor_ref,
  723. pparam->ss_init_delay,
  724. pparam->ss_nb_tone_thr,
  725. pparam->ss_str_bin_thr,
  726. pparam->ss_wb_rpt_mode,
  727. pparam->ss_rssi_rpt_mode,
  728. (int8_t)pparam->ss_rssi_thr,
  729. pparam->ss_pwr_format,
  730. pparam->ss_rpt_mode,
  731. pparam->ss_bin_scale,
  732. pparam->ss_dbm_adj, pparam->ss_chn_mask);
  733. }
  734. /**
  735. * target_if_spectral_info_read() - Read spectral information from the cache.
  736. * @spectral: Pointer to Spectral target_if internal private data
  737. * @smode: Spectral scan mode
  738. * @specifier: target_if_spectral_info enumeration specifying which
  739. * information is required
  740. * @output: Void output pointer into which the information will be read
  741. * @output_len: size of object pointed to by output pointer
  742. *
  743. * Read spectral parameters or the desired state information from the cache.
  744. *
  745. * Return: 0 on success, negative error code on failure
  746. */
  747. static int
  748. target_if_spectral_info_read(
  749. struct target_if_spectral *spectral,
  750. enum spectral_scan_mode smode,
  751. enum target_if_spectral_info specifier,
  752. void *output, int output_len)
  753. {
  754. /*
  755. * Note: This function is designed to be able to accommodate
  756. * WMI reads for defaults, non-cacheable information, etc
  757. * if required.
  758. */
  759. struct target_if_spectral_param_state_info *info;
  760. int is_cacheable = 0;
  761. int init_def_retval = 0;
  762. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  763. spectral_err("Invalid Spectral mode %u", smode);
  764. return -EINVAL;
  765. }
  766. info = &spectral->param_info[smode];
  767. if (!output)
  768. return -EINVAL;
  769. switch (specifier) {
  770. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  771. if (output_len != sizeof(info->osps_cache.osc_spectral_active))
  772. return -EINVAL;
  773. is_cacheable = 1;
  774. break;
  775. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  776. if (output_len != sizeof(info->osps_cache.osc_spectral_enabled))
  777. return -EINVAL;
  778. is_cacheable = 1;
  779. break;
  780. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  781. if (output_len != sizeof(info->osps_cache.osc_params))
  782. return -EINVAL;
  783. is_cacheable = 1;
  784. break;
  785. default:
  786. spectral_err("Unknown target_if_spectral_info specifier");
  787. return -EINVAL;
  788. }
  789. qdf_spin_lock_bh(&info->osps_lock);
  790. if (is_cacheable) {
  791. if (info->osps_cache.osc_is_valid) {
  792. switch (specifier) {
  793. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  794. qdf_mem_copy(
  795. output,
  796. &info->osps_cache.osc_spectral_active,
  797. sizeof(info->osps_cache.osc_spectral_active));
  798. target_if_log_read_spectral_active(
  799. __func__,
  800. *((unsigned char *)output));
  801. break;
  802. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  803. qdf_mem_copy(
  804. output,
  805. &info->osps_cache.osc_spectral_enabled,
  806. sizeof(
  807. info->osps_cache.osc_spectral_enabled));
  808. target_if_log_read_spectral_enabled(
  809. __func__,
  810. *((unsigned char *)output));
  811. break;
  812. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  813. qdf_mem_copy(
  814. output,
  815. &info->osps_cache.osc_params,
  816. sizeof(info->osps_cache.osc_params));
  817. target_if_log_read_spectral_params(
  818. __func__,
  819. (struct spectral_config *)output);
  820. break;
  821. default:
  822. /* We can't reach this point */
  823. break;
  824. }
  825. qdf_spin_unlock_bh(&info->osps_lock);
  826. return 0;
  827. }
  828. }
  829. /* Cache is invalid */
  830. /*
  831. * If WMI Reads are implemented to fetch defaults/non-cacheable info,
  832. * then the below implementation will change
  833. */
  834. init_def_retval =
  835. target_if_spectral_info_init_defaults(spectral, smode);
  836. if (init_def_retval != QDF_STATUS_SUCCESS) {
  837. qdf_spin_unlock_bh(&info->osps_lock);
  838. if (init_def_retval == QDF_STATUS_E_NOENT)
  839. return -ENOENT;
  840. else
  841. return -EINVAL;
  842. }
  843. /* target_if_spectral_info_init_defaults() has set cache to valid */
  844. switch (specifier) {
  845. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  846. qdf_mem_copy(output,
  847. &info->osps_cache.osc_spectral_active,
  848. sizeof(info->osps_cache.osc_spectral_active));
  849. target_if_log_read_spectral_active_catch_validate(
  850. __func__,
  851. *((unsigned char *)output));
  852. break;
  853. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  854. qdf_mem_copy(output,
  855. &info->osps_cache.osc_spectral_enabled,
  856. sizeof(info->osps_cache.osc_spectral_enabled));
  857. target_if_log_read_spectral_enabled_catch_validate(
  858. __func__,
  859. *((unsigned char *)output));
  860. break;
  861. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  862. qdf_mem_copy(output,
  863. &info->osps_cache.osc_params,
  864. sizeof(info->osps_cache.osc_params));
  865. target_if_log_read_spectral_params_catch_validate(
  866. __func__,
  867. (struct spectral_config *)output);
  868. break;
  869. default:
  870. /* We can't reach this point */
  871. break;
  872. }
  873. qdf_spin_unlock_bh(&info->osps_lock);
  874. return 0;
  875. }
  876. /**
  877. * target_if_log_write_spectral_active() - Helper function to log inputs and
  878. * return value of call to configure the Spectral 'active' configuration,
  879. * TARGET_IF_SPECTRAL_INFO_ACTIVE into firmware
  880. * @function_name: Function name in which this is called
  881. * @pval: whether spectral is active or not
  882. * @ret: return value of the firmware write function
  883. *
  884. * Return: none
  885. */
  886. static void
  887. target_if_log_write_spectral_active(
  888. const char *function_name,
  889. uint8_t pval,
  890. int ret)
  891. {
  892. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE with val=%u status=%d",
  893. function_name, pval, ret);
  894. }
  895. /**
  896. * target_if_log_write_spectral_enabled() - Helper function to log inputs and
  897. * return value of call to configure the Spectral 'enabled' configuration,
  898. * TARGET_IF_SPECTRAL_INFO_ENABLED into firmware
  899. * @function_name: Function name in which this is called
  900. * @pval: whether spectral is enabled or not
  901. * @ret: return value of the firmware write function
  902. *
  903. * Return: none
  904. */
  905. static void
  906. target_if_log_write_spectral_enabled(
  907. const char *function_name,
  908. uint8_t pval,
  909. int ret)
  910. {
  911. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED with val=%u status=%d",
  912. function_name, pval, ret);
  913. }
  914. /**
  915. * target_if_log_write_spectral_params() - Helper function to log inputs and
  916. * return value of call to configure Spectral parameters,
  917. * TARGET_IF_SPECTRAL_INFO_PARAMS into firmware
  918. * @param: Spectral parameters
  919. * @function_name: Function name in which this is called
  920. * @ret: return value of the firmware write function
  921. *
  922. * Return: none
  923. */
  924. static void
  925. target_if_log_write_spectral_params(
  926. struct spectral_config *param,
  927. const char *function_name,
  928. int ret)
  929. {
  930. 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",
  931. function_name,
  932. param->ss_count,
  933. param->ss_period,
  934. param->ss_spectral_pri,
  935. param->ss_fft_size,
  936. param->ss_gc_ena,
  937. param->ss_restart_ena,
  938. (int8_t)param->ss_noise_floor_ref,
  939. param->ss_init_delay,
  940. param->ss_nb_tone_thr,
  941. param->ss_str_bin_thr,
  942. param->ss_wb_rpt_mode,
  943. param->ss_rssi_rpt_mode,
  944. (int8_t)param->ss_rssi_thr,
  945. param->ss_pwr_format,
  946. param->ss_rpt_mode,
  947. param->ss_bin_scale,
  948. param->ss_dbm_adj,
  949. param->ss_chn_mask,
  950. param->ss_frequency.cfreq1,
  951. param->ss_frequency.cfreq2,
  952. ret);
  953. }
  954. /**
  955. * target_if_spectral_info_write() - Write Spectral information to the
  956. * firmware, and update cache
  957. * @spectral: Pointer to Spectral target_if internal private data
  958. * @smode: Spectral scan mode
  959. * @specifier: target_if_spectral_info enumeration specifying which
  960. * information is involved
  961. * @input: void input pointer containing the information to be written
  962. * @input_len: size of object pointed to by input pointer
  963. *
  964. * Write Spectral parameters or the desired state information to
  965. * the firmware, and update cache
  966. *
  967. * Return: 0 on success, negative error code on failure
  968. */
  969. static int
  970. target_if_spectral_info_write(
  971. struct target_if_spectral *spectral,
  972. enum spectral_scan_mode smode,
  973. enum target_if_spectral_info specifier,
  974. void *input, int input_len)
  975. {
  976. struct target_if_spectral_param_state_info *info;
  977. int ret;
  978. uint8_t *pval = NULL;
  979. struct spectral_config *param = NULL;
  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 (!input)
  986. return -EINVAL;
  987. switch (specifier) {
  988. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  989. if (input_len != sizeof(info->osps_cache.osc_spectral_active))
  990. return -EINVAL;
  991. pval = (uint8_t *)input;
  992. qdf_spin_lock_bh(&info->osps_lock);
  993. ret = target_if_send_vdev_spectral_enable_cmd(spectral, smode,
  994. 1, *pval, 0, 0);
  995. target_if_log_write_spectral_active(
  996. __func__,
  997. *pval,
  998. ret);
  999. if (ret < 0) {
  1000. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  1001. ret);
  1002. qdf_spin_unlock_bh(&info->osps_lock);
  1003. return ret;
  1004. }
  1005. info->osps_cache.osc_spectral_active = *pval;
  1006. /* The cache is now valid */
  1007. info->osps_cache.osc_is_valid = 1;
  1008. qdf_spin_unlock_bh(&info->osps_lock);
  1009. break;
  1010. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  1011. if (input_len != sizeof(info->osps_cache.osc_spectral_enabled))
  1012. return -EINVAL;
  1013. pval = (uint8_t *)input;
  1014. qdf_spin_lock_bh(&info->osps_lock);
  1015. ret = target_if_send_vdev_spectral_enable_cmd(spectral, smode,
  1016. 0, 0, 1, *pval);
  1017. target_if_log_write_spectral_enabled(
  1018. __func__,
  1019. *pval,
  1020. ret);
  1021. if (ret < 0) {
  1022. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  1023. ret);
  1024. qdf_spin_unlock_bh(&info->osps_lock);
  1025. return ret;
  1026. }
  1027. info->osps_cache.osc_spectral_enabled = *pval;
  1028. /* The cache is now valid */
  1029. info->osps_cache.osc_is_valid = 1;
  1030. qdf_spin_unlock_bh(&info->osps_lock);
  1031. break;
  1032. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  1033. if (input_len != sizeof(info->osps_cache.osc_params))
  1034. return -EINVAL;
  1035. param = (struct spectral_config *)input;
  1036. qdf_spin_lock_bh(&info->osps_lock);
  1037. ret = target_if_send_vdev_spectral_configure_cmd(spectral,
  1038. smode, param);
  1039. target_if_log_write_spectral_params(
  1040. param,
  1041. __func__,
  1042. ret);
  1043. if (ret < 0) {
  1044. spectral_err("target_if_send_vdev_spectral_configure_cmd failed with error=%d",
  1045. ret);
  1046. qdf_spin_unlock_bh(&info->osps_lock);
  1047. return ret;
  1048. }
  1049. qdf_mem_copy(&info->osps_cache.osc_params,
  1050. param, sizeof(info->osps_cache.osc_params));
  1051. /* The cache is now valid */
  1052. info->osps_cache.osc_is_valid = 1;
  1053. qdf_spin_unlock_bh(&info->osps_lock);
  1054. break;
  1055. default:
  1056. spectral_err("Unknown target_if_spectral_info specifier");
  1057. return -EINVAL;
  1058. }
  1059. return 0;
  1060. }
  1061. /**
  1062. * target_if_spectral_get_tsf64() - Function to get the TSF value
  1063. * @arg: Pointer to handle for Spectral target_if internal private data
  1064. *
  1065. * Get the last TSF received in WMI buffer
  1066. *
  1067. * Return: TSF value
  1068. */
  1069. static uint64_t
  1070. target_if_spectral_get_tsf64(void *arg)
  1071. {
  1072. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1073. return spectral->tsf64;
  1074. }
  1075. /**
  1076. * target_if_spectral_get_capability() - Function to get whether a
  1077. * given Spectral hardware capability is available
  1078. * @arg: Pointer to handle for Spectral target_if internal private data
  1079. * @type: Spectral hardware capability type
  1080. *
  1081. * Get whether a given Spectral hardware capability is available
  1082. *
  1083. * Return: True if the capability is available, false if the capability is not
  1084. * available
  1085. */
  1086. uint32_t
  1087. target_if_spectral_get_capability(void *arg, enum spectral_capability_type type)
  1088. {
  1089. int status = STATUS_FAIL;
  1090. switch (type) {
  1091. case SPECTRAL_CAP_PHYDIAG:
  1092. case SPECTRAL_CAP_RADAR:
  1093. case SPECTRAL_CAP_SPECTRAL_SCAN:
  1094. case SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN:
  1095. status = STATUS_PASS;
  1096. break;
  1097. default:
  1098. status = STATUS_FAIL;
  1099. }
  1100. return status;
  1101. }
  1102. /**
  1103. * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
  1104. * @arg: Pointer to handle for Spectral target_if internal private data
  1105. * @rxfilter: Rx filter to be used
  1106. *
  1107. * Note: This is only a placeholder function. It is not currently required since
  1108. * FW should be taking care of setting the required filters.
  1109. *
  1110. * Return: 0
  1111. */
  1112. uint32_t
  1113. target_if_spectral_set_rxfilter(void *arg, int rxfilter)
  1114. {
  1115. /*
  1116. * Will not be required since enabling of spectral in firmware
  1117. * will take care of this
  1118. */
  1119. return 0;
  1120. }
  1121. /**
  1122. * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
  1123. * @arg: Pointer to handle for Spectral target_if internal private data
  1124. *
  1125. * Note: This is only a placeholder function. It is not currently required since
  1126. * FW should be taking care of setting the required filters.
  1127. *
  1128. * Return: 0
  1129. */
  1130. uint32_t
  1131. target_if_spectral_get_rxfilter(void *arg)
  1132. {
  1133. /*
  1134. * Will not be required since enabling of spectral in firmware
  1135. * will take care of this
  1136. */
  1137. return 0;
  1138. }
  1139. /**
  1140. * target_if_sops_is_spectral_active() - Get whether Spectral is active
  1141. * @arg: Pointer to handle for Spectral target_if internal private data
  1142. * @smode: Spectral scan mode
  1143. *
  1144. * Function to check whether Spectral is active
  1145. *
  1146. * Return: True if Spectral is active, false if Spectral is not active
  1147. */
  1148. uint32_t
  1149. target_if_sops_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  1150. {
  1151. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1152. uint8_t val = 0;
  1153. int ret;
  1154. ret = target_if_spectral_info_read(
  1155. spectral,
  1156. smode,
  1157. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  1158. &val, sizeof(val));
  1159. if (ret != 0) {
  1160. /*
  1161. * Could not determine if Spectral is active.
  1162. * Return false as a safe value.
  1163. * XXX: Consider changing the function prototype
  1164. * to be able to indicate failure to fetch value.
  1165. */
  1166. return 0;
  1167. }
  1168. return val;
  1169. }
  1170. /**
  1171. * target_if_sops_is_spectral_enabled() - Get whether Spectral is enabled
  1172. * @arg: Pointer to handle for Spectral target_if internal private data
  1173. * @smode: Spectral scan mode
  1174. *
  1175. * Function to check whether Spectral is enabled
  1176. *
  1177. * Return: True if Spectral is enabled, false if Spectral is not enabled
  1178. */
  1179. uint32_t
  1180. target_if_sops_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  1181. {
  1182. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1183. uint8_t val = 0;
  1184. int ret;
  1185. ret = target_if_spectral_info_read(
  1186. spectral,
  1187. smode,
  1188. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1189. &val, sizeof(val));
  1190. if (ret != 0) {
  1191. /*
  1192. * Could not determine if Spectral is enabled.
  1193. * Return false as a safe value.
  1194. * XXX: Consider changing the function prototype
  1195. * to be able to indicate failure to fetch value.
  1196. */
  1197. return 0;
  1198. }
  1199. return val;
  1200. }
  1201. /**
  1202. * target_if_sops_start_spectral_scan() - Start Spectral scan
  1203. * @arg: Pointer to handle for Spectral target_if internal private data
  1204. * @smode: Spectral scan mode
  1205. * @err: Spectral error code
  1206. *
  1207. * Function to start spectral scan
  1208. *
  1209. * Return: 0 on success else failure
  1210. */
  1211. uint32_t
  1212. target_if_sops_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  1213. enum spectral_cp_error_code *err)
  1214. {
  1215. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1216. uint8_t val = 1;
  1217. uint8_t enabled = 0;
  1218. int ret;
  1219. ret = target_if_spectral_info_read(
  1220. spectral,
  1221. smode,
  1222. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1223. &enabled, sizeof(enabled));
  1224. if (ret != 0) {
  1225. /*
  1226. * Could not determine if Spectral is enabled. Assume we need
  1227. * to enable it
  1228. */
  1229. enabled = 0;
  1230. }
  1231. if (!enabled) {
  1232. ret = target_if_spectral_info_write(
  1233. spectral,
  1234. smode,
  1235. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1236. &val, sizeof(val));
  1237. if (ret != 0)
  1238. return ret;
  1239. }
  1240. ret = target_if_spectral_info_write(
  1241. spectral,
  1242. smode,
  1243. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  1244. &val, sizeof(val));
  1245. if (ret != 0)
  1246. return ret;
  1247. return 0;
  1248. }
  1249. /**
  1250. * target_if_sops_stop_spectral_scan() - Stop Spectral scan
  1251. * @arg: Pointer to handle for Spectral target_if internal private data
  1252. * @smode: Spectral scan mode
  1253. *
  1254. * Function to stop spectral scan
  1255. *
  1256. * Return: 0 on success else failure
  1257. */
  1258. uint32_t
  1259. target_if_sops_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  1260. {
  1261. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1262. uint8_t val = 0;
  1263. int tempret, ret = 0;
  1264. uint8_t enabled = 0;
  1265. tempret = target_if_spectral_info_read(
  1266. spectral,
  1267. smode,
  1268. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1269. &enabled, sizeof(enabled));
  1270. if (tempret)
  1271. /*
  1272. * Could not determine if Spectral is enabled. Assume scan is
  1273. * not in progress
  1274. */
  1275. enabled = 0;
  1276. /* if scan is not enabled, no need to send stop to FW */
  1277. if (!enabled)
  1278. return -EPERM;
  1279. tempret = target_if_spectral_info_write(
  1280. spectral,
  1281. smode,
  1282. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  1283. &val, sizeof(val));
  1284. if (tempret != 0)
  1285. ret = tempret;
  1286. tempret = target_if_spectral_info_write(
  1287. spectral,
  1288. smode,
  1289. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1290. &val, sizeof(val));
  1291. if (tempret != 0)
  1292. ret = tempret;
  1293. if (ret == 0 && smode == SPECTRAL_SCAN_MODE_AGILE) {
  1294. struct target_if_spectral_ops *p_sops;
  1295. struct spectral_config *sparams;
  1296. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1297. sparams = &spectral->params[smode];
  1298. sparams->ss_frequency.cfreq1 = 0;
  1299. sparams->ss_frequency.cfreq2 = 0;
  1300. p_sops->configure_spectral(spectral, sparams, smode);
  1301. }
  1302. return ret;
  1303. }
  1304. /**
  1305. * target_if_spectral_get_extension_channel() - Get the Extension channel
  1306. * @arg: Pointer to handle for Spectral target_if internal private data
  1307. * @smode: Spectral scan mode
  1308. *
  1309. * Function to get the current Extension channel (in MHz)
  1310. *
  1311. * Return: Current Extension channel (in MHz) on success, 0 on failure or if
  1312. * extension channel is not present.
  1313. */
  1314. uint32_t
  1315. target_if_spectral_get_extension_channel(void *arg,
  1316. enum spectral_scan_mode smode)
  1317. {
  1318. /*
  1319. * XXX: Once we expand to use cases where Spectral could be activated
  1320. * without a channel being set to VDEV, we need to consider returning a
  1321. * negative value in case of failure and having all callers handle this.
  1322. */
  1323. struct target_if_spectral *spectral = NULL;
  1324. struct wlan_objmgr_vdev *vdev = NULL;
  1325. uint16_t sec20chan_freq = 0;
  1326. qdf_assert_always(arg);
  1327. spectral = (struct target_if_spectral *)arg;
  1328. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1329. spectral_err("Invalid Spectral mode %u", smode);
  1330. return 0;
  1331. }
  1332. vdev = target_if_spectral_get_vdev(spectral, smode);
  1333. if (!vdev)
  1334. return 0;
  1335. if (target_if_vdev_get_sec20chan_freq_mhz(vdev, &sec20chan_freq) < 0) {
  1336. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1337. return 0;
  1338. }
  1339. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1340. return sec20chan_freq;
  1341. }
  1342. /**
  1343. * target_if_spectral_get_current_channel() - Get the current channel
  1344. * @arg: Pointer to handle for Spectral target_if internal private data
  1345. * @smode: Spectral scan mode
  1346. *
  1347. * Function to get the current channel (in MHz)
  1348. *
  1349. * Return: Current channel (in MHz) on success, 0 on failure
  1350. */
  1351. uint32_t
  1352. target_if_spectral_get_current_channel(void *arg, enum spectral_scan_mode smode)
  1353. {
  1354. /*
  1355. * XXX: Once we expand to use cases where Spectral could be activated
  1356. * without a channel being set to VDEV, we need to consider returning a
  1357. * negative value in case of failure and having all callers handle this.
  1358. */
  1359. struct target_if_spectral *spectral = NULL;
  1360. int16_t chan_freq = 0;
  1361. struct wlan_objmgr_vdev *vdev = NULL;
  1362. qdf_assert_always(arg);
  1363. spectral = (struct target_if_spectral *)arg;
  1364. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1365. spectral_err("Invalid Spectral mode %u", smode);
  1366. return 0;
  1367. }
  1368. vdev = target_if_spectral_get_vdev(spectral, smode);
  1369. if (!vdev)
  1370. return 0;
  1371. chan_freq = target_if_vdev_get_chan_freq(vdev);
  1372. if (chan_freq < 0) {
  1373. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1374. return 0;
  1375. }
  1376. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1377. return chan_freq;
  1378. }
  1379. /**
  1380. * target_if_spectral_reset_hw() - Reset the hardware
  1381. * @arg: Pointer to handle for Spectral target_if internal private data
  1382. *
  1383. * This is only a placeholder since it is not currently required in the offload
  1384. * case.
  1385. *
  1386. * Return: 0
  1387. */
  1388. uint32_t
  1389. target_if_spectral_reset_hw(void *arg)
  1390. {
  1391. not_yet_implemented();
  1392. return 0;
  1393. }
  1394. /**
  1395. * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
  1396. * Noisefloor history buffer
  1397. * @arg: Pointer to handle for Spectral target_if internal private data
  1398. * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
  1399. *
  1400. * This is only a placeholder since it is not currently required in the offload
  1401. * case.
  1402. *
  1403. * Return: 0
  1404. */
  1405. uint32_t
  1406. target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1407. {
  1408. not_yet_implemented();
  1409. return 0;
  1410. }
  1411. /**
  1412. * target_if_spectral_get_ext_noisefloor() - Get the extension channel
  1413. * noisefloor
  1414. * @arg: Pointer to handle for Spectral target_if internal private data
  1415. *
  1416. * This is only a placeholder since it is not currently required in the offload
  1417. * case.
  1418. *
  1419. * Return: 0
  1420. */
  1421. int8_t
  1422. target_if_spectral_get_ext_noisefloor(void *arg)
  1423. {
  1424. not_yet_implemented();
  1425. return 0;
  1426. }
  1427. /**
  1428. * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
  1429. * @arg: Pointer to handle for Spectral target_if internal private data
  1430. *
  1431. * This is only a placeholder since it is not currently required in the offload
  1432. * case.
  1433. *
  1434. * Return: 0
  1435. */
  1436. int8_t
  1437. target_if_spectral_get_ctl_noisefloor(void *arg)
  1438. {
  1439. not_yet_implemented();
  1440. return 0;
  1441. }
  1442. /**
  1443. * target_if_spectral_sops_configure_params() - Configure user supplied Spectral
  1444. * parameters
  1445. * @arg: Pointer to handle for Spectral target_if internal private data
  1446. * @params: Spectral parameters
  1447. * @smode: Spectral scan mode
  1448. *
  1449. * Function to configure spectral parameters
  1450. *
  1451. * Return: 0 on success else failure
  1452. */
  1453. uint32_t
  1454. target_if_spectral_sops_configure_params(
  1455. void *arg, struct spectral_config *params,
  1456. enum spectral_scan_mode smode)
  1457. {
  1458. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1459. return target_if_spectral_info_write(
  1460. spectral,
  1461. smode,
  1462. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1463. params, sizeof(*params));
  1464. }
  1465. /**
  1466. * target_if_spectral_sops_get_params() - Get user configured Spectral
  1467. * parameters
  1468. * @arg: Pointer to handle for Spectral target_if internal private data
  1469. * @params: Pointer to buffer into which Spectral parameters should be copied
  1470. * @smode: Spectral scan mode
  1471. *
  1472. * Function to get the configured spectral parameters
  1473. *
  1474. * Return: 0 on success else failure
  1475. */
  1476. uint32_t
  1477. target_if_spectral_sops_get_params(void *arg, struct spectral_config *params,
  1478. enum spectral_scan_mode smode)
  1479. {
  1480. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1481. return target_if_spectral_info_read(
  1482. spectral,
  1483. smode,
  1484. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1485. params, sizeof(*params));
  1486. }
  1487. /**
  1488. * target_if_spectral_get_ent_mask() - Get enterprise mask
  1489. * @arg: Pointer to handle for Spectral target_if internal private data
  1490. *
  1491. * This is only a placeholder since it is not currently required in the offload
  1492. * case.
  1493. *
  1494. * Return: 0
  1495. */
  1496. static uint32_t
  1497. target_if_spectral_get_ent_mask(void *arg)
  1498. {
  1499. not_yet_implemented();
  1500. return 0;
  1501. }
  1502. /**
  1503. * target_if_spectral_get_macaddr() - Get radio MAC address
  1504. * @arg: Pointer to handle for Spectral target_if internal private data
  1505. * @addr: Pointer to buffer into which MAC address should be copied
  1506. *
  1507. * Function to get the MAC address of the pdev
  1508. *
  1509. * Return: 0 on success, -1 on failure
  1510. */
  1511. static uint32_t
  1512. target_if_spectral_get_macaddr(void *arg, char *addr)
  1513. {
  1514. uint8_t *myaddr = NULL;
  1515. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1516. struct wlan_objmgr_pdev *pdev = NULL;
  1517. pdev = spectral->pdev_obj;
  1518. wlan_pdev_obj_lock(pdev);
  1519. myaddr = wlan_pdev_get_hw_macaddr(pdev);
  1520. wlan_pdev_obj_unlock(pdev);
  1521. qdf_mem_copy(addr, myaddr, QDF_MAC_ADDR_SIZE);
  1522. return 0;
  1523. }
  1524. /**
  1525. * target_if_init_spectral_param_min_max() - Initialize Spectral parameter
  1526. * min and max values
  1527. *
  1528. * @param_min_max: Pointer to Spectral parameter min and max structure
  1529. * @gen: Spectral HW generation
  1530. * @target_type: Target type
  1531. *
  1532. * Initialize Spectral parameter min and max values
  1533. *
  1534. * Return: QDF_STATUS
  1535. */
  1536. static QDF_STATUS
  1537. target_if_init_spectral_param_min_max(
  1538. struct spectral_param_min_max *param_min_max,
  1539. enum spectral_gen gen, uint32_t target_type)
  1540. {
  1541. switch (gen) {
  1542. case SPECTRAL_GEN3:
  1543. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3;
  1544. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1545. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1546. if (target_type == TARGET_TYPE_QCN9000 ||
  1547. target_type == TARGET_TYPE_QCN6122 ||
  1548. target_type == TARGET_TYPE_QCA5018 ||
  1549. target_type == TARGET_TYPE_QCA6490) {
  1550. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1551. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1552. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1553. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1554. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1555. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1556. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1557. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1558. } else {
  1559. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1560. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1561. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1562. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1563. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1564. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1565. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1566. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1567. }
  1568. break;
  1569. case SPECTRAL_GEN2:
  1570. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1571. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1572. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1573. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1574. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1575. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1576. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1577. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1578. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1579. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1580. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1581. break;
  1582. default:
  1583. spectral_err("Invalid spectral generation %d", gen);
  1584. return QDF_STATUS_E_INVAL;
  1585. }
  1586. return QDF_STATUS_SUCCESS;
  1587. }
  1588. /**
  1589. * target_if_init_spectral_param_properties() - Initialize Spectral parameter
  1590. * properties
  1591. * @spectral: Pointer to Spectral target_if internal private data
  1592. *
  1593. * Initialize Spectral parameter properties
  1594. *
  1595. * Return: QDF_STATUS
  1596. */
  1597. static QDF_STATUS
  1598. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1599. {
  1600. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1601. int param;
  1602. /* Initialize default values for properties.
  1603. * Default values are supported for all the parameters for all modes
  1604. * and allows different values for each mode for all the parameters .
  1605. */
  1606. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1607. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1608. spectral->properties[smode][param].supported = true;
  1609. spectral->properties[smode][param].common_all_modes =
  1610. false;
  1611. }
  1612. }
  1613. /* Once FW advertisement is in place remove this hard coding */
  1614. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1615. spectral->properties[SPECTRAL_SCAN_MODE_NORMAL]
  1616. [SPECTRAL_PARAM_FREQUENCY].supported = false;
  1617. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1618. spectral->properties[smode]
  1619. [SPECTRAL_PARAM_SPECT_PRI].common_all_modes = true;
  1620. spectral->properties[smode]
  1621. [SPECTRAL_PARAM_SCAN_PERIOD].common_all_modes = true;
  1622. spectral->properties[smode]
  1623. [SPECTRAL_PARAM_INIT_DELAY].common_all_modes = true;
  1624. }
  1625. return QDF_STATUS_SUCCESS;
  1626. }
  1627. QDF_STATUS
  1628. target_if_init_spectral_capability(struct target_if_spectral *spectral,
  1629. uint32_t target_type)
  1630. {
  1631. struct wlan_objmgr_psoc *psoc;
  1632. struct wlan_objmgr_pdev *pdev;
  1633. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  1634. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  1635. struct target_psoc_info *tgt_psoc_info;
  1636. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  1637. struct spectral_caps *pcap = &spectral->capability;
  1638. pdev = spectral->pdev_obj;
  1639. psoc = wlan_pdev_get_psoc(pdev);
  1640. if (!psoc) {
  1641. spectral_err("psoc is null");
  1642. return QDF_STATUS_E_FAILURE;
  1643. }
  1644. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  1645. if (!tgt_psoc_info) {
  1646. spectral_err("target_psoc_info is null");
  1647. return QDF_STATUS_E_FAILURE;
  1648. }
  1649. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  1650. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  1651. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  1652. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  1653. /* XXX : Workaround: Set Spectral capability */
  1654. pcap = &spectral->capability;
  1655. pcap->phydiag_cap = 1;
  1656. pcap->radar_cap = 1;
  1657. pcap->spectral_cap = wlan_pdev_nif_feat_ext_cap_get(
  1658. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  1659. pcap->advncd_spectral_cap = pcap->spectral_cap;
  1660. pcap->hw_gen = spectral->spectral_gen;
  1661. pcap->agile_spectral_cap = !wlan_pdev_nif_feat_ext_cap_get(
  1662. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  1663. pcap->agile_spectral_cap_160 = !wlan_pdev_nif_feat_ext_cap_get(
  1664. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  1665. pcap->agile_spectral_cap_80p80 = !wlan_pdev_nif_feat_ext_cap_get(
  1666. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  1667. if (scaling_params) {
  1668. for (param_idx = 0; param_idx < num_bin_scaling_params;
  1669. param_idx++) {
  1670. if (scaling_params[param_idx].pdev_id == pdev_id) {
  1671. pcap->is_scaling_params_populated = true;
  1672. pcap->formula_id =
  1673. scaling_params[param_idx].formula_id;
  1674. pcap->low_level_offset =
  1675. scaling_params[param_idx].low_level_offset;
  1676. pcap->high_level_offset =
  1677. scaling_params[param_idx].high_level_offset;
  1678. pcap->rssi_thr =
  1679. scaling_params[param_idx].rssi_thr;
  1680. pcap->default_agc_max_gain =
  1681. scaling_params[param_idx].default_agc_max_gain;
  1682. break;
  1683. }
  1684. }
  1685. }
  1686. pcap->num_detectors_20mhz = 1;
  1687. pcap->num_detectors_40mhz = 1;
  1688. pcap->num_detectors_80mhz = 1;
  1689. if (target_type == TARGET_TYPE_QCN9000 ||
  1690. target_type == TARGET_TYPE_QCN6122 ||
  1691. target_type == TARGET_TYPE_QCA6490) {
  1692. pcap->num_detectors_160mhz = 1;
  1693. pcap->num_detectors_80p80mhz = 1;
  1694. } else {
  1695. pcap->num_detectors_160mhz = 2;
  1696. pcap->num_detectors_80p80mhz = 2;
  1697. }
  1698. return QDF_STATUS_SUCCESS;
  1699. }
  1700. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1701. /**
  1702. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1703. * internal operations with functions related to spectral simulation
  1704. * @p_sops: spectral low level ops table
  1705. *
  1706. * Initialize spectral target_if internal operations with functions
  1707. * related to spectral simulation
  1708. *
  1709. * Return: None
  1710. */
  1711. static void
  1712. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1713. {
  1714. /*
  1715. * Spectral simulation is currently intended for platform transitions
  1716. * where underlying HW support may not be available for some time.
  1717. * Hence, we do not currently provide a runtime switch to turn the
  1718. * simulation on or off.
  1719. * In case of future requirements where runtime switches are required,
  1720. * this can be added. But it is suggested to use application layer
  1721. * simulation as far as possible in such cases, since the main
  1722. * use of record and replay of samples would concern higher
  1723. * level sample processing rather than lower level delivery.
  1724. */
  1725. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  1726. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  1727. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  1728. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  1729. p_sops->configure_spectral =
  1730. target_if_spectral_sops_sim_configure_params;
  1731. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  1732. }
  1733. #else
  1734. /**
  1735. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1736. * internal operations
  1737. * @p_sops: spectral low level ops table
  1738. *
  1739. * Return: None
  1740. */
  1741. static void
  1742. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1743. {
  1744. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  1745. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  1746. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  1747. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  1748. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  1749. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  1750. }
  1751. #endif
  1752. /**
  1753. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  1754. * operations common to all Spectral chipset generations
  1755. *
  1756. * Initializes target_if_spectral_ops common to all chipset generations
  1757. *
  1758. * Return: None
  1759. */
  1760. static void
  1761. target_if_init_spectral_ops_common(void)
  1762. {
  1763. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1764. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  1765. p_sops->get_capability = target_if_spectral_get_capability;
  1766. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  1767. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  1768. target_if_init_spectral_simulation_ops(p_sops);
  1769. p_sops->get_extension_channel =
  1770. target_if_spectral_get_extension_channel;
  1771. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  1772. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  1773. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  1774. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  1775. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  1776. p_sops->reset_hw = target_if_spectral_reset_hw;
  1777. p_sops->get_chain_noise_floor =
  1778. target_if_spectral_get_chain_noise_floor;
  1779. }
  1780. /**
  1781. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  1782. * operations specific to Spectral chipset generation 2.
  1783. *
  1784. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  1785. *
  1786. * Return: None
  1787. */
  1788. static void
  1789. target_if_init_spectral_ops_gen2(void)
  1790. {
  1791. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1792. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  1793. }
  1794. #ifdef BIG_ENDIAN_HOST
  1795. /**
  1796. * target_if_spectral_init_byte_swap_funcs_gen3() - Initialize byte-swap
  1797. * operations for Spectral chipset generation 3.
  1798. *
  1799. * @p_sops: Spectral function pointer table
  1800. *
  1801. * Return: None
  1802. */
  1803. static void
  1804. target_if_spectral_init_byte_swap_funcs_gen3(
  1805. struct target_if_spectral_ops *p_sops)
  1806. {
  1807. qdf_assert_always(p_sops);
  1808. /* None of current Gen3 chipsets support byte-swap inside the target.
  1809. * so, Host would have to implement the byte-swap for these chipsets.
  1810. *
  1811. * If a chipset supports byte-swap inside the target itself in future,
  1812. * then, for that chipset, initialize these function pointers with
  1813. * NULL based on the capability advertisement.
  1814. */
  1815. p_sops->byte_swap_headers = target_if_byte_swap_spectral_headers_gen3;
  1816. p_sops->byte_swap_fft_bins = target_if_byte_swap_spectral_fft_bins_gen3;
  1817. }
  1818. #else
  1819. static void
  1820. target_if_spectral_init_byte_swap_funcs_gen3(
  1821. struct target_if_spectral_ops *p_sops)
  1822. {
  1823. qdf_assert_always(p_sops);
  1824. /* Byte-swap is not required for little-endian Hosts */
  1825. p_sops->byte_swap_headers = NULL;
  1826. p_sops->byte_swap_fft_bins = NULL;
  1827. }
  1828. #endif /* BIG_ENDIAN_HOST */
  1829. /**
  1830. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  1831. * operations specific to Spectral chipset generation 3.
  1832. *
  1833. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  1834. *
  1835. * Return: None
  1836. */
  1837. static void
  1838. target_if_init_spectral_ops_gen3(void)
  1839. {
  1840. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1841. p_sops->process_spectral_report =
  1842. target_if_spectral_process_report_gen3;
  1843. target_if_spectral_init_byte_swap_funcs_gen3(p_sops);
  1844. }
  1845. /**
  1846. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  1847. * operations.
  1848. * @spectral: Pointer to Spectral target_if internal private data
  1849. *
  1850. * Initializes all function pointers in target_if_spectral_ops for
  1851. * all generations
  1852. *
  1853. * Return: None
  1854. */
  1855. static void
  1856. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  1857. {
  1858. target_if_init_spectral_ops_common();
  1859. if (spectral->spectral_gen == SPECTRAL_GEN2)
  1860. target_if_init_spectral_ops_gen2();
  1861. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  1862. target_if_init_spectral_ops_gen3();
  1863. else
  1864. spectral_err("Invalid Spectral generation");
  1865. }
  1866. /*
  1867. * Dummy Functions:
  1868. * These functions are initially registered to avoid any crashes due to
  1869. * invocation of spectral functions before they are registered.
  1870. */
  1871. static uint64_t
  1872. null_get_tsf64(void *arg)
  1873. {
  1874. spectral_ops_not_registered("get_tsf64");
  1875. return 0;
  1876. }
  1877. static uint32_t
  1878. null_get_capability(void *arg, enum spectral_capability_type type)
  1879. {
  1880. /*
  1881. * TODO : We should have conditional compilation to get the capability
  1882. * : We have not yet attahced ATH layer here, so there is no
  1883. * : way to check the HAL capbalities
  1884. */
  1885. spectral_ops_not_registered("get_capability");
  1886. /* TODO : For the time being, we are returning TRUE */
  1887. return true;
  1888. }
  1889. static uint32_t
  1890. null_set_rxfilter(void *arg, int rxfilter)
  1891. {
  1892. spectral_ops_not_registered("set_rxfilter");
  1893. return 1;
  1894. }
  1895. static uint32_t
  1896. null_get_rxfilter(void *arg)
  1897. {
  1898. spectral_ops_not_registered("get_rxfilter");
  1899. return 0;
  1900. }
  1901. static uint32_t
  1902. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  1903. {
  1904. spectral_ops_not_registered("is_spectral_active");
  1905. return 1;
  1906. }
  1907. static uint32_t
  1908. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  1909. {
  1910. spectral_ops_not_registered("is_spectral_enabled");
  1911. return 1;
  1912. }
  1913. static uint32_t
  1914. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  1915. enum spectral_cp_error_code *err)
  1916. {
  1917. spectral_ops_not_registered("start_spectral_scan");
  1918. return 1;
  1919. }
  1920. static uint32_t
  1921. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  1922. {
  1923. spectral_ops_not_registered("stop_spectral_scan");
  1924. return 1;
  1925. }
  1926. static uint32_t
  1927. null_get_extension_channel(void *arg, enum spectral_scan_mode smode)
  1928. {
  1929. spectral_ops_not_registered("get_extension_channel");
  1930. return 1;
  1931. }
  1932. static int8_t
  1933. null_get_ctl_noisefloor(void *arg)
  1934. {
  1935. spectral_ops_not_registered("get_ctl_noisefloor");
  1936. return 1;
  1937. }
  1938. static int8_t
  1939. null_get_ext_noisefloor(void *arg)
  1940. {
  1941. spectral_ops_not_registered("get_ext_noisefloor");
  1942. return 0;
  1943. }
  1944. static uint32_t
  1945. null_configure_spectral(void *arg, struct spectral_config *params,
  1946. enum spectral_scan_mode smode)
  1947. {
  1948. spectral_ops_not_registered("configure_spectral");
  1949. return 0;
  1950. }
  1951. static uint32_t
  1952. null_get_spectral_config(void *arg, struct spectral_config *params,
  1953. enum spectral_scan_mode smode)
  1954. {
  1955. spectral_ops_not_registered("get_spectral_config");
  1956. return 0;
  1957. }
  1958. static uint32_t
  1959. null_get_ent_spectral_mask(void *arg)
  1960. {
  1961. spectral_ops_not_registered("get_ent_spectral_mask");
  1962. return 0;
  1963. }
  1964. static uint32_t
  1965. null_get_mac_address(void *arg, char *addr)
  1966. {
  1967. spectral_ops_not_registered("get_mac_address");
  1968. return 0;
  1969. }
  1970. static uint32_t
  1971. null_get_current_channel(void *arg, enum spectral_scan_mode smode)
  1972. {
  1973. spectral_ops_not_registered("get_current_channel");
  1974. return 0;
  1975. }
  1976. static uint32_t
  1977. null_reset_hw(void *arg)
  1978. {
  1979. spectral_ops_not_registered("get_current_channel");
  1980. return 0;
  1981. }
  1982. static uint32_t
  1983. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1984. {
  1985. spectral_ops_not_registered("get_chain_noise_floor");
  1986. return 0;
  1987. }
  1988. static int
  1989. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  1990. uint8_t *data,
  1991. uint32_t datalen,
  1992. struct target_if_spectral_rfqual_info *p_rfqual,
  1993. struct target_if_spectral_chan_info *p_chaninfo,
  1994. uint64_t tsf64,
  1995. struct target_if_spectral_acs_stats *acs_stats)
  1996. {
  1997. spectral_ops_not_registered("spectral_process_phyerr");
  1998. return 0;
  1999. }
  2000. static int
  2001. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  2002. void *payload)
  2003. {
  2004. spectral_ops_not_registered("process_spectral_report");
  2005. return 0;
  2006. }
  2007. /**
  2008. * target_if_spectral_init_dummy_function_table() -
  2009. * Initialize target_if internal
  2010. * Spectral operations to dummy functions
  2011. * @ps: Pointer to Spectral target_if internal private data
  2012. *
  2013. * Initialize all the function pointers in target_if_spectral_ops with
  2014. * dummy functions.
  2015. *
  2016. * Return: None
  2017. */
  2018. static void
  2019. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  2020. {
  2021. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  2022. p_sops->get_tsf64 = null_get_tsf64;
  2023. p_sops->get_capability = null_get_capability;
  2024. p_sops->set_rxfilter = null_set_rxfilter;
  2025. p_sops->get_rxfilter = null_get_rxfilter;
  2026. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  2027. p_sops->is_spectral_active = null_is_spectral_active;
  2028. p_sops->start_spectral_scan = null_start_spectral_scan;
  2029. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  2030. p_sops->get_extension_channel = null_get_extension_channel;
  2031. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  2032. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  2033. p_sops->configure_spectral = null_configure_spectral;
  2034. p_sops->get_spectral_config = null_get_spectral_config;
  2035. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  2036. p_sops->get_mac_address = null_get_mac_address;
  2037. p_sops->get_current_channel = null_get_current_channel;
  2038. p_sops->reset_hw = null_reset_hw;
  2039. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  2040. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  2041. p_sops->process_spectral_report = null_process_spectral_report;
  2042. }
  2043. /**
  2044. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  2045. * operations
  2046. * @spectral: Pointer to Spectral target_if internal private data
  2047. * @p: Pointer to Spectral function table
  2048. *
  2049. * Return: None
  2050. */
  2051. static void
  2052. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  2053. struct target_if_spectral_ops *p)
  2054. {
  2055. struct target_if_spectral_ops *p_sops =
  2056. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2057. *p_sops = *p;
  2058. }
  2059. /**
  2060. * target_if_spectral_clear_stats() - Clear Spectral stats
  2061. * @spectral: Pointer to Spectral target_if internal private data
  2062. *
  2063. * Function to clear spectral stats
  2064. *
  2065. * Return: None
  2066. */
  2067. static void
  2068. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  2069. {
  2070. struct target_if_spectral_ops *p_sops =
  2071. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2072. qdf_mem_zero(&spectral->spectral_stats,
  2073. sizeof(struct target_if_spectral_stats));
  2074. spectral->spectral_stats.last_reset_tstamp =
  2075. p_sops->get_tsf64(spectral);
  2076. }
  2077. /**
  2078. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  2079. * @spectral: Pointer to Spectral target_if internal private data
  2080. *
  2081. * Function to check whether hardware supports spectral
  2082. *
  2083. * Return: True if HW supports Spectral, false if HW does not support Spectral
  2084. */
  2085. static int
  2086. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  2087. {
  2088. struct target_if_spectral_ops *p_sops = NULL;
  2089. struct spectral_caps *pcap = NULL;
  2090. int is_spectral_supported = true;
  2091. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2092. pcap = &spectral->capability;
  2093. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  2094. is_spectral_supported = false;
  2095. spectral_info("SPECTRAL : No PHYDIAG support");
  2096. return is_spectral_supported;
  2097. }
  2098. pcap->phydiag_cap = 1;
  2099. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  2100. is_spectral_supported = false;
  2101. spectral_info("SPECTRAL : No RADAR support");
  2102. return is_spectral_supported;
  2103. }
  2104. pcap->radar_cap = 1;
  2105. if (p_sops->get_capability(spectral,
  2106. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  2107. is_spectral_supported = false;
  2108. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  2109. return is_spectral_supported;
  2110. }
  2111. pcap->spectral_cap = 1;
  2112. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  2113. == false) {
  2114. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  2115. } else {
  2116. pcap->advncd_spectral_cap = 1;
  2117. }
  2118. return is_spectral_supported;
  2119. }
  2120. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2121. /**
  2122. * target_if_spectral_detach_simulation() - De-initialize Spectral
  2123. * Simulation functionality
  2124. * @spectral: Pointer to Spectral target_if internal private data
  2125. *
  2126. * Function to de-initialize Spectral Simulation functionality
  2127. *
  2128. * Return: None
  2129. */
  2130. static void
  2131. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  2132. {
  2133. target_if_spectral_sim_detach(spectral);
  2134. }
  2135. #else
  2136. static void
  2137. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  2138. {
  2139. }
  2140. #endif
  2141. /**
  2142. * target_if_spectral_detach() - De-initialize target_if Spectral
  2143. * @pdev: Pointer to pdev object
  2144. *
  2145. * Function to detach target_if spectral
  2146. *
  2147. * Return: None
  2148. */
  2149. static void
  2150. target_if_spectral_detach(struct target_if_spectral *spectral)
  2151. {
  2152. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  2153. spectral_info("spectral detach");
  2154. if (spectral) {
  2155. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2156. qdf_spinlock_destroy
  2157. (&spectral->param_info[smode].osps_lock);
  2158. target_if_spectral_detach_simulation(spectral);
  2159. qdf_spinlock_destroy(&spectral->spectral_lock);
  2160. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  2161. qdf_mem_free(spectral);
  2162. spectral = NULL;
  2163. }
  2164. }
  2165. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2166. /**
  2167. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  2168. * functionality
  2169. * @spectral: Pointer to Spectral target_if internal private data
  2170. *
  2171. * Function to initialize spectral simulation functionality
  2172. *
  2173. * Return: 0 on success, negative error code on failure
  2174. */
  2175. static int
  2176. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  2177. {
  2178. if (target_if_spectral_sim_attach(spectral)) {
  2179. qdf_mem_free(spectral);
  2180. return -EPERM;
  2181. }
  2182. return 0;
  2183. }
  2184. #else
  2185. static int
  2186. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  2187. {
  2188. return 0;
  2189. }
  2190. #endif
  2191. /**
  2192. * target_if_spectral_len_adj_swar_init() - Initialize FFT bin length adjustment
  2193. * related info
  2194. * @swar: Pointer to Spectral FFT bin length adjustment SWAR params
  2195. * @target_type: Target type
  2196. *
  2197. * Function to Initialize parameters related to Spectral FFT bin
  2198. * length adjustment SWARs.
  2199. *
  2200. * Return: void
  2201. */
  2202. static void
  2203. target_if_spectral_len_adj_swar_init(struct spectral_fft_bin_len_adj_swar *swar,
  2204. uint32_t target_type)
  2205. {
  2206. if (target_type == TARGET_TYPE_QCA8074V2 ||
  2207. target_type == TARGET_TYPE_QCA9574 ||
  2208. target_type == TARGET_TYPE_QCN9000 ||
  2209. target_type == TARGET_TYPE_QCN6122 ||
  2210. target_type == TARGET_TYPE_QCA5018 ||
  2211. target_type == TARGET_TYPE_QCA6750 ||
  2212. target_type == TARGET_TYPE_QCA6490)
  2213. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  2214. else if (target_type == TARGET_TYPE_QCA8074 ||
  2215. target_type == TARGET_TYPE_QCA6018 ||
  2216. target_type == TARGET_TYPE_QCA6390)
  2217. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  2218. else
  2219. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  2220. if (target_type == TARGET_TYPE_QCA8074 ||
  2221. target_type == TARGET_TYPE_QCA8074V2 ||
  2222. target_type == TARGET_TYPE_QCA9574 ||
  2223. target_type == TARGET_TYPE_QCA6018 ||
  2224. target_type == TARGET_TYPE_QCN6122 ||
  2225. target_type == TARGET_TYPE_QCA5018 ||
  2226. target_type == TARGET_TYPE_QCN9000 ||
  2227. target_type == TARGET_TYPE_QCA6490) {
  2228. swar->inband_fftbin_size_adj = 1;
  2229. swar->null_fftbin_adj = 1;
  2230. } else {
  2231. swar->inband_fftbin_size_adj = 0;
  2232. swar->null_fftbin_adj = 0;
  2233. }
  2234. if (target_type == TARGET_TYPE_QCA8074V2 ||
  2235. target_type == TARGET_TYPE_QCA9574)
  2236. swar->packmode_fftbin_size_adj = 1;
  2237. else
  2238. swar->packmode_fftbin_size_adj = 0;
  2239. }
  2240. /**
  2241. * target_if_spectral_report_params_init() - Initialize parameters which
  2242. * describes the structure of Spectral reports
  2243. *
  2244. * @rparams: Pointer to Spectral report parameter object
  2245. * @target_type: target type
  2246. *
  2247. * Function to Initialize parameters related to the structure of Spectral
  2248. * reports.
  2249. *
  2250. * Return: void
  2251. */
  2252. static void
  2253. target_if_spectral_report_params_init(
  2254. struct spectral_report_params *rparams,
  2255. uint32_t target_type)
  2256. {
  2257. enum spectral_scan_mode smode;
  2258. /* This entries are currently used by gen3 chipsets only. Hence
  2259. * initialization is done for gen3 alone. In future if other generations
  2260. * needs to use them they have to add proper initial values.
  2261. */
  2262. if (target_type == TARGET_TYPE_QCN9000 ||
  2263. target_type == TARGET_TYPE_QCN6122 ||
  2264. target_type == TARGET_TYPE_QCA5018 ||
  2265. target_type == TARGET_TYPE_QCA6750 ||
  2266. target_type == TARGET_TYPE_QCA6490) {
  2267. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_2;
  2268. rparams->num_spectral_detectors =
  2269. NUM_SPECTRAL_DETECTORS_GEN3_V2;
  2270. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2271. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2272. rparams->fragmentation_160[smode] = false;
  2273. rparams->max_agile_ch_width = CH_WIDTH_80P80MHZ;
  2274. } else {
  2275. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_1;
  2276. rparams->num_spectral_detectors =
  2277. NUM_SPECTRAL_DETECTORS_GEN3_V1;
  2278. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2279. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2280. rparams->fragmentation_160[smode] = true;
  2281. rparams->max_agile_ch_width = CH_WIDTH_80MHZ;
  2282. }
  2283. switch (rparams->version) {
  2284. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  2285. rparams->ssumaary_padding_bytes =
  2286. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1;
  2287. rparams->fft_report_hdr_len =
  2288. FFT_REPORT_HEADER_LENGTH_GEN3_V1;
  2289. break;
  2290. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  2291. rparams->ssumaary_padding_bytes =
  2292. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2;
  2293. rparams->fft_report_hdr_len =
  2294. FFT_REPORT_HEADER_LENGTH_GEN3_V2;
  2295. break;
  2296. default:
  2297. qdf_assert_always(0);
  2298. }
  2299. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_0] =
  2300. SPECTRAL_SCAN_MODE_NORMAL;
  2301. if (target_type == TARGET_TYPE_QCN9000 ||
  2302. target_type == TARGET_TYPE_QCN6122 ||
  2303. target_type == TARGET_TYPE_QCA6490) {
  2304. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2305. SPECTRAL_SCAN_MODE_AGILE;
  2306. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2307. SPECTRAL_SCAN_MODE_INVALID;
  2308. } else {
  2309. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2310. SPECTRAL_SCAN_MODE_NORMAL;
  2311. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2312. SPECTRAL_SCAN_MODE_AGILE;
  2313. }
  2314. }
  2315. /**
  2316. * target_if_spectral_timestamp_war_init() - Initialize Spectral timestamp WAR
  2317. * related info
  2318. * @twar: Pointer to Spectral timstamp WAR related info
  2319. *
  2320. * Function to Initialize parameters related to Spectral timestamp WAR
  2321. *
  2322. * Return: void
  2323. */
  2324. static void
  2325. target_if_spectral_timestamp_war_init(struct spectral_timestamp_war *twar)
  2326. {
  2327. enum spectral_scan_mode smode;
  2328. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2329. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2330. twar->last_fft_timestamp[smode] = 0;
  2331. twar->timestamp_war_offset[smode] = 0;
  2332. }
  2333. twar->target_reset_count = 0;
  2334. }
  2335. #ifdef OPTIMIZED_SAMP_MESSAGE
  2336. /**
  2337. * target_if_spectral_detector_list_init() - Initialize Spectral detector list
  2338. * based on target type
  2339. * @spectral: Pointer to Spectral target_if
  2340. *
  2341. * Function to initialize Spectral detector list for possible combinations of
  2342. * Spectral scan mode and channel width, based on target type.
  2343. *
  2344. * Return: Success/Failure
  2345. */
  2346. static QDF_STATUS
  2347. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  2348. {
  2349. struct sscan_detector_list *det_list;
  2350. enum spectral_scan_mode smode;
  2351. enum phy_ch_width ch_width;
  2352. if (!spectral) {
  2353. spectral_err_rl("Spectral LMAC object is null");
  2354. return QDF_STATUS_E_NULL_VALUE;
  2355. }
  2356. /**
  2357. * We assume there are 2 detectors. The Detector ID coming first will
  2358. * always be pri80 detector, and second detector for sec80.
  2359. */
  2360. ch_width = CH_WIDTH_20MHZ;
  2361. for (; ch_width <= CH_WIDTH_80P80MHZ; ch_width++) {
  2362. /* Normal spectral scan */
  2363. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2364. det_list = &spectral->detector_list[smode][ch_width];
  2365. det_list->num_detectors = 1;
  2366. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_0;
  2367. if (is_ch_width_160_or_80p80(ch_width) &&
  2368. spectral->rparams.fragmentation_160[smode]) {
  2369. det_list->num_detectors += 1;
  2370. det_list->detectors[1] = SPECTRAL_DETECTOR_ID_1;
  2371. }
  2372. /* Agile spectral scan */
  2373. smode = SPECTRAL_SCAN_MODE_AGILE;
  2374. det_list = &spectral->detector_list[smode][ch_width];
  2375. det_list->num_detectors = 1;
  2376. if (spectral->rparams.fragmentation_160[smode]) {
  2377. /**
  2378. * Skip to next iteration if 160/80p80 MHz for Agile
  2379. * scan. Only 20/40/80 MHz is supported on platforms
  2380. * with fragmentation, as only 1 detector is available.
  2381. */
  2382. if (is_ch_width_160_or_80p80(ch_width))
  2383. continue;
  2384. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_2;
  2385. } else {
  2386. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_1;
  2387. }
  2388. }
  2389. return QDF_STATUS_SUCCESS;
  2390. }
  2391. #else
  2392. static QDF_STATUS
  2393. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  2394. {
  2395. return QDF_STATUS_SUCCESS;
  2396. }
  2397. #endif /* OPTIMIZED_SAMP_MESSAGE */
  2398. /**
  2399. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  2400. * functionality for the given pdev
  2401. * @pdev: Pointer to pdev object
  2402. *
  2403. * Function to initialize pointer to spectral target_if internal private data
  2404. *
  2405. * Return: On success, pointer to Spectral target_if internal private data, on
  2406. * failure, NULL
  2407. */
  2408. void *
  2409. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  2410. {
  2411. struct target_if_spectral_ops *p_sops = NULL;
  2412. struct target_if_spectral *spectral = NULL;
  2413. uint32_t target_type;
  2414. uint32_t target_revision;
  2415. struct wlan_objmgr_psoc *psoc;
  2416. struct wlan_lmac_if_target_tx_ops *tgt_tx_ops;
  2417. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  2418. QDF_STATUS status;
  2419. struct wlan_lmac_if_tx_ops *tx_ops;
  2420. if (!pdev) {
  2421. spectral_err("SPECTRAL: pdev is NULL!");
  2422. return NULL;
  2423. }
  2424. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  2425. sizeof(struct target_if_spectral));
  2426. if (!spectral)
  2427. return spectral;
  2428. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  2429. /* Store pdev in Spectral */
  2430. spectral->pdev_obj = pdev;
  2431. spectral->vdev_id[SPECTRAL_SCAN_MODE_NORMAL] = WLAN_INVALID_VDEV_ID;
  2432. spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE] = WLAN_INVALID_VDEV_ID;
  2433. psoc = wlan_pdev_get_psoc(pdev);
  2434. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  2435. if (!tx_ops) {
  2436. spectral_err("tx_ops is NULL");
  2437. qdf_mem_free(spectral);
  2438. return NULL;
  2439. }
  2440. tgt_tx_ops = &tx_ops->target_tx_ops;
  2441. if (tgt_tx_ops->tgt_get_tgt_type) {
  2442. target_type = tgt_tx_ops->tgt_get_tgt_type(psoc);
  2443. } else {
  2444. qdf_mem_free(spectral);
  2445. return NULL;
  2446. }
  2447. if (tgt_tx_ops->tgt_get_tgt_revision) {
  2448. target_revision = tgt_tx_ops->tgt_get_tgt_revision(psoc);
  2449. } else {
  2450. qdf_mem_free(spectral);
  2451. return NULL;
  2452. }
  2453. /* init the function ptr table */
  2454. target_if_spectral_init_dummy_function_table(spectral);
  2455. /* get spectral function table */
  2456. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2457. /* TODO : Should this be called here of after ath_attach ? */
  2458. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  2459. spectral_info("HAL_CAP_PHYDIAG : Capable");
  2460. /* TODO: Need to fix the capablity check for RADAR */
  2461. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  2462. spectral_info("HAL_CAP_RADAR : Capable");
  2463. /* TODO : Need to fix the capablity check for SPECTRAL */
  2464. /* TODO : Should this be called here of after ath_attach ? */
  2465. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  2466. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  2467. qdf_spinlock_create(&spectral->spectral_lock);
  2468. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  2469. target_if_spectral_clear_stats(spectral);
  2470. if (target_type == TARGET_TYPE_QCA8074 ||
  2471. target_type == TARGET_TYPE_QCA8074V2 ||
  2472. target_type == TARGET_TYPE_QCA9574 ||
  2473. target_type == TARGET_TYPE_QCA6018 ||
  2474. target_type == TARGET_TYPE_QCA5018 ||
  2475. target_type == TARGET_TYPE_QCA6390 ||
  2476. target_type == TARGET_TYPE_QCN6122 ||
  2477. target_type == TARGET_TYPE_QCA6490 ||
  2478. target_type == TARGET_TYPE_QCN9000 ||
  2479. target_type == TARGET_TYPE_QCA6750)
  2480. spectral->direct_dma_support = true;
  2481. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  2482. target_type);
  2483. target_if_spectral_report_params_init(&spectral->rparams, target_type);
  2484. if ((target_type == TARGET_TYPE_QCA8074) ||
  2485. (target_type == TARGET_TYPE_QCA8074V2) ||
  2486. (target_type == TARGET_TYPE_QCA9574) ||
  2487. (target_type == TARGET_TYPE_QCA6018) ||
  2488. (target_type == TARGET_TYPE_QCA5018) ||
  2489. (target_type == TARGET_TYPE_QCN6122) ||
  2490. (target_type == TARGET_TYPE_QCN9000) ||
  2491. (target_type == TARGET_TYPE_QCA6290) ||
  2492. (target_type == TARGET_TYPE_QCA6390) ||
  2493. (target_type == TARGET_TYPE_QCA6490) ||
  2494. (target_type == TARGET_TYPE_QCA6750)) {
  2495. spectral->spectral_gen = SPECTRAL_GEN3;
  2496. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  2497. spectral->tag_sscan_summary_exp =
  2498. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  2499. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  2500. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  2501. } else {
  2502. spectral->spectral_gen = SPECTRAL_GEN2;
  2503. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  2504. spectral->tag_sscan_summary_exp =
  2505. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  2506. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  2507. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  2508. }
  2509. status = target_if_init_spectral_param_min_max(
  2510. &spectral->param_min_max,
  2511. spectral->spectral_gen, target_type);
  2512. if (QDF_IS_STATUS_ERROR(status)) {
  2513. spectral_err("Failed to initialize parameter min max values");
  2514. goto fail;
  2515. }
  2516. target_if_init_spectral_param_properties(spectral);
  2517. /* Init spectral capability */
  2518. if (target_if_init_spectral_capability(spectral, target_type) !=
  2519. QDF_STATUS_SUCCESS) {
  2520. qdf_mem_free(spectral);
  2521. return NULL;
  2522. }
  2523. if (target_if_spectral_attach_simulation(spectral) < 0)
  2524. return NULL;
  2525. target_if_init_spectral_ops(spectral);
  2526. target_if_spectral_timestamp_war_init(&spectral->timestamp_war);
  2527. /* Spectral mode specific init */
  2528. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2529. spectral->params_valid[smode] = false;
  2530. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  2531. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  2532. }
  2533. target_if_spectral_register_funcs(spectral, &spectral_ops);
  2534. if (target_if_spectral_check_hw_capability(spectral) == false) {
  2535. goto fail;
  2536. } else {
  2537. /*
  2538. * TODO: Once the driver architecture transitions to chipset
  2539. * versioning based checks, reflect this here.
  2540. */
  2541. spectral->is_160_format = false;
  2542. spectral->is_lb_edge_extrabins_format = false;
  2543. spectral->is_rb_edge_extrabins_format = false;
  2544. if (target_type == TARGET_TYPE_QCA9984 ||
  2545. target_type == TARGET_TYPE_QCA9888) {
  2546. spectral->is_160_format = true;
  2547. spectral->is_lb_edge_extrabins_format = true;
  2548. spectral->is_rb_edge_extrabins_format = true;
  2549. } else if ((target_type == TARGET_TYPE_AR900B) &&
  2550. (target_revision == AR900B_REV_2)) {
  2551. spectral->is_rb_edge_extrabins_format = true;
  2552. }
  2553. if (target_type == TARGET_TYPE_QCA9984 ||
  2554. target_type == TARGET_TYPE_QCA9888)
  2555. spectral->is_sec80_rssi_war_required = true;
  2556. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  2557. if (spectral->spectral_gen == SPECTRAL_GEN3)
  2558. init_160mhz_delivery_state_machine(spectral);
  2559. }
  2560. target_if_spectral_detector_list_init(spectral);
  2561. return spectral;
  2562. fail:
  2563. target_if_spectral_detach(spectral);
  2564. return NULL;
  2565. }
  2566. /**
  2567. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  2568. * functionality for the given pdev
  2569. * @pdev: Pointer to pdev object
  2570. *
  2571. * Function to de-initialize pointer to spectral target_if internal private data
  2572. *
  2573. * Return: None
  2574. */
  2575. void
  2576. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  2577. {
  2578. struct target_if_spectral *spectral = NULL;
  2579. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2580. if (!spectral) {
  2581. spectral_err("SPECTRAL : Module doesn't exist");
  2582. return;
  2583. }
  2584. target_if_spectral_detach(spectral);
  2585. return;
  2586. }
  2587. /**
  2588. * target_if_psoc_spectral_deinit() - De-initialize target_if Spectral
  2589. * functionality for the given psoc
  2590. * @psoc: Pointer to psoc object
  2591. *
  2592. * Function to de-initialize pointer to psoc spectral target_if internal
  2593. * private data
  2594. *
  2595. * Return: None
  2596. */
  2597. static void
  2598. target_if_psoc_spectral_deinit(struct wlan_objmgr_psoc *psoc)
  2599. {
  2600. struct target_if_psoc_spectral *psoc_spectral;
  2601. if (!psoc) {
  2602. spectral_err("psoc is null");
  2603. return;
  2604. }
  2605. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  2606. if (!psoc_spectral) {
  2607. spectral_err("Spectral target_if psoc object is null");
  2608. return;
  2609. }
  2610. qdf_mem_free(psoc_spectral);
  2611. }
  2612. /**
  2613. * target_if_psoc_spectral_init() - Initialize target_if Spectral
  2614. * functionality for the given psoc
  2615. * @psoc: Pointer to psoc object
  2616. *
  2617. * Function to initialize pointer to psoc spectral target_if internal
  2618. * private data
  2619. *
  2620. * Return: On success, pointer to Spectral psoc target_if internal
  2621. * private data, on failure, NULL
  2622. */
  2623. static void *
  2624. target_if_psoc_spectral_init(struct wlan_objmgr_psoc *psoc)
  2625. {
  2626. struct target_if_psoc_spectral *psoc_spectral = NULL;
  2627. if (!psoc) {
  2628. spectral_err("psoc is null");
  2629. goto fail;
  2630. }
  2631. psoc_spectral = (struct target_if_psoc_spectral *)qdf_mem_malloc(
  2632. sizeof(struct target_if_psoc_spectral));
  2633. if (!psoc_spectral) {
  2634. spectral_err("Spectral lmac psoc object allocation failed");
  2635. goto fail;
  2636. }
  2637. psoc_spectral->psoc_obj = psoc;
  2638. return psoc_spectral;
  2639. fail:
  2640. if (psoc_spectral)
  2641. target_if_psoc_spectral_deinit(psoc);
  2642. return psoc_spectral;
  2643. }
  2644. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  2645. * corresponding translation for Agile channel width.
  2646. * @spectral: pointer to Spectral object
  2647. * @chwidth: operating channel width
  2648. * @is_80_80_agile: Indicates an 80+80 agile Scan request
  2649. *
  2650. * Return: The translated channel width enum.
  2651. */
  2652. static enum phy_ch_width
  2653. target_if_spectral_find_agile_width(struct target_if_spectral *spectral,
  2654. enum phy_ch_width chwidth,
  2655. bool is_80_80_agile)
  2656. {
  2657. enum phy_ch_width agile_width;
  2658. struct wlan_objmgr_pdev *pdev;
  2659. struct wlan_objmgr_psoc *psoc;
  2660. if (!spectral) {
  2661. spectral_err("Spectral object is null");
  2662. return CH_WIDTH_INVALID;
  2663. }
  2664. pdev = spectral->pdev_obj;
  2665. if (!pdev) {
  2666. spectral_err("pdev is null");
  2667. return CH_WIDTH_INVALID;
  2668. }
  2669. psoc = wlan_pdev_get_psoc(pdev);
  2670. if (!psoc) {
  2671. spectral_err("psoc is null");
  2672. return CH_WIDTH_INVALID;
  2673. }
  2674. switch (chwidth) {
  2675. case CH_WIDTH_20MHZ:
  2676. agile_width = CH_WIDTH_20MHZ;
  2677. break;
  2678. case CH_WIDTH_40MHZ:
  2679. agile_width = CH_WIDTH_40MHZ;
  2680. break;
  2681. case CH_WIDTH_80MHZ:
  2682. agile_width = CH_WIDTH_80MHZ;
  2683. break;
  2684. case CH_WIDTH_80P80MHZ:
  2685. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  2686. WLAN_SOC_RESTRICTED_80P80_SUPPORT) && !is_80_80_agile)
  2687. agile_width = CH_WIDTH_160MHZ;
  2688. else
  2689. agile_width = CH_WIDTH_80P80MHZ;
  2690. if (agile_width > spectral->rparams.max_agile_ch_width)
  2691. agile_width = spectral->rparams.max_agile_ch_width;
  2692. break;
  2693. case CH_WIDTH_160MHZ:
  2694. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  2695. WLAN_SOC_RESTRICTED_80P80_SUPPORT) && is_80_80_agile)
  2696. agile_width = CH_WIDTH_80P80MHZ;
  2697. else
  2698. agile_width = CH_WIDTH_160MHZ;
  2699. if (agile_width > spectral->rparams.max_agile_ch_width)
  2700. agile_width = spectral->rparams.max_agile_ch_width;
  2701. break;
  2702. default:
  2703. spectral_err("Invalid channel width %d", chwidth);
  2704. agile_width = CH_WIDTH_INVALID;
  2705. break;
  2706. }
  2707. return agile_width;
  2708. }
  2709. /**
  2710. * target_if_calculate_center_freq() - Helper routine to
  2711. * check whether given frequency is center frequency of a
  2712. * WLAN channel
  2713. *
  2714. * @spectral: Pointer to Spectral object
  2715. * @chan_freq: Center frequency of a WLAN channel
  2716. * @is_valid: Indicates whether given frequency is valid
  2717. *
  2718. * Return: QDF_STATUS
  2719. */
  2720. static QDF_STATUS
  2721. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  2722. uint32_t chan_freq,
  2723. bool *is_valid)
  2724. {
  2725. struct regulatory_channel *cur_chan_list;
  2726. int i;
  2727. if (!pdev) {
  2728. spectral_err("pdev object is null");
  2729. return QDF_STATUS_E_FAILURE;
  2730. }
  2731. if (!is_valid) {
  2732. spectral_err("is valid argument is null");
  2733. return QDF_STATUS_E_FAILURE;
  2734. }
  2735. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  2736. if (!cur_chan_list)
  2737. return QDF_STATUS_E_FAILURE;
  2738. if (wlan_reg_get_current_chan_list(
  2739. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  2740. spectral_err("Failed to get cur_chan list");
  2741. qdf_mem_free(cur_chan_list);
  2742. return QDF_STATUS_E_FAILURE;
  2743. }
  2744. *is_valid = false;
  2745. for (i = 0; i < NUM_CHANNELS; i++) {
  2746. uint32_t flags;
  2747. uint32_t center_freq;
  2748. flags = cur_chan_list[i].chan_flags;
  2749. center_freq = cur_chan_list[i].center_freq;
  2750. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  2751. (center_freq == chan_freq)) {
  2752. *is_valid = true;
  2753. break;
  2754. }
  2755. }
  2756. qdf_mem_free(cur_chan_list);
  2757. return QDF_STATUS_SUCCESS;
  2758. }
  2759. /**
  2760. * target_if_calculate_center_freq() - Helper routine to
  2761. * find the center frequency of the agile span from a
  2762. * WLAN channel center frequency
  2763. *
  2764. * @spectral: Pointer to Spectral object
  2765. * @ch_width: Channel width array
  2766. * @chan_freq: Center frequency of a WLAN channel
  2767. * @center_freq: Pointer to center frequency
  2768. *
  2769. * Return: QDF_STATUS
  2770. */
  2771. static QDF_STATUS
  2772. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  2773. enum phy_ch_width *ch_width,
  2774. uint16_t chan_freq,
  2775. uint16_t *center_freq)
  2776. {
  2777. enum phy_ch_width agile_ch_width;
  2778. if (!spectral) {
  2779. spectral_err("spectral target if object is null");
  2780. return QDF_STATUS_E_FAILURE;
  2781. }
  2782. if (!ch_width) {
  2783. spectral_err("Channel width array is null");
  2784. return QDF_STATUS_E_INVAL;
  2785. }
  2786. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2787. if (!center_freq) {
  2788. spectral_err("center_freq argument is null");
  2789. return QDF_STATUS_E_FAILURE;
  2790. }
  2791. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2792. *center_freq = chan_freq;
  2793. } else {
  2794. uint16_t start_freq;
  2795. uint16_t end_freq;
  2796. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2797. enum channel_state state;
  2798. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2799. (spectral->pdev_obj, chan_freq, agile_ch_width,
  2800. &bonded_chan_ptr);
  2801. if (state == CHANNEL_STATE_DISABLE ||
  2802. state == CHANNEL_STATE_INVALID) {
  2803. spectral_err("Channel state is disable or invalid");
  2804. return QDF_STATUS_E_FAILURE;
  2805. }
  2806. if (!bonded_chan_ptr) {
  2807. spectral_err("Bonded channel is not found");
  2808. return QDF_STATUS_E_FAILURE;
  2809. }
  2810. start_freq = bonded_chan_ptr->start_freq;
  2811. end_freq = bonded_chan_ptr->end_freq;
  2812. *center_freq = (start_freq + end_freq) >> 1;
  2813. }
  2814. return QDF_STATUS_SUCCESS;
  2815. }
  2816. /**
  2817. * target_if_validate_center_freq() - Helper routine to
  2818. * validate user provided agile center frequency
  2819. *
  2820. * @spectral: Pointer to Spectral object
  2821. * @ch_width: Channel width array
  2822. * @center_freq: User provided agile span center frequency
  2823. * @is_valid: Indicates whether agile span center frequency is valid
  2824. *
  2825. * Return: QDF_STATUS
  2826. */
  2827. static QDF_STATUS
  2828. target_if_validate_center_freq(struct target_if_spectral *spectral,
  2829. enum phy_ch_width *ch_width,
  2830. uint16_t center_freq,
  2831. bool *is_valid)
  2832. {
  2833. enum phy_ch_width agile_ch_width;
  2834. struct wlan_objmgr_pdev *pdev;
  2835. QDF_STATUS status;
  2836. if (!spectral) {
  2837. spectral_err("spectral target if object is null");
  2838. return QDF_STATUS_E_FAILURE;
  2839. }
  2840. if (!ch_width) {
  2841. spectral_err("channel width array is null");
  2842. return QDF_STATUS_E_INVAL;
  2843. }
  2844. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2845. if (!is_valid) {
  2846. spectral_err("is_valid argument is null");
  2847. return QDF_STATUS_E_FAILURE;
  2848. }
  2849. pdev = spectral->pdev_obj;
  2850. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2851. status = target_if_is_center_freq_of_any_chan
  2852. (pdev, center_freq, is_valid);
  2853. if (QDF_IS_STATUS_ERROR(status))
  2854. return QDF_STATUS_E_FAILURE;
  2855. } else {
  2856. uint16_t start_freq;
  2857. uint16_t end_freq;
  2858. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2859. bool is_chan;
  2860. status = target_if_is_center_freq_of_any_chan
  2861. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2862. &is_chan);
  2863. if (QDF_IS_STATUS_ERROR(status))
  2864. return QDF_STATUS_E_FAILURE;
  2865. if (is_chan) {
  2866. uint32_t calulated_center_freq;
  2867. enum channel_state st;
  2868. st = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2869. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2870. agile_ch_width,
  2871. &bonded_chan_ptr);
  2872. if (st == CHANNEL_STATE_DISABLE ||
  2873. st == CHANNEL_STATE_INVALID) {
  2874. spectral_err("Channel state disable/invalid");
  2875. return QDF_STATUS_E_FAILURE;
  2876. }
  2877. if (!bonded_chan_ptr) {
  2878. spectral_err("Bonded channel is not found");
  2879. return QDF_STATUS_E_FAILURE;
  2880. }
  2881. start_freq = bonded_chan_ptr->start_freq;
  2882. end_freq = bonded_chan_ptr->end_freq;
  2883. calulated_center_freq = (start_freq + end_freq) >> 1;
  2884. *is_valid = (center_freq == calulated_center_freq);
  2885. } else {
  2886. *is_valid = false;
  2887. }
  2888. }
  2889. return QDF_STATUS_SUCCESS;
  2890. }
  2891. /**
  2892. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  2893. * check whether agile span overlaps with current operating band.
  2894. *
  2895. * @spectral: Pointer to Spectral object
  2896. * @ch_width: Channel width array
  2897. * @center_freq: Agile span center frequency
  2898. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  2899. *
  2900. * Helper routine to check whether agile span overlaps with current
  2901. * operating band.
  2902. *
  2903. * Return: QDF_STATUS
  2904. */
  2905. static QDF_STATUS
  2906. target_if_is_agile_span_overlap_with_operating_span
  2907. (struct target_if_spectral *spectral,
  2908. enum phy_ch_width *ch_width,
  2909. struct spectral_config_frequency *center_freq,
  2910. bool *is_overlapping)
  2911. {
  2912. enum phy_ch_width op_ch_width;
  2913. enum phy_ch_width agile_ch_width;
  2914. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2915. struct wlan_objmgr_vdev *vdev;
  2916. struct wlan_objmgr_pdev *pdev;
  2917. int16_t chan_freq;
  2918. uint32_t op_start_freq;
  2919. uint32_t op_end_freq;
  2920. uint32_t agile_start_freq;
  2921. uint32_t agile_end_freq;
  2922. uint32_t cfreq2;
  2923. if (!spectral) {
  2924. spectral_err("Spectral object is NULL");
  2925. return QDF_STATUS_E_FAILURE;
  2926. }
  2927. pdev = spectral->pdev_obj;
  2928. if (!pdev) {
  2929. spectral_err("pdev object is NULL");
  2930. return QDF_STATUS_E_FAILURE;
  2931. }
  2932. if (!ch_width) {
  2933. spectral_err("channel width array is null");
  2934. return QDF_STATUS_E_FAILURE;
  2935. }
  2936. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  2937. if (op_ch_width == CH_WIDTH_INVALID) {
  2938. spectral_err("Invalid channel width");
  2939. return QDF_STATUS_E_INVAL;
  2940. }
  2941. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2942. if (agile_ch_width == CH_WIDTH_INVALID) {
  2943. spectral_err("Invalid channel width");
  2944. return QDF_STATUS_E_INVAL;
  2945. }
  2946. if (!is_overlapping) {
  2947. spectral_err("Argument(is_overlapping) is NULL");
  2948. return QDF_STATUS_E_FAILURE;
  2949. }
  2950. *is_overlapping = false;
  2951. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  2952. if (!vdev) {
  2953. spectral_err("vdev is NULL");
  2954. return QDF_STATUS_E_FAILURE;
  2955. }
  2956. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2957. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2958. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2959. if (cfreq2 < 0) {
  2960. spectral_err("cfreq2 is invalid");
  2961. return QDF_STATUS_E_FAILURE;
  2962. }
  2963. if (op_ch_width == CH_WIDTH_20MHZ) {
  2964. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  2965. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  2966. } else {
  2967. enum channel_state state;
  2968. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2969. (pdev, chan_freq, op_ch_width, &bonded_chan_ptr);
  2970. if (state == CHANNEL_STATE_DISABLE ||
  2971. state == CHANNEL_STATE_INVALID) {
  2972. spectral_err("Channel state is disable or invalid");
  2973. return QDF_STATUS_E_FAILURE;
  2974. }
  2975. if (!bonded_chan_ptr) {
  2976. spectral_err("Bonded channel is not found");
  2977. return QDF_STATUS_E_FAILURE;
  2978. }
  2979. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  2980. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  2981. }
  2982. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  2983. agile_start_freq = center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  2984. agile_end_freq = center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  2985. if (agile_end_freq > op_start_freq &&
  2986. op_end_freq > agile_start_freq)
  2987. *is_overlapping = true;
  2988. agile_start_freq = center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  2989. agile_end_freq = center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  2990. if (agile_end_freq > op_start_freq &&
  2991. op_end_freq > agile_start_freq)
  2992. *is_overlapping = true;
  2993. } else {
  2994. agile_start_freq = center_freq->cfreq1 -
  2995. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2996. agile_end_freq = center_freq->cfreq1 +
  2997. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2998. if (agile_end_freq > op_start_freq &&
  2999. op_end_freq > agile_start_freq)
  3000. *is_overlapping = true;
  3001. }
  3002. if (op_ch_width == CH_WIDTH_80P80MHZ) {
  3003. uint32_t sec80_start_feq;
  3004. uint32_t sec80_end_freq;
  3005. sec80_start_feq = cfreq2 - FREQ_OFFSET_40MHZ;
  3006. sec80_end_freq = cfreq2 + FREQ_OFFSET_40MHZ;
  3007. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3008. agile_start_freq =
  3009. center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3010. agile_end_freq =
  3011. center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3012. if (agile_end_freq > sec80_start_feq &&
  3013. sec80_end_freq > agile_start_freq)
  3014. *is_overlapping = true;
  3015. agile_start_freq =
  3016. center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3017. agile_end_freq =
  3018. center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3019. if (agile_end_freq > sec80_start_feq &&
  3020. sec80_end_freq > agile_start_freq)
  3021. *is_overlapping = true;
  3022. } else {
  3023. agile_start_freq = center_freq->cfreq1 -
  3024. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3025. agile_end_freq = center_freq->cfreq1 +
  3026. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3027. if (agile_end_freq > sec80_start_feq &&
  3028. sec80_end_freq > agile_start_freq)
  3029. *is_overlapping = true;
  3030. }
  3031. }
  3032. return QDF_STATUS_SUCCESS;
  3033. }
  3034. /**
  3035. * target_if_spectral_populate_chwidth() - Helper routine to
  3036. * populate channel width for different Spectral modes
  3037. *
  3038. * @spectral: Pointer to Spectral object
  3039. * @ch_width: Channel width array
  3040. * @is_80_80_agile: Indicates whether 80+80 agile scan is requested
  3041. *
  3042. * Helper routine to populate channel width for different Spectral modes
  3043. *
  3044. * Return: QDF_STATUS
  3045. */
  3046. static QDF_STATUS
  3047. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral,
  3048. enum phy_ch_width *ch_width,
  3049. bool is_80_80_agile) {
  3050. struct wlan_objmgr_vdev *vdev;
  3051. enum spectral_scan_mode smode;
  3052. enum phy_ch_width vdev_ch_width;
  3053. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3054. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  3055. ch_width[smode] = CH_WIDTH_INVALID;
  3056. if (!spectral) {
  3057. spectral_err("Spectral object is null");
  3058. return QDF_STATUS_E_INVAL;
  3059. }
  3060. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_NORMAL);
  3061. if (!vdev) {
  3062. spectral_err("vdev is null");
  3063. return QDF_STATUS_E_FAILURE;
  3064. }
  3065. vdev_ch_width = target_if_vdev_get_ch_width(vdev);
  3066. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3067. if (vdev_ch_width == CH_WIDTH_INVALID) {
  3068. spectral_err("Invalid channel width %d", vdev_ch_width);
  3069. return QDF_STATUS_E_FAILURE;
  3070. }
  3071. ch_width[SPECTRAL_SCAN_MODE_NORMAL] = vdev_ch_width;
  3072. ch_width[SPECTRAL_SCAN_MODE_AGILE] =
  3073. target_if_spectral_find_agile_width(spectral, vdev_ch_width,
  3074. is_80_80_agile);
  3075. return QDF_STATUS_SUCCESS;
  3076. }
  3077. /**
  3078. * target_if_spectral_is_valid_80p80_freq() - API to check whether given
  3079. * (cfreq1, cfreq2) pair forms a valid 80+80 combination
  3080. * @pdev: pointer to pdev
  3081. * @cfreq1: center frequency 1
  3082. * @cfreq2: center frequency 2
  3083. *
  3084. * API to check whether given (cfreq1, cfreq2) pair forms a valid 80+80
  3085. * combination
  3086. *
  3087. * Return: true or false
  3088. */
  3089. static bool
  3090. target_if_spectral_is_valid_80p80_freq(struct wlan_objmgr_pdev *pdev,
  3091. uint32_t cfreq1, uint32_t cfreq2)
  3092. {
  3093. struct ch_params ch_params;
  3094. enum channel_state chan_state1;
  3095. enum channel_state chan_state2;
  3096. struct wlan_objmgr_psoc *psoc;
  3097. qdf_assert_always(pdev);
  3098. psoc = wlan_pdev_get_psoc(pdev);
  3099. qdf_assert_always(psoc);
  3100. /* In restricted 80P80 MHz enabled, only one 80+80 MHz
  3101. * channel is supported with cfreq=5690 and cfreq=5775.
  3102. */
  3103. if (wlan_psoc_nif_fw_ext_cap_get(
  3104. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  3105. return CHAN_WITHIN_RESTRICTED_80P80(cfreq1, cfreq2);
  3106. ch_params.center_freq_seg1 = wlan_reg_freq_to_chan(pdev, cfreq2);
  3107. ch_params.mhz_freq_seg1 = cfreq2;
  3108. ch_params.ch_width = CH_WIDTH_80P80MHZ;
  3109. wlan_reg_set_channel_params_for_freq(pdev, cfreq1 - FREQ_OFFSET_10MHZ,
  3110. 0, &ch_params);
  3111. if (ch_params.ch_width != CH_WIDTH_80P80MHZ)
  3112. return false;
  3113. if (ch_params.mhz_freq_seg0 != cfreq1 ||
  3114. ch_params.mhz_freq_seg1 != cfreq2)
  3115. return false;
  3116. chan_state1 = wlan_reg_get_5g_bonded_channel_state_for_freq(
  3117. pdev,
  3118. ch_params.mhz_freq_seg0 - FREQ_OFFSET_10MHZ,
  3119. CH_WIDTH_80MHZ);
  3120. if ((chan_state1 == CHANNEL_STATE_DISABLE) ||
  3121. (chan_state1 == CHANNEL_STATE_INVALID))
  3122. return false;
  3123. chan_state2 = wlan_reg_get_5g_bonded_channel_state_for_freq(
  3124. pdev,
  3125. ch_params.mhz_freq_seg1 - FREQ_OFFSET_10MHZ,
  3126. CH_WIDTH_80MHZ);
  3127. if ((chan_state2 == CHANNEL_STATE_DISABLE) ||
  3128. (chan_state2 == CHANNEL_STATE_INVALID))
  3129. return false;
  3130. if (abs(ch_params.mhz_freq_seg0 - ch_params.mhz_freq_seg1) <=
  3131. FREQ_OFFSET_80MHZ)
  3132. return false;
  3133. return true;
  3134. }
  3135. /**
  3136. * _target_if_set_spectral_config() - Set spectral config
  3137. * @spectral: Pointer to spectral object
  3138. * @param: Spectral parameter id and value
  3139. * @smode: Spectral scan mode
  3140. * @err: Spectral error code
  3141. *
  3142. * API to set spectral configurations
  3143. *
  3144. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3145. */
  3146. static QDF_STATUS
  3147. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  3148. const struct spectral_cp_param *param,
  3149. const enum spectral_scan_mode smode,
  3150. enum spectral_cp_error_code *err)
  3151. {
  3152. struct spectral_config params;
  3153. struct target_if_spectral_ops *p_sops;
  3154. struct spectral_config *sparams;
  3155. QDF_STATUS status;
  3156. bool is_overlapping;
  3157. uint16_t agile_cfreq;
  3158. bool is_valid_chan;
  3159. struct spectral_param_min_max *param_min_max;
  3160. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  3161. enum spectral_scan_mode m;
  3162. struct spectral_config_frequency center_freq = {0};
  3163. if (!err) {
  3164. spectral_err("Error code argument is null");
  3165. QDF_ASSERT(0);
  3166. return QDF_STATUS_E_FAILURE;
  3167. }
  3168. *err = SPECTRAL_SCAN_ERR_INVALID;
  3169. if (!param) {
  3170. spectral_err("Parameter object is null");
  3171. return QDF_STATUS_E_FAILURE;
  3172. }
  3173. if (!spectral) {
  3174. spectral_err("spectral object is NULL");
  3175. return QDF_STATUS_E_FAILURE;
  3176. }
  3177. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3178. param_min_max = &spectral->param_min_max;
  3179. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3180. spectral_err("Invalid Spectral mode %u", smode);
  3181. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3182. return QDF_STATUS_E_FAILURE;
  3183. }
  3184. sparams = &spectral->params[smode];
  3185. m = SPECTRAL_SCAN_MODE_NORMAL;
  3186. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  3187. ch_width[m] = CH_WIDTH_INVALID;
  3188. if (!spectral->params_valid[smode]) {
  3189. target_if_spectral_info_read(spectral,
  3190. smode,
  3191. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3192. &spectral->params[smode],
  3193. sizeof(spectral->params[smode]));
  3194. spectral->params_valid[smode] = true;
  3195. }
  3196. switch (param->id) {
  3197. case SPECTRAL_PARAM_FFT_PERIOD:
  3198. sparams->ss_fft_period = param->value;
  3199. break;
  3200. case SPECTRAL_PARAM_SCAN_PERIOD:
  3201. sparams->ss_period = param->value;
  3202. break;
  3203. case SPECTRAL_PARAM_SCAN_COUNT:
  3204. sparams->ss_count = param->value;
  3205. break;
  3206. case SPECTRAL_PARAM_SHORT_REPORT:
  3207. sparams->ss_short_report = (!!param->value) ? true : false;
  3208. break;
  3209. case SPECTRAL_PARAM_SPECT_PRI:
  3210. sparams->ss_spectral_pri = (!!param->value) ? true : false;
  3211. break;
  3212. case SPECTRAL_PARAM_FFT_SIZE:
  3213. status = target_if_spectral_populate_chwidth
  3214. (spectral, ch_width, spectral->params
  3215. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  3216. if (QDF_IS_STATUS_ERROR(status))
  3217. return QDF_STATUS_E_FAILURE;
  3218. if ((param->value < param_min_max->fft_size_min) ||
  3219. (param->value > param_min_max->fft_size_max
  3220. [ch_width[smode]])) {
  3221. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3222. return QDF_STATUS_E_FAILURE;
  3223. }
  3224. sparams->ss_fft_size = param->value;
  3225. break;
  3226. case SPECTRAL_PARAM_GC_ENA:
  3227. sparams->ss_gc_ena = !!param->value;
  3228. break;
  3229. case SPECTRAL_PARAM_RESTART_ENA:
  3230. sparams->ss_restart_ena = !!param->value;
  3231. break;
  3232. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  3233. sparams->ss_noise_floor_ref = param->value;
  3234. break;
  3235. case SPECTRAL_PARAM_INIT_DELAY:
  3236. sparams->ss_init_delay = param->value;
  3237. break;
  3238. case SPECTRAL_PARAM_NB_TONE_THR:
  3239. sparams->ss_nb_tone_thr = param->value;
  3240. break;
  3241. case SPECTRAL_PARAM_STR_BIN_THR:
  3242. sparams->ss_str_bin_thr = param->value;
  3243. break;
  3244. case SPECTRAL_PARAM_WB_RPT_MODE:
  3245. sparams->ss_wb_rpt_mode = !!param->value;
  3246. break;
  3247. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  3248. sparams->ss_rssi_rpt_mode = !!param->value;
  3249. break;
  3250. case SPECTRAL_PARAM_RSSI_THR:
  3251. sparams->ss_rssi_thr = param->value;
  3252. break;
  3253. case SPECTRAL_PARAM_PWR_FORMAT:
  3254. sparams->ss_pwr_format = !!param->value;
  3255. break;
  3256. case SPECTRAL_PARAM_RPT_MODE:
  3257. if ((param->value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  3258. (param->value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  3259. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3260. return QDF_STATUS_E_FAILURE;
  3261. }
  3262. sparams->ss_rpt_mode = param->value;
  3263. break;
  3264. case SPECTRAL_PARAM_BIN_SCALE:
  3265. sparams->ss_bin_scale = param->value;
  3266. break;
  3267. case SPECTRAL_PARAM_DBM_ADJ:
  3268. sparams->ss_dbm_adj = !!param->value;
  3269. break;
  3270. case SPECTRAL_PARAM_CHN_MASK:
  3271. sparams->ss_chn_mask = param->value;
  3272. break;
  3273. case SPECTRAL_PARAM_FREQUENCY:
  3274. status = target_if_spectral_populate_chwidth(
  3275. spectral, ch_width, param->freq.cfreq2 > 0);
  3276. if (QDF_IS_STATUS_ERROR(status)) {
  3277. spectral_err("Failed to populate channel width");
  3278. return QDF_STATUS_E_FAILURE;
  3279. }
  3280. if (ch_width[smode] != CH_WIDTH_80P80MHZ &&
  3281. param->freq.cfreq2) {
  3282. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3283. spectral_err("Non zero cfreq2 expected for 80p80 only");
  3284. return QDF_STATUS_E_INVAL;
  3285. }
  3286. if (ch_width[smode] == CH_WIDTH_80P80MHZ &&
  3287. !param->freq.cfreq2) {
  3288. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3289. spectral_err("Non zero cfreq2 expected for 80p80");
  3290. return QDF_STATUS_E_INVAL;
  3291. }
  3292. status = target_if_is_center_freq_of_any_chan
  3293. (spectral->pdev_obj, param->freq.cfreq1,
  3294. &is_valid_chan);
  3295. if (QDF_IS_STATUS_ERROR(status))
  3296. return QDF_STATUS_E_FAILURE;
  3297. if (is_valid_chan) {
  3298. status = target_if_calculate_center_freq(
  3299. spectral, ch_width,
  3300. param->freq.cfreq1,
  3301. &agile_cfreq);
  3302. if (QDF_IS_STATUS_ERROR(status)) {
  3303. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3304. return QDF_STATUS_E_FAILURE;
  3305. }
  3306. } else {
  3307. bool is_valid_agile_cfreq;
  3308. status = target_if_validate_center_freq
  3309. (spectral, ch_width, param->freq.cfreq1,
  3310. &is_valid_agile_cfreq);
  3311. if (QDF_IS_STATUS_ERROR(status))
  3312. return QDF_STATUS_E_FAILURE;
  3313. if (!is_valid_agile_cfreq) {
  3314. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3315. spectral_err("Invalid agile center frequency");
  3316. return QDF_STATUS_E_FAILURE;
  3317. }
  3318. agile_cfreq = param->freq.cfreq1;
  3319. }
  3320. center_freq.cfreq1 = agile_cfreq;
  3321. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  3322. status = target_if_is_center_freq_of_any_chan
  3323. (spectral->pdev_obj, param->freq.cfreq2,
  3324. &is_valid_chan);
  3325. if (QDF_IS_STATUS_ERROR(status))
  3326. return QDF_STATUS_E_FAILURE;
  3327. if (is_valid_chan) {
  3328. status = target_if_calculate_center_freq(
  3329. spectral, ch_width,
  3330. param->freq.cfreq2,
  3331. &agile_cfreq);
  3332. if (QDF_IS_STATUS_ERROR(status)) {
  3333. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3334. return QDF_STATUS_E_FAILURE;
  3335. }
  3336. } else {
  3337. bool is_valid_agile_cfreq;
  3338. status = target_if_validate_center_freq
  3339. (spectral, ch_width, param->freq.cfreq2,
  3340. &is_valid_agile_cfreq);
  3341. if (QDF_IS_STATUS_ERROR(status))
  3342. return QDF_STATUS_E_FAILURE;
  3343. if (!is_valid_agile_cfreq) {
  3344. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3345. spectral_err("Invalid agile center frequency");
  3346. return QDF_STATUS_E_FAILURE;
  3347. }
  3348. agile_cfreq = param->freq.cfreq2;
  3349. }
  3350. center_freq.cfreq2 = agile_cfreq;
  3351. }
  3352. status = target_if_is_agile_span_overlap_with_operating_span
  3353. (spectral, ch_width,
  3354. &center_freq, &is_overlapping);
  3355. if (QDF_IS_STATUS_ERROR(status))
  3356. return QDF_STATUS_E_FAILURE;
  3357. if (is_overlapping) {
  3358. spectral_err("Agile freq %u, %u overlaps with operating span",
  3359. center_freq.cfreq1, center_freq.cfreq2);
  3360. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3361. return QDF_STATUS_E_FAILURE;
  3362. }
  3363. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  3364. bool is_valid_80p80;
  3365. is_valid_80p80 = target_if_spectral_is_valid_80p80_freq(
  3366. spectral->pdev_obj,
  3367. center_freq.cfreq1,
  3368. center_freq.cfreq2);
  3369. if (!is_valid_80p80) {
  3370. spectral_err("Agile freq %u, %u is invalid 80+80 combination",
  3371. center_freq.cfreq1,
  3372. center_freq.cfreq2);
  3373. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3374. return QDF_STATUS_E_FAILURE;
  3375. }
  3376. }
  3377. sparams->ss_frequency.cfreq1 = center_freq.cfreq1;
  3378. sparams->ss_frequency.cfreq2 = center_freq.cfreq2;
  3379. break;
  3380. }
  3381. p_sops->configure_spectral(spectral, sparams, smode);
  3382. /* only to validate the writes */
  3383. p_sops->get_spectral_config(spectral, &params, smode);
  3384. return QDF_STATUS_SUCCESS;
  3385. }
  3386. QDF_STATUS
  3387. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  3388. const struct spectral_cp_param *param,
  3389. const enum spectral_scan_mode smode,
  3390. enum spectral_cp_error_code *err)
  3391. {
  3392. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  3393. struct target_if_spectral *spectral;
  3394. QDF_STATUS status;
  3395. if (!err) {
  3396. spectral_err("Error code argument is null");
  3397. QDF_ASSERT(0);
  3398. return QDF_STATUS_E_FAILURE;
  3399. }
  3400. *err = SPECTRAL_SCAN_ERR_INVALID;
  3401. if (!pdev) {
  3402. spectral_err("pdev object is NULL");
  3403. return QDF_STATUS_E_FAILURE;
  3404. }
  3405. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3406. if (!spectral) {
  3407. spectral_err("spectral object is NULL");
  3408. return QDF_STATUS_E_FAILURE;
  3409. }
  3410. if (!param) {
  3411. spectral_err("parameter object is NULL");
  3412. return QDF_STATUS_E_FAILURE;
  3413. }
  3414. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3415. spectral_err("Invalid Spectral mode %u", smode);
  3416. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3417. return QDF_STATUS_E_FAILURE;
  3418. }
  3419. if (!spectral->properties[smode][param->id].supported) {
  3420. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  3421. param->id, smode);
  3422. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  3423. return QDF_STATUS_E_FAILURE;
  3424. }
  3425. if (spectral->properties[smode][param->id].common_all_modes) {
  3426. spectral_warn("Setting Spectral parameter %u for all modes",
  3427. param->id);
  3428. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  3429. status = _target_if_set_spectral_config
  3430. (spectral, param, mode, err);
  3431. if (QDF_IS_STATUS_ERROR(status))
  3432. return QDF_STATUS_E_FAILURE;
  3433. }
  3434. return QDF_STATUS_SUCCESS;
  3435. }
  3436. return _target_if_set_spectral_config(spectral, param, smode, err);
  3437. }
  3438. /**
  3439. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  3440. * @fft_len: FFT length
  3441. * @pdev: Pointer to pdev object
  3442. *
  3443. * API to get fft bin count for a given fft length
  3444. *
  3445. * Return: FFt bin count
  3446. */
  3447. static int
  3448. target_if_get_fft_bin_count(int fft_len)
  3449. {
  3450. int bin_count = 0;
  3451. switch (fft_len) {
  3452. case 5:
  3453. bin_count = 16;
  3454. break;
  3455. case 6:
  3456. bin_count = 32;
  3457. break;
  3458. case 7:
  3459. bin_count = 64;
  3460. break;
  3461. case 8:
  3462. bin_count = 128;
  3463. break;
  3464. case 9:
  3465. bin_count = 256;
  3466. break;
  3467. default:
  3468. break;
  3469. }
  3470. return bin_count;
  3471. }
  3472. /**
  3473. * target_if_init_upper_lower_flags() - Initializes control and extension
  3474. * segment flags
  3475. * @spectral: pointer to target if spectral object
  3476. * @smode: Spectral scan mode
  3477. *
  3478. * API to initialize the control and extension flags with the lower/upper
  3479. * segment based on the HT mode
  3480. *
  3481. * Return: FFt bin count
  3482. */
  3483. static void
  3484. target_if_init_upper_lower_flags(struct target_if_spectral *spectral,
  3485. enum spectral_scan_mode smode)
  3486. {
  3487. int current_channel = 0;
  3488. int ext_channel = 0;
  3489. struct target_if_spectral_ops *p_sops =
  3490. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3491. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3492. spectral_err("Invalid Spectral mode %u", smode);
  3493. return;
  3494. }
  3495. current_channel = p_sops->get_current_channel(spectral, smode);
  3496. ext_channel = p_sops->get_extension_channel(spectral, smode);
  3497. if ((current_channel == 0) || (ext_channel == 0))
  3498. return;
  3499. if (spectral->sc_spectral_20_40_mode) {
  3500. /* HT40 mode */
  3501. if (ext_channel < current_channel) {
  3502. spectral->lower_is_extension = 1;
  3503. spectral->upper_is_control = 1;
  3504. spectral->lower_is_control = 0;
  3505. spectral->upper_is_extension = 0;
  3506. } else {
  3507. spectral->lower_is_extension = 0;
  3508. spectral->upper_is_control = 0;
  3509. spectral->lower_is_control = 1;
  3510. spectral->upper_is_extension = 1;
  3511. }
  3512. } else {
  3513. /* HT20 mode, lower is always control */
  3514. spectral->lower_is_extension = 0;
  3515. spectral->upper_is_control = 0;
  3516. spectral->lower_is_control = 1;
  3517. spectral->upper_is_extension = 0;
  3518. }
  3519. }
  3520. /**
  3521. * target_if_get_spectral_config() - Get spectral configuration
  3522. * @pdev: Pointer to pdev object
  3523. * @param: Pointer to spectral_config structure in which the configuration
  3524. * should be returned
  3525. * @smode: Spectral scan mode
  3526. *
  3527. * API to get the current spectral configuration
  3528. *
  3529. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3530. */
  3531. QDF_STATUS
  3532. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  3533. struct spectral_config *param,
  3534. enum spectral_scan_mode smode)
  3535. {
  3536. struct target_if_spectral_ops *p_sops = NULL;
  3537. struct target_if_spectral *spectral = NULL;
  3538. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3539. if (!spectral) {
  3540. spectral_err("SPECTRAL : Module doesn't exist");
  3541. return QDF_STATUS_E_FAILURE;
  3542. }
  3543. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3544. if (!p_sops) {
  3545. spectral_err("p_sops is null");
  3546. return QDF_STATUS_E_FAILURE;
  3547. }
  3548. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3549. spectral_err("Invalid Spectral mode %u", smode);
  3550. return QDF_STATUS_E_FAILURE;
  3551. }
  3552. qdf_mem_zero(param, sizeof(struct spectral_config));
  3553. p_sops->get_spectral_config(spectral, param, smode);
  3554. return QDF_STATUS_SUCCESS;
  3555. }
  3556. /**
  3557. * target_if_spectral_get_num_detectors() - Get number of Spectral detectors
  3558. * @spectral: Pointer to target if Spectral object
  3559. * @ch_width: channel width
  3560. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  3561. *
  3562. * API to get number of Spectral detectors used for scan in the given channel
  3563. * width.
  3564. *
  3565. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  3566. */
  3567. static QDF_STATUS
  3568. target_if_spectral_get_num_detectors(struct target_if_spectral *spectral,
  3569. enum phy_ch_width ch_width,
  3570. uint32_t *num_detectors)
  3571. {
  3572. if (!spectral) {
  3573. spectral_err("target if spectral object is null");
  3574. return QDF_STATUS_E_INVAL;
  3575. }
  3576. if (ch_width >= CH_WIDTH_INVALID) {
  3577. spectral_err("Invalid channel width %d", ch_width);
  3578. return QDF_STATUS_E_INVAL;
  3579. }
  3580. if (!num_detectors) {
  3581. spectral_err("Invalid argument, number of detectors");
  3582. return QDF_STATUS_E_INVAL;
  3583. }
  3584. switch (ch_width) {
  3585. case CH_WIDTH_20MHZ:
  3586. *num_detectors = spectral->capability.num_detectors_20mhz;
  3587. break;
  3588. case CH_WIDTH_40MHZ:
  3589. *num_detectors = spectral->capability.num_detectors_40mhz;
  3590. break;
  3591. case CH_WIDTH_80MHZ:
  3592. *num_detectors = spectral->capability.num_detectors_80mhz;
  3593. break;
  3594. case CH_WIDTH_160MHZ:
  3595. *num_detectors = spectral->capability.num_detectors_160mhz;
  3596. break;
  3597. case CH_WIDTH_80P80MHZ:
  3598. *num_detectors = spectral->capability.num_detectors_80p80mhz;
  3599. break;
  3600. default:
  3601. spectral_err("Unsupported channel width %d", ch_width);
  3602. return QDF_STATUS_E_INVAL;
  3603. }
  3604. return QDF_STATUS_SUCCESS;
  3605. }
  3606. /**
  3607. * target_if_spectral_finite_scan_init() - Initializations required for finite
  3608. * Spectral scan
  3609. * @spectral: Pointer to target of Spctral object
  3610. * @smode: Spectral scan mode
  3611. *
  3612. * This routine initializes the finite Spectral scan. Finite Spectral scan is
  3613. * triggered by configuring a non zero scan count.
  3614. *
  3615. * Return: QDF_STATUS_SUCCESS on success
  3616. */
  3617. static QDF_STATUS
  3618. target_if_spectral_finite_scan_init(struct target_if_spectral *spectral,
  3619. enum spectral_scan_mode smode)
  3620. {
  3621. struct target_if_finite_spectral_scan_params *finite_scan;
  3622. enum phy_ch_width ch_width;
  3623. uint32_t num_detectors;
  3624. QDF_STATUS status;
  3625. uint16_t sscan_count;
  3626. if (!spectral) {
  3627. spectral_err("target if spectral object is null");
  3628. return QDF_STATUS_E_INVAL;
  3629. }
  3630. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3631. spectral_err("Invalid Spectral mode");
  3632. return QDF_STATUS_E_INVAL;
  3633. }
  3634. ch_width = spectral->ch_width[smode];
  3635. status = target_if_spectral_get_num_detectors(spectral, ch_width,
  3636. &num_detectors);
  3637. if (QDF_IS_STATUS_ERROR(status)) {
  3638. spectral_err("Failed to get number of detectors");
  3639. return QDF_STATUS_E_FAILURE;
  3640. }
  3641. finite_scan = &spectral->finite_scan[smode];
  3642. sscan_count = spectral->params[smode].ss_count;
  3643. finite_scan->finite_spectral_scan = true;
  3644. finite_scan->num_reports_expected = num_detectors * sscan_count;
  3645. return QDF_STATUS_SUCCESS;
  3646. }
  3647. /**
  3648. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  3649. * parameters
  3650. * @spectral: Pointer to Spectral target_if internal private data
  3651. * @spectral_params: Pointer to Spectral parameters
  3652. * @smode: Spectral scan mode
  3653. * @err: Spectral error code
  3654. *
  3655. * Enable use of desired Spectral parameters by configuring them into HW, and
  3656. * starting Spectral scan
  3657. *
  3658. * Return: 0 on success, 1 on failure
  3659. */
  3660. int
  3661. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  3662. struct spectral_config *spectral_params,
  3663. enum spectral_scan_mode smode,
  3664. enum spectral_cp_error_code *err)
  3665. {
  3666. int extension_channel = 0;
  3667. int current_channel = 0;
  3668. struct target_if_spectral_ops *p_sops = NULL;
  3669. QDF_STATUS status;
  3670. struct wlan_objmgr_pdev *pdev;
  3671. struct wlan_objmgr_psoc *psoc;
  3672. if (!spectral) {
  3673. spectral_err("Spectral LMAC object is NULL");
  3674. return 1;
  3675. }
  3676. pdev = spectral->pdev_obj;
  3677. if (!pdev) {
  3678. spectral_err("pdev is null");
  3679. return QDF_STATUS_E_INVAL;
  3680. }
  3681. psoc = wlan_pdev_get_psoc(pdev);
  3682. if (!psoc) {
  3683. spectral_err("psoc is null");
  3684. return QDF_STATUS_E_INVAL;
  3685. }
  3686. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3687. spectral_err("Invalid Spectral mode %u", smode);
  3688. return 1;
  3689. }
  3690. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3691. if (!p_sops) {
  3692. spectral_err("p_sops is NULL");
  3693. return 1;
  3694. }
  3695. spectral->sc_spectral_noise_pwr_cal =
  3696. spectral_params->ss_spectral_pri ? 1 : 0;
  3697. /* check if extension channel is present */
  3698. extension_channel = p_sops->get_extension_channel(spectral, smode);
  3699. current_channel = p_sops->get_current_channel(spectral, smode);
  3700. status = target_if_spectral_populate_chwidth(
  3701. spectral, spectral->ch_width,
  3702. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  3703. ss_frequency.cfreq2 > 0);
  3704. if (QDF_IS_STATUS_ERROR(status)) {
  3705. spectral_err("Failed to get channel widths");
  3706. return 1;
  3707. }
  3708. if (spectral->capability.advncd_spectral_cap) {
  3709. spectral->lb_edge_extrabins = 0;
  3710. spectral->rb_edge_extrabins = 0;
  3711. if (spectral->is_lb_edge_extrabins_format &&
  3712. spectral->params[smode].ss_rpt_mode == 2) {
  3713. spectral->lb_edge_extrabins = 4;
  3714. }
  3715. if (spectral->is_rb_edge_extrabins_format &&
  3716. spectral->params[smode].ss_rpt_mode == 2) {
  3717. spectral->rb_edge_extrabins = 4;
  3718. }
  3719. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  3720. spectral->sc_spectral_20_40_mode = 0;
  3721. spectral->spectral_numbins =
  3722. target_if_get_fft_bin_count(
  3723. spectral->params[smode].ss_fft_size);
  3724. spectral->spectral_fft_len =
  3725. target_if_get_fft_bin_count(
  3726. spectral->params[smode].ss_fft_size);
  3727. spectral->spectral_data_len =
  3728. target_if_get_fft_bin_count(
  3729. spectral->params[smode].ss_fft_size);
  3730. /*
  3731. * Initialize classifier params to be sent to user
  3732. * space classifier
  3733. */
  3734. spectral->classifier_params.lower_chan_in_mhz =
  3735. current_channel;
  3736. spectral->classifier_params.upper_chan_in_mhz = 0;
  3737. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  3738. /* TODO : Remove this variable */
  3739. spectral->sc_spectral_20_40_mode = 1;
  3740. spectral->spectral_numbins =
  3741. target_if_get_fft_bin_count(
  3742. spectral->params[smode].ss_fft_size);
  3743. spectral->spectral_fft_len =
  3744. target_if_get_fft_bin_count(
  3745. spectral->params[smode].ss_fft_size);
  3746. spectral->spectral_data_len =
  3747. target_if_get_fft_bin_count(
  3748. spectral->params[smode].ss_fft_size);
  3749. /*
  3750. * Initialize classifier params to be sent to user
  3751. * space classifier
  3752. */
  3753. if (extension_channel < current_channel) {
  3754. spectral->classifier_params.lower_chan_in_mhz =
  3755. extension_channel;
  3756. spectral->classifier_params.upper_chan_in_mhz =
  3757. current_channel;
  3758. } else {
  3759. spectral->classifier_params.lower_chan_in_mhz =
  3760. current_channel;
  3761. spectral->classifier_params.upper_chan_in_mhz =
  3762. extension_channel;
  3763. }
  3764. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  3765. /* Set the FFT Size */
  3766. /* TODO : Remove this variable */
  3767. spectral->sc_spectral_20_40_mode = 0;
  3768. spectral->spectral_numbins =
  3769. target_if_get_fft_bin_count(
  3770. spectral->params[smode].ss_fft_size);
  3771. spectral->spectral_fft_len =
  3772. target_if_get_fft_bin_count(
  3773. spectral->params[smode].ss_fft_size);
  3774. spectral->spectral_data_len =
  3775. target_if_get_fft_bin_count(
  3776. spectral->params[smode].ss_fft_size);
  3777. /*
  3778. * Initialize classifier params to be sent to user
  3779. * space classifier
  3780. */
  3781. spectral->classifier_params.lower_chan_in_mhz =
  3782. current_channel;
  3783. spectral->classifier_params.upper_chan_in_mhz = 0;
  3784. /*
  3785. * Initialize classifier params to be sent to user
  3786. * space classifier
  3787. */
  3788. if (extension_channel < current_channel) {
  3789. spectral->classifier_params.lower_chan_in_mhz =
  3790. extension_channel;
  3791. spectral->classifier_params.upper_chan_in_mhz =
  3792. current_channel;
  3793. } else {
  3794. spectral->classifier_params.lower_chan_in_mhz =
  3795. current_channel;
  3796. spectral->classifier_params.upper_chan_in_mhz =
  3797. extension_channel;
  3798. }
  3799. } else if (is_ch_width_160_or_80p80(
  3800. spectral->ch_width[smode])) {
  3801. /* Set the FFT Size */
  3802. /* The below applies to both 160 and 80+80 cases */
  3803. /* TODO : Remove this variable */
  3804. spectral->sc_spectral_20_40_mode = 0;
  3805. spectral->spectral_numbins =
  3806. target_if_get_fft_bin_count(
  3807. spectral->params[smode].ss_fft_size);
  3808. spectral->spectral_fft_len =
  3809. target_if_get_fft_bin_count(
  3810. spectral->params[smode].ss_fft_size);
  3811. spectral->spectral_data_len =
  3812. target_if_get_fft_bin_count(
  3813. spectral->params[smode].ss_fft_size);
  3814. /*
  3815. * Initialize classifier params to be sent to user
  3816. * space classifier
  3817. */
  3818. spectral->classifier_params.lower_chan_in_mhz =
  3819. current_channel;
  3820. spectral->classifier_params.upper_chan_in_mhz = 0;
  3821. /*
  3822. * Initialize classifier params to be sent to user
  3823. * space classifier
  3824. */
  3825. if (extension_channel < current_channel) {
  3826. spectral->classifier_params.lower_chan_in_mhz =
  3827. extension_channel;
  3828. spectral->classifier_params.upper_chan_in_mhz =
  3829. current_channel;
  3830. } else {
  3831. spectral->classifier_params.lower_chan_in_mhz =
  3832. current_channel;
  3833. spectral->classifier_params.upper_chan_in_mhz =
  3834. extension_channel;
  3835. }
  3836. }
  3837. if (spectral->spectral_numbins) {
  3838. spectral->spectral_numbins +=
  3839. spectral->lb_edge_extrabins;
  3840. spectral->spectral_numbins +=
  3841. spectral->rb_edge_extrabins;
  3842. }
  3843. if (spectral->spectral_fft_len) {
  3844. spectral->spectral_fft_len +=
  3845. spectral->lb_edge_extrabins;
  3846. spectral->spectral_fft_len +=
  3847. spectral->rb_edge_extrabins;
  3848. }
  3849. if (spectral->spectral_data_len) {
  3850. spectral->spectral_data_len +=
  3851. spectral->lb_edge_extrabins;
  3852. spectral->spectral_data_len +=
  3853. spectral->rb_edge_extrabins;
  3854. }
  3855. } else {
  3856. /*
  3857. * The decision to find 20/40 mode is found based on the
  3858. * presence of extension channel
  3859. * instead of channel width, as the channel width can
  3860. * dynamically change
  3861. */
  3862. if (extension_channel == 0) {
  3863. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  3864. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  3865. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  3866. spectral->spectral_data_len =
  3867. SPECTRAL_HT20_TOTAL_DATA_LEN;
  3868. /* only valid in 20-40 mode */
  3869. spectral->spectral_lower_max_index_offset = -1;
  3870. /* only valid in 20-40 mode */
  3871. spectral->spectral_upper_max_index_offset = -1;
  3872. spectral->spectral_max_index_offset =
  3873. spectral->spectral_fft_len + 2;
  3874. spectral->sc_spectral_20_40_mode = 0;
  3875. /*
  3876. * Initialize classifier params to be sent to user
  3877. * space classifier
  3878. */
  3879. spectral->classifier_params.lower_chan_in_mhz =
  3880. current_channel;
  3881. spectral->classifier_params.upper_chan_in_mhz = 0;
  3882. } else {
  3883. spectral->spectral_numbins =
  3884. SPECTRAL_HT40_TOTAL_NUM_BINS;
  3885. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  3886. spectral->spectral_data_len =
  3887. SPECTRAL_HT40_TOTAL_DATA_LEN;
  3888. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  3889. /* only valid in 20 mode */
  3890. spectral->spectral_max_index_offset = -1;
  3891. spectral->spectral_lower_max_index_offset =
  3892. spectral->spectral_fft_len + 2;
  3893. spectral->spectral_upper_max_index_offset =
  3894. spectral->spectral_fft_len + 5;
  3895. spectral->sc_spectral_20_40_mode = 1;
  3896. /*
  3897. * Initialize classifier params to be sent to user
  3898. * space classifier
  3899. */
  3900. if (extension_channel < current_channel) {
  3901. spectral->classifier_params.lower_chan_in_mhz =
  3902. extension_channel;
  3903. spectral->classifier_params.upper_chan_in_mhz =
  3904. current_channel;
  3905. } else {
  3906. spectral->classifier_params.lower_chan_in_mhz =
  3907. current_channel;
  3908. spectral->classifier_params.upper_chan_in_mhz =
  3909. extension_channel;
  3910. }
  3911. }
  3912. }
  3913. spectral->send_single_packet = 0;
  3914. spectral->classifier_params.spectral_20_40_mode =
  3915. spectral->sc_spectral_20_40_mode;
  3916. spectral->classifier_params.spectral_dc_index =
  3917. spectral->spectral_dc_index;
  3918. spectral->spectral_sent_msg = 0;
  3919. spectral->classify_scan = 0;
  3920. spectral->num_spectral_data = 0;
  3921. if (!p_sops->is_spectral_active(spectral, smode)) {
  3922. p_sops->configure_spectral(spectral, spectral_params, smode);
  3923. spectral->rparams.marker[smode].is_valid = false;
  3924. if (spectral->params[smode].ss_count) {
  3925. status = target_if_spectral_finite_scan_init(spectral,
  3926. smode);
  3927. if (QDF_IS_STATUS_ERROR(status)) {
  3928. spectral_err("Failed to init finite scan");
  3929. return 1;
  3930. }
  3931. }
  3932. p_sops->start_spectral_scan(spectral, smode, err);
  3933. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  3934. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  3935. }
  3936. /* get current spectral configuration */
  3937. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  3938. target_if_init_upper_lower_flags(spectral, smode);
  3939. return 0;
  3940. }
  3941. /**
  3942. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  3943. * Agile DFS
  3944. * @psoc: Pointer to psoc
  3945. * @object: Pointer to pdev
  3946. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  3947. *
  3948. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  3949. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  3950. *
  3951. * Return: void
  3952. */
  3953. static void
  3954. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  3955. void *object, void *arg)
  3956. {
  3957. bool *is_aspectral_prohibited = arg;
  3958. struct wlan_objmgr_pdev *cur_pdev = object;
  3959. bool is_agile_precac_enabled_cur_pdev = false;
  3960. bool is_agile_rcac_enabled_cur_pdev = false;
  3961. QDF_STATUS status;
  3962. qdf_assert_always(is_aspectral_prohibited);
  3963. if (*is_aspectral_prohibited)
  3964. return;
  3965. qdf_assert_always(psoc);
  3966. qdf_assert_always(cur_pdev);
  3967. status = ucfg_dfs_get_agile_precac_enable
  3968. (cur_pdev,
  3969. &is_agile_precac_enabled_cur_pdev);
  3970. if (QDF_IS_STATUS_ERROR(status)) {
  3971. spectral_err("Get agile precac failed, prohibiting aSpectral");
  3972. *is_aspectral_prohibited = true;
  3973. return;
  3974. }
  3975. status = ucfg_dfs_get_rcac_enable(cur_pdev,
  3976. &is_agile_rcac_enabled_cur_pdev);
  3977. if (QDF_IS_STATUS_ERROR(status)) {
  3978. spectral_err("Get agile RCAC failed, prohibiting aSpectral");
  3979. *is_aspectral_prohibited = true;
  3980. return;
  3981. }
  3982. if (is_agile_precac_enabled_cur_pdev) {
  3983. spectral_err("aDFS preCAC is in progress on one of the pdevs");
  3984. *is_aspectral_prohibited = true;
  3985. } else if (is_agile_rcac_enabled_cur_pdev) {
  3986. spectral_err("aDFS RCAC is in progress on one of the pdevs");
  3987. *is_aspectral_prohibited = true;
  3988. }
  3989. }
  3990. /**
  3991. * target_if_get_curr_band() - Get current operating band of pdev
  3992. *
  3993. * @pdev: pointer to pdev object
  3994. *
  3995. * API to get current operating band of a given pdev.
  3996. *
  3997. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  3998. */
  3999. static enum reg_wifi_band
  4000. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id)
  4001. {
  4002. struct wlan_objmgr_vdev *vdev;
  4003. int16_t chan_freq;
  4004. enum reg_wifi_band cur_band;
  4005. if (!pdev) {
  4006. spectral_err("pdev is NULL");
  4007. return REG_BAND_UNKNOWN;
  4008. }
  4009. if (vdev_id == WLAN_INVALID_VDEV_ID)
  4010. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  4011. else
  4012. vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, vdev_id,
  4013. WLAN_SPECTRAL_ID);
  4014. if (!vdev) {
  4015. spectral_debug("vdev is NULL");
  4016. return REG_BAND_UNKNOWN;
  4017. }
  4018. chan_freq = target_if_vdev_get_chan_freq(vdev);
  4019. cur_band = wlan_reg_freq_to_band(chan_freq);
  4020. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4021. return cur_band;
  4022. }
  4023. /**
  4024. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  4025. * any of the 5G pdevs
  4026. * @psoc: Pointer to psoc
  4027. * @object: Pointer to pdev
  4028. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  4029. * progress in any 5G pdevs
  4030. *
  4031. * Return: void
  4032. */
  4033. static void
  4034. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  4035. void *object, void *arg)
  4036. {
  4037. enum reg_wifi_band band;
  4038. bool *is_agile_scan_inprog_5g_pdev = arg;
  4039. struct target_if_spectral *spectral;
  4040. struct wlan_objmgr_pdev *cur_pdev = object;
  4041. struct target_if_spectral_ops *p_sops;
  4042. if (*is_agile_scan_inprog_5g_pdev)
  4043. return;
  4044. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  4045. if (!spectral) {
  4046. spectral_err("target if spectral handle is NULL");
  4047. return;
  4048. }
  4049. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4050. band = target_if_get_curr_band(
  4051. cur_pdev, spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE]);
  4052. if (band == REG_BAND_UNKNOWN) {
  4053. spectral_debug("Failed to get current band");
  4054. return;
  4055. }
  4056. if (band == REG_BAND_5G &&
  4057. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  4058. *is_agile_scan_inprog_5g_pdev = true;
  4059. }
  4060. /**
  4061. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  4062. * for current vdev rx chainmask.
  4063. *
  4064. * @spectral: Pointer to Spectral object
  4065. * @is_supported: Pointer to is_supported
  4066. *
  4067. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4068. */
  4069. static QDF_STATUS
  4070. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  4071. bool *is_supported)
  4072. {
  4073. struct wlan_objmgr_vdev *vdev;
  4074. uint8_t vdev_rxchainmask;
  4075. struct wlan_objmgr_psoc *psoc;
  4076. struct wlan_objmgr_pdev *pdev;
  4077. struct target_psoc_info *tgt_psoc_info;
  4078. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  4079. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  4080. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  4081. struct wlan_psoc_host_chainmask_table *table;
  4082. int j;
  4083. uint32_t table_id;
  4084. enum phy_ch_width ch_width;
  4085. uint8_t pdev_id;
  4086. if (!spectral) {
  4087. spectral_err("spectral target if object is null");
  4088. return QDF_STATUS_E_FAILURE;
  4089. }
  4090. if (!is_supported) {
  4091. spectral_err("is supported argument is null");
  4092. return QDF_STATUS_E_FAILURE;
  4093. }
  4094. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  4095. spectral_err("HW Agile mode is not supported up to gen 2");
  4096. return QDF_STATUS_E_FAILURE;
  4097. }
  4098. pdev = spectral->pdev_obj;
  4099. if (!pdev) {
  4100. spectral_err("pdev is null");
  4101. return QDF_STATUS_E_FAILURE;
  4102. }
  4103. psoc = wlan_pdev_get_psoc(pdev);
  4104. if (!psoc) {
  4105. spectral_err("psoc is null");
  4106. return QDF_STATUS_E_FAILURE;
  4107. }
  4108. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  4109. if (!vdev) {
  4110. spectral_err("First vdev is NULL");
  4111. return QDF_STATUS_E_FAILURE;
  4112. }
  4113. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  4114. if (!vdev_rxchainmask) {
  4115. spectral_err("vdev rx chainmask is zero");
  4116. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4117. return QDF_STATUS_E_FAILURE;
  4118. }
  4119. ch_width = target_if_vdev_get_ch_width(vdev);
  4120. if (ch_width == CH_WIDTH_INVALID) {
  4121. spectral_err("Invalid channel width");
  4122. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4123. return QDF_STATUS_E_FAILURE;
  4124. }
  4125. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4126. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  4127. if (!tgt_psoc_info) {
  4128. spectral_err("target_psoc_info is null");
  4129. return QDF_STATUS_E_FAILURE;
  4130. }
  4131. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  4132. if (!ext_svc_param) {
  4133. spectral_err("Extended service ready param null");
  4134. return QDF_STATUS_E_FAILURE;
  4135. }
  4136. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  4137. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  4138. if (!mac_phy_cap_arr) {
  4139. spectral_err("mac phy cap array is null");
  4140. return QDF_STATUS_E_FAILURE;
  4141. }
  4142. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  4143. if (!mac_phy_cap) {
  4144. spectral_err("mac phy cap is null");
  4145. return QDF_STATUS_E_FAILURE;
  4146. }
  4147. table_id = mac_phy_cap->chainmask_table_id;
  4148. table = &ext_svc_param->chainmask_table[table_id];
  4149. if (!table) {
  4150. spectral_err("chainmask table not found");
  4151. return QDF_STATUS_E_FAILURE;
  4152. }
  4153. for (j = 0; j < table->num_valid_chainmasks; j++) {
  4154. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  4155. if (ch_width <= CH_WIDTH_80MHZ)
  4156. *is_supported =
  4157. table->cap_list[j].supports_aSpectral;
  4158. else
  4159. *is_supported =
  4160. table->cap_list[j].supports_aSpectral_160;
  4161. break;
  4162. }
  4163. }
  4164. if (j == table->num_valid_chainmasks) {
  4165. spectral_err("vdev rx chainmask %u not found in table id = %u",
  4166. vdev_rxchainmask, table_id);
  4167. return QDF_STATUS_E_FAILURE;
  4168. }
  4169. return QDF_STATUS_SUCCESS;
  4170. }
  4171. #ifdef OPTIMIZED_SAMP_MESSAGE
  4172. /**
  4173. * target_if_spectral_populate_session_report_info() - Populate per-session
  4174. * report level information.
  4175. *
  4176. * @spectral: Pointer to Spectral object
  4177. * @smode: Spectral scan mode
  4178. *
  4179. * Return: Success/Failure
  4180. */
  4181. static QDF_STATUS
  4182. target_if_spectral_populate_session_report_info(
  4183. struct target_if_spectral *spectral,
  4184. enum spectral_scan_mode smode)
  4185. {
  4186. struct per_session_report_info *rpt_info;
  4187. struct wlan_objmgr_psoc *psoc;
  4188. if (!spectral) {
  4189. spectral_err_rl("Spectral LMAC object is null");
  4190. return QDF_STATUS_E_NULL_VALUE;
  4191. }
  4192. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  4193. spectral_err_rl("Invalid Spectral scan mode");
  4194. return QDF_STATUS_E_FAILURE;
  4195. }
  4196. if (!spectral->pdev_obj) {
  4197. spectral_err_rl("Spectral PDEV is null");
  4198. return QDF_STATUS_E_NULL_VALUE;
  4199. }
  4200. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  4201. if (!psoc) {
  4202. spectral_err_rl("psoc is null");
  4203. return QDF_STATUS_E_NULL_VALUE;
  4204. }
  4205. /* Fill per-session report information, based on the spectral mode */
  4206. rpt_info = &spectral->report_info[smode];
  4207. rpt_info->operating_bw = spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  4208. rpt_info->sscan_bw = spectral->ch_width[smode];
  4209. rpt_info->sscan_cfreq1 = spectral->params[smode].ss_frequency.cfreq1;
  4210. rpt_info->sscan_cfreq2 = spectral->params[smode].ss_frequency.cfreq2;
  4211. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ) {
  4212. rpt_info->num_spans = 2;
  4213. if (wlan_psoc_nif_fw_ext_cap_get(
  4214. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  4215. /* 5 MHz frequency span in restricted 80p80 case */
  4216. rpt_info->num_spans += 1;
  4217. } else {
  4218. rpt_info->num_spans = 1;
  4219. }
  4220. return QDF_STATUS_SUCCESS;
  4221. }
  4222. /**
  4223. * target_if_spectral_populate_session_detector_info() - Populate per-session
  4224. * detector level information.
  4225. *
  4226. * @spectral: Pointer to Spectral object
  4227. * @smode: Spectral scan mode
  4228. *
  4229. * Return: Success/Failure
  4230. */
  4231. static QDF_STATUS
  4232. target_if_spectral_populate_session_detector_info(
  4233. struct target_if_spectral *spectral,
  4234. enum spectral_scan_mode smode)
  4235. {
  4236. struct per_session_report_info *rpt_info;
  4237. struct sscan_detector_list *detector_list;
  4238. struct wlan_objmgr_psoc *psoc;
  4239. uint16_t dest_det_idx = 0;
  4240. uint16_t dest_span_idx = 0;
  4241. bool is_sec80 = false;
  4242. uint8_t det, dest_det;
  4243. if (!spectral) {
  4244. spectral_err_rl("Spectral LMAC object is null");
  4245. return QDF_STATUS_E_NULL_VALUE;
  4246. }
  4247. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  4248. spectral_err_rl("Invalid Spectral scan mode");
  4249. return QDF_STATUS_E_FAILURE;
  4250. }
  4251. if (!spectral->pdev_obj) {
  4252. spectral_err_rl("Spectral PDEV is null");
  4253. return QDF_STATUS_E_NULL_VALUE;
  4254. }
  4255. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  4256. if (!psoc) {
  4257. spectral_err_rl("psoc is null");
  4258. return QDF_STATUS_E_NULL_VALUE;
  4259. }
  4260. rpt_info = &spectral->report_info[smode];
  4261. /* Fill per-sesion detector-level information */
  4262. detector_list = &spectral->detector_list[smode][rpt_info->sscan_bw];
  4263. for (det = 0; det < detector_list->num_detectors; det++) {
  4264. struct per_session_det_map *det_map;
  4265. det_map = &spectral->det_map[detector_list->detectors[det]];
  4266. if (detector_list->num_detectors > 1) {
  4267. if (det == 0) {
  4268. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  4269. det_map->send_to_upper_layers = false;
  4270. } else if (det == detector_list->num_detectors - 1) {
  4271. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  4272. det_map->send_to_upper_layers = true;
  4273. } else {
  4274. /* middle fragments */
  4275. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  4276. det_map->send_to_upper_layers = false;
  4277. }
  4278. } else {
  4279. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  4280. det_map->send_to_upper_layers = true;
  4281. }
  4282. det_map->num_dest_det_info = 1;
  4283. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ &&
  4284. wlan_psoc_nif_fw_ext_cap_get(
  4285. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  4286. /**
  4287. * In 165MHz case, 1 Spectral HW detector maps to 3
  4288. * detectors in SAMP msg.
  4289. */
  4290. det_map->num_dest_det_info += 2;
  4291. }
  4292. for (dest_det = 0; dest_det < det_map->num_dest_det_info;
  4293. dest_det++) {
  4294. struct per_session_dest_det_info *map_det_info;
  4295. map_det_info = &det_map->dest_det_info[dest_det];
  4296. map_det_info->freq_span_id = dest_span_idx;
  4297. map_det_info->det_id = dest_det_idx;
  4298. map_det_info->is_sec80 = is_sec80;
  4299. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ) {
  4300. /* Increment span ID for non-contiguous modes */
  4301. dest_det_idx = 0;
  4302. dest_span_idx++;
  4303. } else {
  4304. /* Increment detector ID for contiguous modes */
  4305. dest_det_idx++;
  4306. }
  4307. is_sec80 = !is_sec80;
  4308. }
  4309. }
  4310. return QDF_STATUS_SUCCESS;
  4311. }
  4312. #else
  4313. static QDF_STATUS
  4314. target_if_spectral_populate_session_report_info(
  4315. struct target_if_spectral *spectral,
  4316. enum spectral_scan_mode smode)
  4317. {
  4318. return QDF_STATUS_SUCCESS;
  4319. }
  4320. static QDF_STATUS
  4321. target_if_spectral_populate_session_detector_info(
  4322. struct target_if_spectral *spectral,
  4323. enum spectral_scan_mode smode)
  4324. {
  4325. return QDF_STATUS_SUCCESS;
  4326. }
  4327. #endif /* OPTIMIZED_SAMP_MESSAGE */
  4328. QDF_STATUS
  4329. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  4330. uint8_t vdev_id,
  4331. const enum spectral_scan_mode smode,
  4332. enum spectral_cp_error_code *err)
  4333. {
  4334. struct target_if_spectral_ops *p_sops;
  4335. struct target_if_spectral *spectral;
  4336. struct wlan_objmgr_psoc *psoc;
  4337. enum reg_wifi_band band;
  4338. QDF_STATUS ret;
  4339. if (!err) {
  4340. spectral_err("Error code argument is null");
  4341. QDF_ASSERT(0);
  4342. return QDF_STATUS_E_FAILURE;
  4343. }
  4344. *err = SPECTRAL_SCAN_ERR_INVALID;
  4345. if (!pdev) {
  4346. spectral_err("pdev object is NUll");
  4347. return QDF_STATUS_E_FAILURE;
  4348. }
  4349. psoc = wlan_pdev_get_psoc(pdev);
  4350. if (!psoc) {
  4351. spectral_err("psoc is null");
  4352. return QDF_STATUS_E_FAILURE;
  4353. }
  4354. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4355. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4356. spectral_err("Invalid Spectral mode %u", smode);
  4357. return QDF_STATUS_E_FAILURE;
  4358. }
  4359. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4360. if (!spectral) {
  4361. spectral_err("Spectral LMAC object is NUll");
  4362. return QDF_STATUS_E_FAILURE;
  4363. }
  4364. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4365. if (!p_sops) {
  4366. spectral_err("p_sops is null");
  4367. return QDF_STATUS_E_FAILURE;
  4368. }
  4369. if (p_sops->is_spectral_active(spectral, smode)) {
  4370. spectral_err("spectral in progress in current pdev, mode %d",
  4371. smode);
  4372. return QDF_STATUS_E_FAILURE;
  4373. }
  4374. spectral->vdev_id[smode] = vdev_id;
  4375. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  4376. QDF_STATUS status;
  4377. bool is_supported = false;
  4378. status = target_if_is_agile_supported_cur_chmask(spectral,
  4379. &is_supported);
  4380. if (QDF_IS_STATUS_ERROR(status)) {
  4381. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4382. return QDF_STATUS_E_FAILURE;
  4383. }
  4384. if (!is_supported) {
  4385. spectral_err("aSpectral unsupported for cur chainmask");
  4386. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4387. return QDF_STATUS_E_FAILURE;
  4388. }
  4389. }
  4390. band = target_if_get_curr_band(spectral->pdev_obj, vdev_id);
  4391. if (band == REG_BAND_UNKNOWN) {
  4392. spectral_err("Failed to get current band");
  4393. return QDF_STATUS_E_FAILURE;
  4394. }
  4395. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  4396. struct target_psoc_info *tgt_hdl;
  4397. enum wmi_host_hw_mode_config_type mode;
  4398. bool is_agile_scan_inprog_5g_pdev;
  4399. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  4400. if (!tgt_hdl) {
  4401. target_if_err("target_psoc_info is null");
  4402. return QDF_STATUS_E_FAILURE;
  4403. }
  4404. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  4405. switch (mode) {
  4406. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  4407. case WMI_HOST_HW_MODE_SBS:
  4408. case WMI_HOST_HW_MODE_DBS_SBS:
  4409. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  4410. is_agile_scan_inprog_5g_pdev = false;
  4411. wlan_objmgr_iterate_obj_list
  4412. (psoc, WLAN_PDEV_OP,
  4413. target_if_is_agile_scan_active_in_5g,
  4414. &is_agile_scan_inprog_5g_pdev, 0,
  4415. WLAN_SPECTRAL_ID);
  4416. break;
  4417. default:
  4418. is_agile_scan_inprog_5g_pdev = false;
  4419. break;
  4420. }
  4421. if (is_agile_scan_inprog_5g_pdev) {
  4422. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  4423. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4424. return QDF_STATUS_E_FAILURE;
  4425. }
  4426. }
  4427. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  4428. bool is_aspectral_prohibited = false;
  4429. QDF_STATUS status;
  4430. status = wlan_objmgr_iterate_obj_list
  4431. (psoc, WLAN_PDEV_OP,
  4432. target_if_is_aspectral_prohibited_by_adfs,
  4433. &is_aspectral_prohibited, 0,
  4434. WLAN_SPECTRAL_ID);
  4435. if (QDF_IS_STATUS_ERROR(status)) {
  4436. spectral_err("Failed to iterate over pdevs");
  4437. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4438. return QDF_STATUS_E_FAILURE;
  4439. }
  4440. if (is_aspectral_prohibited) {
  4441. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4442. return QDF_STATUS_E_FAILURE;
  4443. }
  4444. }
  4445. if (!spectral->params_valid[smode]) {
  4446. target_if_spectral_info_read(spectral,
  4447. smode,
  4448. TARGET_IF_SPECTRAL_INFO_PARAMS,
  4449. &spectral->params[smode],
  4450. sizeof(spectral->params[smode]));
  4451. spectral->params_valid[smode] = true;
  4452. }
  4453. qdf_spin_lock(&spectral->spectral_lock);
  4454. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  4455. QDF_STATUS status;
  4456. bool is_overlapping;
  4457. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  4458. enum spectral_scan_mode m;
  4459. enum phy_ch_width op_ch_width;
  4460. enum phy_ch_width agile_ch_width;
  4461. m = SPECTRAL_SCAN_MODE_NORMAL;
  4462. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  4463. ch_width[m] = CH_WIDTH_INVALID;
  4464. status = target_if_spectral_populate_chwidth
  4465. (spectral, ch_width, spectral->params
  4466. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  4467. if (QDF_IS_STATUS_ERROR(status)) {
  4468. qdf_spin_unlock(&spectral->spectral_lock);
  4469. spectral_err("Failed to populate channel width");
  4470. return QDF_STATUS_E_FAILURE;
  4471. }
  4472. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  4473. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  4474. if (!spectral->params[smode].ss_frequency.cfreq1) {
  4475. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  4476. qdf_spin_unlock(&spectral->spectral_lock);
  4477. spectral_err("Agile Spectral cfreq1 is 0");
  4478. return QDF_STATUS_E_FAILURE;
  4479. } else if (agile_ch_width == CH_WIDTH_80P80MHZ &&
  4480. !spectral->params[smode].ss_frequency.cfreq2) {
  4481. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  4482. qdf_spin_unlock(&spectral->spectral_lock);
  4483. spectral_err("Agile Spectral cfreq2 is 0");
  4484. return QDF_STATUS_E_FAILURE;
  4485. }
  4486. status = target_if_is_agile_span_overlap_with_operating_span
  4487. (spectral, ch_width,
  4488. &spectral->params[smode].ss_frequency,
  4489. &is_overlapping);
  4490. if (QDF_IS_STATUS_ERROR(status)) {
  4491. qdf_spin_unlock(&spectral->spectral_lock);
  4492. return QDF_STATUS_E_FAILURE;
  4493. }
  4494. if (is_overlapping) {
  4495. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4496. qdf_spin_unlock(&spectral->spectral_lock);
  4497. return QDF_STATUS_E_FAILURE;
  4498. }
  4499. }
  4500. target_if_spectral_scan_enable_params(spectral,
  4501. &spectral->params[smode], smode,
  4502. err);
  4503. ret = target_if_spectral_populate_session_report_info(spectral, smode);
  4504. if (QDF_IS_STATUS_ERROR(ret)) {
  4505. spectral_err_rl("Failed to populate per-session report info");
  4506. return QDF_STATUS_E_FAILURE;
  4507. }
  4508. ret = target_if_spectral_populate_session_detector_info(spectral,
  4509. smode);
  4510. if (QDF_IS_STATUS_ERROR(ret)) {
  4511. spectral_err_rl("Failed to populate per-session report info");
  4512. return QDF_STATUS_E_FAILURE;
  4513. }
  4514. qdf_spin_unlock(&spectral->spectral_lock);
  4515. return QDF_STATUS_SUCCESS;
  4516. }
  4517. QDF_STATUS
  4518. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  4519. const enum spectral_scan_mode smode,
  4520. enum spectral_cp_error_code *err)
  4521. {
  4522. struct target_if_spectral_ops *p_sops;
  4523. struct target_if_spectral *spectral;
  4524. if (!pdev) {
  4525. spectral_err("pdev object is NULL");
  4526. return QDF_STATUS_E_INVAL;
  4527. }
  4528. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  4529. spectral_info("Spectral feature is disabled");
  4530. return QDF_STATUS_COMP_DISABLED;
  4531. }
  4532. if (!err) {
  4533. spectral_err("Error code argument is null");
  4534. QDF_ASSERT(0);
  4535. return QDF_STATUS_E_FAILURE;
  4536. }
  4537. *err = SPECTRAL_SCAN_ERR_INVALID;
  4538. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4539. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4540. spectral_err("Invalid Spectral mode %u", smode);
  4541. return QDF_STATUS_E_FAILURE;
  4542. }
  4543. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4544. if (!spectral) {
  4545. spectral_err("Spectral LMAC object is NUll ");
  4546. return QDF_STATUS_E_FAILURE;
  4547. }
  4548. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4549. qdf_spin_lock(&spectral->spectral_lock);
  4550. p_sops->stop_spectral_scan(spectral, smode);
  4551. if (spectral->classify_scan) {
  4552. /* TODO : Check if this logic is necessary */
  4553. spectral->detects_control_channel = 0;
  4554. spectral->detects_extension_channel = 0;
  4555. spectral->detects_above_dc = 0;
  4556. spectral->detects_below_dc = 0;
  4557. spectral->classify_scan = 0;
  4558. }
  4559. spectral->send_single_packet = 0;
  4560. spectral->sc_spectral_scan = 0;
  4561. qdf_spin_unlock(&spectral->spectral_lock);
  4562. return QDF_STATUS_SUCCESS;
  4563. }
  4564. /**
  4565. * target_if_is_spectral_active() - Get whether Spectral is active
  4566. * @pdev: Pointer to pdev object
  4567. * @smode: Spectral scan mode
  4568. *
  4569. * API to get whether Spectral is active
  4570. *
  4571. * Return: True if Spectral is active, false if Spectral is not active
  4572. */
  4573. bool
  4574. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  4575. const enum spectral_scan_mode smode)
  4576. {
  4577. struct target_if_spectral *spectral = NULL;
  4578. struct target_if_spectral_ops *p_sops = NULL;
  4579. if (!pdev) {
  4580. spectral_err("pdev is null");
  4581. return false;
  4582. }
  4583. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  4584. spectral_info("Spectral feature is disabled");
  4585. return false;
  4586. }
  4587. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4588. if (!spectral) {
  4589. spectral_err("SPECTRAL : Module doesn't exist");
  4590. return false;
  4591. }
  4592. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4593. if (!p_sops) {
  4594. spectral_err("p_sops is null");
  4595. return false;
  4596. }
  4597. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4598. spectral_err("Invalid Spectral mode %u", smode);
  4599. return false;
  4600. }
  4601. return p_sops->is_spectral_active(spectral, smode);
  4602. }
  4603. /**
  4604. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  4605. * @pdev: Pointer to pdev object
  4606. * @smode: Spectral scan mode
  4607. *
  4608. * API to get whether Spectral is enabled
  4609. *
  4610. * Return: True if Spectral is enabled, false if Spectral is not enabled
  4611. */
  4612. bool
  4613. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  4614. enum spectral_scan_mode smode)
  4615. {
  4616. struct target_if_spectral *spectral = NULL;
  4617. struct target_if_spectral_ops *p_sops = NULL;
  4618. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4619. if (!spectral) {
  4620. spectral_err("SPECTRAL : Module doesn't exist");
  4621. return false;
  4622. }
  4623. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4624. if (!p_sops) {
  4625. spectral_err("p_sops is null");
  4626. return false;
  4627. }
  4628. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4629. spectral_err("Invalid Spectral mode %u", smode);
  4630. return false;
  4631. }
  4632. return p_sops->is_spectral_enabled(spectral, smode);
  4633. }
  4634. #ifdef DIRECT_BUF_RX_DEBUG
  4635. /**
  4636. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  4637. * @pdev: Pointer to pdev object
  4638. * @enable: Enable/Disable Spectral DMA ring debug
  4639. *
  4640. * Start/stop Spectral DMA ring debug based on @enable.
  4641. * Also save the state for future use.
  4642. *
  4643. * Return: QDF_STATUS of operation
  4644. */
  4645. static QDF_STATUS
  4646. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  4647. {
  4648. struct target_if_spectral *spectral;
  4649. struct wlan_lmac_if_tx_ops *tx_ops;
  4650. struct wlan_objmgr_psoc *psoc;
  4651. if (!pdev)
  4652. return QDF_STATUS_E_FAILURE;
  4653. psoc = wlan_pdev_get_psoc(pdev);
  4654. if (!psoc) {
  4655. spectral_err("psoc is null");
  4656. return QDF_STATUS_E_INVAL;
  4657. }
  4658. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  4659. if (!tx_ops) {
  4660. spectral_err("tx_ops is NULL");
  4661. return QDF_STATUS_E_INVAL;
  4662. }
  4663. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4664. if (!spectral) {
  4665. spectral_err("Spectal LMAC object is NULL");
  4666. return QDF_STATUS_E_INVAL;
  4667. }
  4668. /* Save the state */
  4669. spectral->dbr_ring_debug = enable;
  4670. if (enable)
  4671. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  4672. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  4673. else
  4674. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  4675. pdev, 0);
  4676. return QDF_STATUS_SUCCESS;
  4677. }
  4678. /**
  4679. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  4680. * @pdev: Pointer to pdev object
  4681. * @enable: Enable/Disable Spectral DMA buffer debug
  4682. *
  4683. * Start/stop Spectral DMA buffer debug based on @enable.
  4684. * Also save the state for future use.
  4685. *
  4686. * Return: QDF_STATUS of operation
  4687. */
  4688. static QDF_STATUS
  4689. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  4690. {
  4691. struct target_if_spectral *spectral;
  4692. struct wlan_lmac_if_tx_ops *tx_ops;
  4693. struct wlan_objmgr_psoc *psoc;
  4694. if (!pdev)
  4695. return QDF_STATUS_E_FAILURE;
  4696. psoc = wlan_pdev_get_psoc(pdev);
  4697. if (!psoc) {
  4698. spectral_err("psoc is null");
  4699. return QDF_STATUS_E_INVAL;
  4700. }
  4701. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  4702. if (!tx_ops) {
  4703. spectral_err("tx_ops is NULL");
  4704. return QDF_STATUS_E_INVAL;
  4705. }
  4706. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4707. if (!spectral) {
  4708. spectral_err("Spectal LMAC object is NULL");
  4709. return QDF_STATUS_E_INVAL;
  4710. }
  4711. /* Save the state */
  4712. spectral->dbr_buff_debug = enable;
  4713. if (enable)
  4714. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  4715. pdev, 0, MEM_POISON_SIGNATURE);
  4716. else
  4717. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  4718. pdev, 0);
  4719. }
  4720. /**
  4721. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  4722. * debug based on the previous state
  4723. * @pdev: Pointer to pdev object
  4724. *
  4725. * Return: QDF_STATUS of operation
  4726. */
  4727. static QDF_STATUS
  4728. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  4729. {
  4730. struct target_if_spectral *spectral;
  4731. if (!pdev) {
  4732. spectral_err("pdev is NULL!");
  4733. return QDF_STATUS_E_FAILURE;
  4734. }
  4735. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4736. if (!spectral) {
  4737. spectral_err("Spectal LMAC object is NULL");
  4738. return QDF_STATUS_E_INVAL;
  4739. }
  4740. if (spectral->dbr_buff_debug)
  4741. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  4742. else
  4743. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  4744. }
  4745. /**
  4746. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  4747. * debug based on the previous state
  4748. * @pdev: Pointer to pdev object
  4749. *
  4750. * Return: QDF_STATUS of operation
  4751. */
  4752. static QDF_STATUS
  4753. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  4754. {
  4755. struct target_if_spectral *spectral;
  4756. if (!pdev) {
  4757. spectral_err("pdev is NULL!");
  4758. return QDF_STATUS_E_FAILURE;
  4759. }
  4760. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4761. if (!spectral) {
  4762. spectral_err("Spectal LMAC object is NULL");
  4763. return QDF_STATUS_E_INVAL;
  4764. }
  4765. if (spectral->dbr_ring_debug)
  4766. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  4767. else
  4768. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  4769. }
  4770. /**
  4771. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  4772. * @pdev: Pointer to pdev object
  4773. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  4774. * @debug_value: Value to be set for @dma_debug_type
  4775. *
  4776. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  4777. * based on @debug_value
  4778. *
  4779. * Return: QDF_STATUS of operation
  4780. */
  4781. static QDF_STATUS
  4782. target_if_spectral_set_dma_debug(
  4783. struct wlan_objmgr_pdev *pdev,
  4784. enum spectral_dma_debug dma_debug_type,
  4785. bool debug_value)
  4786. {
  4787. struct target_if_spectral_ops *p_sops;
  4788. struct wlan_objmgr_psoc *psoc;
  4789. struct wlan_lmac_if_tx_ops *tx_ops;
  4790. struct target_if_spectral *spectral;
  4791. if (!pdev)
  4792. return QDF_STATUS_E_FAILURE;
  4793. psoc = wlan_pdev_get_psoc(pdev);
  4794. if (!psoc) {
  4795. spectral_err("psoc is null");
  4796. return QDF_STATUS_E_INVAL;
  4797. }
  4798. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  4799. if (!tx_ops) {
  4800. spectral_err("tx_ops is NULL");
  4801. return QDF_STATUS_E_FAILURE;
  4802. }
  4803. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  4804. spectral_err("Unable to fetch target type");
  4805. return QDF_STATUS_E_FAILURE;
  4806. }
  4807. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4808. if (!spectral) {
  4809. spectral_err("Spectal LMAC object is NULL");
  4810. return QDF_STATUS_E_INVAL;
  4811. }
  4812. if (spectral->direct_dma_support) {
  4813. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4814. if (p_sops->is_spectral_active(spectral,
  4815. SPECTRAL_SCAN_MODE_NORMAL) ||
  4816. p_sops->is_spectral_active(spectral,
  4817. SPECTRAL_SCAN_MODE_AGILE)) {
  4818. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  4819. return QDF_STATUS_E_FAILURE;
  4820. }
  4821. switch (dma_debug_type) {
  4822. case SPECTRAL_DMA_RING_DEBUG:
  4823. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  4824. break;
  4825. case SPECTRAL_DMA_BUFFER_DEBUG:
  4826. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  4827. break;
  4828. default:
  4829. spectral_err("Unsupported DMA debug type : %d",
  4830. dma_debug_type);
  4831. return QDF_STATUS_E_FAILURE;
  4832. }
  4833. }
  4834. return QDF_STATUS_SUCCESS;
  4835. }
  4836. #endif /* DIRECT_BUF_RX_DEBUG */
  4837. /**
  4838. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  4839. * @pdev: Pointer to pdev object
  4840. *
  4841. * Return: Whether Direct-DMA is supported on this radio
  4842. */
  4843. static bool
  4844. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  4845. {
  4846. struct target_if_spectral *spectral;
  4847. if (!pdev) {
  4848. spectral_err("pdev is NULL!");
  4849. return false;
  4850. }
  4851. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4852. if (!spectral) {
  4853. spectral_err("Spectral LMAC object is NULL");
  4854. return false;
  4855. }
  4856. return spectral->direct_dma_support;
  4857. }
  4858. /**
  4859. * target_if_set_debug_level() - Set debug level for Spectral
  4860. * @pdev: Pointer to pdev object
  4861. * @debug_level: Debug level
  4862. *
  4863. * API to set the debug level for Spectral
  4864. *
  4865. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4866. */
  4867. QDF_STATUS
  4868. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  4869. {
  4870. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  4871. return QDF_STATUS_SUCCESS;
  4872. }
  4873. /**
  4874. * target_if_get_debug_level() - Get debug level for Spectral
  4875. * @pdev: Pointer to pdev object
  4876. *
  4877. * API to get the debug level for Spectral
  4878. *
  4879. * Return: Current debug level
  4880. */
  4881. uint32_t
  4882. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  4883. {
  4884. return spectral_debug_level;
  4885. }
  4886. /**
  4887. * target_if_get_spectral_capinfo() - Get Spectral capability information
  4888. * @pdev: Pointer to pdev object
  4889. * @scaps: Buffer into which data should be copied
  4890. *
  4891. * API to get the spectral capability information
  4892. *
  4893. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4894. */
  4895. QDF_STATUS
  4896. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  4897. struct spectral_caps *scaps)
  4898. {
  4899. struct target_if_spectral *spectral = NULL;
  4900. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4901. if (!spectral) {
  4902. spectral_err("SPECTRAL : Module doesn't exist");
  4903. return QDF_STATUS_E_FAILURE;
  4904. }
  4905. qdf_mem_copy(scaps, &spectral->capability,
  4906. sizeof(struct spectral_caps));
  4907. return QDF_STATUS_SUCCESS;
  4908. }
  4909. /**
  4910. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  4911. * @pdev: Pointer to pdev object
  4912. * @stats: Buffer into which data should be copied
  4913. *
  4914. * API to get the spectral diagnostic statistics
  4915. *
  4916. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4917. */
  4918. QDF_STATUS
  4919. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  4920. struct spectral_diag_stats *stats)
  4921. {
  4922. struct target_if_spectral *spectral = NULL;
  4923. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4924. if (!spectral) {
  4925. spectral_err("SPECTRAL : Module doesn't exist");
  4926. return QDF_STATUS_E_FAILURE;
  4927. }
  4928. qdf_mem_copy(stats, &spectral->diag_stats,
  4929. sizeof(struct spectral_diag_stats));
  4930. return QDF_STATUS_SUCCESS;
  4931. }
  4932. /**
  4933. * target_if_register_spectral_wmi_ops() - Register Spectral WMI operations
  4934. * @psoc: Pointer to psoc object
  4935. * @wmi_ops: Pointer to the structure having Spectral WMI operations
  4936. *
  4937. * API for registering Spectral WMI operations in
  4938. * spectral internal data structure
  4939. *
  4940. * Return: QDF_STATUS
  4941. */
  4942. static QDF_STATUS
  4943. target_if_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
  4944. struct spectral_wmi_ops *wmi_ops)
  4945. {
  4946. struct target_if_psoc_spectral *psoc_spectral;
  4947. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4948. if (!psoc_spectral) {
  4949. spectral_err("Spectral LMAC object is null");
  4950. return QDF_STATUS_E_INVAL;
  4951. }
  4952. psoc_spectral->wmi_ops = *wmi_ops;
  4953. return QDF_STATUS_SUCCESS;
  4954. }
  4955. /**
  4956. * target_if_register_spectral_tgt_ops() - Register Spectral target operations
  4957. * @psoc: Pointer to psoc object
  4958. * @tgt_ops: Pointer to the structure having Spectral target operations
  4959. *
  4960. * API for registering Spectral target operations in
  4961. * spectral internal data structure
  4962. *
  4963. * Return: QDF_STATUS
  4964. */
  4965. static QDF_STATUS
  4966. target_if_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
  4967. struct spectral_tgt_ops *tgt_ops)
  4968. {
  4969. if (!psoc) {
  4970. spectral_err("psoc is null");
  4971. return QDF_STATUS_E_INVAL;
  4972. }
  4973. ops_tgt = *tgt_ops;
  4974. return QDF_STATUS_SUCCESS;
  4975. }
  4976. /**
  4977. * target_if_register_netlink_cb() - Register Netlink callbacks
  4978. * @pdev: Pointer to pdev object
  4979. * @nl_cb: Netlink callbacks to register
  4980. *
  4981. * Return: void
  4982. */
  4983. static void
  4984. target_if_register_netlink_cb(
  4985. struct wlan_objmgr_pdev *pdev,
  4986. struct spectral_nl_cb *nl_cb)
  4987. {
  4988. struct target_if_spectral *spectral = NULL;
  4989. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4990. if (!spectral) {
  4991. spectral_err("SPECTRAL : Module doesn't exist");
  4992. return;
  4993. }
  4994. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  4995. if (spectral->use_nl_bcast)
  4996. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  4997. else
  4998. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  4999. }
  5000. /**
  5001. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  5002. * Netlink messages to the application layer
  5003. * @pdev: Pointer to pdev object
  5004. *
  5005. * Return: true for broadcast, false for unicast
  5006. */
  5007. static bool
  5008. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  5009. {
  5010. struct target_if_spectral *spectral = NULL;
  5011. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5012. if (!spectral) {
  5013. spectral_err("SPECTRAL : Module doesn't exist");
  5014. return false;
  5015. }
  5016. return spectral->use_nl_bcast;
  5017. }
  5018. /**
  5019. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  5020. * @pdev: Pointer to pdev object
  5021. *
  5022. * Return: void
  5023. */
  5024. static void
  5025. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  5026. {
  5027. struct target_if_spectral *spectral = NULL;
  5028. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5029. if (!spectral) {
  5030. spectral_err("SPECTRAL : Module doesn't exist");
  5031. return;
  5032. }
  5033. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  5034. }
  5035. static int
  5036. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  5037. void *payload)
  5038. {
  5039. struct target_if_spectral *spectral = NULL;
  5040. struct target_if_spectral_ops *p_sops = NULL;
  5041. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5042. if (!spectral) {
  5043. spectral_err("SPECTRAL : Module doesn't exist");
  5044. return -EPERM;
  5045. }
  5046. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5047. if (!p_sops) {
  5048. spectral_err("p_sops is null");
  5049. return -EPERM;
  5050. }
  5051. return p_sops->process_spectral_report(pdev, payload);
  5052. }
  5053. #ifdef DIRECT_BUF_RX_DEBUG
  5054. static inline void
  5055. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5056. {
  5057. if (!tx_ops) {
  5058. spectral_err("tx_ops is NULL");
  5059. return;
  5060. }
  5061. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  5062. target_if_spectral_set_dma_debug;
  5063. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  5064. target_if_spectral_check_and_do_dbr_ring_debug;
  5065. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  5066. target_if_spectral_check_and_do_dbr_buff_debug;
  5067. }
  5068. #else
  5069. static inline void
  5070. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5071. {
  5072. }
  5073. #endif
  5074. #if defined(WLAN_CONV_SPECTRAL_ENABLE) && defined(SPECTRAL_MODULIZED_ENABLE)
  5075. /**
  5076. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  5077. * register WMI event handler
  5078. * @psoc: Pointer to psoc object
  5079. * @event_id: Event id
  5080. * @handler_func: Handler function
  5081. * @rx_ctx: Context of WMI event processing
  5082. *
  5083. * Wrapper function to register WMI event handler
  5084. *
  5085. * Return: 0 for success else failure
  5086. */
  5087. static int
  5088. target_if_spectral_wmi_unified_register_event_handler(
  5089. struct wlan_objmgr_psoc *psoc,
  5090. wmi_conv_event_id event_id,
  5091. wmi_unified_event_handler handler_func,
  5092. uint8_t rx_ctx)
  5093. {
  5094. wmi_unified_t wmi_handle;
  5095. struct target_if_psoc_spectral *psoc_spectral;
  5096. QDF_STATUS ret;
  5097. if (!psoc) {
  5098. spectral_err("psoc is null");
  5099. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5100. }
  5101. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5102. if (!wmi_handle) {
  5103. spectral_err("WMI handle is null");
  5104. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5105. }
  5106. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5107. if (!psoc_spectral) {
  5108. spectral_err("spectral object is null");
  5109. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5110. }
  5111. ret = psoc_spectral->wmi_ops.wmi_unified_register_event_handler(
  5112. wmi_handle, event_id, handler_func, rx_ctx);
  5113. return qdf_status_to_os_return(ret);
  5114. }
  5115. /**
  5116. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  5117. * to unregister WMI event handler
  5118. * @psoc: Pointer to psoc object
  5119. * @event_id: Event id
  5120. *
  5121. * Wrapper function to unregister WMI event handler
  5122. *
  5123. * Return: 0 for success else failure
  5124. */
  5125. static int
  5126. target_if_spectral_wmi_unified_unregister_event_handler(
  5127. struct wlan_objmgr_psoc *psoc,
  5128. wmi_conv_event_id event_id)
  5129. {
  5130. wmi_unified_t wmi_handle;
  5131. struct target_if_psoc_spectral *psoc_spectral;
  5132. QDF_STATUS ret;
  5133. if (!psoc) {
  5134. spectral_err("psoc is null");
  5135. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5136. }
  5137. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5138. if (!wmi_handle) {
  5139. spectral_err("WMI handle is null");
  5140. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5141. }
  5142. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5143. if (!psoc_spectral) {
  5144. spectral_err("spectral object is null");
  5145. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5146. }
  5147. ret = psoc_spectral->wmi_ops.wmi_unified_unregister_event_handler(
  5148. wmi_handle, event_id);
  5149. return qdf_status_to_os_return(ret);
  5150. }
  5151. /**
  5152. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  5153. * function to extract fixed parameters from start scan response event
  5154. * @psoc: Pointer to psoc object
  5155. * @evt_buf: Event buffer
  5156. * @param: Start scan response parameters
  5157. *
  5158. * Wrapper function to extract fixed parameters from start scan response event
  5159. *
  5160. * Return: QDF_STATUS
  5161. */
  5162. static QDF_STATUS
  5163. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  5164. struct wlan_objmgr_psoc *psoc,
  5165. uint8_t *evt_buf,
  5166. struct spectral_startscan_resp_params *param)
  5167. {
  5168. wmi_unified_t wmi_handle;
  5169. struct target_if_psoc_spectral *psoc_spectral;
  5170. if (!psoc) {
  5171. spectral_err("psoc is null");
  5172. return QDF_STATUS_E_INVAL;
  5173. }
  5174. if (!evt_buf) {
  5175. spectral_err("WMI event buffer is null");
  5176. return QDF_STATUS_E_INVAL;
  5177. }
  5178. if (!param) {
  5179. spectral_err("Spectral startscan response parameters is null");
  5180. return QDF_STATUS_E_INVAL;
  5181. }
  5182. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5183. if (!wmi_handle) {
  5184. spectral_err("WMI handle is null");
  5185. return QDF_STATUS_E_INVAL;
  5186. }
  5187. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5188. if (!psoc_spectral) {
  5189. spectral_err("spectral object is null");
  5190. return QDF_STATUS_E_FAILURE;
  5191. }
  5192. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  5193. wmi_handle, evt_buf, param);
  5194. }
  5195. /**
  5196. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  5197. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  5198. * secondary 80 MHz FFT bins
  5199. * @psoc: Pointer to psoc object
  5200. * @evt_buf: Event buffer
  5201. * @param: FFT bin start and end indices
  5202. *
  5203. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  5204. * and secondary 80 MHz FFT bins
  5205. *
  5206. * Return: QDF_STATUS
  5207. */
  5208. static QDF_STATUS
  5209. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  5210. struct wlan_objmgr_psoc *psoc,
  5211. uint8_t *evt_buf,
  5212. struct spectral_fft_bin_markers_160_165mhz *param)
  5213. {
  5214. wmi_unified_t wmi_handle;
  5215. struct target_if_psoc_spectral *psoc_spectral;
  5216. if (!psoc) {
  5217. spectral_err("psoc is null");
  5218. return QDF_STATUS_E_INVAL;
  5219. }
  5220. if (!evt_buf) {
  5221. spectral_err("WMI event buffer is null");
  5222. return QDF_STATUS_E_INVAL;
  5223. }
  5224. if (!param) {
  5225. spectral_err("Spectral FFT bin markers is null");
  5226. return QDF_STATUS_E_INVAL;
  5227. }
  5228. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5229. if (!wmi_handle) {
  5230. spectral_err("WMI handle is null");
  5231. return QDF_STATUS_E_INVAL;
  5232. }
  5233. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5234. if (!psoc_spectral) {
  5235. spectral_err("spectral object is null");
  5236. return QDF_STATUS_E_FAILURE;
  5237. }
  5238. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fft_bin_index(
  5239. wmi_handle, evt_buf, param);
  5240. }
  5241. /**
  5242. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  5243. * object from scn handle
  5244. * @scn: scn handle
  5245. *
  5246. * Wrapper function to get psoc object from scn handle
  5247. *
  5248. * Return: Pointer to psoc object
  5249. */
  5250. static struct wlan_objmgr_psoc *
  5251. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  5252. {
  5253. if (!scn) {
  5254. spectral_err("scn is null");
  5255. return NULL;
  5256. }
  5257. return ops_tgt.tgt_get_psoc_from_scn_hdl(scn);
  5258. }
  5259. #else
  5260. /**
  5261. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  5262. * register WMI event handler
  5263. * @psoc: Pointer to psoc object
  5264. * @event_id: Event id
  5265. * @handler_func: Handler function
  5266. * @rx_ctx: Context of WMI event processing
  5267. *
  5268. * Wrapper function to register WMI event handler
  5269. *
  5270. * Return: 0 for success else failure
  5271. */
  5272. static int
  5273. target_if_spectral_wmi_unified_register_event_handler(
  5274. struct wlan_objmgr_psoc *psoc,
  5275. wmi_conv_event_id event_id,
  5276. wmi_unified_event_handler handler_func,
  5277. uint8_t rx_ctx)
  5278. {
  5279. wmi_unified_t wmi_handle;
  5280. QDF_STATUS ret;
  5281. if (!psoc) {
  5282. spectral_err("psoc is null");
  5283. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5284. }
  5285. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5286. if (!wmi_handle) {
  5287. spectral_err("WMI handle is null");
  5288. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5289. }
  5290. ret = wmi_unified_register_event_handler(wmi_handle, event_id,
  5291. handler_func, rx_ctx);
  5292. return qdf_status_to_os_return(ret);
  5293. }
  5294. /**
  5295. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  5296. * to unregister WMI event handler
  5297. * @psoc: Pointer to psoc object
  5298. * @event_id: Event id
  5299. *
  5300. * Wrapper function to unregister WMI event handler
  5301. *
  5302. * Return: 0 for success else failure
  5303. */
  5304. static int
  5305. target_if_spectral_wmi_unified_unregister_event_handler(
  5306. struct wlan_objmgr_psoc *psoc,
  5307. wmi_conv_event_id event_id)
  5308. {
  5309. wmi_unified_t wmi_handle;
  5310. QDF_STATUS ret;
  5311. if (!psoc) {
  5312. spectral_err("psoc is null");
  5313. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5314. }
  5315. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5316. if (!wmi_handle) {
  5317. spectral_err("WMI handle is null");
  5318. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5319. }
  5320. ret = wmi_unified_unregister_event_handler(wmi_handle, event_id);
  5321. return qdf_status_to_os_return(ret);
  5322. }
  5323. /**
  5324. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  5325. * function to extract fixed parameters from start scan response event
  5326. * @psoc: Pointer to psoc object
  5327. * @evt_buf: Event buffer
  5328. * @param: Start scan response parameters
  5329. *
  5330. * Wrapper function to extract fixed parameters from start scan response event
  5331. *
  5332. * Return: QDF_STATUS
  5333. */
  5334. static QDF_STATUS
  5335. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  5336. struct wlan_objmgr_psoc *psoc,
  5337. uint8_t *evt_buf,
  5338. struct spectral_startscan_resp_params *param)
  5339. {
  5340. wmi_unified_t wmi_handle;
  5341. if (!psoc) {
  5342. spectral_err("psoc is null");
  5343. return QDF_STATUS_E_INVAL;
  5344. }
  5345. if (!evt_buf) {
  5346. spectral_err("WMI event buffer is null");
  5347. return QDF_STATUS_E_INVAL;
  5348. }
  5349. if (!param) {
  5350. spectral_err("Spectral startscan response parameters is null");
  5351. return QDF_STATUS_E_INVAL;
  5352. }
  5353. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5354. if (!wmi_handle) {
  5355. spectral_err("WMI handle is null");
  5356. return QDF_STATUS_E_INVAL;
  5357. }
  5358. return wmi_extract_pdev_sscan_fw_cmd_fixed_param(wmi_handle, evt_buf,
  5359. param);
  5360. }
  5361. /**
  5362. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  5363. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  5364. * secondary 80 MHz FFT bins
  5365. * @psoc: Pointer to psoc object
  5366. * @evt_buf: Event buffer
  5367. * @param: FFT bin start and end indices
  5368. *
  5369. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  5370. * and secondary 80 MHz FFT bins
  5371. *
  5372. * Return: QDF_STATUS
  5373. */
  5374. static QDF_STATUS
  5375. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  5376. struct wlan_objmgr_psoc *psoc,
  5377. uint8_t *evt_buf,
  5378. struct spectral_fft_bin_markers_160_165mhz *param)
  5379. {
  5380. wmi_unified_t wmi_handle;
  5381. if (!psoc) {
  5382. spectral_err("psoc is null");
  5383. return QDF_STATUS_E_INVAL;
  5384. }
  5385. if (!evt_buf) {
  5386. spectral_err("WMI event buffer is null");
  5387. return QDF_STATUS_E_INVAL;
  5388. }
  5389. if (!param) {
  5390. spectral_err("Spectral FFT bin markers is null");
  5391. return QDF_STATUS_E_INVAL;
  5392. }
  5393. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5394. if (!wmi_handle) {
  5395. spectral_err("WMI handle is null");
  5396. return QDF_STATUS_E_INVAL;
  5397. }
  5398. return wmi_extract_pdev_sscan_fft_bin_index(wmi_handle, evt_buf, param);
  5399. }
  5400. /**
  5401. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  5402. * object from scn handle
  5403. * @scn: scn handle
  5404. *
  5405. * Wrapper function to get psoc object from scn handle
  5406. *
  5407. * Return: Pointer to psoc object
  5408. */
  5409. static struct wlan_objmgr_psoc *
  5410. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  5411. {
  5412. if (!scn) {
  5413. spectral_err("scn is null");
  5414. return NULL;
  5415. }
  5416. return target_if_get_psoc_from_scn_hdl(scn);
  5417. }
  5418. #endif
  5419. /**
  5420. * target_if_spectral_fw_param_event_handler() - WMI event handler to
  5421. * process start scan response event
  5422. * @scn: Pointer to scn object
  5423. * @data_buf: Pointer to event buffer
  5424. * @data_len: Length of event buffer
  5425. *
  5426. * Return: 0 for success, else failure
  5427. */
  5428. static int
  5429. target_if_spectral_fw_param_event_handler(ol_scn_t scn, uint8_t *data_buf,
  5430. uint32_t data_len)
  5431. {
  5432. QDF_STATUS status;
  5433. struct wlan_objmgr_psoc *psoc;
  5434. struct wlan_objmgr_pdev *pdev;
  5435. struct wmi_unified *wmi_handle;
  5436. struct spectral_startscan_resp_params event_params = {0};
  5437. struct target_if_psoc_spectral *psoc_spectral;
  5438. struct target_if_spectral *spectral;
  5439. if (!scn) {
  5440. spectral_err("scn handle is null");
  5441. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5442. }
  5443. if (!data_buf) {
  5444. spectral_err("WMI event buffer null");
  5445. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5446. }
  5447. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  5448. if (!psoc) {
  5449. spectral_err("psoc is null");
  5450. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5451. }
  5452. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5453. if (!psoc_spectral) {
  5454. spectral_err("spectral object is null");
  5455. return QDF_STATUS_E_FAILURE;
  5456. }
  5457. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5458. if (!wmi_handle) {
  5459. spectral_err("WMI handle is null");
  5460. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5461. }
  5462. status = target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  5463. psoc, data_buf, &event_params);
  5464. if (QDF_IS_STATUS_ERROR(status)) {
  5465. spectral_err("unable to extract sscan fw fixed params");
  5466. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5467. }
  5468. pdev = wlan_objmgr_get_pdev_by_id(psoc, event_params.pdev_id,
  5469. WLAN_SPECTRAL_ID);
  5470. if (!pdev) {
  5471. spectral_err("pdev is null");
  5472. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5473. }
  5474. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5475. if (!spectral) {
  5476. spectral_err("spectral object is null");
  5477. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  5478. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5479. }
  5480. if (event_params.num_fft_bin_index == 1) {
  5481. status =
  5482. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  5483. psoc, data_buf,
  5484. &spectral->rparams.marker[event_params.smode]);
  5485. if (QDF_IS_STATUS_ERROR(status)) {
  5486. spectral_err("unable to extract sscan fw fixed params");
  5487. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  5488. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5489. }
  5490. } else {
  5491. spectral->rparams.marker[event_params.smode].is_valid = false;
  5492. }
  5493. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  5494. return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
  5495. }
  5496. static QDF_STATUS
  5497. target_if_spectral_register_events(struct wlan_objmgr_psoc *psoc)
  5498. {
  5499. int ret;
  5500. if (!psoc) {
  5501. spectral_err("psoc is null");
  5502. return QDF_STATUS_E_INVAL;
  5503. }
  5504. ret = target_if_spectral_wmi_unified_register_event_handler(
  5505. psoc,
  5506. wmi_pdev_sscan_fw_param_eventid,
  5507. target_if_spectral_fw_param_event_handler,
  5508. WMI_RX_UMAC_CTX);
  5509. if (ret)
  5510. spectral_debug("event handler not supported, ret=%d", ret);
  5511. return QDF_STATUS_SUCCESS;
  5512. }
  5513. static QDF_STATUS
  5514. target_if_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
  5515. {
  5516. int ret;
  5517. if (!psoc) {
  5518. spectral_err("psoc is null");
  5519. return QDF_STATUS_E_INVAL;
  5520. }
  5521. ret = target_if_spectral_wmi_unified_unregister_event_handler(
  5522. psoc, wmi_pdev_sscan_fw_param_eventid);
  5523. if (ret)
  5524. spectral_debug("Unregister WMI event handler failed, ret = %d",
  5525. ret);
  5526. return QDF_STATUS_SUCCESS;
  5527. }
  5528. void
  5529. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5530. {
  5531. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  5532. target_if_pdev_spectral_init;
  5533. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  5534. target_if_pdev_spectral_deinit;
  5535. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init =
  5536. target_if_psoc_spectral_init;
  5537. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit =
  5538. target_if_psoc_spectral_deinit;
  5539. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  5540. target_if_set_spectral_config;
  5541. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  5542. target_if_get_spectral_config;
  5543. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  5544. target_if_start_spectral_scan;
  5545. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  5546. target_if_stop_spectral_scan;
  5547. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  5548. target_if_is_spectral_active;
  5549. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  5550. target_if_is_spectral_enabled;
  5551. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  5552. target_if_set_debug_level;
  5553. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  5554. target_if_get_debug_level;
  5555. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  5556. target_if_get_spectral_capinfo;
  5557. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  5558. target_if_get_spectral_diagstats;
  5559. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_wmi_ops =
  5560. target_if_register_spectral_wmi_ops;
  5561. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_tgt_ops =
  5562. target_if_register_spectral_tgt_ops;
  5563. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  5564. target_if_register_netlink_cb;
  5565. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  5566. target_if_use_nl_bcast;
  5567. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  5568. target_if_deregister_netlink_cb;
  5569. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  5570. target_if_process_spectral_report;
  5571. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  5572. target_if_spectral_direct_dma_support;
  5573. tx_ops->sptrl_tx_ops.sptrlto_register_events =
  5574. target_if_spectral_register_events;
  5575. tx_ops->sptrl_tx_ops.sptrlto_unregister_events =
  5576. target_if_spectral_unregister_events;
  5577. tx_ops->sptrl_tx_ops.sptrlto_init_pdev_feature_caps =
  5578. target_if_spectral_init_pdev_feature_caps;
  5579. target_if_sptrl_debug_register_tx_ops(tx_ops);
  5580. }
  5581. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  5582. void
  5583. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  5584. uint16_t cw_int, uint32_t dcs_enabled)
  5585. {
  5586. struct spectral_samp_msg *msg = NULL;
  5587. struct target_if_spectral_ops *p_sops = NULL;
  5588. struct target_if_spectral *spectral = NULL;
  5589. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5590. if (!spectral) {
  5591. spectral_err("SPECTRAL : Module doesn't exist");
  5592. return;
  5593. }
  5594. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5595. if (!p_sops) {
  5596. spectral_err("p_sops is null");
  5597. return;
  5598. }
  5599. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  5600. spectral->pdev_obj,
  5601. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  5602. SPECTRAL_MSG_BUF_NEW);
  5603. if (msg) {
  5604. msg->int_type = cw_int ?
  5605. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  5606. msg->dcs_enabled = dcs_enabled;
  5607. msg->signature = SPECTRAL_SIGNATURE;
  5608. p_sops->get_mac_address(spectral, msg->macaddr);
  5609. if (spectral->send_phy_data
  5610. (pdev,
  5611. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  5612. spectral->spectral_sent_msg++;
  5613. }
  5614. }
  5615. qdf_export_symbol(target_if_spectral_send_intf_found_msg);
  5616. QDF_STATUS
  5617. target_if_spectral_is_finite_scan(struct target_if_spectral *spectral,
  5618. enum spectral_scan_mode smode,
  5619. bool *finite_spectral_scan)
  5620. {
  5621. struct target_if_finite_spectral_scan_params *finite_scan;
  5622. if (!spectral) {
  5623. spectral_err_rl("target if spectral object is null");
  5624. return QDF_STATUS_E_INVAL;
  5625. }
  5626. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5627. spectral_err_rl("invalid spectral mode %d", smode);
  5628. return QDF_STATUS_E_INVAL;
  5629. }
  5630. if (!finite_spectral_scan) {
  5631. spectral_err_rl("Invalid pointer");
  5632. return QDF_STATUS_E_INVAL;
  5633. }
  5634. finite_scan = &spectral->finite_scan[smode];
  5635. *finite_spectral_scan = finite_scan->finite_spectral_scan;
  5636. return QDF_STATUS_SUCCESS;
  5637. }
  5638. QDF_STATUS
  5639. target_if_spectral_finite_scan_update(struct target_if_spectral *spectral,
  5640. enum spectral_scan_mode smode)
  5641. {
  5642. struct target_if_finite_spectral_scan_params *finite_scan;
  5643. if (!spectral) {
  5644. spectral_err_rl("target if spectral object is null");
  5645. return QDF_STATUS_E_INVAL;
  5646. }
  5647. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5648. spectral_err_rl("Invalid Spectral mode");
  5649. return QDF_STATUS_E_INVAL;
  5650. }
  5651. finite_scan = &spectral->finite_scan[smode];
  5652. if (!finite_scan->num_reports_expected) {
  5653. spectral_err_rl("Error, No reports expected");
  5654. return QDF_STATUS_E_FAILURE;
  5655. }
  5656. finite_scan->num_reports_expected--;
  5657. if (!finite_scan->num_reports_expected) {
  5658. QDF_STATUS status;
  5659. enum spectral_cp_error_code err;
  5660. /* received expected number of reports from target, stop scan */
  5661. status = target_if_stop_spectral_scan(spectral->pdev_obj, smode,
  5662. &err);
  5663. if (QDF_IS_STATUS_ERROR(status)) {
  5664. spectral_err_rl("Failed to stop finite Spectral scan");
  5665. return QDF_STATUS_E_FAILURE;
  5666. }
  5667. finite_scan->finite_spectral_scan = false;
  5668. }
  5669. return QDF_STATUS_SUCCESS;
  5670. }