target_if_spectral.c 177 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504
  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_QCN9224 ||
  2267. target_type == TARGET_TYPE_QCA6490) {
  2268. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_2;
  2269. rparams->num_spectral_detectors =
  2270. NUM_SPECTRAL_DETECTORS_GEN3_V2;
  2271. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2272. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2273. rparams->fragmentation_160[smode] = false;
  2274. rparams->max_agile_ch_width = CH_WIDTH_80P80MHZ;
  2275. } else {
  2276. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_1;
  2277. rparams->num_spectral_detectors =
  2278. NUM_SPECTRAL_DETECTORS_GEN3_V1;
  2279. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2280. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2281. rparams->fragmentation_160[smode] = true;
  2282. rparams->max_agile_ch_width = CH_WIDTH_80MHZ;
  2283. }
  2284. switch (rparams->version) {
  2285. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  2286. rparams->ssumaary_padding_bytes =
  2287. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1;
  2288. rparams->fft_report_hdr_len =
  2289. FFT_REPORT_HEADER_LENGTH_GEN3_V1;
  2290. break;
  2291. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  2292. rparams->ssumaary_padding_bytes =
  2293. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2;
  2294. rparams->fft_report_hdr_len =
  2295. FFT_REPORT_HEADER_LENGTH_GEN3_V2;
  2296. break;
  2297. default:
  2298. qdf_assert_always(0);
  2299. }
  2300. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_0] =
  2301. SPECTRAL_SCAN_MODE_NORMAL;
  2302. if (target_type == TARGET_TYPE_QCN9000 ||
  2303. target_type == TARGET_TYPE_QCN6122 ||
  2304. target_type == TARGET_TYPE_QCA6490) {
  2305. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2306. SPECTRAL_SCAN_MODE_AGILE;
  2307. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2308. SPECTRAL_SCAN_MODE_INVALID;
  2309. } else {
  2310. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2311. SPECTRAL_SCAN_MODE_NORMAL;
  2312. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2313. SPECTRAL_SCAN_MODE_AGILE;
  2314. }
  2315. }
  2316. /**
  2317. * target_if_spectral_timestamp_war_init() - Initialize Spectral timestamp WAR
  2318. * related info
  2319. * @twar: Pointer to Spectral timstamp WAR related info
  2320. *
  2321. * Function to Initialize parameters related to Spectral timestamp WAR
  2322. *
  2323. * Return: void
  2324. */
  2325. static void
  2326. target_if_spectral_timestamp_war_init(struct spectral_timestamp_war *twar)
  2327. {
  2328. enum spectral_scan_mode smode;
  2329. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2330. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2331. twar->last_fft_timestamp[smode] = 0;
  2332. twar->timestamp_war_offset[smode] = 0;
  2333. }
  2334. twar->target_reset_count = 0;
  2335. }
  2336. #ifdef OPTIMIZED_SAMP_MESSAGE
  2337. /**
  2338. * target_if_spectral_detector_list_init() - Initialize Spectral detector list
  2339. * based on target type
  2340. * @spectral: Pointer to Spectral target_if
  2341. *
  2342. * Function to initialize Spectral detector list for possible combinations of
  2343. * Spectral scan mode and channel width, based on target type.
  2344. *
  2345. * Return: Success/Failure
  2346. */
  2347. static QDF_STATUS
  2348. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  2349. {
  2350. struct sscan_detector_list *det_list;
  2351. enum spectral_scan_mode smode;
  2352. enum phy_ch_width ch_width;
  2353. if (!spectral) {
  2354. spectral_err_rl("Spectral LMAC object is null");
  2355. return QDF_STATUS_E_NULL_VALUE;
  2356. }
  2357. /**
  2358. * We assume there are 2 detectors. The Detector ID coming first will
  2359. * always be pri80 detector, and second detector for sec80.
  2360. */
  2361. ch_width = CH_WIDTH_20MHZ;
  2362. for (; ch_width <= CH_WIDTH_80P80MHZ; ch_width++) {
  2363. /* Normal spectral scan */
  2364. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2365. det_list = &spectral->detector_list[smode][ch_width];
  2366. det_list->num_detectors = 1;
  2367. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_0;
  2368. if (is_ch_width_160_or_80p80(ch_width) &&
  2369. spectral->rparams.fragmentation_160[smode]) {
  2370. det_list->num_detectors += 1;
  2371. det_list->detectors[1] = SPECTRAL_DETECTOR_ID_1;
  2372. }
  2373. /* Agile spectral scan */
  2374. smode = SPECTRAL_SCAN_MODE_AGILE;
  2375. det_list = &spectral->detector_list[smode][ch_width];
  2376. det_list->num_detectors = 1;
  2377. if (spectral->rparams.fragmentation_160[smode]) {
  2378. /**
  2379. * Skip to next iteration if 160/80p80 MHz for Agile
  2380. * scan. Only 20/40/80 MHz is supported on platforms
  2381. * with fragmentation, as only 1 detector is available.
  2382. */
  2383. if (is_ch_width_160_or_80p80(ch_width))
  2384. continue;
  2385. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_2;
  2386. } else {
  2387. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_1;
  2388. }
  2389. }
  2390. return QDF_STATUS_SUCCESS;
  2391. }
  2392. #else
  2393. static QDF_STATUS
  2394. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  2395. {
  2396. return QDF_STATUS_SUCCESS;
  2397. }
  2398. #endif /* OPTIMIZED_SAMP_MESSAGE */
  2399. /**
  2400. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  2401. * functionality for the given pdev
  2402. * @pdev: Pointer to pdev object
  2403. *
  2404. * Function to initialize pointer to spectral target_if internal private data
  2405. *
  2406. * Return: On success, pointer to Spectral target_if internal private data, on
  2407. * failure, NULL
  2408. */
  2409. void *
  2410. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  2411. {
  2412. struct target_if_spectral_ops *p_sops = NULL;
  2413. struct target_if_spectral *spectral = NULL;
  2414. uint32_t target_type;
  2415. uint32_t target_revision;
  2416. struct wlan_objmgr_psoc *psoc;
  2417. struct wlan_lmac_if_target_tx_ops *tgt_tx_ops;
  2418. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  2419. QDF_STATUS status;
  2420. struct wlan_lmac_if_tx_ops *tx_ops;
  2421. if (!pdev) {
  2422. spectral_err("SPECTRAL: pdev is NULL!");
  2423. return NULL;
  2424. }
  2425. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  2426. sizeof(struct target_if_spectral));
  2427. if (!spectral)
  2428. return spectral;
  2429. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  2430. /* Store pdev in Spectral */
  2431. spectral->pdev_obj = pdev;
  2432. spectral->vdev_id[SPECTRAL_SCAN_MODE_NORMAL] = WLAN_INVALID_VDEV_ID;
  2433. spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE] = WLAN_INVALID_VDEV_ID;
  2434. psoc = wlan_pdev_get_psoc(pdev);
  2435. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  2436. if (!tx_ops) {
  2437. spectral_err("tx_ops is NULL");
  2438. qdf_mem_free(spectral);
  2439. return NULL;
  2440. }
  2441. tgt_tx_ops = &tx_ops->target_tx_ops;
  2442. if (tgt_tx_ops->tgt_get_tgt_type) {
  2443. target_type = tgt_tx_ops->tgt_get_tgt_type(psoc);
  2444. } else {
  2445. qdf_mem_free(spectral);
  2446. return NULL;
  2447. }
  2448. if (tgt_tx_ops->tgt_get_tgt_revision) {
  2449. target_revision = tgt_tx_ops->tgt_get_tgt_revision(psoc);
  2450. } else {
  2451. qdf_mem_free(spectral);
  2452. return NULL;
  2453. }
  2454. /* init the function ptr table */
  2455. target_if_spectral_init_dummy_function_table(spectral);
  2456. /* get spectral function table */
  2457. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2458. /* TODO : Should this be called here of after ath_attach ? */
  2459. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  2460. spectral_info("HAL_CAP_PHYDIAG : Capable");
  2461. /* TODO: Need to fix the capablity check for RADAR */
  2462. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  2463. spectral_info("HAL_CAP_RADAR : Capable");
  2464. /* TODO : Need to fix the capablity check for SPECTRAL */
  2465. /* TODO : Should this be called here of after ath_attach ? */
  2466. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  2467. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  2468. qdf_spinlock_create(&spectral->spectral_lock);
  2469. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  2470. target_if_spectral_clear_stats(spectral);
  2471. if (target_type == TARGET_TYPE_QCA8074 ||
  2472. target_type == TARGET_TYPE_QCA8074V2 ||
  2473. target_type == TARGET_TYPE_QCA9574 ||
  2474. target_type == TARGET_TYPE_QCA6018 ||
  2475. target_type == TARGET_TYPE_QCA5018 ||
  2476. target_type == TARGET_TYPE_QCA6390 ||
  2477. target_type == TARGET_TYPE_QCN6122 ||
  2478. target_type == TARGET_TYPE_QCA6490 ||
  2479. target_type == TARGET_TYPE_QCN9000 ||
  2480. target_type == TARGET_TYPE_QCN9224 ||
  2481. target_type == TARGET_TYPE_QCA6750)
  2482. spectral->direct_dma_support = true;
  2483. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  2484. target_type);
  2485. target_if_spectral_report_params_init(&spectral->rparams, target_type);
  2486. if ((target_type == TARGET_TYPE_QCA8074) ||
  2487. (target_type == TARGET_TYPE_QCA8074V2) ||
  2488. (target_type == TARGET_TYPE_QCA9574) ||
  2489. (target_type == TARGET_TYPE_QCA6018) ||
  2490. (target_type == TARGET_TYPE_QCA5018) ||
  2491. (target_type == TARGET_TYPE_QCN6122) ||
  2492. (target_type == TARGET_TYPE_QCN9000) ||
  2493. (target_type == TARGET_TYPE_QCA6290) ||
  2494. (target_type == TARGET_TYPE_QCA6390) ||
  2495. (target_type == TARGET_TYPE_QCA6490) ||
  2496. (target_type == TARGET_TYPE_QCN9224) ||
  2497. (target_type == TARGET_TYPE_QCA6750)) {
  2498. spectral->spectral_gen = SPECTRAL_GEN3;
  2499. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  2500. spectral->tag_sscan_summary_exp =
  2501. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  2502. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  2503. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  2504. } else {
  2505. spectral->spectral_gen = SPECTRAL_GEN2;
  2506. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  2507. spectral->tag_sscan_summary_exp =
  2508. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  2509. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  2510. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  2511. }
  2512. status = target_if_init_spectral_param_min_max(
  2513. &spectral->param_min_max,
  2514. spectral->spectral_gen, target_type);
  2515. if (QDF_IS_STATUS_ERROR(status)) {
  2516. spectral_err("Failed to initialize parameter min max values");
  2517. goto fail;
  2518. }
  2519. target_if_init_spectral_param_properties(spectral);
  2520. /* Init spectral capability */
  2521. if (target_if_init_spectral_capability(spectral, target_type) !=
  2522. QDF_STATUS_SUCCESS) {
  2523. qdf_mem_free(spectral);
  2524. return NULL;
  2525. }
  2526. if (target_if_spectral_attach_simulation(spectral) < 0)
  2527. return NULL;
  2528. target_if_init_spectral_ops(spectral);
  2529. target_if_spectral_timestamp_war_init(&spectral->timestamp_war);
  2530. /* Spectral mode specific init */
  2531. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2532. spectral->params_valid[smode] = false;
  2533. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  2534. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  2535. }
  2536. target_if_spectral_register_funcs(spectral, &spectral_ops);
  2537. if (target_if_spectral_check_hw_capability(spectral) == false) {
  2538. goto fail;
  2539. } else {
  2540. /*
  2541. * TODO: Once the driver architecture transitions to chipset
  2542. * versioning based checks, reflect this here.
  2543. */
  2544. spectral->is_160_format = false;
  2545. spectral->is_lb_edge_extrabins_format = false;
  2546. spectral->is_rb_edge_extrabins_format = false;
  2547. if (target_type == TARGET_TYPE_QCA9984 ||
  2548. target_type == TARGET_TYPE_QCA9888) {
  2549. spectral->is_160_format = true;
  2550. spectral->is_lb_edge_extrabins_format = true;
  2551. spectral->is_rb_edge_extrabins_format = true;
  2552. } else if ((target_type == TARGET_TYPE_AR900B) &&
  2553. (target_revision == AR900B_REV_2)) {
  2554. spectral->is_rb_edge_extrabins_format = true;
  2555. }
  2556. if (target_type == TARGET_TYPE_QCA9984 ||
  2557. target_type == TARGET_TYPE_QCA9888)
  2558. spectral->is_sec80_rssi_war_required = true;
  2559. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  2560. if (spectral->spectral_gen == SPECTRAL_GEN3)
  2561. init_160mhz_delivery_state_machine(spectral);
  2562. }
  2563. target_if_spectral_detector_list_init(spectral);
  2564. return spectral;
  2565. fail:
  2566. target_if_spectral_detach(spectral);
  2567. return NULL;
  2568. }
  2569. /**
  2570. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  2571. * functionality for the given pdev
  2572. * @pdev: Pointer to pdev object
  2573. *
  2574. * Function to de-initialize pointer to spectral target_if internal private data
  2575. *
  2576. * Return: None
  2577. */
  2578. void
  2579. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  2580. {
  2581. struct target_if_spectral *spectral = NULL;
  2582. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2583. if (!spectral) {
  2584. spectral_err("SPECTRAL : Module doesn't exist");
  2585. return;
  2586. }
  2587. target_if_spectral_detach(spectral);
  2588. return;
  2589. }
  2590. /**
  2591. * target_if_psoc_spectral_deinit() - De-initialize target_if Spectral
  2592. * functionality for the given psoc
  2593. * @psoc: Pointer to psoc object
  2594. *
  2595. * Function to de-initialize pointer to psoc spectral target_if internal
  2596. * private data
  2597. *
  2598. * Return: None
  2599. */
  2600. static void
  2601. target_if_psoc_spectral_deinit(struct wlan_objmgr_psoc *psoc)
  2602. {
  2603. struct target_if_psoc_spectral *psoc_spectral;
  2604. if (!psoc) {
  2605. spectral_err("psoc is null");
  2606. return;
  2607. }
  2608. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  2609. if (!psoc_spectral) {
  2610. spectral_err("Spectral target_if psoc object is null");
  2611. return;
  2612. }
  2613. qdf_mem_free(psoc_spectral);
  2614. }
  2615. /**
  2616. * target_if_psoc_spectral_init() - Initialize target_if Spectral
  2617. * functionality for the given psoc
  2618. * @psoc: Pointer to psoc object
  2619. *
  2620. * Function to initialize pointer to psoc spectral target_if internal
  2621. * private data
  2622. *
  2623. * Return: On success, pointer to Spectral psoc target_if internal
  2624. * private data, on failure, NULL
  2625. */
  2626. static void *
  2627. target_if_psoc_spectral_init(struct wlan_objmgr_psoc *psoc)
  2628. {
  2629. struct target_if_psoc_spectral *psoc_spectral = NULL;
  2630. if (!psoc) {
  2631. spectral_err("psoc is null");
  2632. goto fail;
  2633. }
  2634. psoc_spectral = (struct target_if_psoc_spectral *)qdf_mem_malloc(
  2635. sizeof(struct target_if_psoc_spectral));
  2636. if (!psoc_spectral) {
  2637. spectral_err("Spectral lmac psoc object allocation failed");
  2638. goto fail;
  2639. }
  2640. psoc_spectral->psoc_obj = psoc;
  2641. return psoc_spectral;
  2642. fail:
  2643. if (psoc_spectral)
  2644. target_if_psoc_spectral_deinit(psoc);
  2645. return psoc_spectral;
  2646. }
  2647. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  2648. * corresponding translation for Agile channel width.
  2649. * @spectral: pointer to Spectral object
  2650. * @chwidth: operating channel width
  2651. * @is_80_80_agile: Indicates an 80+80 agile Scan request
  2652. *
  2653. * Return: The translated channel width enum.
  2654. */
  2655. static enum phy_ch_width
  2656. target_if_spectral_find_agile_width(struct target_if_spectral *spectral,
  2657. enum phy_ch_width chwidth,
  2658. bool is_80_80_agile)
  2659. {
  2660. enum phy_ch_width agile_width;
  2661. struct wlan_objmgr_pdev *pdev;
  2662. struct wlan_objmgr_psoc *psoc;
  2663. if (!spectral) {
  2664. spectral_err("Spectral object is null");
  2665. return CH_WIDTH_INVALID;
  2666. }
  2667. pdev = spectral->pdev_obj;
  2668. if (!pdev) {
  2669. spectral_err("pdev is null");
  2670. return CH_WIDTH_INVALID;
  2671. }
  2672. psoc = wlan_pdev_get_psoc(pdev);
  2673. if (!psoc) {
  2674. spectral_err("psoc is null");
  2675. return CH_WIDTH_INVALID;
  2676. }
  2677. switch (chwidth) {
  2678. case CH_WIDTH_20MHZ:
  2679. agile_width = CH_WIDTH_20MHZ;
  2680. break;
  2681. case CH_WIDTH_40MHZ:
  2682. agile_width = CH_WIDTH_40MHZ;
  2683. break;
  2684. case CH_WIDTH_80MHZ:
  2685. agile_width = CH_WIDTH_80MHZ;
  2686. break;
  2687. case CH_WIDTH_80P80MHZ:
  2688. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  2689. WLAN_SOC_RESTRICTED_80P80_SUPPORT) && !is_80_80_agile)
  2690. agile_width = CH_WIDTH_160MHZ;
  2691. else
  2692. agile_width = CH_WIDTH_80P80MHZ;
  2693. if (agile_width > spectral->rparams.max_agile_ch_width)
  2694. agile_width = spectral->rparams.max_agile_ch_width;
  2695. break;
  2696. case CH_WIDTH_160MHZ:
  2697. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  2698. WLAN_SOC_RESTRICTED_80P80_SUPPORT) && is_80_80_agile)
  2699. agile_width = CH_WIDTH_80P80MHZ;
  2700. else
  2701. agile_width = CH_WIDTH_160MHZ;
  2702. if (agile_width > spectral->rparams.max_agile_ch_width)
  2703. agile_width = spectral->rparams.max_agile_ch_width;
  2704. break;
  2705. default:
  2706. spectral_err("Invalid channel width %d", chwidth);
  2707. agile_width = CH_WIDTH_INVALID;
  2708. break;
  2709. }
  2710. return agile_width;
  2711. }
  2712. /**
  2713. * target_if_calculate_center_freq() - Helper routine to
  2714. * check whether given frequency is center frequency of a
  2715. * WLAN channel
  2716. *
  2717. * @spectral: Pointer to Spectral object
  2718. * @chan_freq: Center frequency of a WLAN channel
  2719. * @is_valid: Indicates whether given frequency is valid
  2720. *
  2721. * Return: QDF_STATUS
  2722. */
  2723. static QDF_STATUS
  2724. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  2725. uint32_t chan_freq,
  2726. bool *is_valid)
  2727. {
  2728. struct regulatory_channel *cur_chan_list;
  2729. int i;
  2730. if (!pdev) {
  2731. spectral_err("pdev object is null");
  2732. return QDF_STATUS_E_FAILURE;
  2733. }
  2734. if (!is_valid) {
  2735. spectral_err("is valid argument is null");
  2736. return QDF_STATUS_E_FAILURE;
  2737. }
  2738. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  2739. if (!cur_chan_list)
  2740. return QDF_STATUS_E_FAILURE;
  2741. if (wlan_reg_get_current_chan_list(
  2742. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  2743. spectral_err("Failed to get cur_chan list");
  2744. qdf_mem_free(cur_chan_list);
  2745. return QDF_STATUS_E_FAILURE;
  2746. }
  2747. *is_valid = false;
  2748. for (i = 0; i < NUM_CHANNELS; i++) {
  2749. uint32_t flags;
  2750. uint32_t center_freq;
  2751. flags = cur_chan_list[i].chan_flags;
  2752. center_freq = cur_chan_list[i].center_freq;
  2753. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  2754. (center_freq == chan_freq)) {
  2755. *is_valid = true;
  2756. break;
  2757. }
  2758. }
  2759. qdf_mem_free(cur_chan_list);
  2760. return QDF_STATUS_SUCCESS;
  2761. }
  2762. /**
  2763. * target_if_calculate_center_freq() - Helper routine to
  2764. * find the center frequency of the agile span from a
  2765. * WLAN channel center frequency
  2766. *
  2767. * @spectral: Pointer to Spectral object
  2768. * @ch_width: Channel width array
  2769. * @chan_freq: Center frequency of a WLAN channel
  2770. * @center_freq: Pointer to center frequency
  2771. *
  2772. * Return: QDF_STATUS
  2773. */
  2774. static QDF_STATUS
  2775. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  2776. enum phy_ch_width *ch_width,
  2777. uint16_t chan_freq,
  2778. uint16_t *center_freq)
  2779. {
  2780. enum phy_ch_width agile_ch_width;
  2781. if (!spectral) {
  2782. spectral_err("spectral target if object is null");
  2783. return QDF_STATUS_E_FAILURE;
  2784. }
  2785. if (!ch_width) {
  2786. spectral_err("Channel width array is null");
  2787. return QDF_STATUS_E_INVAL;
  2788. }
  2789. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2790. if (!center_freq) {
  2791. spectral_err("center_freq argument is null");
  2792. return QDF_STATUS_E_FAILURE;
  2793. }
  2794. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2795. *center_freq = chan_freq;
  2796. } else {
  2797. uint16_t start_freq;
  2798. uint16_t end_freq;
  2799. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2800. enum channel_state state;
  2801. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2802. (spectral->pdev_obj, chan_freq, agile_ch_width,
  2803. &bonded_chan_ptr);
  2804. if (state == CHANNEL_STATE_DISABLE ||
  2805. state == CHANNEL_STATE_INVALID) {
  2806. spectral_err("Channel state is disable or invalid");
  2807. return QDF_STATUS_E_FAILURE;
  2808. }
  2809. if (!bonded_chan_ptr) {
  2810. spectral_err("Bonded channel is not found");
  2811. return QDF_STATUS_E_FAILURE;
  2812. }
  2813. start_freq = bonded_chan_ptr->start_freq;
  2814. end_freq = bonded_chan_ptr->end_freq;
  2815. *center_freq = (start_freq + end_freq) >> 1;
  2816. }
  2817. return QDF_STATUS_SUCCESS;
  2818. }
  2819. /**
  2820. * target_if_validate_center_freq() - Helper routine to
  2821. * validate user provided agile center frequency
  2822. *
  2823. * @spectral: Pointer to Spectral object
  2824. * @ch_width: Channel width array
  2825. * @center_freq: User provided agile span center frequency
  2826. * @is_valid: Indicates whether agile span center frequency is valid
  2827. *
  2828. * Return: QDF_STATUS
  2829. */
  2830. static QDF_STATUS
  2831. target_if_validate_center_freq(struct target_if_spectral *spectral,
  2832. enum phy_ch_width *ch_width,
  2833. uint16_t center_freq,
  2834. bool *is_valid)
  2835. {
  2836. enum phy_ch_width agile_ch_width;
  2837. struct wlan_objmgr_pdev *pdev;
  2838. QDF_STATUS status;
  2839. if (!spectral) {
  2840. spectral_err("spectral target if object is null");
  2841. return QDF_STATUS_E_FAILURE;
  2842. }
  2843. if (!ch_width) {
  2844. spectral_err("channel width array is null");
  2845. return QDF_STATUS_E_INVAL;
  2846. }
  2847. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2848. if (!is_valid) {
  2849. spectral_err("is_valid argument is null");
  2850. return QDF_STATUS_E_FAILURE;
  2851. }
  2852. pdev = spectral->pdev_obj;
  2853. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2854. status = target_if_is_center_freq_of_any_chan
  2855. (pdev, center_freq, is_valid);
  2856. if (QDF_IS_STATUS_ERROR(status))
  2857. return QDF_STATUS_E_FAILURE;
  2858. } else {
  2859. uint16_t start_freq;
  2860. uint16_t end_freq;
  2861. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2862. bool is_chan;
  2863. status = target_if_is_center_freq_of_any_chan
  2864. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2865. &is_chan);
  2866. if (QDF_IS_STATUS_ERROR(status))
  2867. return QDF_STATUS_E_FAILURE;
  2868. if (is_chan) {
  2869. uint32_t calulated_center_freq;
  2870. enum channel_state st;
  2871. st = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2872. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2873. agile_ch_width,
  2874. &bonded_chan_ptr);
  2875. if (st == CHANNEL_STATE_DISABLE ||
  2876. st == CHANNEL_STATE_INVALID) {
  2877. spectral_err("Channel state disable/invalid");
  2878. return QDF_STATUS_E_FAILURE;
  2879. }
  2880. if (!bonded_chan_ptr) {
  2881. spectral_err("Bonded channel is not found");
  2882. return QDF_STATUS_E_FAILURE;
  2883. }
  2884. start_freq = bonded_chan_ptr->start_freq;
  2885. end_freq = bonded_chan_ptr->end_freq;
  2886. calulated_center_freq = (start_freq + end_freq) >> 1;
  2887. *is_valid = (center_freq == calulated_center_freq);
  2888. } else {
  2889. *is_valid = false;
  2890. }
  2891. }
  2892. return QDF_STATUS_SUCCESS;
  2893. }
  2894. /**
  2895. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  2896. * check whether agile span overlaps with current operating band.
  2897. *
  2898. * @spectral: Pointer to Spectral object
  2899. * @ch_width: Channel width array
  2900. * @center_freq: Agile span center frequency
  2901. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  2902. *
  2903. * Helper routine to check whether agile span overlaps with current
  2904. * operating band.
  2905. *
  2906. * Return: QDF_STATUS
  2907. */
  2908. static QDF_STATUS
  2909. target_if_is_agile_span_overlap_with_operating_span
  2910. (struct target_if_spectral *spectral,
  2911. enum phy_ch_width *ch_width,
  2912. struct spectral_config_frequency *center_freq,
  2913. bool *is_overlapping)
  2914. {
  2915. enum phy_ch_width op_ch_width;
  2916. enum phy_ch_width agile_ch_width;
  2917. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2918. struct wlan_objmgr_vdev *vdev;
  2919. struct wlan_objmgr_pdev *pdev;
  2920. int16_t chan_freq;
  2921. uint32_t op_start_freq;
  2922. uint32_t op_end_freq;
  2923. uint32_t agile_start_freq;
  2924. uint32_t agile_end_freq;
  2925. uint32_t cfreq2;
  2926. if (!spectral) {
  2927. spectral_err("Spectral object is NULL");
  2928. return QDF_STATUS_E_FAILURE;
  2929. }
  2930. pdev = spectral->pdev_obj;
  2931. if (!pdev) {
  2932. spectral_err("pdev object is NULL");
  2933. return QDF_STATUS_E_FAILURE;
  2934. }
  2935. if (!ch_width) {
  2936. spectral_err("channel width array is null");
  2937. return QDF_STATUS_E_FAILURE;
  2938. }
  2939. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  2940. if (op_ch_width == CH_WIDTH_INVALID) {
  2941. spectral_err("Invalid channel width");
  2942. return QDF_STATUS_E_INVAL;
  2943. }
  2944. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2945. if (agile_ch_width == CH_WIDTH_INVALID) {
  2946. spectral_err("Invalid channel width");
  2947. return QDF_STATUS_E_INVAL;
  2948. }
  2949. if (!is_overlapping) {
  2950. spectral_err("Argument(is_overlapping) is NULL");
  2951. return QDF_STATUS_E_FAILURE;
  2952. }
  2953. *is_overlapping = false;
  2954. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  2955. if (!vdev) {
  2956. spectral_err("vdev is NULL");
  2957. return QDF_STATUS_E_FAILURE;
  2958. }
  2959. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2960. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2961. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2962. if (cfreq2 < 0) {
  2963. spectral_err("cfreq2 is invalid");
  2964. return QDF_STATUS_E_FAILURE;
  2965. }
  2966. if (op_ch_width == CH_WIDTH_20MHZ) {
  2967. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  2968. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  2969. } else {
  2970. enum channel_state state;
  2971. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2972. (pdev, chan_freq, op_ch_width, &bonded_chan_ptr);
  2973. if (state == CHANNEL_STATE_DISABLE ||
  2974. state == CHANNEL_STATE_INVALID) {
  2975. spectral_err("Channel state is disable or invalid");
  2976. return QDF_STATUS_E_FAILURE;
  2977. }
  2978. if (!bonded_chan_ptr) {
  2979. spectral_err("Bonded channel is not found");
  2980. return QDF_STATUS_E_FAILURE;
  2981. }
  2982. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  2983. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  2984. }
  2985. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  2986. agile_start_freq = center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  2987. agile_end_freq = center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  2988. if (agile_end_freq > op_start_freq &&
  2989. op_end_freq > agile_start_freq)
  2990. *is_overlapping = true;
  2991. agile_start_freq = center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  2992. agile_end_freq = center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  2993. if (agile_end_freq > op_start_freq &&
  2994. op_end_freq > agile_start_freq)
  2995. *is_overlapping = true;
  2996. } else {
  2997. agile_start_freq = center_freq->cfreq1 -
  2998. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2999. agile_end_freq = center_freq->cfreq1 +
  3000. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3001. if (agile_end_freq > op_start_freq &&
  3002. op_end_freq > agile_start_freq)
  3003. *is_overlapping = true;
  3004. }
  3005. if (op_ch_width == CH_WIDTH_80P80MHZ) {
  3006. uint32_t sec80_start_feq;
  3007. uint32_t sec80_end_freq;
  3008. sec80_start_feq = cfreq2 - FREQ_OFFSET_40MHZ;
  3009. sec80_end_freq = cfreq2 + FREQ_OFFSET_40MHZ;
  3010. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3011. agile_start_freq =
  3012. center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3013. agile_end_freq =
  3014. center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3015. if (agile_end_freq > sec80_start_feq &&
  3016. sec80_end_freq > agile_start_freq)
  3017. *is_overlapping = true;
  3018. agile_start_freq =
  3019. center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3020. agile_end_freq =
  3021. center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3022. if (agile_end_freq > sec80_start_feq &&
  3023. sec80_end_freq > agile_start_freq)
  3024. *is_overlapping = true;
  3025. } else {
  3026. agile_start_freq = center_freq->cfreq1 -
  3027. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3028. agile_end_freq = center_freq->cfreq1 +
  3029. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3030. if (agile_end_freq > sec80_start_feq &&
  3031. sec80_end_freq > agile_start_freq)
  3032. *is_overlapping = true;
  3033. }
  3034. }
  3035. return QDF_STATUS_SUCCESS;
  3036. }
  3037. /**
  3038. * target_if_spectral_populate_chwidth() - Helper routine to
  3039. * populate channel width for different Spectral modes
  3040. *
  3041. * @spectral: Pointer to Spectral object
  3042. * @ch_width: Channel width array
  3043. * @is_80_80_agile: Indicates whether 80+80 agile scan is requested
  3044. *
  3045. * Helper routine to populate channel width for different Spectral modes
  3046. *
  3047. * Return: QDF_STATUS
  3048. */
  3049. static QDF_STATUS
  3050. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral,
  3051. enum phy_ch_width *ch_width,
  3052. bool is_80_80_agile) {
  3053. struct wlan_objmgr_vdev *vdev;
  3054. enum spectral_scan_mode smode;
  3055. enum phy_ch_width vdev_ch_width;
  3056. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3057. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  3058. ch_width[smode] = CH_WIDTH_INVALID;
  3059. if (!spectral) {
  3060. spectral_err("Spectral object is null");
  3061. return QDF_STATUS_E_INVAL;
  3062. }
  3063. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_NORMAL);
  3064. if (!vdev) {
  3065. spectral_err("vdev is null");
  3066. return QDF_STATUS_E_FAILURE;
  3067. }
  3068. vdev_ch_width = target_if_vdev_get_ch_width(vdev);
  3069. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3070. if (vdev_ch_width == CH_WIDTH_INVALID) {
  3071. spectral_err("Invalid channel width %d", vdev_ch_width);
  3072. return QDF_STATUS_E_FAILURE;
  3073. }
  3074. ch_width[SPECTRAL_SCAN_MODE_NORMAL] = vdev_ch_width;
  3075. ch_width[SPECTRAL_SCAN_MODE_AGILE] =
  3076. target_if_spectral_find_agile_width(spectral, vdev_ch_width,
  3077. is_80_80_agile);
  3078. return QDF_STATUS_SUCCESS;
  3079. }
  3080. /**
  3081. * target_if_spectral_is_valid_80p80_freq() - API to check whether given
  3082. * (cfreq1, cfreq2) pair forms a valid 80+80 combination
  3083. * @pdev: pointer to pdev
  3084. * @cfreq1: center frequency 1
  3085. * @cfreq2: center frequency 2
  3086. *
  3087. * API to check whether given (cfreq1, cfreq2) pair forms a valid 80+80
  3088. * combination
  3089. *
  3090. * Return: true or false
  3091. */
  3092. static bool
  3093. target_if_spectral_is_valid_80p80_freq(struct wlan_objmgr_pdev *pdev,
  3094. uint32_t cfreq1, uint32_t cfreq2)
  3095. {
  3096. struct ch_params ch_params;
  3097. enum channel_state chan_state1;
  3098. enum channel_state chan_state2;
  3099. struct wlan_objmgr_psoc *psoc;
  3100. qdf_assert_always(pdev);
  3101. psoc = wlan_pdev_get_psoc(pdev);
  3102. qdf_assert_always(psoc);
  3103. /* In restricted 80P80 MHz enabled, only one 80+80 MHz
  3104. * channel is supported with cfreq=5690 and cfreq=5775.
  3105. */
  3106. if (wlan_psoc_nif_fw_ext_cap_get(
  3107. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  3108. return CHAN_WITHIN_RESTRICTED_80P80(cfreq1, cfreq2);
  3109. ch_params.center_freq_seg1 = wlan_reg_freq_to_chan(pdev, cfreq2);
  3110. ch_params.mhz_freq_seg1 = cfreq2;
  3111. ch_params.ch_width = CH_WIDTH_80P80MHZ;
  3112. wlan_reg_set_channel_params_for_freq(pdev, cfreq1 - FREQ_OFFSET_10MHZ,
  3113. 0, &ch_params);
  3114. if (ch_params.ch_width != CH_WIDTH_80P80MHZ)
  3115. return false;
  3116. if (ch_params.mhz_freq_seg0 != cfreq1 ||
  3117. ch_params.mhz_freq_seg1 != cfreq2)
  3118. return false;
  3119. chan_state1 = wlan_reg_get_5g_bonded_channel_state_for_freq(
  3120. pdev,
  3121. ch_params.mhz_freq_seg0 - FREQ_OFFSET_10MHZ,
  3122. CH_WIDTH_80MHZ);
  3123. if ((chan_state1 == CHANNEL_STATE_DISABLE) ||
  3124. (chan_state1 == CHANNEL_STATE_INVALID))
  3125. return false;
  3126. chan_state2 = wlan_reg_get_5g_bonded_channel_state_for_freq(
  3127. pdev,
  3128. ch_params.mhz_freq_seg1 - FREQ_OFFSET_10MHZ,
  3129. CH_WIDTH_80MHZ);
  3130. if ((chan_state2 == CHANNEL_STATE_DISABLE) ||
  3131. (chan_state2 == CHANNEL_STATE_INVALID))
  3132. return false;
  3133. if (abs(ch_params.mhz_freq_seg0 - ch_params.mhz_freq_seg1) <=
  3134. FREQ_OFFSET_80MHZ)
  3135. return false;
  3136. return true;
  3137. }
  3138. /**
  3139. * _target_if_set_spectral_config() - Set spectral config
  3140. * @spectral: Pointer to spectral object
  3141. * @param: Spectral parameter id and value
  3142. * @smode: Spectral scan mode
  3143. * @err: Spectral error code
  3144. *
  3145. * API to set spectral configurations
  3146. *
  3147. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3148. */
  3149. static QDF_STATUS
  3150. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  3151. const struct spectral_cp_param *param,
  3152. const enum spectral_scan_mode smode,
  3153. enum spectral_cp_error_code *err)
  3154. {
  3155. struct spectral_config params;
  3156. struct target_if_spectral_ops *p_sops;
  3157. struct spectral_config *sparams;
  3158. QDF_STATUS status;
  3159. bool is_overlapping;
  3160. uint16_t agile_cfreq;
  3161. bool is_valid_chan;
  3162. struct spectral_param_min_max *param_min_max;
  3163. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  3164. enum spectral_scan_mode m;
  3165. struct spectral_config_frequency center_freq = {0};
  3166. if (!err) {
  3167. spectral_err("Error code argument is null");
  3168. QDF_ASSERT(0);
  3169. return QDF_STATUS_E_FAILURE;
  3170. }
  3171. *err = SPECTRAL_SCAN_ERR_INVALID;
  3172. if (!param) {
  3173. spectral_err("Parameter object is null");
  3174. return QDF_STATUS_E_FAILURE;
  3175. }
  3176. if (!spectral) {
  3177. spectral_err("spectral object is NULL");
  3178. return QDF_STATUS_E_FAILURE;
  3179. }
  3180. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3181. param_min_max = &spectral->param_min_max;
  3182. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3183. spectral_err("Invalid Spectral mode %u", smode);
  3184. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3185. return QDF_STATUS_E_FAILURE;
  3186. }
  3187. sparams = &spectral->params[smode];
  3188. m = SPECTRAL_SCAN_MODE_NORMAL;
  3189. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  3190. ch_width[m] = CH_WIDTH_INVALID;
  3191. if (!spectral->params_valid[smode]) {
  3192. target_if_spectral_info_read(spectral,
  3193. smode,
  3194. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3195. &spectral->params[smode],
  3196. sizeof(spectral->params[smode]));
  3197. spectral->params_valid[smode] = true;
  3198. }
  3199. switch (param->id) {
  3200. case SPECTRAL_PARAM_FFT_PERIOD:
  3201. sparams->ss_fft_period = param->value;
  3202. break;
  3203. case SPECTRAL_PARAM_SCAN_PERIOD:
  3204. sparams->ss_period = param->value;
  3205. break;
  3206. case SPECTRAL_PARAM_SCAN_COUNT:
  3207. sparams->ss_count = param->value;
  3208. break;
  3209. case SPECTRAL_PARAM_SHORT_REPORT:
  3210. sparams->ss_short_report = (!!param->value) ? true : false;
  3211. break;
  3212. case SPECTRAL_PARAM_SPECT_PRI:
  3213. sparams->ss_spectral_pri = (!!param->value) ? true : false;
  3214. break;
  3215. case SPECTRAL_PARAM_FFT_SIZE:
  3216. status = target_if_spectral_populate_chwidth
  3217. (spectral, ch_width, spectral->params
  3218. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  3219. if (QDF_IS_STATUS_ERROR(status))
  3220. return QDF_STATUS_E_FAILURE;
  3221. if ((param->value < param_min_max->fft_size_min) ||
  3222. (param->value > param_min_max->fft_size_max
  3223. [ch_width[smode]])) {
  3224. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3225. return QDF_STATUS_E_FAILURE;
  3226. }
  3227. sparams->ss_fft_size = param->value;
  3228. break;
  3229. case SPECTRAL_PARAM_GC_ENA:
  3230. sparams->ss_gc_ena = !!param->value;
  3231. break;
  3232. case SPECTRAL_PARAM_RESTART_ENA:
  3233. sparams->ss_restart_ena = !!param->value;
  3234. break;
  3235. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  3236. sparams->ss_noise_floor_ref = param->value;
  3237. break;
  3238. case SPECTRAL_PARAM_INIT_DELAY:
  3239. sparams->ss_init_delay = param->value;
  3240. break;
  3241. case SPECTRAL_PARAM_NB_TONE_THR:
  3242. sparams->ss_nb_tone_thr = param->value;
  3243. break;
  3244. case SPECTRAL_PARAM_STR_BIN_THR:
  3245. sparams->ss_str_bin_thr = param->value;
  3246. break;
  3247. case SPECTRAL_PARAM_WB_RPT_MODE:
  3248. sparams->ss_wb_rpt_mode = !!param->value;
  3249. break;
  3250. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  3251. sparams->ss_rssi_rpt_mode = !!param->value;
  3252. break;
  3253. case SPECTRAL_PARAM_RSSI_THR:
  3254. sparams->ss_rssi_thr = param->value;
  3255. break;
  3256. case SPECTRAL_PARAM_PWR_FORMAT:
  3257. sparams->ss_pwr_format = !!param->value;
  3258. break;
  3259. case SPECTRAL_PARAM_RPT_MODE:
  3260. if ((param->value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  3261. (param->value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  3262. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3263. return QDF_STATUS_E_FAILURE;
  3264. }
  3265. sparams->ss_rpt_mode = param->value;
  3266. break;
  3267. case SPECTRAL_PARAM_BIN_SCALE:
  3268. sparams->ss_bin_scale = param->value;
  3269. break;
  3270. case SPECTRAL_PARAM_DBM_ADJ:
  3271. sparams->ss_dbm_adj = !!param->value;
  3272. break;
  3273. case SPECTRAL_PARAM_CHN_MASK:
  3274. sparams->ss_chn_mask = param->value;
  3275. break;
  3276. case SPECTRAL_PARAM_FREQUENCY:
  3277. status = target_if_spectral_populate_chwidth(
  3278. spectral, ch_width, param->freq.cfreq2 > 0);
  3279. if (QDF_IS_STATUS_ERROR(status)) {
  3280. spectral_err("Failed to populate channel width");
  3281. return QDF_STATUS_E_FAILURE;
  3282. }
  3283. if (ch_width[smode] != CH_WIDTH_80P80MHZ &&
  3284. param->freq.cfreq2) {
  3285. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3286. spectral_err("Non zero cfreq2 expected for 80p80 only");
  3287. return QDF_STATUS_E_INVAL;
  3288. }
  3289. if (ch_width[smode] == CH_WIDTH_80P80MHZ &&
  3290. !param->freq.cfreq2) {
  3291. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3292. spectral_err("Non zero cfreq2 expected for 80p80");
  3293. return QDF_STATUS_E_INVAL;
  3294. }
  3295. status = target_if_is_center_freq_of_any_chan
  3296. (spectral->pdev_obj, param->freq.cfreq1,
  3297. &is_valid_chan);
  3298. if (QDF_IS_STATUS_ERROR(status))
  3299. return QDF_STATUS_E_FAILURE;
  3300. if (is_valid_chan) {
  3301. status = target_if_calculate_center_freq(
  3302. spectral, ch_width,
  3303. param->freq.cfreq1,
  3304. &agile_cfreq);
  3305. if (QDF_IS_STATUS_ERROR(status)) {
  3306. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3307. return QDF_STATUS_E_FAILURE;
  3308. }
  3309. } else {
  3310. bool is_valid_agile_cfreq;
  3311. status = target_if_validate_center_freq
  3312. (spectral, ch_width, param->freq.cfreq1,
  3313. &is_valid_agile_cfreq);
  3314. if (QDF_IS_STATUS_ERROR(status))
  3315. return QDF_STATUS_E_FAILURE;
  3316. if (!is_valid_agile_cfreq) {
  3317. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3318. spectral_err("Invalid agile center frequency");
  3319. return QDF_STATUS_E_FAILURE;
  3320. }
  3321. agile_cfreq = param->freq.cfreq1;
  3322. }
  3323. center_freq.cfreq1 = agile_cfreq;
  3324. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  3325. status = target_if_is_center_freq_of_any_chan
  3326. (spectral->pdev_obj, param->freq.cfreq2,
  3327. &is_valid_chan);
  3328. if (QDF_IS_STATUS_ERROR(status))
  3329. return QDF_STATUS_E_FAILURE;
  3330. if (is_valid_chan) {
  3331. status = target_if_calculate_center_freq(
  3332. spectral, ch_width,
  3333. param->freq.cfreq2,
  3334. &agile_cfreq);
  3335. if (QDF_IS_STATUS_ERROR(status)) {
  3336. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3337. return QDF_STATUS_E_FAILURE;
  3338. }
  3339. } else {
  3340. bool is_valid_agile_cfreq;
  3341. status = target_if_validate_center_freq
  3342. (spectral, ch_width, param->freq.cfreq2,
  3343. &is_valid_agile_cfreq);
  3344. if (QDF_IS_STATUS_ERROR(status))
  3345. return QDF_STATUS_E_FAILURE;
  3346. if (!is_valid_agile_cfreq) {
  3347. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3348. spectral_err("Invalid agile center frequency");
  3349. return QDF_STATUS_E_FAILURE;
  3350. }
  3351. agile_cfreq = param->freq.cfreq2;
  3352. }
  3353. center_freq.cfreq2 = agile_cfreq;
  3354. }
  3355. status = target_if_is_agile_span_overlap_with_operating_span
  3356. (spectral, ch_width,
  3357. &center_freq, &is_overlapping);
  3358. if (QDF_IS_STATUS_ERROR(status))
  3359. return QDF_STATUS_E_FAILURE;
  3360. if (is_overlapping) {
  3361. spectral_err("Agile freq %u, %u overlaps with operating span",
  3362. center_freq.cfreq1, center_freq.cfreq2);
  3363. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3364. return QDF_STATUS_E_FAILURE;
  3365. }
  3366. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  3367. bool is_valid_80p80;
  3368. is_valid_80p80 = target_if_spectral_is_valid_80p80_freq(
  3369. spectral->pdev_obj,
  3370. center_freq.cfreq1,
  3371. center_freq.cfreq2);
  3372. if (!is_valid_80p80) {
  3373. spectral_err("Agile freq %u, %u is invalid 80+80 combination",
  3374. center_freq.cfreq1,
  3375. center_freq.cfreq2);
  3376. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3377. return QDF_STATUS_E_FAILURE;
  3378. }
  3379. }
  3380. sparams->ss_frequency.cfreq1 = center_freq.cfreq1;
  3381. sparams->ss_frequency.cfreq2 = center_freq.cfreq2;
  3382. break;
  3383. }
  3384. p_sops->configure_spectral(spectral, sparams, smode);
  3385. /* only to validate the writes */
  3386. p_sops->get_spectral_config(spectral, &params, smode);
  3387. return QDF_STATUS_SUCCESS;
  3388. }
  3389. QDF_STATUS
  3390. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  3391. const struct spectral_cp_param *param,
  3392. const enum spectral_scan_mode smode,
  3393. enum spectral_cp_error_code *err)
  3394. {
  3395. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  3396. struct target_if_spectral *spectral;
  3397. QDF_STATUS status;
  3398. if (!err) {
  3399. spectral_err("Error code argument is null");
  3400. QDF_ASSERT(0);
  3401. return QDF_STATUS_E_FAILURE;
  3402. }
  3403. *err = SPECTRAL_SCAN_ERR_INVALID;
  3404. if (!pdev) {
  3405. spectral_err("pdev object is NULL");
  3406. return QDF_STATUS_E_FAILURE;
  3407. }
  3408. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3409. if (!spectral) {
  3410. spectral_err("spectral object is NULL");
  3411. return QDF_STATUS_E_FAILURE;
  3412. }
  3413. if (!param) {
  3414. spectral_err("parameter object is NULL");
  3415. return QDF_STATUS_E_FAILURE;
  3416. }
  3417. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3418. spectral_err("Invalid Spectral mode %u", smode);
  3419. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3420. return QDF_STATUS_E_FAILURE;
  3421. }
  3422. if (!spectral->properties[smode][param->id].supported) {
  3423. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  3424. param->id, smode);
  3425. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  3426. return QDF_STATUS_E_FAILURE;
  3427. }
  3428. if (spectral->properties[smode][param->id].common_all_modes) {
  3429. spectral_warn("Setting Spectral parameter %u for all modes",
  3430. param->id);
  3431. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  3432. status = _target_if_set_spectral_config
  3433. (spectral, param, mode, err);
  3434. if (QDF_IS_STATUS_ERROR(status))
  3435. return QDF_STATUS_E_FAILURE;
  3436. }
  3437. return QDF_STATUS_SUCCESS;
  3438. }
  3439. return _target_if_set_spectral_config(spectral, param, smode, err);
  3440. }
  3441. /**
  3442. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  3443. * @fft_len: FFT length
  3444. * @pdev: Pointer to pdev object
  3445. *
  3446. * API to get fft bin count for a given fft length
  3447. *
  3448. * Return: FFt bin count
  3449. */
  3450. static int
  3451. target_if_get_fft_bin_count(int fft_len)
  3452. {
  3453. int bin_count = 0;
  3454. switch (fft_len) {
  3455. case 5:
  3456. bin_count = 16;
  3457. break;
  3458. case 6:
  3459. bin_count = 32;
  3460. break;
  3461. case 7:
  3462. bin_count = 64;
  3463. break;
  3464. case 8:
  3465. bin_count = 128;
  3466. break;
  3467. case 9:
  3468. bin_count = 256;
  3469. break;
  3470. default:
  3471. break;
  3472. }
  3473. return bin_count;
  3474. }
  3475. /**
  3476. * target_if_init_upper_lower_flags() - Initializes control and extension
  3477. * segment flags
  3478. * @spectral: pointer to target if spectral object
  3479. * @smode: Spectral scan mode
  3480. *
  3481. * API to initialize the control and extension flags with the lower/upper
  3482. * segment based on the HT mode
  3483. *
  3484. * Return: FFt bin count
  3485. */
  3486. static void
  3487. target_if_init_upper_lower_flags(struct target_if_spectral *spectral,
  3488. enum spectral_scan_mode smode)
  3489. {
  3490. int current_channel = 0;
  3491. int ext_channel = 0;
  3492. struct target_if_spectral_ops *p_sops =
  3493. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3494. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3495. spectral_err("Invalid Spectral mode %u", smode);
  3496. return;
  3497. }
  3498. current_channel = p_sops->get_current_channel(spectral, smode);
  3499. ext_channel = p_sops->get_extension_channel(spectral, smode);
  3500. if ((current_channel == 0) || (ext_channel == 0))
  3501. return;
  3502. if (spectral->sc_spectral_20_40_mode) {
  3503. /* HT40 mode */
  3504. if (ext_channel < current_channel) {
  3505. spectral->lower_is_extension = 1;
  3506. spectral->upper_is_control = 1;
  3507. spectral->lower_is_control = 0;
  3508. spectral->upper_is_extension = 0;
  3509. } else {
  3510. spectral->lower_is_extension = 0;
  3511. spectral->upper_is_control = 0;
  3512. spectral->lower_is_control = 1;
  3513. spectral->upper_is_extension = 1;
  3514. }
  3515. } else {
  3516. /* HT20 mode, lower is always control */
  3517. spectral->lower_is_extension = 0;
  3518. spectral->upper_is_control = 0;
  3519. spectral->lower_is_control = 1;
  3520. spectral->upper_is_extension = 0;
  3521. }
  3522. }
  3523. /**
  3524. * target_if_get_spectral_config() - Get spectral configuration
  3525. * @pdev: Pointer to pdev object
  3526. * @param: Pointer to spectral_config structure in which the configuration
  3527. * should be returned
  3528. * @smode: Spectral scan mode
  3529. *
  3530. * API to get the current spectral configuration
  3531. *
  3532. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3533. */
  3534. QDF_STATUS
  3535. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  3536. struct spectral_config *param,
  3537. enum spectral_scan_mode smode)
  3538. {
  3539. struct target_if_spectral_ops *p_sops = NULL;
  3540. struct target_if_spectral *spectral = NULL;
  3541. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3542. if (!spectral) {
  3543. spectral_err("SPECTRAL : Module doesn't exist");
  3544. return QDF_STATUS_E_FAILURE;
  3545. }
  3546. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3547. if (!p_sops) {
  3548. spectral_err("p_sops is null");
  3549. return QDF_STATUS_E_FAILURE;
  3550. }
  3551. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3552. spectral_err("Invalid Spectral mode %u", smode);
  3553. return QDF_STATUS_E_FAILURE;
  3554. }
  3555. qdf_mem_zero(param, sizeof(struct spectral_config));
  3556. p_sops->get_spectral_config(spectral, param, smode);
  3557. return QDF_STATUS_SUCCESS;
  3558. }
  3559. /**
  3560. * target_if_spectral_get_num_detectors() - Get number of Spectral detectors
  3561. * @spectral: Pointer to target if Spectral object
  3562. * @ch_width: channel width
  3563. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  3564. *
  3565. * API to get number of Spectral detectors used for scan in the given channel
  3566. * width.
  3567. *
  3568. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  3569. */
  3570. static QDF_STATUS
  3571. target_if_spectral_get_num_detectors(struct target_if_spectral *spectral,
  3572. enum phy_ch_width ch_width,
  3573. uint32_t *num_detectors)
  3574. {
  3575. if (!spectral) {
  3576. spectral_err("target if spectral object is null");
  3577. return QDF_STATUS_E_INVAL;
  3578. }
  3579. if (ch_width >= CH_WIDTH_INVALID) {
  3580. spectral_err("Invalid channel width %d", ch_width);
  3581. return QDF_STATUS_E_INVAL;
  3582. }
  3583. if (!num_detectors) {
  3584. spectral_err("Invalid argument, number of detectors");
  3585. return QDF_STATUS_E_INVAL;
  3586. }
  3587. switch (ch_width) {
  3588. case CH_WIDTH_20MHZ:
  3589. *num_detectors = spectral->capability.num_detectors_20mhz;
  3590. break;
  3591. case CH_WIDTH_40MHZ:
  3592. *num_detectors = spectral->capability.num_detectors_40mhz;
  3593. break;
  3594. case CH_WIDTH_80MHZ:
  3595. *num_detectors = spectral->capability.num_detectors_80mhz;
  3596. break;
  3597. case CH_WIDTH_160MHZ:
  3598. *num_detectors = spectral->capability.num_detectors_160mhz;
  3599. break;
  3600. case CH_WIDTH_80P80MHZ:
  3601. *num_detectors = spectral->capability.num_detectors_80p80mhz;
  3602. break;
  3603. default:
  3604. spectral_err("Unsupported channel width %d", ch_width);
  3605. return QDF_STATUS_E_INVAL;
  3606. }
  3607. return QDF_STATUS_SUCCESS;
  3608. }
  3609. /**
  3610. * target_if_spectral_finite_scan_init() - Initializations required for finite
  3611. * Spectral scan
  3612. * @spectral: Pointer to target of Spctral object
  3613. * @smode: Spectral scan mode
  3614. *
  3615. * This routine initializes the finite Spectral scan. Finite Spectral scan is
  3616. * triggered by configuring a non zero scan count.
  3617. *
  3618. * Return: QDF_STATUS_SUCCESS on success
  3619. */
  3620. static QDF_STATUS
  3621. target_if_spectral_finite_scan_init(struct target_if_spectral *spectral,
  3622. enum spectral_scan_mode smode)
  3623. {
  3624. struct target_if_finite_spectral_scan_params *finite_scan;
  3625. enum phy_ch_width ch_width;
  3626. uint32_t num_detectors;
  3627. QDF_STATUS status;
  3628. uint16_t sscan_count;
  3629. if (!spectral) {
  3630. spectral_err("target if spectral object is null");
  3631. return QDF_STATUS_E_INVAL;
  3632. }
  3633. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3634. spectral_err("Invalid Spectral mode");
  3635. return QDF_STATUS_E_INVAL;
  3636. }
  3637. ch_width = spectral->ch_width[smode];
  3638. status = target_if_spectral_get_num_detectors(spectral, ch_width,
  3639. &num_detectors);
  3640. if (QDF_IS_STATUS_ERROR(status)) {
  3641. spectral_err("Failed to get number of detectors");
  3642. return QDF_STATUS_E_FAILURE;
  3643. }
  3644. finite_scan = &spectral->finite_scan[smode];
  3645. sscan_count = spectral->params[smode].ss_count;
  3646. finite_scan->finite_spectral_scan = true;
  3647. finite_scan->num_reports_expected = num_detectors * sscan_count;
  3648. return QDF_STATUS_SUCCESS;
  3649. }
  3650. /**
  3651. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  3652. * parameters
  3653. * @spectral: Pointer to Spectral target_if internal private data
  3654. * @spectral_params: Pointer to Spectral parameters
  3655. * @smode: Spectral scan mode
  3656. * @err: Spectral error code
  3657. *
  3658. * Enable use of desired Spectral parameters by configuring them into HW, and
  3659. * starting Spectral scan
  3660. *
  3661. * Return: 0 on success, 1 on failure
  3662. */
  3663. int
  3664. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  3665. struct spectral_config *spectral_params,
  3666. enum spectral_scan_mode smode,
  3667. enum spectral_cp_error_code *err)
  3668. {
  3669. int extension_channel = 0;
  3670. int current_channel = 0;
  3671. struct target_if_spectral_ops *p_sops = NULL;
  3672. QDF_STATUS status;
  3673. struct wlan_objmgr_pdev *pdev;
  3674. struct wlan_objmgr_psoc *psoc;
  3675. if (!spectral) {
  3676. spectral_err("Spectral LMAC object is NULL");
  3677. return 1;
  3678. }
  3679. pdev = spectral->pdev_obj;
  3680. if (!pdev) {
  3681. spectral_err("pdev is null");
  3682. return QDF_STATUS_E_INVAL;
  3683. }
  3684. psoc = wlan_pdev_get_psoc(pdev);
  3685. if (!psoc) {
  3686. spectral_err("psoc is null");
  3687. return QDF_STATUS_E_INVAL;
  3688. }
  3689. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3690. spectral_err("Invalid Spectral mode %u", smode);
  3691. return 1;
  3692. }
  3693. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3694. if (!p_sops) {
  3695. spectral_err("p_sops is NULL");
  3696. return 1;
  3697. }
  3698. spectral->sc_spectral_noise_pwr_cal =
  3699. spectral_params->ss_spectral_pri ? 1 : 0;
  3700. /* check if extension channel is present */
  3701. extension_channel = p_sops->get_extension_channel(spectral, smode);
  3702. current_channel = p_sops->get_current_channel(spectral, smode);
  3703. status = target_if_spectral_populate_chwidth(
  3704. spectral, spectral->ch_width,
  3705. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  3706. ss_frequency.cfreq2 > 0);
  3707. if (QDF_IS_STATUS_ERROR(status)) {
  3708. spectral_err("Failed to get channel widths");
  3709. return 1;
  3710. }
  3711. if (spectral->capability.advncd_spectral_cap) {
  3712. spectral->lb_edge_extrabins = 0;
  3713. spectral->rb_edge_extrabins = 0;
  3714. if (spectral->is_lb_edge_extrabins_format &&
  3715. spectral->params[smode].ss_rpt_mode == 2) {
  3716. spectral->lb_edge_extrabins = 4;
  3717. }
  3718. if (spectral->is_rb_edge_extrabins_format &&
  3719. spectral->params[smode].ss_rpt_mode == 2) {
  3720. spectral->rb_edge_extrabins = 4;
  3721. }
  3722. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  3723. spectral->sc_spectral_20_40_mode = 0;
  3724. spectral->spectral_numbins =
  3725. target_if_get_fft_bin_count(
  3726. spectral->params[smode].ss_fft_size);
  3727. spectral->spectral_fft_len =
  3728. target_if_get_fft_bin_count(
  3729. spectral->params[smode].ss_fft_size);
  3730. spectral->spectral_data_len =
  3731. target_if_get_fft_bin_count(
  3732. spectral->params[smode].ss_fft_size);
  3733. /*
  3734. * Initialize classifier params to be sent to user
  3735. * space classifier
  3736. */
  3737. spectral->classifier_params.lower_chan_in_mhz =
  3738. current_channel;
  3739. spectral->classifier_params.upper_chan_in_mhz = 0;
  3740. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  3741. /* TODO : Remove this variable */
  3742. spectral->sc_spectral_20_40_mode = 1;
  3743. spectral->spectral_numbins =
  3744. target_if_get_fft_bin_count(
  3745. spectral->params[smode].ss_fft_size);
  3746. spectral->spectral_fft_len =
  3747. target_if_get_fft_bin_count(
  3748. spectral->params[smode].ss_fft_size);
  3749. spectral->spectral_data_len =
  3750. target_if_get_fft_bin_count(
  3751. spectral->params[smode].ss_fft_size);
  3752. /*
  3753. * Initialize classifier params to be sent to user
  3754. * space classifier
  3755. */
  3756. if (extension_channel < current_channel) {
  3757. spectral->classifier_params.lower_chan_in_mhz =
  3758. extension_channel;
  3759. spectral->classifier_params.upper_chan_in_mhz =
  3760. current_channel;
  3761. } else {
  3762. spectral->classifier_params.lower_chan_in_mhz =
  3763. current_channel;
  3764. spectral->classifier_params.upper_chan_in_mhz =
  3765. extension_channel;
  3766. }
  3767. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  3768. /* Set the FFT Size */
  3769. /* TODO : Remove this variable */
  3770. spectral->sc_spectral_20_40_mode = 0;
  3771. spectral->spectral_numbins =
  3772. target_if_get_fft_bin_count(
  3773. spectral->params[smode].ss_fft_size);
  3774. spectral->spectral_fft_len =
  3775. target_if_get_fft_bin_count(
  3776. spectral->params[smode].ss_fft_size);
  3777. spectral->spectral_data_len =
  3778. target_if_get_fft_bin_count(
  3779. spectral->params[smode].ss_fft_size);
  3780. /*
  3781. * Initialize classifier params to be sent to user
  3782. * space classifier
  3783. */
  3784. spectral->classifier_params.lower_chan_in_mhz =
  3785. current_channel;
  3786. spectral->classifier_params.upper_chan_in_mhz = 0;
  3787. /*
  3788. * Initialize classifier params to be sent to user
  3789. * space classifier
  3790. */
  3791. if (extension_channel < current_channel) {
  3792. spectral->classifier_params.lower_chan_in_mhz =
  3793. extension_channel;
  3794. spectral->classifier_params.upper_chan_in_mhz =
  3795. current_channel;
  3796. } else {
  3797. spectral->classifier_params.lower_chan_in_mhz =
  3798. current_channel;
  3799. spectral->classifier_params.upper_chan_in_mhz =
  3800. extension_channel;
  3801. }
  3802. } else if (is_ch_width_160_or_80p80(
  3803. spectral->ch_width[smode])) {
  3804. /* Set the FFT Size */
  3805. /* The below applies to both 160 and 80+80 cases */
  3806. /* TODO : Remove this variable */
  3807. spectral->sc_spectral_20_40_mode = 0;
  3808. spectral->spectral_numbins =
  3809. target_if_get_fft_bin_count(
  3810. spectral->params[smode].ss_fft_size);
  3811. spectral->spectral_fft_len =
  3812. target_if_get_fft_bin_count(
  3813. spectral->params[smode].ss_fft_size);
  3814. spectral->spectral_data_len =
  3815. target_if_get_fft_bin_count(
  3816. spectral->params[smode].ss_fft_size);
  3817. /*
  3818. * Initialize classifier params to be sent to user
  3819. * space classifier
  3820. */
  3821. spectral->classifier_params.lower_chan_in_mhz =
  3822. current_channel;
  3823. spectral->classifier_params.upper_chan_in_mhz = 0;
  3824. /*
  3825. * Initialize classifier params to be sent to user
  3826. * space classifier
  3827. */
  3828. if (extension_channel < current_channel) {
  3829. spectral->classifier_params.lower_chan_in_mhz =
  3830. extension_channel;
  3831. spectral->classifier_params.upper_chan_in_mhz =
  3832. current_channel;
  3833. } else {
  3834. spectral->classifier_params.lower_chan_in_mhz =
  3835. current_channel;
  3836. spectral->classifier_params.upper_chan_in_mhz =
  3837. extension_channel;
  3838. }
  3839. }
  3840. if (spectral->spectral_numbins) {
  3841. spectral->spectral_numbins +=
  3842. spectral->lb_edge_extrabins;
  3843. spectral->spectral_numbins +=
  3844. spectral->rb_edge_extrabins;
  3845. }
  3846. if (spectral->spectral_fft_len) {
  3847. spectral->spectral_fft_len +=
  3848. spectral->lb_edge_extrabins;
  3849. spectral->spectral_fft_len +=
  3850. spectral->rb_edge_extrabins;
  3851. }
  3852. if (spectral->spectral_data_len) {
  3853. spectral->spectral_data_len +=
  3854. spectral->lb_edge_extrabins;
  3855. spectral->spectral_data_len +=
  3856. spectral->rb_edge_extrabins;
  3857. }
  3858. } else {
  3859. /*
  3860. * The decision to find 20/40 mode is found based on the
  3861. * presence of extension channel
  3862. * instead of channel width, as the channel width can
  3863. * dynamically change
  3864. */
  3865. if (extension_channel == 0) {
  3866. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  3867. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  3868. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  3869. spectral->spectral_data_len =
  3870. SPECTRAL_HT20_TOTAL_DATA_LEN;
  3871. /* only valid in 20-40 mode */
  3872. spectral->spectral_lower_max_index_offset = -1;
  3873. /* only valid in 20-40 mode */
  3874. spectral->spectral_upper_max_index_offset = -1;
  3875. spectral->spectral_max_index_offset =
  3876. spectral->spectral_fft_len + 2;
  3877. spectral->sc_spectral_20_40_mode = 0;
  3878. /*
  3879. * Initialize classifier params to be sent to user
  3880. * space classifier
  3881. */
  3882. spectral->classifier_params.lower_chan_in_mhz =
  3883. current_channel;
  3884. spectral->classifier_params.upper_chan_in_mhz = 0;
  3885. } else {
  3886. spectral->spectral_numbins =
  3887. SPECTRAL_HT40_TOTAL_NUM_BINS;
  3888. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  3889. spectral->spectral_data_len =
  3890. SPECTRAL_HT40_TOTAL_DATA_LEN;
  3891. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  3892. /* only valid in 20 mode */
  3893. spectral->spectral_max_index_offset = -1;
  3894. spectral->spectral_lower_max_index_offset =
  3895. spectral->spectral_fft_len + 2;
  3896. spectral->spectral_upper_max_index_offset =
  3897. spectral->spectral_fft_len + 5;
  3898. spectral->sc_spectral_20_40_mode = 1;
  3899. /*
  3900. * Initialize classifier params to be sent to user
  3901. * space classifier
  3902. */
  3903. if (extension_channel < current_channel) {
  3904. spectral->classifier_params.lower_chan_in_mhz =
  3905. extension_channel;
  3906. spectral->classifier_params.upper_chan_in_mhz =
  3907. current_channel;
  3908. } else {
  3909. spectral->classifier_params.lower_chan_in_mhz =
  3910. current_channel;
  3911. spectral->classifier_params.upper_chan_in_mhz =
  3912. extension_channel;
  3913. }
  3914. }
  3915. }
  3916. spectral->send_single_packet = 0;
  3917. spectral->classifier_params.spectral_20_40_mode =
  3918. spectral->sc_spectral_20_40_mode;
  3919. spectral->classifier_params.spectral_dc_index =
  3920. spectral->spectral_dc_index;
  3921. spectral->spectral_sent_msg = 0;
  3922. spectral->classify_scan = 0;
  3923. spectral->num_spectral_data = 0;
  3924. if (!p_sops->is_spectral_active(spectral, smode)) {
  3925. p_sops->configure_spectral(spectral, spectral_params, smode);
  3926. spectral->rparams.marker[smode].is_valid = false;
  3927. if (spectral->params[smode].ss_count) {
  3928. status = target_if_spectral_finite_scan_init(spectral,
  3929. smode);
  3930. if (QDF_IS_STATUS_ERROR(status)) {
  3931. spectral_err("Failed to init finite scan");
  3932. return 1;
  3933. }
  3934. }
  3935. p_sops->start_spectral_scan(spectral, smode, err);
  3936. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  3937. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  3938. }
  3939. /* get current spectral configuration */
  3940. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  3941. target_if_init_upper_lower_flags(spectral, smode);
  3942. return 0;
  3943. }
  3944. /**
  3945. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  3946. * Agile DFS
  3947. * @psoc: Pointer to psoc
  3948. * @object: Pointer to pdev
  3949. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  3950. *
  3951. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  3952. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  3953. *
  3954. * Return: void
  3955. */
  3956. static void
  3957. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  3958. void *object, void *arg)
  3959. {
  3960. bool *is_aspectral_prohibited = arg;
  3961. struct wlan_objmgr_pdev *cur_pdev = object;
  3962. bool is_agile_precac_enabled_cur_pdev = false;
  3963. bool is_agile_rcac_enabled_cur_pdev = false;
  3964. QDF_STATUS status;
  3965. qdf_assert_always(is_aspectral_prohibited);
  3966. if (*is_aspectral_prohibited)
  3967. return;
  3968. qdf_assert_always(psoc);
  3969. qdf_assert_always(cur_pdev);
  3970. status = ucfg_dfs_get_agile_precac_enable
  3971. (cur_pdev,
  3972. &is_agile_precac_enabled_cur_pdev);
  3973. if (QDF_IS_STATUS_ERROR(status)) {
  3974. spectral_err("Get agile precac failed, prohibiting aSpectral");
  3975. *is_aspectral_prohibited = true;
  3976. return;
  3977. }
  3978. status = ucfg_dfs_get_rcac_enable(cur_pdev,
  3979. &is_agile_rcac_enabled_cur_pdev);
  3980. if (QDF_IS_STATUS_ERROR(status)) {
  3981. spectral_err("Get agile RCAC failed, prohibiting aSpectral");
  3982. *is_aspectral_prohibited = true;
  3983. return;
  3984. }
  3985. if (is_agile_precac_enabled_cur_pdev) {
  3986. spectral_err("aDFS preCAC is in progress on one of the pdevs");
  3987. *is_aspectral_prohibited = true;
  3988. } else if (is_agile_rcac_enabled_cur_pdev) {
  3989. spectral_err("aDFS RCAC is in progress on one of the pdevs");
  3990. *is_aspectral_prohibited = true;
  3991. }
  3992. }
  3993. /**
  3994. * target_if_get_curr_band() - Get current operating band of pdev
  3995. *
  3996. * @pdev: pointer to pdev object
  3997. *
  3998. * API to get current operating band of a given pdev.
  3999. *
  4000. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  4001. */
  4002. static enum reg_wifi_band
  4003. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id)
  4004. {
  4005. struct wlan_objmgr_vdev *vdev;
  4006. int16_t chan_freq;
  4007. enum reg_wifi_band cur_band;
  4008. if (!pdev) {
  4009. spectral_err("pdev is NULL");
  4010. return REG_BAND_UNKNOWN;
  4011. }
  4012. if (vdev_id == WLAN_INVALID_VDEV_ID)
  4013. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  4014. else
  4015. vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, vdev_id,
  4016. WLAN_SPECTRAL_ID);
  4017. if (!vdev) {
  4018. spectral_debug("vdev is NULL");
  4019. return REG_BAND_UNKNOWN;
  4020. }
  4021. chan_freq = target_if_vdev_get_chan_freq(vdev);
  4022. cur_band = wlan_reg_freq_to_band(chan_freq);
  4023. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4024. return cur_band;
  4025. }
  4026. /**
  4027. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  4028. * any of the 5G pdevs
  4029. * @psoc: Pointer to psoc
  4030. * @object: Pointer to pdev
  4031. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  4032. * progress in any 5G pdevs
  4033. *
  4034. * Return: void
  4035. */
  4036. static void
  4037. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  4038. void *object, void *arg)
  4039. {
  4040. enum reg_wifi_band band;
  4041. bool *is_agile_scan_inprog_5g_pdev = arg;
  4042. struct target_if_spectral *spectral;
  4043. struct wlan_objmgr_pdev *cur_pdev = object;
  4044. struct target_if_spectral_ops *p_sops;
  4045. if (*is_agile_scan_inprog_5g_pdev)
  4046. return;
  4047. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  4048. if (!spectral) {
  4049. spectral_err("target if spectral handle is NULL");
  4050. return;
  4051. }
  4052. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4053. band = target_if_get_curr_band(
  4054. cur_pdev, spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE]);
  4055. if (band == REG_BAND_UNKNOWN) {
  4056. spectral_debug("Failed to get current band");
  4057. return;
  4058. }
  4059. if (band == REG_BAND_5G &&
  4060. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  4061. *is_agile_scan_inprog_5g_pdev = true;
  4062. }
  4063. /**
  4064. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  4065. * for current vdev rx chainmask.
  4066. *
  4067. * @spectral: Pointer to Spectral object
  4068. * @is_supported: Pointer to is_supported
  4069. *
  4070. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4071. */
  4072. static QDF_STATUS
  4073. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  4074. bool *is_supported)
  4075. {
  4076. struct wlan_objmgr_vdev *vdev;
  4077. uint8_t vdev_rxchainmask;
  4078. struct wlan_objmgr_psoc *psoc;
  4079. struct wlan_objmgr_pdev *pdev;
  4080. struct target_psoc_info *tgt_psoc_info;
  4081. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  4082. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  4083. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  4084. struct wlan_psoc_host_chainmask_table *table;
  4085. int j;
  4086. uint32_t table_id;
  4087. enum phy_ch_width ch_width;
  4088. uint8_t pdev_id;
  4089. if (!spectral) {
  4090. spectral_err("spectral target if object is null");
  4091. return QDF_STATUS_E_FAILURE;
  4092. }
  4093. if (!is_supported) {
  4094. spectral_err("is supported argument is null");
  4095. return QDF_STATUS_E_FAILURE;
  4096. }
  4097. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  4098. spectral_err("HW Agile mode is not supported up to gen 2");
  4099. return QDF_STATUS_E_FAILURE;
  4100. }
  4101. pdev = spectral->pdev_obj;
  4102. if (!pdev) {
  4103. spectral_err("pdev is null");
  4104. return QDF_STATUS_E_FAILURE;
  4105. }
  4106. psoc = wlan_pdev_get_psoc(pdev);
  4107. if (!psoc) {
  4108. spectral_err("psoc is null");
  4109. return QDF_STATUS_E_FAILURE;
  4110. }
  4111. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  4112. if (!vdev) {
  4113. spectral_err("First vdev is NULL");
  4114. return QDF_STATUS_E_FAILURE;
  4115. }
  4116. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  4117. if (!vdev_rxchainmask) {
  4118. spectral_err("vdev rx chainmask is zero");
  4119. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4120. return QDF_STATUS_E_FAILURE;
  4121. }
  4122. ch_width = target_if_vdev_get_ch_width(vdev);
  4123. if (ch_width == CH_WIDTH_INVALID) {
  4124. spectral_err("Invalid channel width");
  4125. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4126. return QDF_STATUS_E_FAILURE;
  4127. }
  4128. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4129. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  4130. if (!tgt_psoc_info) {
  4131. spectral_err("target_psoc_info is null");
  4132. return QDF_STATUS_E_FAILURE;
  4133. }
  4134. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  4135. if (!ext_svc_param) {
  4136. spectral_err("Extended service ready param null");
  4137. return QDF_STATUS_E_FAILURE;
  4138. }
  4139. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  4140. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  4141. if (!mac_phy_cap_arr) {
  4142. spectral_err("mac phy cap array is null");
  4143. return QDF_STATUS_E_FAILURE;
  4144. }
  4145. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  4146. if (!mac_phy_cap) {
  4147. spectral_err("mac phy cap is null");
  4148. return QDF_STATUS_E_FAILURE;
  4149. }
  4150. table_id = mac_phy_cap->chainmask_table_id;
  4151. table = &ext_svc_param->chainmask_table[table_id];
  4152. if (!table) {
  4153. spectral_err("chainmask table not found");
  4154. return QDF_STATUS_E_FAILURE;
  4155. }
  4156. for (j = 0; j < table->num_valid_chainmasks; j++) {
  4157. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  4158. if (ch_width <= CH_WIDTH_80MHZ)
  4159. *is_supported =
  4160. table->cap_list[j].supports_aSpectral;
  4161. else
  4162. *is_supported =
  4163. table->cap_list[j].supports_aSpectral_160;
  4164. break;
  4165. }
  4166. }
  4167. if (j == table->num_valid_chainmasks) {
  4168. spectral_err("vdev rx chainmask %u not found in table id = %u",
  4169. vdev_rxchainmask, table_id);
  4170. return QDF_STATUS_E_FAILURE;
  4171. }
  4172. return QDF_STATUS_SUCCESS;
  4173. }
  4174. #ifdef OPTIMIZED_SAMP_MESSAGE
  4175. /**
  4176. * target_if_spectral_populate_session_report_info() - Populate per-session
  4177. * report level information.
  4178. *
  4179. * @spectral: Pointer to Spectral object
  4180. * @smode: Spectral scan mode
  4181. *
  4182. * Return: Success/Failure
  4183. */
  4184. static QDF_STATUS
  4185. target_if_spectral_populate_session_report_info(
  4186. struct target_if_spectral *spectral,
  4187. enum spectral_scan_mode smode)
  4188. {
  4189. struct per_session_report_info *rpt_info;
  4190. struct wlan_objmgr_psoc *psoc;
  4191. if (!spectral) {
  4192. spectral_err_rl("Spectral LMAC object is null");
  4193. return QDF_STATUS_E_NULL_VALUE;
  4194. }
  4195. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  4196. spectral_err_rl("Invalid Spectral scan mode");
  4197. return QDF_STATUS_E_FAILURE;
  4198. }
  4199. if (!spectral->pdev_obj) {
  4200. spectral_err_rl("Spectral PDEV is null");
  4201. return QDF_STATUS_E_NULL_VALUE;
  4202. }
  4203. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  4204. if (!psoc) {
  4205. spectral_err_rl("psoc is null");
  4206. return QDF_STATUS_E_NULL_VALUE;
  4207. }
  4208. /* Fill per-session report information, based on the spectral mode */
  4209. rpt_info = &spectral->report_info[smode];
  4210. rpt_info->operating_bw = spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  4211. rpt_info->sscan_bw = spectral->ch_width[smode];
  4212. rpt_info->sscan_cfreq1 = spectral->params[smode].ss_frequency.cfreq1;
  4213. rpt_info->sscan_cfreq2 = spectral->params[smode].ss_frequency.cfreq2;
  4214. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ) {
  4215. rpt_info->num_spans = 2;
  4216. if (wlan_psoc_nif_fw_ext_cap_get(
  4217. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  4218. /* 5 MHz frequency span in restricted 80p80 case */
  4219. rpt_info->num_spans += 1;
  4220. } else {
  4221. rpt_info->num_spans = 1;
  4222. }
  4223. return QDF_STATUS_SUCCESS;
  4224. }
  4225. /**
  4226. * target_if_spectral_populate_session_detector_info() - Populate per-session
  4227. * detector level information.
  4228. *
  4229. * @spectral: Pointer to Spectral object
  4230. * @smode: Spectral scan mode
  4231. *
  4232. * Return: Success/Failure
  4233. */
  4234. static QDF_STATUS
  4235. target_if_spectral_populate_session_detector_info(
  4236. struct target_if_spectral *spectral,
  4237. enum spectral_scan_mode smode)
  4238. {
  4239. struct per_session_report_info *rpt_info;
  4240. struct sscan_detector_list *detector_list;
  4241. struct wlan_objmgr_psoc *psoc;
  4242. uint16_t dest_det_idx = 0;
  4243. uint16_t dest_span_idx = 0;
  4244. bool is_sec80 = false;
  4245. uint8_t det, dest_det;
  4246. if (!spectral) {
  4247. spectral_err_rl("Spectral LMAC object is null");
  4248. return QDF_STATUS_E_NULL_VALUE;
  4249. }
  4250. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  4251. spectral_err_rl("Invalid Spectral scan mode");
  4252. return QDF_STATUS_E_FAILURE;
  4253. }
  4254. if (!spectral->pdev_obj) {
  4255. spectral_err_rl("Spectral PDEV is null");
  4256. return QDF_STATUS_E_NULL_VALUE;
  4257. }
  4258. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  4259. if (!psoc) {
  4260. spectral_err_rl("psoc is null");
  4261. return QDF_STATUS_E_NULL_VALUE;
  4262. }
  4263. rpt_info = &spectral->report_info[smode];
  4264. /* Fill per-sesion detector-level information */
  4265. detector_list = &spectral->detector_list[smode][rpt_info->sscan_bw];
  4266. for (det = 0; det < detector_list->num_detectors; det++) {
  4267. struct per_session_det_map *det_map;
  4268. det_map = &spectral->det_map[detector_list->detectors[det]];
  4269. if (detector_list->num_detectors > 1) {
  4270. if (det == 0) {
  4271. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  4272. det_map->send_to_upper_layers = false;
  4273. } else if (det == detector_list->num_detectors - 1) {
  4274. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  4275. det_map->send_to_upper_layers = true;
  4276. } else {
  4277. /* middle fragments */
  4278. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  4279. det_map->send_to_upper_layers = false;
  4280. }
  4281. } else {
  4282. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  4283. det_map->send_to_upper_layers = true;
  4284. }
  4285. det_map->num_dest_det_info = 1;
  4286. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ &&
  4287. wlan_psoc_nif_fw_ext_cap_get(
  4288. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  4289. /**
  4290. * In 165MHz case, 1 Spectral HW detector maps to 3
  4291. * detectors in SAMP msg.
  4292. */
  4293. det_map->num_dest_det_info += 2;
  4294. }
  4295. for (dest_det = 0; dest_det < det_map->num_dest_det_info;
  4296. dest_det++) {
  4297. struct per_session_dest_det_info *map_det_info;
  4298. map_det_info = &det_map->dest_det_info[dest_det];
  4299. map_det_info->freq_span_id = dest_span_idx;
  4300. map_det_info->det_id = dest_det_idx;
  4301. map_det_info->is_sec80 = is_sec80;
  4302. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ) {
  4303. /* Increment span ID for non-contiguous modes */
  4304. dest_det_idx = 0;
  4305. dest_span_idx++;
  4306. } else {
  4307. /* Increment detector ID for contiguous modes */
  4308. dest_det_idx++;
  4309. }
  4310. is_sec80 = !is_sec80;
  4311. }
  4312. }
  4313. return QDF_STATUS_SUCCESS;
  4314. }
  4315. #else
  4316. static QDF_STATUS
  4317. target_if_spectral_populate_session_report_info(
  4318. struct target_if_spectral *spectral,
  4319. enum spectral_scan_mode smode)
  4320. {
  4321. return QDF_STATUS_SUCCESS;
  4322. }
  4323. static QDF_STATUS
  4324. target_if_spectral_populate_session_detector_info(
  4325. struct target_if_spectral *spectral,
  4326. enum spectral_scan_mode smode)
  4327. {
  4328. return QDF_STATUS_SUCCESS;
  4329. }
  4330. #endif /* OPTIMIZED_SAMP_MESSAGE */
  4331. QDF_STATUS
  4332. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  4333. uint8_t vdev_id,
  4334. const enum spectral_scan_mode smode,
  4335. enum spectral_cp_error_code *err)
  4336. {
  4337. struct target_if_spectral_ops *p_sops;
  4338. struct target_if_spectral *spectral;
  4339. struct wlan_objmgr_psoc *psoc;
  4340. enum reg_wifi_band band;
  4341. QDF_STATUS ret;
  4342. if (!err) {
  4343. spectral_err("Error code argument is null");
  4344. QDF_ASSERT(0);
  4345. return QDF_STATUS_E_FAILURE;
  4346. }
  4347. *err = SPECTRAL_SCAN_ERR_INVALID;
  4348. if (!pdev) {
  4349. spectral_err("pdev object is NUll");
  4350. return QDF_STATUS_E_FAILURE;
  4351. }
  4352. psoc = wlan_pdev_get_psoc(pdev);
  4353. if (!psoc) {
  4354. spectral_err("psoc is null");
  4355. return QDF_STATUS_E_FAILURE;
  4356. }
  4357. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4358. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4359. spectral_err("Invalid Spectral mode %u", smode);
  4360. return QDF_STATUS_E_FAILURE;
  4361. }
  4362. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4363. if (!spectral) {
  4364. spectral_err("Spectral LMAC object is NUll");
  4365. return QDF_STATUS_E_FAILURE;
  4366. }
  4367. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4368. if (!p_sops) {
  4369. spectral_err("p_sops is null");
  4370. return QDF_STATUS_E_FAILURE;
  4371. }
  4372. if (p_sops->is_spectral_active(spectral, smode)) {
  4373. spectral_err("spectral in progress in current pdev, mode %d",
  4374. smode);
  4375. return QDF_STATUS_E_FAILURE;
  4376. }
  4377. spectral->vdev_id[smode] = vdev_id;
  4378. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  4379. QDF_STATUS status;
  4380. bool is_supported = false;
  4381. status = target_if_is_agile_supported_cur_chmask(spectral,
  4382. &is_supported);
  4383. if (QDF_IS_STATUS_ERROR(status)) {
  4384. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4385. return QDF_STATUS_E_FAILURE;
  4386. }
  4387. if (!is_supported) {
  4388. spectral_err("aSpectral unsupported for cur chainmask");
  4389. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4390. return QDF_STATUS_E_FAILURE;
  4391. }
  4392. }
  4393. band = target_if_get_curr_band(spectral->pdev_obj, vdev_id);
  4394. if (band == REG_BAND_UNKNOWN) {
  4395. spectral_err("Failed to get current band");
  4396. return QDF_STATUS_E_FAILURE;
  4397. }
  4398. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  4399. struct target_psoc_info *tgt_hdl;
  4400. enum wmi_host_hw_mode_config_type mode;
  4401. bool is_agile_scan_inprog_5g_pdev;
  4402. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  4403. if (!tgt_hdl) {
  4404. target_if_err("target_psoc_info is null");
  4405. return QDF_STATUS_E_FAILURE;
  4406. }
  4407. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  4408. switch (mode) {
  4409. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  4410. case WMI_HOST_HW_MODE_SBS:
  4411. case WMI_HOST_HW_MODE_DBS_SBS:
  4412. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  4413. is_agile_scan_inprog_5g_pdev = false;
  4414. wlan_objmgr_iterate_obj_list
  4415. (psoc, WLAN_PDEV_OP,
  4416. target_if_is_agile_scan_active_in_5g,
  4417. &is_agile_scan_inprog_5g_pdev, 0,
  4418. WLAN_SPECTRAL_ID);
  4419. break;
  4420. default:
  4421. is_agile_scan_inprog_5g_pdev = false;
  4422. break;
  4423. }
  4424. if (is_agile_scan_inprog_5g_pdev) {
  4425. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  4426. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4427. return QDF_STATUS_E_FAILURE;
  4428. }
  4429. }
  4430. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  4431. bool is_aspectral_prohibited = false;
  4432. QDF_STATUS status;
  4433. status = wlan_objmgr_iterate_obj_list
  4434. (psoc, WLAN_PDEV_OP,
  4435. target_if_is_aspectral_prohibited_by_adfs,
  4436. &is_aspectral_prohibited, 0,
  4437. WLAN_SPECTRAL_ID);
  4438. if (QDF_IS_STATUS_ERROR(status)) {
  4439. spectral_err("Failed to iterate over pdevs");
  4440. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4441. return QDF_STATUS_E_FAILURE;
  4442. }
  4443. if (is_aspectral_prohibited) {
  4444. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4445. return QDF_STATUS_E_FAILURE;
  4446. }
  4447. }
  4448. if (!spectral->params_valid[smode]) {
  4449. target_if_spectral_info_read(spectral,
  4450. smode,
  4451. TARGET_IF_SPECTRAL_INFO_PARAMS,
  4452. &spectral->params[smode],
  4453. sizeof(spectral->params[smode]));
  4454. spectral->params_valid[smode] = true;
  4455. }
  4456. qdf_spin_lock(&spectral->spectral_lock);
  4457. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  4458. QDF_STATUS status;
  4459. bool is_overlapping;
  4460. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  4461. enum spectral_scan_mode m;
  4462. enum phy_ch_width op_ch_width;
  4463. enum phy_ch_width agile_ch_width;
  4464. m = SPECTRAL_SCAN_MODE_NORMAL;
  4465. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  4466. ch_width[m] = CH_WIDTH_INVALID;
  4467. status = target_if_spectral_populate_chwidth
  4468. (spectral, ch_width, spectral->params
  4469. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  4470. if (QDF_IS_STATUS_ERROR(status)) {
  4471. qdf_spin_unlock(&spectral->spectral_lock);
  4472. spectral_err("Failed to populate channel width");
  4473. return QDF_STATUS_E_FAILURE;
  4474. }
  4475. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  4476. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  4477. if (!spectral->params[smode].ss_frequency.cfreq1) {
  4478. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  4479. qdf_spin_unlock(&spectral->spectral_lock);
  4480. spectral_err("Agile Spectral cfreq1 is 0");
  4481. return QDF_STATUS_E_FAILURE;
  4482. } else if (agile_ch_width == CH_WIDTH_80P80MHZ &&
  4483. !spectral->params[smode].ss_frequency.cfreq2) {
  4484. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  4485. qdf_spin_unlock(&spectral->spectral_lock);
  4486. spectral_err("Agile Spectral cfreq2 is 0");
  4487. return QDF_STATUS_E_FAILURE;
  4488. }
  4489. status = target_if_is_agile_span_overlap_with_operating_span
  4490. (spectral, ch_width,
  4491. &spectral->params[smode].ss_frequency,
  4492. &is_overlapping);
  4493. if (QDF_IS_STATUS_ERROR(status)) {
  4494. qdf_spin_unlock(&spectral->spectral_lock);
  4495. return QDF_STATUS_E_FAILURE;
  4496. }
  4497. if (is_overlapping) {
  4498. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4499. qdf_spin_unlock(&spectral->spectral_lock);
  4500. return QDF_STATUS_E_FAILURE;
  4501. }
  4502. }
  4503. target_if_spectral_scan_enable_params(spectral,
  4504. &spectral->params[smode], smode,
  4505. err);
  4506. ret = target_if_spectral_populate_session_report_info(spectral, smode);
  4507. if (QDF_IS_STATUS_ERROR(ret)) {
  4508. spectral_err_rl("Failed to populate per-session report info");
  4509. return QDF_STATUS_E_FAILURE;
  4510. }
  4511. ret = target_if_spectral_populate_session_detector_info(spectral,
  4512. smode);
  4513. if (QDF_IS_STATUS_ERROR(ret)) {
  4514. spectral_err_rl("Failed to populate per-session report info");
  4515. return QDF_STATUS_E_FAILURE;
  4516. }
  4517. qdf_spin_unlock(&spectral->spectral_lock);
  4518. return QDF_STATUS_SUCCESS;
  4519. }
  4520. QDF_STATUS
  4521. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  4522. const enum spectral_scan_mode smode,
  4523. enum spectral_cp_error_code *err)
  4524. {
  4525. struct target_if_spectral_ops *p_sops;
  4526. struct target_if_spectral *spectral;
  4527. if (!pdev) {
  4528. spectral_err("pdev object is NULL");
  4529. return QDF_STATUS_E_INVAL;
  4530. }
  4531. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  4532. spectral_info("Spectral feature is disabled");
  4533. return QDF_STATUS_COMP_DISABLED;
  4534. }
  4535. if (!err) {
  4536. spectral_err("Error code argument is null");
  4537. QDF_ASSERT(0);
  4538. return QDF_STATUS_E_FAILURE;
  4539. }
  4540. *err = SPECTRAL_SCAN_ERR_INVALID;
  4541. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4542. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4543. spectral_err("Invalid Spectral mode %u", smode);
  4544. return QDF_STATUS_E_FAILURE;
  4545. }
  4546. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4547. if (!spectral) {
  4548. spectral_err("Spectral LMAC object is NUll ");
  4549. return QDF_STATUS_E_FAILURE;
  4550. }
  4551. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4552. qdf_spin_lock(&spectral->spectral_lock);
  4553. p_sops->stop_spectral_scan(spectral, smode);
  4554. if (spectral->classify_scan) {
  4555. /* TODO : Check if this logic is necessary */
  4556. spectral->detects_control_channel = 0;
  4557. spectral->detects_extension_channel = 0;
  4558. spectral->detects_above_dc = 0;
  4559. spectral->detects_below_dc = 0;
  4560. spectral->classify_scan = 0;
  4561. }
  4562. spectral->send_single_packet = 0;
  4563. spectral->sc_spectral_scan = 0;
  4564. qdf_spin_unlock(&spectral->spectral_lock);
  4565. return QDF_STATUS_SUCCESS;
  4566. }
  4567. /**
  4568. * target_if_is_spectral_active() - Get whether Spectral is active
  4569. * @pdev: Pointer to pdev object
  4570. * @smode: Spectral scan mode
  4571. *
  4572. * API to get whether Spectral is active
  4573. *
  4574. * Return: True if Spectral is active, false if Spectral is not active
  4575. */
  4576. bool
  4577. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  4578. const enum spectral_scan_mode smode)
  4579. {
  4580. struct target_if_spectral *spectral = NULL;
  4581. struct target_if_spectral_ops *p_sops = NULL;
  4582. if (!pdev) {
  4583. spectral_err("pdev is null");
  4584. return false;
  4585. }
  4586. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  4587. spectral_info("Spectral feature is disabled");
  4588. return false;
  4589. }
  4590. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4591. if (!spectral) {
  4592. spectral_err("SPECTRAL : Module doesn't exist");
  4593. return false;
  4594. }
  4595. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4596. if (!p_sops) {
  4597. spectral_err("p_sops is null");
  4598. return false;
  4599. }
  4600. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4601. spectral_err("Invalid Spectral mode %u", smode);
  4602. return false;
  4603. }
  4604. return p_sops->is_spectral_active(spectral, smode);
  4605. }
  4606. /**
  4607. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  4608. * @pdev: Pointer to pdev object
  4609. * @smode: Spectral scan mode
  4610. *
  4611. * API to get whether Spectral is enabled
  4612. *
  4613. * Return: True if Spectral is enabled, false if Spectral is not enabled
  4614. */
  4615. bool
  4616. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  4617. enum spectral_scan_mode smode)
  4618. {
  4619. struct target_if_spectral *spectral = NULL;
  4620. struct target_if_spectral_ops *p_sops = NULL;
  4621. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4622. if (!spectral) {
  4623. spectral_err("SPECTRAL : Module doesn't exist");
  4624. return false;
  4625. }
  4626. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4627. if (!p_sops) {
  4628. spectral_err("p_sops is null");
  4629. return false;
  4630. }
  4631. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4632. spectral_err("Invalid Spectral mode %u", smode);
  4633. return false;
  4634. }
  4635. return p_sops->is_spectral_enabled(spectral, smode);
  4636. }
  4637. #ifdef DIRECT_BUF_RX_DEBUG
  4638. /**
  4639. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  4640. * @pdev: Pointer to pdev object
  4641. * @enable: Enable/Disable Spectral DMA ring debug
  4642. *
  4643. * Start/stop Spectral DMA ring debug based on @enable.
  4644. * Also save the state for future use.
  4645. *
  4646. * Return: QDF_STATUS of operation
  4647. */
  4648. static QDF_STATUS
  4649. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  4650. {
  4651. struct target_if_spectral *spectral;
  4652. struct wlan_lmac_if_tx_ops *tx_ops;
  4653. struct wlan_objmgr_psoc *psoc;
  4654. if (!pdev)
  4655. return QDF_STATUS_E_FAILURE;
  4656. psoc = wlan_pdev_get_psoc(pdev);
  4657. if (!psoc) {
  4658. spectral_err("psoc is null");
  4659. return QDF_STATUS_E_INVAL;
  4660. }
  4661. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  4662. if (!tx_ops) {
  4663. spectral_err("tx_ops is NULL");
  4664. return QDF_STATUS_E_INVAL;
  4665. }
  4666. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4667. if (!spectral) {
  4668. spectral_err("Spectal LMAC object is NULL");
  4669. return QDF_STATUS_E_INVAL;
  4670. }
  4671. /* Save the state */
  4672. spectral->dbr_ring_debug = enable;
  4673. if (enable)
  4674. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  4675. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  4676. else
  4677. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  4678. pdev, 0);
  4679. return QDF_STATUS_SUCCESS;
  4680. }
  4681. /**
  4682. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  4683. * @pdev: Pointer to pdev object
  4684. * @enable: Enable/Disable Spectral DMA buffer debug
  4685. *
  4686. * Start/stop Spectral DMA buffer debug based on @enable.
  4687. * Also save the state for future use.
  4688. *
  4689. * Return: QDF_STATUS of operation
  4690. */
  4691. static QDF_STATUS
  4692. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  4693. {
  4694. struct target_if_spectral *spectral;
  4695. struct wlan_lmac_if_tx_ops *tx_ops;
  4696. struct wlan_objmgr_psoc *psoc;
  4697. if (!pdev)
  4698. return QDF_STATUS_E_FAILURE;
  4699. psoc = wlan_pdev_get_psoc(pdev);
  4700. if (!psoc) {
  4701. spectral_err("psoc is null");
  4702. return QDF_STATUS_E_INVAL;
  4703. }
  4704. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  4705. if (!tx_ops) {
  4706. spectral_err("tx_ops is NULL");
  4707. return QDF_STATUS_E_INVAL;
  4708. }
  4709. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4710. if (!spectral) {
  4711. spectral_err("Spectal LMAC object is NULL");
  4712. return QDF_STATUS_E_INVAL;
  4713. }
  4714. /* Save the state */
  4715. spectral->dbr_buff_debug = enable;
  4716. if (enable)
  4717. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  4718. pdev, 0, MEM_POISON_SIGNATURE);
  4719. else
  4720. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  4721. pdev, 0);
  4722. }
  4723. /**
  4724. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  4725. * debug based on the previous state
  4726. * @pdev: Pointer to pdev object
  4727. *
  4728. * Return: QDF_STATUS of operation
  4729. */
  4730. static QDF_STATUS
  4731. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  4732. {
  4733. struct target_if_spectral *spectral;
  4734. if (!pdev) {
  4735. spectral_err("pdev is NULL!");
  4736. return QDF_STATUS_E_FAILURE;
  4737. }
  4738. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4739. if (!spectral) {
  4740. spectral_err("Spectal LMAC object is NULL");
  4741. return QDF_STATUS_E_INVAL;
  4742. }
  4743. if (spectral->dbr_buff_debug)
  4744. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  4745. else
  4746. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  4747. }
  4748. /**
  4749. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  4750. * debug based on the previous state
  4751. * @pdev: Pointer to pdev object
  4752. *
  4753. * Return: QDF_STATUS of operation
  4754. */
  4755. static QDF_STATUS
  4756. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  4757. {
  4758. struct target_if_spectral *spectral;
  4759. if (!pdev) {
  4760. spectral_err("pdev is NULL!");
  4761. return QDF_STATUS_E_FAILURE;
  4762. }
  4763. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4764. if (!spectral) {
  4765. spectral_err("Spectal LMAC object is NULL");
  4766. return QDF_STATUS_E_INVAL;
  4767. }
  4768. if (spectral->dbr_ring_debug)
  4769. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  4770. else
  4771. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  4772. }
  4773. /**
  4774. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  4775. * @pdev: Pointer to pdev object
  4776. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  4777. * @debug_value: Value to be set for @dma_debug_type
  4778. *
  4779. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  4780. * based on @debug_value
  4781. *
  4782. * Return: QDF_STATUS of operation
  4783. */
  4784. static QDF_STATUS
  4785. target_if_spectral_set_dma_debug(
  4786. struct wlan_objmgr_pdev *pdev,
  4787. enum spectral_dma_debug dma_debug_type,
  4788. bool debug_value)
  4789. {
  4790. struct target_if_spectral_ops *p_sops;
  4791. struct wlan_objmgr_psoc *psoc;
  4792. struct wlan_lmac_if_tx_ops *tx_ops;
  4793. struct target_if_spectral *spectral;
  4794. if (!pdev)
  4795. return QDF_STATUS_E_FAILURE;
  4796. psoc = wlan_pdev_get_psoc(pdev);
  4797. if (!psoc) {
  4798. spectral_err("psoc is null");
  4799. return QDF_STATUS_E_INVAL;
  4800. }
  4801. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  4802. if (!tx_ops) {
  4803. spectral_err("tx_ops is NULL");
  4804. return QDF_STATUS_E_FAILURE;
  4805. }
  4806. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  4807. spectral_err("Unable to fetch target type");
  4808. return QDF_STATUS_E_FAILURE;
  4809. }
  4810. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4811. if (!spectral) {
  4812. spectral_err("Spectal LMAC object is NULL");
  4813. return QDF_STATUS_E_INVAL;
  4814. }
  4815. if (spectral->direct_dma_support) {
  4816. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4817. if (p_sops->is_spectral_active(spectral,
  4818. SPECTRAL_SCAN_MODE_NORMAL) ||
  4819. p_sops->is_spectral_active(spectral,
  4820. SPECTRAL_SCAN_MODE_AGILE)) {
  4821. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  4822. return QDF_STATUS_E_FAILURE;
  4823. }
  4824. switch (dma_debug_type) {
  4825. case SPECTRAL_DMA_RING_DEBUG:
  4826. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  4827. break;
  4828. case SPECTRAL_DMA_BUFFER_DEBUG:
  4829. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  4830. break;
  4831. default:
  4832. spectral_err("Unsupported DMA debug type : %d",
  4833. dma_debug_type);
  4834. return QDF_STATUS_E_FAILURE;
  4835. }
  4836. }
  4837. return QDF_STATUS_SUCCESS;
  4838. }
  4839. #endif /* DIRECT_BUF_RX_DEBUG */
  4840. /**
  4841. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  4842. * @pdev: Pointer to pdev object
  4843. *
  4844. * Return: Whether Direct-DMA is supported on this radio
  4845. */
  4846. static bool
  4847. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  4848. {
  4849. struct target_if_spectral *spectral;
  4850. if (!pdev) {
  4851. spectral_err("pdev is NULL!");
  4852. return false;
  4853. }
  4854. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4855. if (!spectral) {
  4856. spectral_err("Spectral LMAC object is NULL");
  4857. return false;
  4858. }
  4859. return spectral->direct_dma_support;
  4860. }
  4861. /**
  4862. * target_if_set_debug_level() - Set debug level for Spectral
  4863. * @pdev: Pointer to pdev object
  4864. * @debug_level: Debug level
  4865. *
  4866. * API to set the debug level for Spectral
  4867. *
  4868. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4869. */
  4870. QDF_STATUS
  4871. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  4872. {
  4873. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  4874. return QDF_STATUS_SUCCESS;
  4875. }
  4876. /**
  4877. * target_if_get_debug_level() - Get debug level for Spectral
  4878. * @pdev: Pointer to pdev object
  4879. *
  4880. * API to get the debug level for Spectral
  4881. *
  4882. * Return: Current debug level
  4883. */
  4884. uint32_t
  4885. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  4886. {
  4887. return spectral_debug_level;
  4888. }
  4889. /**
  4890. * target_if_get_spectral_capinfo() - Get Spectral capability information
  4891. * @pdev: Pointer to pdev object
  4892. * @scaps: Buffer into which data should be copied
  4893. *
  4894. * API to get the spectral capability information
  4895. *
  4896. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4897. */
  4898. QDF_STATUS
  4899. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  4900. struct spectral_caps *scaps)
  4901. {
  4902. struct target_if_spectral *spectral = NULL;
  4903. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4904. if (!spectral) {
  4905. spectral_err("SPECTRAL : Module doesn't exist");
  4906. return QDF_STATUS_E_FAILURE;
  4907. }
  4908. qdf_mem_copy(scaps, &spectral->capability,
  4909. sizeof(struct spectral_caps));
  4910. return QDF_STATUS_SUCCESS;
  4911. }
  4912. /**
  4913. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  4914. * @pdev: Pointer to pdev object
  4915. * @stats: Buffer into which data should be copied
  4916. *
  4917. * API to get the spectral diagnostic statistics
  4918. *
  4919. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4920. */
  4921. QDF_STATUS
  4922. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  4923. struct spectral_diag_stats *stats)
  4924. {
  4925. struct target_if_spectral *spectral = NULL;
  4926. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4927. if (!spectral) {
  4928. spectral_err("SPECTRAL : Module doesn't exist");
  4929. return QDF_STATUS_E_FAILURE;
  4930. }
  4931. qdf_mem_copy(stats, &spectral->diag_stats,
  4932. sizeof(struct spectral_diag_stats));
  4933. return QDF_STATUS_SUCCESS;
  4934. }
  4935. /**
  4936. * target_if_register_spectral_wmi_ops() - Register Spectral WMI operations
  4937. * @psoc: Pointer to psoc object
  4938. * @wmi_ops: Pointer to the structure having Spectral WMI operations
  4939. *
  4940. * API for registering Spectral WMI operations in
  4941. * spectral internal data structure
  4942. *
  4943. * Return: QDF_STATUS
  4944. */
  4945. static QDF_STATUS
  4946. target_if_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
  4947. struct spectral_wmi_ops *wmi_ops)
  4948. {
  4949. struct target_if_psoc_spectral *psoc_spectral;
  4950. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4951. if (!psoc_spectral) {
  4952. spectral_err("Spectral LMAC object is null");
  4953. return QDF_STATUS_E_INVAL;
  4954. }
  4955. psoc_spectral->wmi_ops = *wmi_ops;
  4956. return QDF_STATUS_SUCCESS;
  4957. }
  4958. /**
  4959. * target_if_register_spectral_tgt_ops() - Register Spectral target operations
  4960. * @psoc: Pointer to psoc object
  4961. * @tgt_ops: Pointer to the structure having Spectral target operations
  4962. *
  4963. * API for registering Spectral target operations in
  4964. * spectral internal data structure
  4965. *
  4966. * Return: QDF_STATUS
  4967. */
  4968. static QDF_STATUS
  4969. target_if_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
  4970. struct spectral_tgt_ops *tgt_ops)
  4971. {
  4972. if (!psoc) {
  4973. spectral_err("psoc is null");
  4974. return QDF_STATUS_E_INVAL;
  4975. }
  4976. ops_tgt = *tgt_ops;
  4977. return QDF_STATUS_SUCCESS;
  4978. }
  4979. /**
  4980. * target_if_register_netlink_cb() - Register Netlink callbacks
  4981. * @pdev: Pointer to pdev object
  4982. * @nl_cb: Netlink callbacks to register
  4983. *
  4984. * Return: void
  4985. */
  4986. static void
  4987. target_if_register_netlink_cb(
  4988. struct wlan_objmgr_pdev *pdev,
  4989. struct spectral_nl_cb *nl_cb)
  4990. {
  4991. struct target_if_spectral *spectral = NULL;
  4992. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4993. if (!spectral) {
  4994. spectral_err("SPECTRAL : Module doesn't exist");
  4995. return;
  4996. }
  4997. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  4998. if (spectral->use_nl_bcast)
  4999. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  5000. else
  5001. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  5002. }
  5003. /**
  5004. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  5005. * Netlink messages to the application layer
  5006. * @pdev: Pointer to pdev object
  5007. *
  5008. * Return: true for broadcast, false for unicast
  5009. */
  5010. static bool
  5011. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  5012. {
  5013. struct target_if_spectral *spectral = NULL;
  5014. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5015. if (!spectral) {
  5016. spectral_err("SPECTRAL : Module doesn't exist");
  5017. return false;
  5018. }
  5019. return spectral->use_nl_bcast;
  5020. }
  5021. /**
  5022. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  5023. * @pdev: Pointer to pdev object
  5024. *
  5025. * Return: void
  5026. */
  5027. static void
  5028. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  5029. {
  5030. struct target_if_spectral *spectral = NULL;
  5031. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5032. if (!spectral) {
  5033. spectral_err("SPECTRAL : Module doesn't exist");
  5034. return;
  5035. }
  5036. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  5037. }
  5038. static int
  5039. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  5040. void *payload)
  5041. {
  5042. struct target_if_spectral *spectral = NULL;
  5043. struct target_if_spectral_ops *p_sops = NULL;
  5044. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5045. if (!spectral) {
  5046. spectral_err("SPECTRAL : Module doesn't exist");
  5047. return -EPERM;
  5048. }
  5049. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5050. if (!p_sops) {
  5051. spectral_err("p_sops is null");
  5052. return -EPERM;
  5053. }
  5054. return p_sops->process_spectral_report(pdev, payload);
  5055. }
  5056. #ifdef DIRECT_BUF_RX_DEBUG
  5057. static inline void
  5058. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5059. {
  5060. if (!tx_ops) {
  5061. spectral_err("tx_ops is NULL");
  5062. return;
  5063. }
  5064. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  5065. target_if_spectral_set_dma_debug;
  5066. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  5067. target_if_spectral_check_and_do_dbr_ring_debug;
  5068. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  5069. target_if_spectral_check_and_do_dbr_buff_debug;
  5070. }
  5071. #else
  5072. static inline void
  5073. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5074. {
  5075. }
  5076. #endif
  5077. #if defined(WLAN_CONV_SPECTRAL_ENABLE) && defined(SPECTRAL_MODULIZED_ENABLE)
  5078. /**
  5079. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  5080. * register WMI event handler
  5081. * @psoc: Pointer to psoc object
  5082. * @event_id: Event id
  5083. * @handler_func: Handler function
  5084. * @rx_ctx: Context of WMI event processing
  5085. *
  5086. * Wrapper function to register WMI event handler
  5087. *
  5088. * Return: 0 for success else failure
  5089. */
  5090. static int
  5091. target_if_spectral_wmi_unified_register_event_handler(
  5092. struct wlan_objmgr_psoc *psoc,
  5093. wmi_conv_event_id event_id,
  5094. wmi_unified_event_handler handler_func,
  5095. uint8_t rx_ctx)
  5096. {
  5097. wmi_unified_t wmi_handle;
  5098. struct target_if_psoc_spectral *psoc_spectral;
  5099. QDF_STATUS ret;
  5100. if (!psoc) {
  5101. spectral_err("psoc is null");
  5102. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5103. }
  5104. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5105. if (!wmi_handle) {
  5106. spectral_err("WMI handle is null");
  5107. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5108. }
  5109. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5110. if (!psoc_spectral) {
  5111. spectral_err("spectral object is null");
  5112. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5113. }
  5114. ret = psoc_spectral->wmi_ops.wmi_unified_register_event_handler(
  5115. wmi_handle, event_id, handler_func, rx_ctx);
  5116. return qdf_status_to_os_return(ret);
  5117. }
  5118. /**
  5119. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  5120. * to unregister WMI event handler
  5121. * @psoc: Pointer to psoc object
  5122. * @event_id: Event id
  5123. *
  5124. * Wrapper function to unregister WMI event handler
  5125. *
  5126. * Return: 0 for success else failure
  5127. */
  5128. static int
  5129. target_if_spectral_wmi_unified_unregister_event_handler(
  5130. struct wlan_objmgr_psoc *psoc,
  5131. wmi_conv_event_id event_id)
  5132. {
  5133. wmi_unified_t wmi_handle;
  5134. struct target_if_psoc_spectral *psoc_spectral;
  5135. QDF_STATUS ret;
  5136. if (!psoc) {
  5137. spectral_err("psoc is null");
  5138. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5139. }
  5140. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5141. if (!wmi_handle) {
  5142. spectral_err("WMI handle is null");
  5143. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5144. }
  5145. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5146. if (!psoc_spectral) {
  5147. spectral_err("spectral object is null");
  5148. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5149. }
  5150. ret = psoc_spectral->wmi_ops.wmi_unified_unregister_event_handler(
  5151. wmi_handle, event_id);
  5152. return qdf_status_to_os_return(ret);
  5153. }
  5154. /**
  5155. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  5156. * function to extract fixed parameters from start scan response event
  5157. * @psoc: Pointer to psoc object
  5158. * @evt_buf: Event buffer
  5159. * @param: Start scan response parameters
  5160. *
  5161. * Wrapper function to extract fixed parameters from start scan response event
  5162. *
  5163. * Return: QDF_STATUS
  5164. */
  5165. static QDF_STATUS
  5166. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  5167. struct wlan_objmgr_psoc *psoc,
  5168. uint8_t *evt_buf,
  5169. struct spectral_startscan_resp_params *param)
  5170. {
  5171. wmi_unified_t wmi_handle;
  5172. struct target_if_psoc_spectral *psoc_spectral;
  5173. if (!psoc) {
  5174. spectral_err("psoc is null");
  5175. return QDF_STATUS_E_INVAL;
  5176. }
  5177. if (!evt_buf) {
  5178. spectral_err("WMI event buffer is null");
  5179. return QDF_STATUS_E_INVAL;
  5180. }
  5181. if (!param) {
  5182. spectral_err("Spectral startscan response parameters is null");
  5183. return QDF_STATUS_E_INVAL;
  5184. }
  5185. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5186. if (!wmi_handle) {
  5187. spectral_err("WMI handle is null");
  5188. return QDF_STATUS_E_INVAL;
  5189. }
  5190. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5191. if (!psoc_spectral) {
  5192. spectral_err("spectral object is null");
  5193. return QDF_STATUS_E_FAILURE;
  5194. }
  5195. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  5196. wmi_handle, evt_buf, param);
  5197. }
  5198. /**
  5199. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  5200. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  5201. * secondary 80 MHz FFT bins
  5202. * @psoc: Pointer to psoc object
  5203. * @evt_buf: Event buffer
  5204. * @param: FFT bin start and end indices
  5205. *
  5206. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  5207. * and secondary 80 MHz FFT bins
  5208. *
  5209. * Return: QDF_STATUS
  5210. */
  5211. static QDF_STATUS
  5212. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  5213. struct wlan_objmgr_psoc *psoc,
  5214. uint8_t *evt_buf,
  5215. struct spectral_fft_bin_markers_160_165mhz *param)
  5216. {
  5217. wmi_unified_t wmi_handle;
  5218. struct target_if_psoc_spectral *psoc_spectral;
  5219. if (!psoc) {
  5220. spectral_err("psoc is null");
  5221. return QDF_STATUS_E_INVAL;
  5222. }
  5223. if (!evt_buf) {
  5224. spectral_err("WMI event buffer is null");
  5225. return QDF_STATUS_E_INVAL;
  5226. }
  5227. if (!param) {
  5228. spectral_err("Spectral FFT bin markers is null");
  5229. return QDF_STATUS_E_INVAL;
  5230. }
  5231. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5232. if (!wmi_handle) {
  5233. spectral_err("WMI handle is null");
  5234. return QDF_STATUS_E_INVAL;
  5235. }
  5236. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5237. if (!psoc_spectral) {
  5238. spectral_err("spectral object is null");
  5239. return QDF_STATUS_E_FAILURE;
  5240. }
  5241. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fft_bin_index(
  5242. wmi_handle, evt_buf, param);
  5243. }
  5244. /**
  5245. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  5246. * object from scn handle
  5247. * @scn: scn handle
  5248. *
  5249. * Wrapper function to get psoc object from scn handle
  5250. *
  5251. * Return: Pointer to psoc object
  5252. */
  5253. static struct wlan_objmgr_psoc *
  5254. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  5255. {
  5256. if (!scn) {
  5257. spectral_err("scn is null");
  5258. return NULL;
  5259. }
  5260. return ops_tgt.tgt_get_psoc_from_scn_hdl(scn);
  5261. }
  5262. #else
  5263. /**
  5264. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  5265. * register WMI event handler
  5266. * @psoc: Pointer to psoc object
  5267. * @event_id: Event id
  5268. * @handler_func: Handler function
  5269. * @rx_ctx: Context of WMI event processing
  5270. *
  5271. * Wrapper function to register WMI event handler
  5272. *
  5273. * Return: 0 for success else failure
  5274. */
  5275. static int
  5276. target_if_spectral_wmi_unified_register_event_handler(
  5277. struct wlan_objmgr_psoc *psoc,
  5278. wmi_conv_event_id event_id,
  5279. wmi_unified_event_handler handler_func,
  5280. uint8_t rx_ctx)
  5281. {
  5282. wmi_unified_t wmi_handle;
  5283. QDF_STATUS ret;
  5284. if (!psoc) {
  5285. spectral_err("psoc is null");
  5286. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5287. }
  5288. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5289. if (!wmi_handle) {
  5290. spectral_err("WMI handle is null");
  5291. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5292. }
  5293. ret = wmi_unified_register_event_handler(wmi_handle, event_id,
  5294. handler_func, rx_ctx);
  5295. return qdf_status_to_os_return(ret);
  5296. }
  5297. /**
  5298. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  5299. * to unregister WMI event handler
  5300. * @psoc: Pointer to psoc object
  5301. * @event_id: Event id
  5302. *
  5303. * Wrapper function to unregister WMI event handler
  5304. *
  5305. * Return: 0 for success else failure
  5306. */
  5307. static int
  5308. target_if_spectral_wmi_unified_unregister_event_handler(
  5309. struct wlan_objmgr_psoc *psoc,
  5310. wmi_conv_event_id event_id)
  5311. {
  5312. wmi_unified_t wmi_handle;
  5313. QDF_STATUS ret;
  5314. if (!psoc) {
  5315. spectral_err("psoc is null");
  5316. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5317. }
  5318. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5319. if (!wmi_handle) {
  5320. spectral_err("WMI handle is null");
  5321. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5322. }
  5323. ret = wmi_unified_unregister_event_handler(wmi_handle, event_id);
  5324. return qdf_status_to_os_return(ret);
  5325. }
  5326. /**
  5327. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  5328. * function to extract fixed parameters from start scan response event
  5329. * @psoc: Pointer to psoc object
  5330. * @evt_buf: Event buffer
  5331. * @param: Start scan response parameters
  5332. *
  5333. * Wrapper function to extract fixed parameters from start scan response event
  5334. *
  5335. * Return: QDF_STATUS
  5336. */
  5337. static QDF_STATUS
  5338. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  5339. struct wlan_objmgr_psoc *psoc,
  5340. uint8_t *evt_buf,
  5341. struct spectral_startscan_resp_params *param)
  5342. {
  5343. wmi_unified_t wmi_handle;
  5344. if (!psoc) {
  5345. spectral_err("psoc is null");
  5346. return QDF_STATUS_E_INVAL;
  5347. }
  5348. if (!evt_buf) {
  5349. spectral_err("WMI event buffer is null");
  5350. return QDF_STATUS_E_INVAL;
  5351. }
  5352. if (!param) {
  5353. spectral_err("Spectral startscan response parameters is null");
  5354. return QDF_STATUS_E_INVAL;
  5355. }
  5356. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5357. if (!wmi_handle) {
  5358. spectral_err("WMI handle is null");
  5359. return QDF_STATUS_E_INVAL;
  5360. }
  5361. return wmi_extract_pdev_sscan_fw_cmd_fixed_param(wmi_handle, evt_buf,
  5362. param);
  5363. }
  5364. /**
  5365. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  5366. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  5367. * secondary 80 MHz FFT bins
  5368. * @psoc: Pointer to psoc object
  5369. * @evt_buf: Event buffer
  5370. * @param: FFT bin start and end indices
  5371. *
  5372. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  5373. * and secondary 80 MHz FFT bins
  5374. *
  5375. * Return: QDF_STATUS
  5376. */
  5377. static QDF_STATUS
  5378. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  5379. struct wlan_objmgr_psoc *psoc,
  5380. uint8_t *evt_buf,
  5381. struct spectral_fft_bin_markers_160_165mhz *param)
  5382. {
  5383. wmi_unified_t wmi_handle;
  5384. if (!psoc) {
  5385. spectral_err("psoc is null");
  5386. return QDF_STATUS_E_INVAL;
  5387. }
  5388. if (!evt_buf) {
  5389. spectral_err("WMI event buffer is null");
  5390. return QDF_STATUS_E_INVAL;
  5391. }
  5392. if (!param) {
  5393. spectral_err("Spectral FFT bin markers is null");
  5394. return QDF_STATUS_E_INVAL;
  5395. }
  5396. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5397. if (!wmi_handle) {
  5398. spectral_err("WMI handle is null");
  5399. return QDF_STATUS_E_INVAL;
  5400. }
  5401. return wmi_extract_pdev_sscan_fft_bin_index(wmi_handle, evt_buf, param);
  5402. }
  5403. /**
  5404. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  5405. * object from scn handle
  5406. * @scn: scn handle
  5407. *
  5408. * Wrapper function to get psoc object from scn handle
  5409. *
  5410. * Return: Pointer to psoc object
  5411. */
  5412. static struct wlan_objmgr_psoc *
  5413. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  5414. {
  5415. if (!scn) {
  5416. spectral_err("scn is null");
  5417. return NULL;
  5418. }
  5419. return target_if_get_psoc_from_scn_hdl(scn);
  5420. }
  5421. #endif
  5422. /**
  5423. * target_if_spectral_fw_param_event_handler() - WMI event handler to
  5424. * process start scan response event
  5425. * @scn: Pointer to scn object
  5426. * @data_buf: Pointer to event buffer
  5427. * @data_len: Length of event buffer
  5428. *
  5429. * Return: 0 for success, else failure
  5430. */
  5431. static int
  5432. target_if_spectral_fw_param_event_handler(ol_scn_t scn, uint8_t *data_buf,
  5433. uint32_t data_len)
  5434. {
  5435. QDF_STATUS status;
  5436. struct wlan_objmgr_psoc *psoc;
  5437. struct wlan_objmgr_pdev *pdev;
  5438. struct wmi_unified *wmi_handle;
  5439. struct spectral_startscan_resp_params event_params = {0};
  5440. struct target_if_psoc_spectral *psoc_spectral;
  5441. struct target_if_spectral *spectral;
  5442. if (!scn) {
  5443. spectral_err("scn handle is null");
  5444. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5445. }
  5446. if (!data_buf) {
  5447. spectral_err("WMI event buffer null");
  5448. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5449. }
  5450. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  5451. if (!psoc) {
  5452. spectral_err("psoc is null");
  5453. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5454. }
  5455. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5456. if (!psoc_spectral) {
  5457. spectral_err("spectral object is null");
  5458. return QDF_STATUS_E_FAILURE;
  5459. }
  5460. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5461. if (!wmi_handle) {
  5462. spectral_err("WMI handle is null");
  5463. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5464. }
  5465. status = target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  5466. psoc, data_buf, &event_params);
  5467. if (QDF_IS_STATUS_ERROR(status)) {
  5468. spectral_err("unable to extract sscan fw fixed params");
  5469. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5470. }
  5471. pdev = wlan_objmgr_get_pdev_by_id(psoc, event_params.pdev_id,
  5472. WLAN_SPECTRAL_ID);
  5473. if (!pdev) {
  5474. spectral_err("pdev is null");
  5475. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5476. }
  5477. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5478. if (!spectral) {
  5479. spectral_err("spectral object is null");
  5480. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  5481. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5482. }
  5483. if (event_params.num_fft_bin_index == 1) {
  5484. status =
  5485. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  5486. psoc, data_buf,
  5487. &spectral->rparams.marker[event_params.smode]);
  5488. if (QDF_IS_STATUS_ERROR(status)) {
  5489. spectral_err("unable to extract sscan fw fixed params");
  5490. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  5491. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5492. }
  5493. } else {
  5494. spectral->rparams.marker[event_params.smode].is_valid = false;
  5495. }
  5496. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  5497. return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
  5498. }
  5499. static QDF_STATUS
  5500. target_if_spectral_register_events(struct wlan_objmgr_psoc *psoc)
  5501. {
  5502. int ret;
  5503. if (!psoc) {
  5504. spectral_err("psoc is null");
  5505. return QDF_STATUS_E_INVAL;
  5506. }
  5507. ret = target_if_spectral_wmi_unified_register_event_handler(
  5508. psoc,
  5509. wmi_pdev_sscan_fw_param_eventid,
  5510. target_if_spectral_fw_param_event_handler,
  5511. WMI_RX_UMAC_CTX);
  5512. if (ret)
  5513. spectral_debug("event handler not supported, ret=%d", ret);
  5514. return QDF_STATUS_SUCCESS;
  5515. }
  5516. static QDF_STATUS
  5517. target_if_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
  5518. {
  5519. int ret;
  5520. if (!psoc) {
  5521. spectral_err("psoc is null");
  5522. return QDF_STATUS_E_INVAL;
  5523. }
  5524. ret = target_if_spectral_wmi_unified_unregister_event_handler(
  5525. psoc, wmi_pdev_sscan_fw_param_eventid);
  5526. if (ret)
  5527. spectral_debug("Unregister WMI event handler failed, ret = %d",
  5528. ret);
  5529. return QDF_STATUS_SUCCESS;
  5530. }
  5531. void
  5532. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5533. {
  5534. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  5535. target_if_pdev_spectral_init;
  5536. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  5537. target_if_pdev_spectral_deinit;
  5538. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init =
  5539. target_if_psoc_spectral_init;
  5540. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit =
  5541. target_if_psoc_spectral_deinit;
  5542. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  5543. target_if_set_spectral_config;
  5544. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  5545. target_if_get_spectral_config;
  5546. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  5547. target_if_start_spectral_scan;
  5548. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  5549. target_if_stop_spectral_scan;
  5550. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  5551. target_if_is_spectral_active;
  5552. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  5553. target_if_is_spectral_enabled;
  5554. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  5555. target_if_set_debug_level;
  5556. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  5557. target_if_get_debug_level;
  5558. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  5559. target_if_get_spectral_capinfo;
  5560. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  5561. target_if_get_spectral_diagstats;
  5562. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_wmi_ops =
  5563. target_if_register_spectral_wmi_ops;
  5564. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_tgt_ops =
  5565. target_if_register_spectral_tgt_ops;
  5566. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  5567. target_if_register_netlink_cb;
  5568. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  5569. target_if_use_nl_bcast;
  5570. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  5571. target_if_deregister_netlink_cb;
  5572. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  5573. target_if_process_spectral_report;
  5574. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  5575. target_if_spectral_direct_dma_support;
  5576. tx_ops->sptrl_tx_ops.sptrlto_register_events =
  5577. target_if_spectral_register_events;
  5578. tx_ops->sptrl_tx_ops.sptrlto_unregister_events =
  5579. target_if_spectral_unregister_events;
  5580. tx_ops->sptrl_tx_ops.sptrlto_init_pdev_feature_caps =
  5581. target_if_spectral_init_pdev_feature_caps;
  5582. target_if_sptrl_debug_register_tx_ops(tx_ops);
  5583. }
  5584. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  5585. void
  5586. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  5587. uint16_t cw_int, uint32_t dcs_enabled)
  5588. {
  5589. struct spectral_samp_msg *msg = NULL;
  5590. struct target_if_spectral_ops *p_sops = NULL;
  5591. struct target_if_spectral *spectral = NULL;
  5592. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5593. if (!spectral) {
  5594. spectral_err("SPECTRAL : Module doesn't exist");
  5595. return;
  5596. }
  5597. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5598. if (!p_sops) {
  5599. spectral_err("p_sops is null");
  5600. return;
  5601. }
  5602. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  5603. spectral->pdev_obj,
  5604. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  5605. SPECTRAL_MSG_BUF_NEW);
  5606. if (msg) {
  5607. msg->int_type = cw_int ?
  5608. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  5609. msg->dcs_enabled = dcs_enabled;
  5610. msg->signature = SPECTRAL_SIGNATURE;
  5611. p_sops->get_mac_address(spectral, msg->macaddr);
  5612. if (spectral->send_phy_data
  5613. (pdev,
  5614. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  5615. spectral->spectral_sent_msg++;
  5616. }
  5617. }
  5618. qdf_export_symbol(target_if_spectral_send_intf_found_msg);
  5619. QDF_STATUS
  5620. target_if_spectral_is_finite_scan(struct target_if_spectral *spectral,
  5621. enum spectral_scan_mode smode,
  5622. bool *finite_spectral_scan)
  5623. {
  5624. struct target_if_finite_spectral_scan_params *finite_scan;
  5625. if (!spectral) {
  5626. spectral_err_rl("target if spectral object is null");
  5627. return QDF_STATUS_E_INVAL;
  5628. }
  5629. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5630. spectral_err_rl("invalid spectral mode %d", smode);
  5631. return QDF_STATUS_E_INVAL;
  5632. }
  5633. if (!finite_spectral_scan) {
  5634. spectral_err_rl("Invalid pointer");
  5635. return QDF_STATUS_E_INVAL;
  5636. }
  5637. finite_scan = &spectral->finite_scan[smode];
  5638. *finite_spectral_scan = finite_scan->finite_spectral_scan;
  5639. return QDF_STATUS_SUCCESS;
  5640. }
  5641. QDF_STATUS
  5642. target_if_spectral_finite_scan_update(struct target_if_spectral *spectral,
  5643. enum spectral_scan_mode smode)
  5644. {
  5645. struct target_if_finite_spectral_scan_params *finite_scan;
  5646. if (!spectral) {
  5647. spectral_err_rl("target if spectral object is null");
  5648. return QDF_STATUS_E_INVAL;
  5649. }
  5650. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5651. spectral_err_rl("Invalid Spectral mode");
  5652. return QDF_STATUS_E_INVAL;
  5653. }
  5654. finite_scan = &spectral->finite_scan[smode];
  5655. if (!finite_scan->num_reports_expected) {
  5656. spectral_err_rl("Error, No reports expected");
  5657. return QDF_STATUS_E_FAILURE;
  5658. }
  5659. finite_scan->num_reports_expected--;
  5660. if (!finite_scan->num_reports_expected) {
  5661. QDF_STATUS status;
  5662. enum spectral_cp_error_code err;
  5663. /* received expected number of reports from target, stop scan */
  5664. status = target_if_stop_spectral_scan(spectral->pdev_obj, smode,
  5665. &err);
  5666. if (QDF_IS_STATUS_ERROR(status)) {
  5667. spectral_err_rl("Failed to stop finite Spectral scan");
  5668. return QDF_STATUS_E_FAILURE;
  5669. }
  5670. finite_scan->finite_spectral_scan = false;
  5671. }
  5672. return QDF_STATUS_SUCCESS;
  5673. }