target_if_spectral.c 211 KB

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