target_if_spectral.c 166 KB

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