target_if_spectral.c 183 KB

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