target_if_spectral.c 168 KB

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