target_if_spectral.c 215 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907
  1. /*
  2. * Copyright (c) 2011,2017-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2022 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. target_type == TARGET_TYPE_KIWI) {
  1822. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1823. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1824. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1825. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1826. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1827. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1828. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1829. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1830. } else {
  1831. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1832. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1833. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1834. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1835. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1836. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1837. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1838. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1839. }
  1840. break;
  1841. case SPECTRAL_GEN2:
  1842. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1843. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1844. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1845. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1846. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1847. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1848. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1849. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1850. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1851. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1852. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1853. break;
  1854. default:
  1855. spectral_err("Invalid spectral generation %d", gen);
  1856. return QDF_STATUS_E_INVAL;
  1857. }
  1858. return QDF_STATUS_SUCCESS;
  1859. }
  1860. /**
  1861. * target_if_init_spectral_param_properties() - Initialize Spectral parameter
  1862. * properties
  1863. * @spectral: Pointer to Spectral target_if internal private data
  1864. *
  1865. * Initialize Spectral parameter properties
  1866. *
  1867. * Return: QDF_STATUS
  1868. */
  1869. static QDF_STATUS
  1870. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1871. {
  1872. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1873. int param;
  1874. /* Initialize default values for properties.
  1875. * Default values are supported for all the parameters for all modes
  1876. * and allows different values for each mode for all the parameters .
  1877. */
  1878. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1879. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1880. spectral->properties[smode][param].supported = true;
  1881. spectral->properties[smode][param].common_all_modes =
  1882. false;
  1883. }
  1884. }
  1885. /* Once FW advertisement is in place remove this hard coding */
  1886. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1887. spectral->properties[SPECTRAL_SCAN_MODE_NORMAL]
  1888. [SPECTRAL_PARAM_FREQUENCY].supported = false;
  1889. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1890. spectral->properties[smode]
  1891. [SPECTRAL_PARAM_SPECT_PRI].common_all_modes = true;
  1892. spectral->properties[smode]
  1893. [SPECTRAL_PARAM_SCAN_PERIOD].common_all_modes = true;
  1894. spectral->properties[smode]
  1895. [SPECTRAL_PARAM_INIT_DELAY].common_all_modes = true;
  1896. }
  1897. return QDF_STATUS_SUCCESS;
  1898. }
  1899. /* Bandwidth to half bandwidth mapping */
  1900. static const enum phy_ch_width half_bw_map[] = {
  1901. #ifdef WLAN_FEATURE_11BE
  1902. [CH_WIDTH_320MHZ] = CH_WIDTH_160MHZ,
  1903. #endif
  1904. [CH_WIDTH_80P80MHZ] = CH_WIDTH_80MHZ,
  1905. [CH_WIDTH_160MHZ] = CH_WIDTH_80MHZ,
  1906. [CH_WIDTH_80MHZ] = CH_WIDTH_40MHZ,
  1907. [CH_WIDTH_40MHZ] = CH_WIDTH_20MHZ,
  1908. [CH_WIDTH_20MHZ] = CH_WIDTH_10MHZ,
  1909. [CH_WIDTH_10MHZ] = CH_WIDTH_5MHZ,
  1910. [CH_WIDTH_5MHZ] = CH_WIDTH_INVALID
  1911. };
  1912. /**
  1913. * target_if_get_half_bandwidth() - Get half bandwidth for a given bandwidth
  1914. * @bw: bandwidth
  1915. *
  1916. * Return: Half bandwidth of @bw
  1917. */
  1918. static enum phy_ch_width target_if_get_half_bandwidth(enum phy_ch_width bw)
  1919. {
  1920. if (bw >= CH_WIDTH_INVALID)
  1921. return CH_WIDTH_INVALID;
  1922. return half_bw_map[bw];
  1923. }
  1924. /**
  1925. * target_if_populate_supported_sscan_bws_be() - Populate supported spectral
  1926. * scan bandwidths for beryllium chipsets
  1927. * @spectral: Spectral LMAC object
  1928. *
  1929. * Return: QDF_STATUS of operation
  1930. */
  1931. static QDF_STATUS
  1932. target_if_populate_supported_sscan_bws_be(struct target_if_spectral *spectral)
  1933. {
  1934. enum phy_ch_width op_bw;
  1935. struct spectral_supported_bws *supported_bws;
  1936. QDF_STATUS status;
  1937. qdf_assert_always(spectral);
  1938. /* 20MHz */
  1939. op_bw = CH_WIDTH_20MHZ;
  1940. supported_bws = &spectral->supported_bws
  1941. [SPECTRAL_SCAN_MODE_NORMAL][op_bw];
  1942. supported_bws->bandwidths |= 1 << get_supported_sscan_bw_pos(op_bw);
  1943. spectral->supported_sscan_bw_list
  1944. [SPECTRAL_SCAN_MODE_NORMAL][op_bw] = true;
  1945. supported_bws = &spectral->supported_bws
  1946. [SPECTRAL_SCAN_MODE_AGILE][op_bw];
  1947. supported_bws->bandwidths |= 1 << get_supported_sscan_bw_pos(op_bw);
  1948. spectral->supported_sscan_bw_list
  1949. [SPECTRAL_SCAN_MODE_AGILE][op_bw] = true;
  1950. for (op_bw = CH_WIDTH_40MHZ; op_bw < CH_WIDTH_MAX; op_bw++) {
  1951. bool is_supported;
  1952. enum phy_ch_width half_op_bw;
  1953. status = wlan_reg_is_chwidth_supported(spectral->pdev_obj,
  1954. op_bw, &is_supported);
  1955. if (QDF_IS_STATUS_ERROR(status)) {
  1956. spectral_err("Unable to check if ch_width(%d) is supported",
  1957. op_bw);
  1958. return QDF_STATUS_E_FAILURE;
  1959. }
  1960. if (!is_supported)
  1961. continue;
  1962. spectral_debug("Updating supported bw for op_bw: %d", op_bw);
  1963. /* Normal mode */
  1964. supported_bws = &spectral->supported_bws
  1965. [SPECTRAL_SCAN_MODE_NORMAL][op_bw];
  1966. supported_bws->bandwidths |=
  1967. 1 << get_supported_sscan_bw_pos(op_bw);
  1968. spectral->supported_sscan_bw_list
  1969. [SPECTRAL_SCAN_MODE_NORMAL][op_bw] = true;
  1970. /* Agile mode */
  1971. supported_bws = &spectral->supported_bws
  1972. [SPECTRAL_SCAN_MODE_AGILE][op_bw];
  1973. supported_bws->bandwidths |=
  1974. 1 << get_supported_sscan_bw_pos(op_bw);
  1975. spectral->supported_sscan_bw_list
  1976. [SPECTRAL_SCAN_MODE_AGILE][op_bw] = true;
  1977. half_op_bw = target_if_get_half_bandwidth(op_bw);
  1978. if (half_op_bw != CH_WIDTH_INVALID) {
  1979. supported_bws->bandwidths |=
  1980. 1 << get_supported_sscan_bw_pos(half_op_bw);
  1981. spectral->supported_sscan_bw_list
  1982. [SPECTRAL_SCAN_MODE_AGILE][half_op_bw] = true;
  1983. }
  1984. }
  1985. return QDF_STATUS_SUCCESS;
  1986. }
  1987. /**
  1988. * target_if_populate_supported_sscan_bws() - Populate supported spectral
  1989. * scan bandwidths
  1990. * @spectral: Spectral LMAC object
  1991. * @target_type: Target type
  1992. *
  1993. * Return: QDF_STATUS of operation
  1994. */
  1995. static QDF_STATUS
  1996. target_if_populate_supported_sscan_bws(struct target_if_spectral *spectral,
  1997. uint32_t target_type)
  1998. {
  1999. enum spectral_scan_mode smode;
  2000. enum phy_ch_width op_bw;
  2001. struct spectral_supported_bws *supported_bws;
  2002. struct wlan_objmgr_psoc *psoc;
  2003. QDF_STATUS status;
  2004. qdf_assert_always(spectral);
  2005. if (is_spectral_arch_beryllium(target_type))
  2006. return target_if_populate_supported_sscan_bws_be(spectral);
  2007. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  2008. if (!psoc) {
  2009. spectral_err("psoc is null");
  2010. return QDF_STATUS_E_NULL_VALUE;
  2011. }
  2012. for (op_bw = CH_WIDTH_20MHZ; op_bw < CH_WIDTH_MAX; op_bw++) {
  2013. bool is_supported;
  2014. status = wlan_reg_is_chwidth_supported(spectral->pdev_obj,
  2015. op_bw, &is_supported);
  2016. if (QDF_IS_STATUS_ERROR(status)) {
  2017. spectral_err("Unable to check if ch_width(%d) is supported",
  2018. op_bw);
  2019. return QDF_STATUS_E_FAILURE;
  2020. }
  2021. if (!is_supported)
  2022. continue;
  2023. spectral_debug("Updating supported bw for op_bw: %d", op_bw);
  2024. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2025. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2026. supported_bws = &spectral->supported_bws[smode][op_bw];
  2027. if (is_ch_width_160_or_80p80(op_bw) &&
  2028. smode == SPECTRAL_SCAN_MODE_AGILE) {
  2029. /**
  2030. * If fragmentation is supported, then only 80Hz
  2031. * agile width is supported
  2032. */
  2033. if (spectral->rparams.
  2034. fragmentation_160[smode]) {
  2035. supported_bws->bandwidths |=
  2036. 1 << get_supported_sscan_bw_pos(
  2037. CH_WIDTH_80MHZ);
  2038. spectral->supported_sscan_bw_list
  2039. [smode][CH_WIDTH_80MHZ] = true;
  2040. }
  2041. /**
  2042. * If restricted 80p80 is supported, then both
  2043. * 160 and 80p80 agile widths are supported for
  2044. * 160MHz, and only 160MHz agile width is
  2045. * supported for 80p80
  2046. */
  2047. if (wlan_psoc_nif_fw_ext_cap_get(
  2048. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  2049. supported_bws->bandwidths |=
  2050. 1 << get_supported_sscan_bw_pos(
  2051. CH_WIDTH_160MHZ);
  2052. spectral->supported_sscan_bw_list
  2053. [smode][CH_WIDTH_160MHZ] = true;
  2054. if (op_bw == CH_WIDTH_160MHZ) {
  2055. supported_bws->bandwidths |=
  2056. 1 << get_supported_sscan_bw_pos(
  2057. CH_WIDTH_80P80MHZ);
  2058. spectral->supported_sscan_bw_list
  2059. [smode][CH_WIDTH_80P80MHZ] = true;
  2060. }
  2061. }
  2062. } else {
  2063. supported_bws->bandwidths |=
  2064. 1 << get_supported_sscan_bw_pos(
  2065. op_bw);
  2066. spectral->supported_sscan_bw_list
  2067. [smode][op_bw] = true;
  2068. }
  2069. }
  2070. }
  2071. return QDF_STATUS_SUCCESS;
  2072. }
  2073. QDF_STATUS
  2074. target_if_init_spectral_capability(struct target_if_spectral *spectral,
  2075. uint32_t target_type)
  2076. {
  2077. struct wlan_objmgr_psoc *psoc;
  2078. struct wlan_objmgr_pdev *pdev;
  2079. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  2080. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  2081. struct target_psoc_info *tgt_psoc_info;
  2082. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  2083. struct spectral_caps *pcap = &spectral->capability;
  2084. QDF_STATUS status;
  2085. pdev = spectral->pdev_obj;
  2086. psoc = wlan_pdev_get_psoc(pdev);
  2087. if (!psoc) {
  2088. spectral_err("psoc is null");
  2089. return QDF_STATUS_E_FAILURE;
  2090. }
  2091. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  2092. if (!tgt_psoc_info) {
  2093. spectral_err("target_psoc_info is null");
  2094. return QDF_STATUS_E_FAILURE;
  2095. }
  2096. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  2097. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  2098. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  2099. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  2100. /* XXX : Workaround: Set Spectral capability */
  2101. pcap = &spectral->capability;
  2102. pcap->phydiag_cap = 1;
  2103. pcap->radar_cap = 1;
  2104. pcap->spectral_cap = wlan_pdev_nif_feat_ext_cap_get(
  2105. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  2106. pcap->advncd_spectral_cap = pcap->spectral_cap;
  2107. pcap->hw_gen = spectral->spectral_gen;
  2108. pcap->agile_spectral_cap = !wlan_pdev_nif_feat_ext_cap_get(
  2109. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  2110. pcap->agile_spectral_cap_160 = !wlan_pdev_nif_feat_ext_cap_get(
  2111. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  2112. pcap->agile_spectral_cap_80p80 = !wlan_pdev_nif_feat_ext_cap_get(
  2113. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  2114. pcap->agile_spectral_cap_320 = !wlan_pdev_nif_feat_ext_cap_get(
  2115. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  2116. if (scaling_params) {
  2117. for (param_idx = 0; param_idx < num_bin_scaling_params;
  2118. param_idx++) {
  2119. if (scaling_params[param_idx].pdev_id == pdev_id) {
  2120. pcap->is_scaling_params_populated = true;
  2121. pcap->formula_id =
  2122. scaling_params[param_idx].formula_id;
  2123. pcap->low_level_offset =
  2124. scaling_params[param_idx].low_level_offset;
  2125. pcap->high_level_offset =
  2126. scaling_params[param_idx].high_level_offset;
  2127. pcap->rssi_thr =
  2128. scaling_params[param_idx].rssi_thr;
  2129. pcap->default_agc_max_gain =
  2130. scaling_params[param_idx].default_agc_max_gain;
  2131. break;
  2132. }
  2133. }
  2134. }
  2135. pcap->num_detectors_20mhz = 1;
  2136. pcap->num_detectors_40mhz = 1;
  2137. pcap->num_detectors_80mhz = 1;
  2138. if (target_type == TARGET_TYPE_QCN9000 ||
  2139. target_type == TARGET_TYPE_QCN6122 ||
  2140. target_type == TARGET_TYPE_QCA6490 ||
  2141. target_type == TARGET_TYPE_KIWI) {
  2142. pcap->num_detectors_160mhz = 1;
  2143. pcap->num_detectors_80p80mhz = 1;
  2144. pcap->num_detectors_320mhz = 0;
  2145. } else if (is_spectral_arch_beryllium(target_type)) {
  2146. pcap->num_detectors_160mhz = 1;
  2147. pcap->num_detectors_80p80mhz = 0;
  2148. pcap->num_detectors_320mhz = 1;
  2149. } else {
  2150. pcap->num_detectors_160mhz = 2;
  2151. pcap->num_detectors_80p80mhz = 2;
  2152. pcap->num_detectors_320mhz = 0;
  2153. }
  2154. status = target_if_populate_supported_sscan_bws(spectral, target_type);
  2155. if (QDF_IS_STATUS_ERROR(status)) {
  2156. spectral_err("Unable to populate supported sscan BWs");
  2157. return QDF_STATUS_E_FAILURE;
  2158. }
  2159. return QDF_STATUS_SUCCESS;
  2160. }
  2161. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2162. /**
  2163. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  2164. * internal operations with functions related to spectral simulation
  2165. * @p_sops: spectral low level ops table
  2166. *
  2167. * Initialize spectral target_if internal operations with functions
  2168. * related to spectral simulation
  2169. *
  2170. * Return: None
  2171. */
  2172. static void
  2173. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  2174. {
  2175. /*
  2176. * Spectral simulation is currently intended for platform transitions
  2177. * where underlying HW support may not be available for some time.
  2178. * Hence, we do not currently provide a runtime switch to turn the
  2179. * simulation on or off.
  2180. * In case of future requirements where runtime switches are required,
  2181. * this can be added. But it is suggested to use application layer
  2182. * simulation as far as possible in such cases, since the main
  2183. * use of record and replay of samples would concern higher
  2184. * level sample processing rather than lower level delivery.
  2185. */
  2186. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  2187. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  2188. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  2189. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  2190. p_sops->configure_spectral =
  2191. target_if_spectral_sops_sim_configure_params;
  2192. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  2193. }
  2194. #else
  2195. /**
  2196. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  2197. * internal operations
  2198. * @p_sops: spectral low level ops table
  2199. *
  2200. * Return: None
  2201. */
  2202. static void
  2203. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  2204. {
  2205. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  2206. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  2207. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  2208. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  2209. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  2210. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  2211. }
  2212. #endif
  2213. /**
  2214. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  2215. * operations common to all Spectral chipset generations
  2216. *
  2217. * Initializes target_if_spectral_ops common to all chipset generations
  2218. *
  2219. * Return: None
  2220. */
  2221. static void
  2222. target_if_init_spectral_ops_common(void)
  2223. {
  2224. struct target_if_spectral_ops *p_sops = &spectral_ops;
  2225. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  2226. p_sops->get_capability = target_if_spectral_get_capability;
  2227. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  2228. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  2229. target_if_init_spectral_simulation_ops(p_sops);
  2230. p_sops->get_extension_channel =
  2231. target_if_spectral_get_extension_channel;
  2232. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  2233. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  2234. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  2235. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  2236. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  2237. p_sops->reset_hw = target_if_spectral_reset_hw;
  2238. p_sops->get_chain_noise_floor =
  2239. target_if_spectral_get_chain_noise_floor;
  2240. }
  2241. /**
  2242. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  2243. * operations specific to Spectral chipset generation 2.
  2244. *
  2245. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  2246. *
  2247. * Return: None
  2248. */
  2249. static void
  2250. target_if_init_spectral_ops_gen2(void)
  2251. {
  2252. struct target_if_spectral_ops *p_sops = &spectral_ops;
  2253. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  2254. }
  2255. #ifdef BIG_ENDIAN_HOST
  2256. /**
  2257. * spectral_is_host_byte_swap_required() - Check if byte swap has to be done
  2258. * on the Host
  2259. * @pdev: pdev pointer
  2260. * @is_swap_required: Pointer to caller variable
  2261. *
  2262. * Return: QDF_STATUS of operation
  2263. */
  2264. static QDF_STATUS
  2265. spectral_is_host_byte_swap_required(struct wlan_objmgr_pdev *pdev,
  2266. bool *is_swap_required)
  2267. {
  2268. struct wlan_objmgr_psoc *psoc;
  2269. struct wmi_unified *wmi_handle;
  2270. if (!pdev) {
  2271. spectral_err("pdev is null");
  2272. return QDF_STATUS_E_INVAL;
  2273. }
  2274. psoc = wlan_pdev_get_psoc(pdev);
  2275. if (!psoc) {
  2276. spectral_err("psoc is null");
  2277. return QDF_STATUS_E_INVAL;
  2278. }
  2279. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  2280. if (!wmi_handle) {
  2281. spectral_err("wmi handle is null");
  2282. return QDF_STATUS_E_INVAL;
  2283. }
  2284. /**
  2285. * If a chipset supports byte-swap inside the target itself, then no
  2286. * need to apply byte swap on the Host.
  2287. */
  2288. *is_swap_required = !target_if_spectral_wmi_service_enabled(
  2289. psoc, wmi_handle,
  2290. wmi_service_phy_dma_byte_swap_support);
  2291. return QDF_STATUS_SUCCESS;
  2292. }
  2293. /**
  2294. * target_if_spectral_init_byte_swap_funcs_gen3() - Initialize byte-swap
  2295. * operations for Spectral chipset generation 3.
  2296. * @spectral: Spectral LMAC object
  2297. * @p_sops: Spectral function pointer table
  2298. *
  2299. * Return: None
  2300. */
  2301. static void
  2302. target_if_spectral_init_byte_swap_funcs_gen3(
  2303. struct target_if_spectral *spectral,
  2304. struct target_if_spectral_ops *p_sops)
  2305. {
  2306. bool is_swap_required;
  2307. QDF_STATUS status;
  2308. qdf_assert_always(spectral);
  2309. qdf_assert_always(p_sops);
  2310. status = spectral_is_host_byte_swap_required(spectral->pdev_obj,
  2311. &is_swap_required);
  2312. if (QDF_IS_STATUS_ERROR(status)) {
  2313. spectral_err("Failed to check whether byte swap is required");
  2314. return;
  2315. }
  2316. if (is_swap_required) {
  2317. p_sops->byte_swap_headers =
  2318. target_if_byte_swap_spectral_headers_gen3;
  2319. p_sops->byte_swap_fft_bins =
  2320. target_if_byte_swap_spectral_fft_bins_gen3;
  2321. } else {
  2322. p_sops->byte_swap_headers = NULL;
  2323. p_sops->byte_swap_fft_bins = NULL;
  2324. }
  2325. }
  2326. #else
  2327. static void
  2328. target_if_spectral_init_byte_swap_funcs_gen3(
  2329. struct target_if_spectral *spectral,
  2330. struct target_if_spectral_ops *p_sops)
  2331. {
  2332. qdf_assert_always(p_sops);
  2333. /* Byte-swap is not required for little-endian Hosts */
  2334. p_sops->byte_swap_headers = NULL;
  2335. p_sops->byte_swap_fft_bins = NULL;
  2336. }
  2337. #endif /* BIG_ENDIAN_HOST */
  2338. /**
  2339. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  2340. * operations specific to Spectral chipset generation 3.
  2341. * @spectral: Spectral LMAC object
  2342. *
  2343. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  2344. *
  2345. * Return: None
  2346. */
  2347. static void
  2348. target_if_init_spectral_ops_gen3(struct target_if_spectral *spectral)
  2349. {
  2350. struct target_if_spectral_ops *p_sops = &spectral_ops;
  2351. p_sops->process_spectral_report =
  2352. target_if_spectral_process_report_gen3;
  2353. target_if_spectral_init_byte_swap_funcs_gen3(spectral, p_sops);
  2354. }
  2355. /**
  2356. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  2357. * operations.
  2358. * @spectral: Pointer to Spectral target_if internal private data
  2359. *
  2360. * Initializes all function pointers in target_if_spectral_ops for
  2361. * all generations
  2362. *
  2363. * Return: None
  2364. */
  2365. static void
  2366. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  2367. {
  2368. target_if_init_spectral_ops_common();
  2369. if (spectral->spectral_gen == SPECTRAL_GEN2)
  2370. target_if_init_spectral_ops_gen2();
  2371. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  2372. target_if_init_spectral_ops_gen3(spectral);
  2373. else
  2374. spectral_err("Invalid Spectral generation");
  2375. }
  2376. /*
  2377. * Dummy Functions:
  2378. * These functions are initially registered to avoid any crashes due to
  2379. * invocation of spectral functions before they are registered.
  2380. */
  2381. static uint64_t
  2382. null_get_tsf64(void *arg)
  2383. {
  2384. spectral_ops_not_registered("get_tsf64");
  2385. return 0;
  2386. }
  2387. static uint32_t
  2388. null_get_capability(void *arg, enum spectral_capability_type type)
  2389. {
  2390. /*
  2391. * TODO : We should have conditional compilation to get the capability
  2392. * : We have not yet attahced ATH layer here, so there is no
  2393. * : way to check the HAL capbalities
  2394. */
  2395. spectral_ops_not_registered("get_capability");
  2396. /* TODO : For the time being, we are returning TRUE */
  2397. return true;
  2398. }
  2399. static uint32_t
  2400. null_set_rxfilter(void *arg, int rxfilter)
  2401. {
  2402. spectral_ops_not_registered("set_rxfilter");
  2403. return 1;
  2404. }
  2405. static uint32_t
  2406. null_get_rxfilter(void *arg)
  2407. {
  2408. spectral_ops_not_registered("get_rxfilter");
  2409. return 0;
  2410. }
  2411. static uint32_t
  2412. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  2413. {
  2414. spectral_ops_not_registered("is_spectral_active");
  2415. return 1;
  2416. }
  2417. static uint32_t
  2418. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  2419. {
  2420. spectral_ops_not_registered("is_spectral_enabled");
  2421. return 1;
  2422. }
  2423. static uint32_t
  2424. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  2425. enum spectral_cp_error_code *err)
  2426. {
  2427. spectral_ops_not_registered("start_spectral_scan");
  2428. return 1;
  2429. }
  2430. static uint32_t
  2431. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  2432. {
  2433. spectral_ops_not_registered("stop_spectral_scan");
  2434. return 1;
  2435. }
  2436. static uint32_t
  2437. null_get_extension_channel(void *arg, enum spectral_scan_mode smode)
  2438. {
  2439. spectral_ops_not_registered("get_extension_channel");
  2440. return 1;
  2441. }
  2442. static int8_t
  2443. null_get_ctl_noisefloor(void *arg)
  2444. {
  2445. spectral_ops_not_registered("get_ctl_noisefloor");
  2446. return 1;
  2447. }
  2448. static int8_t
  2449. null_get_ext_noisefloor(void *arg)
  2450. {
  2451. spectral_ops_not_registered("get_ext_noisefloor");
  2452. return 0;
  2453. }
  2454. static uint32_t
  2455. null_configure_spectral(void *arg, struct spectral_config *params,
  2456. enum spectral_scan_mode smode)
  2457. {
  2458. spectral_ops_not_registered("configure_spectral");
  2459. return 0;
  2460. }
  2461. static uint32_t
  2462. null_get_spectral_config(void *arg, struct spectral_config *params,
  2463. enum spectral_scan_mode smode)
  2464. {
  2465. spectral_ops_not_registered("get_spectral_config");
  2466. return 0;
  2467. }
  2468. static uint32_t
  2469. null_get_ent_spectral_mask(void *arg)
  2470. {
  2471. spectral_ops_not_registered("get_ent_spectral_mask");
  2472. return 0;
  2473. }
  2474. static uint32_t
  2475. null_get_mac_address(void *arg, char *addr)
  2476. {
  2477. spectral_ops_not_registered("get_mac_address");
  2478. return 0;
  2479. }
  2480. static uint32_t
  2481. null_get_current_channel(void *arg, enum spectral_scan_mode smode)
  2482. {
  2483. spectral_ops_not_registered("get_current_channel");
  2484. return 0;
  2485. }
  2486. static uint32_t
  2487. null_reset_hw(void *arg)
  2488. {
  2489. spectral_ops_not_registered("get_current_channel");
  2490. return 0;
  2491. }
  2492. static uint32_t
  2493. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  2494. {
  2495. spectral_ops_not_registered("get_chain_noise_floor");
  2496. return 0;
  2497. }
  2498. static int
  2499. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  2500. uint8_t *data,
  2501. uint32_t datalen,
  2502. struct target_if_spectral_rfqual_info *p_rfqual,
  2503. struct target_if_spectral_chan_info *p_chaninfo,
  2504. uint64_t tsf64,
  2505. struct target_if_spectral_acs_stats *acs_stats)
  2506. {
  2507. spectral_ops_not_registered("spectral_process_phyerr");
  2508. return 0;
  2509. }
  2510. static int
  2511. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  2512. void *payload)
  2513. {
  2514. spectral_ops_not_registered("process_spectral_report");
  2515. return 0;
  2516. }
  2517. /**
  2518. * target_if_spectral_init_dummy_function_table() -
  2519. * Initialize target_if internal
  2520. * Spectral operations to dummy functions
  2521. * @ps: Pointer to Spectral target_if internal private data
  2522. *
  2523. * Initialize all the function pointers in target_if_spectral_ops with
  2524. * dummy functions.
  2525. *
  2526. * Return: None
  2527. */
  2528. static void
  2529. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  2530. {
  2531. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  2532. p_sops->get_tsf64 = null_get_tsf64;
  2533. p_sops->get_capability = null_get_capability;
  2534. p_sops->set_rxfilter = null_set_rxfilter;
  2535. p_sops->get_rxfilter = null_get_rxfilter;
  2536. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  2537. p_sops->is_spectral_active = null_is_spectral_active;
  2538. p_sops->start_spectral_scan = null_start_spectral_scan;
  2539. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  2540. p_sops->get_extension_channel = null_get_extension_channel;
  2541. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  2542. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  2543. p_sops->configure_spectral = null_configure_spectral;
  2544. p_sops->get_spectral_config = null_get_spectral_config;
  2545. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  2546. p_sops->get_mac_address = null_get_mac_address;
  2547. p_sops->get_current_channel = null_get_current_channel;
  2548. p_sops->reset_hw = null_reset_hw;
  2549. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  2550. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  2551. p_sops->process_spectral_report = null_process_spectral_report;
  2552. }
  2553. /**
  2554. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  2555. * operations
  2556. * @spectral: Pointer to Spectral target_if internal private data
  2557. * @p: Pointer to Spectral function table
  2558. *
  2559. * Return: None
  2560. */
  2561. static void
  2562. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  2563. struct target_if_spectral_ops *p)
  2564. {
  2565. struct target_if_spectral_ops *p_sops =
  2566. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2567. *p_sops = *p;
  2568. }
  2569. /**
  2570. * target_if_spectral_clear_stats() - Clear Spectral stats
  2571. * @spectral: Pointer to Spectral target_if internal private data
  2572. *
  2573. * Function to clear spectral stats
  2574. *
  2575. * Return: None
  2576. */
  2577. static void
  2578. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  2579. {
  2580. struct target_if_spectral_ops *p_sops =
  2581. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2582. qdf_mem_zero(&spectral->spectral_stats,
  2583. sizeof(struct target_if_spectral_stats));
  2584. spectral->spectral_stats.last_reset_tstamp =
  2585. p_sops->get_tsf64(spectral);
  2586. }
  2587. /**
  2588. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  2589. * @spectral: Pointer to Spectral target_if internal private data
  2590. *
  2591. * Function to check whether hardware supports spectral
  2592. *
  2593. * Return: True if HW supports Spectral, false if HW does not support Spectral
  2594. */
  2595. static int
  2596. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  2597. {
  2598. struct target_if_spectral_ops *p_sops = NULL;
  2599. struct spectral_caps *pcap = NULL;
  2600. int is_spectral_supported = true;
  2601. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2602. pcap = &spectral->capability;
  2603. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  2604. is_spectral_supported = false;
  2605. spectral_info("SPECTRAL : No PHYDIAG support");
  2606. return is_spectral_supported;
  2607. }
  2608. pcap->phydiag_cap = 1;
  2609. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  2610. is_spectral_supported = false;
  2611. spectral_info("SPECTRAL : No RADAR support");
  2612. return is_spectral_supported;
  2613. }
  2614. pcap->radar_cap = 1;
  2615. if (p_sops->get_capability(spectral,
  2616. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  2617. is_spectral_supported = false;
  2618. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  2619. return is_spectral_supported;
  2620. }
  2621. pcap->spectral_cap = 1;
  2622. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  2623. == false) {
  2624. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  2625. } else {
  2626. pcap->advncd_spectral_cap = 1;
  2627. }
  2628. return is_spectral_supported;
  2629. }
  2630. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2631. /**
  2632. * target_if_spectral_detach_simulation() - De-initialize Spectral
  2633. * Simulation functionality
  2634. * @spectral: Pointer to Spectral target_if internal private data
  2635. *
  2636. * Function to de-initialize Spectral Simulation functionality
  2637. *
  2638. * Return: None
  2639. */
  2640. static void
  2641. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  2642. {
  2643. target_if_spectral_sim_detach(spectral);
  2644. }
  2645. #else
  2646. static void
  2647. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  2648. {
  2649. }
  2650. #endif
  2651. /**
  2652. * target_if_spectral_detach() - De-initialize target_if Spectral
  2653. * @pdev: Pointer to pdev object
  2654. *
  2655. * Function to detach target_if spectral
  2656. *
  2657. * Return: None
  2658. */
  2659. static void
  2660. target_if_spectral_detach(struct target_if_spectral *spectral)
  2661. {
  2662. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  2663. spectral_info("spectral detach");
  2664. if (spectral) {
  2665. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2666. qdf_spinlock_destroy
  2667. (&spectral->param_info[smode].osps_lock);
  2668. target_if_spectral_detach_simulation(spectral);
  2669. qdf_spinlock_destroy(&spectral->spectral_lock);
  2670. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  2671. qdf_spinlock_destroy(&spectral->detector_list_lock);
  2672. qdf_spinlock_destroy(&spectral->session_report_info_lock);
  2673. qdf_spinlock_destroy(&spectral->session_det_map_lock);
  2674. qdf_mem_free(spectral);
  2675. spectral = NULL;
  2676. }
  2677. }
  2678. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2679. /**
  2680. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  2681. * functionality
  2682. * @spectral: Pointer to Spectral target_if internal private data
  2683. *
  2684. * Function to initialize spectral simulation functionality
  2685. *
  2686. * Return: 0 on success, negative error code on failure
  2687. */
  2688. static int
  2689. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  2690. {
  2691. if (target_if_spectral_sim_attach(spectral)) {
  2692. qdf_mem_free(spectral);
  2693. return -EPERM;
  2694. }
  2695. return 0;
  2696. }
  2697. #else
  2698. static int
  2699. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  2700. {
  2701. return 0;
  2702. }
  2703. #endif
  2704. /**
  2705. * target_if_spectral_len_adj_swar_init() - Initialize FFT bin length adjustment
  2706. * related info
  2707. * @swar: Pointer to Spectral FFT bin length adjustment SWAR params
  2708. * @rparams: Pointer to Spectral report parameter object
  2709. * @target_type: Target type
  2710. *
  2711. * Function to Initialize parameters related to Spectral FFT bin
  2712. * length adjustment SWARs.
  2713. *
  2714. * Return: void
  2715. */
  2716. static void
  2717. target_if_spectral_len_adj_swar_init(struct spectral_fft_bin_len_adj_swar *swar,
  2718. struct spectral_report_params *rparams,
  2719. uint32_t target_type)
  2720. {
  2721. if (target_type == TARGET_TYPE_QCA8074V2 ||
  2722. target_type == TARGET_TYPE_QCA9574 ||
  2723. target_type == TARGET_TYPE_QCN9000 ||
  2724. target_type == TARGET_TYPE_QCN6122 ||
  2725. target_type == TARGET_TYPE_QCA5018 ||
  2726. target_type == TARGET_TYPE_QCA6750 ||
  2727. target_type == TARGET_TYPE_QCA6490 ||
  2728. target_type == TARGET_TYPE_KIWI) {
  2729. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  2730. rparams->hw_fft_bin_width = 2;
  2731. } else if (target_type == TARGET_TYPE_QCA8074 ||
  2732. target_type == TARGET_TYPE_QCA6018 ||
  2733. target_type == TARGET_TYPE_QCA6390) {
  2734. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  2735. rparams->hw_fft_bin_width = 4;
  2736. } else {
  2737. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  2738. rparams->hw_fft_bin_width = 1;
  2739. }
  2740. if (target_type == TARGET_TYPE_QCA8074 ||
  2741. target_type == TARGET_TYPE_QCA8074V2 ||
  2742. target_type == TARGET_TYPE_QCA9574 ||
  2743. target_type == TARGET_TYPE_QCA6018 ||
  2744. target_type == TARGET_TYPE_QCN6122 ||
  2745. target_type == TARGET_TYPE_QCA5018 ||
  2746. target_type == TARGET_TYPE_QCN9000 ||
  2747. target_type == TARGET_TYPE_QCA6490 ||
  2748. target_type == TARGET_TYPE_KIWI) {
  2749. swar->inband_fftbin_size_adj = 1;
  2750. swar->null_fftbin_adj = 1;
  2751. } else {
  2752. swar->inband_fftbin_size_adj = 0;
  2753. swar->null_fftbin_adj = 0;
  2754. }
  2755. if (target_type == TARGET_TYPE_QCA8074V2 ||
  2756. target_type == TARGET_TYPE_QCA9574)
  2757. swar->packmode_fftbin_size_adj = 1;
  2758. else
  2759. swar->packmode_fftbin_size_adj = 0;
  2760. }
  2761. /**
  2762. * target_if_spectral_report_params_init() - Initialize parameters which
  2763. * describes the structure of Spectral reports
  2764. *
  2765. * @rparams: Pointer to Spectral report parameter object
  2766. * @target_type: target type
  2767. *
  2768. * Function to Initialize parameters related to the structure of Spectral
  2769. * reports.
  2770. *
  2771. * Return: void
  2772. */
  2773. static void
  2774. target_if_spectral_report_params_init(
  2775. struct spectral_report_params *rparams,
  2776. uint32_t target_type)
  2777. {
  2778. enum spectral_scan_mode smode;
  2779. /* This entries are currently used by gen3 chipsets only. Hence
  2780. * initialization is done for gen3 alone. In future if other generations
  2781. * needs to use them they have to add proper initial values.
  2782. */
  2783. if (target_type == TARGET_TYPE_QCN9000 ||
  2784. target_type == TARGET_TYPE_QCN6122 ||
  2785. target_type == TARGET_TYPE_QCA5018 ||
  2786. target_type == TARGET_TYPE_QCA6750 ||
  2787. target_type == TARGET_TYPE_QCA6490 ||
  2788. target_type == TARGET_TYPE_KIWI) {
  2789. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_2;
  2790. rparams->num_spectral_detectors =
  2791. NUM_SPECTRAL_DETECTORS_GEN3_V2;
  2792. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2793. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2794. rparams->fragmentation_160[smode] = false;
  2795. } else {
  2796. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_1;
  2797. rparams->num_spectral_detectors =
  2798. NUM_SPECTRAL_DETECTORS_GEN3_V1;
  2799. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2800. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2801. rparams->fragmentation_160[smode] = true;
  2802. }
  2803. switch (rparams->version) {
  2804. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  2805. rparams->ssumaary_padding_bytes =
  2806. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1;
  2807. rparams->fft_report_hdr_len =
  2808. FFT_REPORT_HEADER_LENGTH_GEN3_V1;
  2809. break;
  2810. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  2811. rparams->ssumaary_padding_bytes =
  2812. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2;
  2813. rparams->fft_report_hdr_len =
  2814. FFT_REPORT_HEADER_LENGTH_GEN3_V2;
  2815. break;
  2816. default:
  2817. qdf_assert_always(0);
  2818. }
  2819. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_0] =
  2820. SPECTRAL_SCAN_MODE_NORMAL;
  2821. if (target_type == TARGET_TYPE_QCN9000 ||
  2822. target_type == TARGET_TYPE_QCN6122 ||
  2823. target_type == TARGET_TYPE_QCA6490 ||
  2824. target_type == TARGET_TYPE_KIWI) {
  2825. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2826. SPECTRAL_SCAN_MODE_AGILE;
  2827. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2828. SPECTRAL_SCAN_MODE_INVALID;
  2829. } else {
  2830. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2831. SPECTRAL_SCAN_MODE_NORMAL;
  2832. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2833. SPECTRAL_SCAN_MODE_AGILE;
  2834. }
  2835. }
  2836. /**
  2837. * target_if_spectral_timestamp_war_init() - Initialize Spectral timestamp WAR
  2838. * related info
  2839. * @twar: Pointer to Spectral timstamp WAR related info
  2840. *
  2841. * Function to Initialize parameters related to Spectral timestamp WAR
  2842. *
  2843. * Return: void
  2844. */
  2845. static void
  2846. target_if_spectral_timestamp_war_init(struct spectral_timestamp_war *twar)
  2847. {
  2848. enum spectral_scan_mode smode;
  2849. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2850. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2851. twar->last_fft_timestamp[smode] = 0;
  2852. twar->timestamp_war_offset[smode] = 0;
  2853. }
  2854. twar->target_reset_count = 0;
  2855. }
  2856. #ifdef OPTIMIZED_SAMP_MESSAGE
  2857. /**
  2858. * target_if_spectral_is_hw_mode_sbs() - Check if the given pdev is in SBS mode
  2859. * @pdev: pdev pointer
  2860. * @is_hw_mode_sbs: Pointer to the variable where this function should write
  2861. * whether the given pdev is in SBS mode
  2862. *
  2863. * Return: QDF_STATUS of operation
  2864. */
  2865. static QDF_STATUS
  2866. target_if_spectral_is_hw_mode_sbs(struct wlan_objmgr_pdev *pdev,
  2867. bool *is_hw_mode_sbs)
  2868. {
  2869. struct wlan_objmgr_psoc *psoc;
  2870. struct target_psoc_info *tgt_hdl;
  2871. enum wmi_host_hw_mode_config_type mode;
  2872. qdf_assert_always(is_hw_mode_sbs);
  2873. psoc = wlan_pdev_get_psoc(pdev);
  2874. if (!psoc) {
  2875. spectral_err("psoc is null");
  2876. return QDF_STATUS_E_NULL_VALUE;
  2877. }
  2878. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  2879. if (!tgt_hdl) {
  2880. spectral_err("target_psoc_info is null");
  2881. return QDF_STATUS_E_NULL_VALUE;
  2882. }
  2883. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  2884. switch (mode) {
  2885. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  2886. case WMI_HOST_HW_MODE_SBS:
  2887. case WMI_HOST_HW_MODE_DBS_SBS:
  2888. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  2889. *is_hw_mode_sbs = true;
  2890. break;
  2891. default:
  2892. *is_hw_mode_sbs = false;
  2893. break;
  2894. }
  2895. return QDF_STATUS_SUCCESS;
  2896. }
  2897. /**
  2898. * target_if_get_pdev_mac_phy_caps() - Get the MAC_PHY capabilities of a pdev
  2899. * @pdev: pdev pointer
  2900. *
  2901. * Return: On success, pointer to MAC_PHY capabilities of @pdev.
  2902. * On failure, NULL
  2903. */
  2904. static struct wlan_psoc_host_mac_phy_caps *
  2905. target_if_get_pdev_mac_phy_caps(struct wlan_objmgr_pdev *pdev)
  2906. {
  2907. struct wlan_objmgr_psoc *psoc;
  2908. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr;
  2909. struct target_psoc_info *tgt_psoc_info;
  2910. uint8_t pdev_id;
  2911. if (!pdev) {
  2912. spectral_err("pdev is NULL");
  2913. return NULL;
  2914. }
  2915. psoc = wlan_pdev_get_psoc(pdev);
  2916. if (!psoc) {
  2917. spectral_err("psoc is null");
  2918. return NULL;
  2919. }
  2920. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  2921. if (!tgt_psoc_info) {
  2922. spectral_err("target_psoc_info is null");
  2923. return NULL;
  2924. }
  2925. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  2926. if (!mac_phy_cap_arr) {
  2927. spectral_err("mac phy cap array is null");
  2928. return NULL;
  2929. }
  2930. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  2931. return &mac_phy_cap_arr[pdev_id];
  2932. }
  2933. /**
  2934. * struct target_if_sscan_pdev_phy_info - PHY information of the pdev on
  2935. * which sscan is done. A pointer to an instance of this structure is passed
  2936. * as an argument to the iterator function target_if_find_sscan_pdev_phya1()
  2937. * @phy_id: PHY ID of this pdev
  2938. * @is_using_phya1: Pointer to the variable where the iterator function should
  2939. * populate whether the given pdev is using PHYA1
  2940. */
  2941. struct target_if_sscan_pdev_phy_info {
  2942. uint8_t phy_id;
  2943. bool *is_using_phya1;
  2944. };
  2945. /**
  2946. * target_if_find_sscan_pdev_phya1() - This is an iterator function to
  2947. * wlan_objmgr_iterate_obj_list(). It checks whether a given sscan_pdev (pdev on
  2948. * which sscan is currenly issued) is using PHYA1 by comparing against the pdev
  2949. * argument given by the wlan_objmgr_iterate_obj_list()
  2950. * @psoc: Pointer to psoc
  2951. * @object: Pointer to pdev
  2952. * @arg: Pointer to target_if_sscan_pdev_phy_info of the sscan_pdev for which
  2953. * we want to check if it uses PHYA1
  2954. *
  2955. * Return: None
  2956. */
  2957. static void
  2958. target_if_find_sscan_pdev_phya1(struct wlan_objmgr_psoc *psoc,
  2959. void *object, void *arg)
  2960. {
  2961. struct target_if_sscan_pdev_phy_info *sscan_pdev_phy_info = arg;
  2962. struct wlan_objmgr_pdev *cur_pdev = object;
  2963. struct wlan_psoc_host_mac_phy_caps *cur_mac_phy_caps;
  2964. cur_mac_phy_caps = target_if_get_pdev_mac_phy_caps(cur_pdev);
  2965. if (!cur_mac_phy_caps) {
  2966. spectral_err("Failed to get MAC PHY Capabilities of"
  2967. "pdev %pK", cur_pdev);
  2968. return;
  2969. }
  2970. spectral_debug("supported_bands: %0x phy_id: %d",
  2971. cur_mac_phy_caps->supported_bands,
  2972. cur_mac_phy_caps->phy_id);
  2973. /* No need to do anything if the current pdev is not a 5GHz pdev */
  2974. if (!(cur_mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAPABILITY))
  2975. return;
  2976. /* No need to do anything if the current pdev is same as sscan_pdev */
  2977. if (sscan_pdev_phy_info->phy_id == cur_mac_phy_caps->phy_id)
  2978. return;
  2979. /**
  2980. * Compare the phy_id of both the SBS pdevs to figure out if
  2981. * the sscan_pdev using PHYA1
  2982. */
  2983. if (sscan_pdev_phy_info->phy_id > cur_mac_phy_caps->phy_id)
  2984. *sscan_pdev_phy_info->is_using_phya1 = true;
  2985. else
  2986. *sscan_pdev_phy_info->is_using_phya1 = false;
  2987. }
  2988. /**
  2989. * target_if_spectral_detector_list_init() - Initialize Spectral detector list
  2990. * based on target type
  2991. * @spectral: Pointer to Spectral target_if
  2992. *
  2993. * Function to initialize Spectral detector list for possible combinations of
  2994. * Spectral scan mode and channel width, based on target type.
  2995. *
  2996. * Return: Success/Failure
  2997. */
  2998. static QDF_STATUS
  2999. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  3000. {
  3001. struct sscan_detector_list *det_list;
  3002. enum spectral_scan_mode smode;
  3003. enum phy_ch_width ch_width;
  3004. QDF_STATUS ret;
  3005. bool is_hw_mode_sbs = false, is_using_phya1 = false;
  3006. if (!spectral) {
  3007. spectral_err_rl("Spectral LMAC object is null");
  3008. return QDF_STATUS_E_NULL_VALUE;
  3009. }
  3010. /**
  3011. * Special handling is required for SBS mode where the detector
  3012. * list should be following for the 5GHz pdevs.
  3013. * For the pdev that use PHYA0:
  3014. * detector 0 for normal mode
  3015. * detector 2 for agile mode
  3016. * For the pdev that use PHYA1:
  3017. * detector 1 for normal mode
  3018. * detector 2 for agile mode
  3019. *
  3020. * There is no direct way of knowing which pdevs are using PHYA0 or
  3021. * PHYA1. We need to look at the phy_id of a given pdev and compare
  3022. * against other pdevs on the same psoc to figure out whether the given
  3023. * pdev is operating using PHYA1.
  3024. */
  3025. /* First check whether this pdev is in SBS mode */
  3026. ret = target_if_spectral_is_hw_mode_sbs(spectral->pdev_obj,
  3027. &is_hw_mode_sbs);
  3028. if (QDF_IS_STATUS_ERROR(ret)) {
  3029. spectral_err("Failed to check whether hw mode is SBS");
  3030. return ret;
  3031. }
  3032. if (is_hw_mode_sbs) {
  3033. struct wlan_psoc_host_mac_phy_caps *mac_phy_caps;
  3034. mac_phy_caps =
  3035. target_if_get_pdev_mac_phy_caps(spectral->pdev_obj);
  3036. if (!mac_phy_caps) {
  3037. spectral_err("Failed to get MAC PHY Capabilities of"
  3038. "pdev %pK", spectral->pdev_obj);
  3039. return QDF_STATUS_E_FAILURE;
  3040. }
  3041. spectral_debug("bands: %0x phy_id: %d",
  3042. mac_phy_caps->supported_bands,
  3043. mac_phy_caps->phy_id);
  3044. /* We only care about 5GHz pdevs */
  3045. if (mac_phy_caps->supported_bands &
  3046. WMI_HOST_WLAN_5G_CAPABILITY) {
  3047. struct target_if_sscan_pdev_phy_info pdev_phy_info;
  3048. pdev_phy_info.phy_id = mac_phy_caps->phy_id;
  3049. pdev_phy_info.is_using_phya1 = &is_using_phya1;
  3050. /* Iterate over all pdevs on this psoc */
  3051. wlan_objmgr_iterate_obj_list
  3052. (wlan_pdev_get_psoc(spectral->pdev_obj),
  3053. WLAN_PDEV_OP,
  3054. target_if_find_sscan_pdev_phya1,
  3055. &pdev_phy_info, 0,
  3056. WLAN_SPECTRAL_ID);
  3057. }
  3058. }
  3059. /**
  3060. * We assume there are 2 detectors. The Detector ID coming first will
  3061. * always be pri80 detector, and second detector for sec80.
  3062. */
  3063. ch_width = CH_WIDTH_20MHZ;
  3064. for (; ch_width < CH_WIDTH_MAX; ch_width++) {
  3065. /* Normal spectral scan */
  3066. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3067. spectral_debug("is_hw_mode_sbs: %d is_using_phya1:%d",
  3068. is_hw_mode_sbs, is_using_phya1);
  3069. qdf_spin_lock_bh(&spectral->detector_list_lock);
  3070. if (!spectral->supported_sscan_bw_list[smode][ch_width])
  3071. goto agile_handling;
  3072. det_list = &spectral->detector_list[smode][ch_width];
  3073. det_list->num_detectors = 1;
  3074. if (is_hw_mode_sbs && is_using_phya1)
  3075. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_1;
  3076. else
  3077. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_0;
  3078. if (is_ch_width_160_or_80p80(ch_width) &&
  3079. spectral->rparams.fragmentation_160[smode]) {
  3080. det_list->num_detectors += 1;
  3081. det_list->detectors[1] = SPECTRAL_DETECTOR_ID_1;
  3082. }
  3083. agile_handling:
  3084. /* Agile spectral scan */
  3085. smode = SPECTRAL_SCAN_MODE_AGILE;
  3086. if (!spectral->supported_sscan_bw_list[smode][ch_width]) {
  3087. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  3088. continue;
  3089. }
  3090. det_list = &spectral->detector_list[smode][ch_width];
  3091. det_list->num_detectors = 1;
  3092. if (spectral->rparams.fragmentation_160[smode])
  3093. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_2;
  3094. else
  3095. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_1;
  3096. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  3097. }
  3098. return QDF_STATUS_SUCCESS;
  3099. }
  3100. #else
  3101. static QDF_STATUS
  3102. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  3103. {
  3104. return QDF_STATUS_SUCCESS;
  3105. }
  3106. #endif /* OPTIMIZED_SAMP_MESSAGE */
  3107. /**
  3108. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  3109. * functionality for the given pdev
  3110. * @pdev: Pointer to pdev object
  3111. *
  3112. * Function to initialize pointer to spectral target_if internal private data
  3113. *
  3114. * Return: On success, pointer to Spectral target_if internal private data, on
  3115. * failure, NULL
  3116. */
  3117. void *
  3118. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  3119. {
  3120. struct target_if_spectral_ops *p_sops = NULL;
  3121. struct target_if_spectral *spectral = NULL;
  3122. uint32_t target_type;
  3123. uint32_t target_revision;
  3124. struct wlan_objmgr_psoc *psoc;
  3125. struct wlan_lmac_if_target_tx_ops *tgt_tx_ops;
  3126. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  3127. QDF_STATUS status;
  3128. struct wlan_lmac_if_tx_ops *tx_ops;
  3129. if (!pdev) {
  3130. spectral_err("SPECTRAL: pdev is NULL!");
  3131. return NULL;
  3132. }
  3133. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  3134. sizeof(struct target_if_spectral));
  3135. if (!spectral)
  3136. return spectral;
  3137. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  3138. /* Store pdev in Spectral */
  3139. spectral->pdev_obj = pdev;
  3140. spectral->vdev_id[SPECTRAL_SCAN_MODE_NORMAL] = WLAN_INVALID_VDEV_ID;
  3141. spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE] = WLAN_INVALID_VDEV_ID;
  3142. psoc = wlan_pdev_get_psoc(pdev);
  3143. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  3144. if (!tx_ops) {
  3145. spectral_err("tx_ops is NULL");
  3146. qdf_mem_free(spectral);
  3147. return NULL;
  3148. }
  3149. tgt_tx_ops = &tx_ops->target_tx_ops;
  3150. if (tgt_tx_ops->tgt_get_tgt_type) {
  3151. target_type = tgt_tx_ops->tgt_get_tgt_type(psoc);
  3152. } else {
  3153. qdf_mem_free(spectral);
  3154. return NULL;
  3155. }
  3156. if (tgt_tx_ops->tgt_get_tgt_revision) {
  3157. target_revision = tgt_tx_ops->tgt_get_tgt_revision(psoc);
  3158. } else {
  3159. qdf_mem_free(spectral);
  3160. return NULL;
  3161. }
  3162. /* init the function ptr table */
  3163. target_if_spectral_init_dummy_function_table(spectral);
  3164. /* get spectral function table */
  3165. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3166. /* TODO : Should this be called here of after ath_attach ? */
  3167. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  3168. spectral_info("HAL_CAP_PHYDIAG : Capable");
  3169. /* TODO: Need to fix the capablity check for RADAR */
  3170. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  3171. spectral_info("HAL_CAP_RADAR : Capable");
  3172. /* TODO : Need to fix the capablity check for SPECTRAL */
  3173. /* TODO : Should this be called here of after ath_attach ? */
  3174. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  3175. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  3176. qdf_spinlock_create(&spectral->spectral_lock);
  3177. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  3178. target_if_spectral_clear_stats(spectral);
  3179. if (target_type == TARGET_TYPE_QCA8074 ||
  3180. target_type == TARGET_TYPE_QCA8074V2 ||
  3181. target_type == TARGET_TYPE_QCA9574 ||
  3182. target_type == TARGET_TYPE_QCA6018 ||
  3183. target_type == TARGET_TYPE_QCA5018 ||
  3184. target_type == TARGET_TYPE_QCA6390 ||
  3185. target_type == TARGET_TYPE_QCN6122 ||
  3186. target_type == TARGET_TYPE_QCA6490 ||
  3187. target_type == TARGET_TYPE_QCN9000 ||
  3188. target_type == TARGET_TYPE_QCA6750 ||
  3189. target_type == TARGET_TYPE_KIWI)
  3190. spectral->direct_dma_support = true;
  3191. target_if_spectral_report_params_init(&spectral->rparams,
  3192. target_type);
  3193. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  3194. &spectral->rparams,
  3195. target_type);
  3196. if ((target_type == TARGET_TYPE_QCA8074) ||
  3197. (target_type == TARGET_TYPE_QCA8074V2) ||
  3198. (target_type == TARGET_TYPE_QCA9574) ||
  3199. (target_type == TARGET_TYPE_QCA6018) ||
  3200. (target_type == TARGET_TYPE_QCA5018) ||
  3201. (target_type == TARGET_TYPE_QCN6122) ||
  3202. (target_type == TARGET_TYPE_QCN9000) ||
  3203. (target_type == TARGET_TYPE_QCA6290) ||
  3204. (target_type == TARGET_TYPE_QCA6390) ||
  3205. (target_type == TARGET_TYPE_QCA6490) ||
  3206. (target_type == TARGET_TYPE_QCA6750) ||
  3207. (target_type == TARGET_TYPE_KIWI)) {
  3208. spectral->spectral_gen = SPECTRAL_GEN3;
  3209. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  3210. spectral->tag_sscan_summary_exp =
  3211. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  3212. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  3213. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  3214. } else {
  3215. spectral->spectral_gen = SPECTRAL_GEN2;
  3216. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  3217. spectral->tag_sscan_summary_exp =
  3218. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  3219. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  3220. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  3221. }
  3222. status = target_if_init_spectral_param_min_max(
  3223. spectral,
  3224. spectral->spectral_gen, target_type);
  3225. if (QDF_IS_STATUS_ERROR(status)) {
  3226. spectral_err("Failed to initialize parameter min max values");
  3227. goto fail;
  3228. }
  3229. target_if_init_spectral_param_properties(spectral);
  3230. /* Init spectral capability */
  3231. if (target_if_init_spectral_capability(spectral, target_type) !=
  3232. QDF_STATUS_SUCCESS) {
  3233. qdf_mem_free(spectral);
  3234. return NULL;
  3235. }
  3236. if (target_if_spectral_attach_simulation(spectral) < 0)
  3237. return NULL;
  3238. target_if_init_spectral_ops(spectral);
  3239. target_if_spectral_timestamp_war_init(&spectral->timestamp_war);
  3240. /* Spectral mode specific init */
  3241. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  3242. spectral->params_valid[smode] = false;
  3243. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  3244. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  3245. }
  3246. target_if_spectral_register_funcs(spectral, &spectral_ops);
  3247. if (target_if_spectral_check_hw_capability(spectral) == false) {
  3248. goto fail;
  3249. } else {
  3250. /*
  3251. * TODO: Once the driver architecture transitions to chipset
  3252. * versioning based checks, reflect this here.
  3253. */
  3254. spectral->is_160_format = false;
  3255. spectral->is_lb_edge_extrabins_format = false;
  3256. spectral->is_rb_edge_extrabins_format = false;
  3257. if (target_type == TARGET_TYPE_QCA9984 ||
  3258. target_type == TARGET_TYPE_QCA9888) {
  3259. spectral->is_160_format = true;
  3260. spectral->is_lb_edge_extrabins_format = true;
  3261. spectral->is_rb_edge_extrabins_format = true;
  3262. } else if ((target_type == TARGET_TYPE_AR900B) &&
  3263. (target_revision == AR900B_REV_2)) {
  3264. spectral->is_rb_edge_extrabins_format = true;
  3265. }
  3266. if (target_type == TARGET_TYPE_QCA9984 ||
  3267. target_type == TARGET_TYPE_QCA9888)
  3268. spectral->is_sec80_rssi_war_required = true;
  3269. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  3270. if (spectral->spectral_gen == SPECTRAL_GEN3)
  3271. init_160mhz_delivery_state_machine(spectral);
  3272. }
  3273. qdf_spinlock_create(&spectral->detector_list_lock);
  3274. qdf_spinlock_create(&spectral->session_report_info_lock);
  3275. qdf_spinlock_create(&spectral->session_det_map_lock);
  3276. return spectral;
  3277. fail:
  3278. target_if_spectral_detach(spectral);
  3279. return NULL;
  3280. }
  3281. /**
  3282. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  3283. * functionality for the given pdev
  3284. * @pdev: Pointer to pdev object
  3285. *
  3286. * Function to de-initialize pointer to spectral target_if internal private data
  3287. *
  3288. * Return: None
  3289. */
  3290. void
  3291. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  3292. {
  3293. struct target_if_spectral *spectral = NULL;
  3294. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3295. if (!spectral) {
  3296. spectral_err("SPECTRAL : Module doesn't exist");
  3297. return;
  3298. }
  3299. target_if_spectral_detach(spectral);
  3300. return;
  3301. }
  3302. /**
  3303. * target_if_psoc_spectral_deinit() - De-initialize target_if Spectral
  3304. * functionality for the given psoc
  3305. * @psoc: Pointer to psoc object
  3306. *
  3307. * Function to de-initialize pointer to psoc spectral target_if internal
  3308. * private data
  3309. *
  3310. * Return: None
  3311. */
  3312. static void
  3313. target_if_psoc_spectral_deinit(struct wlan_objmgr_psoc *psoc)
  3314. {
  3315. struct target_if_psoc_spectral *psoc_spectral;
  3316. if (!psoc) {
  3317. spectral_err("psoc is null");
  3318. return;
  3319. }
  3320. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  3321. if (!psoc_spectral) {
  3322. spectral_err("Spectral target_if psoc object is null");
  3323. return;
  3324. }
  3325. qdf_mem_free(psoc_spectral);
  3326. }
  3327. /**
  3328. * target_if_psoc_spectral_init() - Initialize target_if Spectral
  3329. * functionality for the given psoc
  3330. * @psoc: Pointer to psoc object
  3331. *
  3332. * Function to initialize pointer to psoc spectral target_if internal
  3333. * private data
  3334. *
  3335. * Return: On success, pointer to Spectral psoc target_if internal
  3336. * private data, on failure, NULL
  3337. */
  3338. static void *
  3339. target_if_psoc_spectral_init(struct wlan_objmgr_psoc *psoc)
  3340. {
  3341. struct target_if_psoc_spectral *psoc_spectral = NULL;
  3342. if (!psoc) {
  3343. spectral_err("psoc is null");
  3344. goto fail;
  3345. }
  3346. psoc_spectral = (struct target_if_psoc_spectral *)qdf_mem_malloc(
  3347. sizeof(struct target_if_psoc_spectral));
  3348. if (!psoc_spectral) {
  3349. spectral_err("Spectral lmac psoc object allocation failed");
  3350. goto fail;
  3351. }
  3352. psoc_spectral->psoc_obj = psoc;
  3353. return psoc_spectral;
  3354. fail:
  3355. if (psoc_spectral)
  3356. target_if_psoc_spectral_deinit(psoc);
  3357. return psoc_spectral;
  3358. }
  3359. /**
  3360. * target_if_calculate_center_freq() - Helper routine to
  3361. * check whether given frequency is center frequency of a
  3362. * WLAN channel
  3363. *
  3364. * @spectral: Pointer to Spectral object
  3365. * @chan_freq: Center frequency of a WLAN channel
  3366. * @is_valid: Indicates whether given frequency is valid
  3367. *
  3368. * Return: QDF_STATUS
  3369. */
  3370. static QDF_STATUS
  3371. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  3372. uint32_t chan_freq,
  3373. bool *is_valid)
  3374. {
  3375. struct regulatory_channel *cur_chan_list;
  3376. int i;
  3377. if (!pdev) {
  3378. spectral_err("pdev object is null");
  3379. return QDF_STATUS_E_FAILURE;
  3380. }
  3381. if (!is_valid) {
  3382. spectral_err("is valid argument is null");
  3383. return QDF_STATUS_E_FAILURE;
  3384. }
  3385. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  3386. if (!cur_chan_list)
  3387. return QDF_STATUS_E_FAILURE;
  3388. if (wlan_reg_get_current_chan_list(
  3389. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  3390. spectral_err("Failed to get cur_chan list");
  3391. qdf_mem_free(cur_chan_list);
  3392. return QDF_STATUS_E_FAILURE;
  3393. }
  3394. *is_valid = false;
  3395. for (i = 0; i < NUM_CHANNELS; i++) {
  3396. uint32_t flags;
  3397. uint32_t center_freq;
  3398. flags = cur_chan_list[i].chan_flags;
  3399. center_freq = cur_chan_list[i].center_freq;
  3400. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  3401. (center_freq == chan_freq)) {
  3402. *is_valid = true;
  3403. break;
  3404. }
  3405. }
  3406. qdf_mem_free(cur_chan_list);
  3407. return QDF_STATUS_SUCCESS;
  3408. }
  3409. /**
  3410. * target_if_calculate_center_freq() - Helper routine to
  3411. * find the center frequency of the agile span from a
  3412. * WLAN channel center frequency
  3413. *
  3414. * @spectral: Pointer to Spectral object
  3415. * @ch_width: Channel width array
  3416. * @chan_freq: Center frequency of a WLAN channel
  3417. * @center_freq: Pointer to center frequency
  3418. *
  3419. * Return: QDF_STATUS
  3420. */
  3421. static QDF_STATUS
  3422. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  3423. enum phy_ch_width *ch_width,
  3424. uint16_t chan_freq,
  3425. uint16_t *center_freq)
  3426. {
  3427. enum phy_ch_width agile_ch_width;
  3428. if (!spectral) {
  3429. spectral_err("spectral target if object is null");
  3430. return QDF_STATUS_E_FAILURE;
  3431. }
  3432. if (!ch_width) {
  3433. spectral_err("Channel width array is null");
  3434. return QDF_STATUS_E_INVAL;
  3435. }
  3436. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3437. if (!center_freq) {
  3438. spectral_err("center_freq argument is null");
  3439. return QDF_STATUS_E_FAILURE;
  3440. }
  3441. if (agile_ch_width == CH_WIDTH_20MHZ) {
  3442. *center_freq = chan_freq;
  3443. } else {
  3444. uint16_t start_freq;
  3445. uint16_t end_freq;
  3446. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3447. enum channel_state state;
  3448. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  3449. (spectral->pdev_obj, chan_freq, agile_ch_width,
  3450. &bonded_chan_ptr, REG_CURRENT_PWR_MODE);
  3451. if (state == CHANNEL_STATE_DISABLE ||
  3452. state == CHANNEL_STATE_INVALID) {
  3453. spectral_err("Channel state is disable or invalid");
  3454. return QDF_STATUS_E_FAILURE;
  3455. }
  3456. if (!bonded_chan_ptr) {
  3457. spectral_err("Bonded channel is not found");
  3458. return QDF_STATUS_E_FAILURE;
  3459. }
  3460. start_freq = bonded_chan_ptr->start_freq;
  3461. end_freq = bonded_chan_ptr->end_freq;
  3462. *center_freq = (start_freq + end_freq) >> 1;
  3463. }
  3464. return QDF_STATUS_SUCCESS;
  3465. }
  3466. /**
  3467. * target_if_validate_center_freq() - Helper routine to
  3468. * validate user provided agile center frequency
  3469. *
  3470. * @spectral: Pointer to Spectral object
  3471. * @ch_width: Channel width array
  3472. * @center_freq: User provided agile span center frequency
  3473. * @is_valid: Indicates whether agile span center frequency is valid
  3474. *
  3475. * Return: QDF_STATUS
  3476. */
  3477. static QDF_STATUS
  3478. target_if_validate_center_freq(struct target_if_spectral *spectral,
  3479. enum phy_ch_width *ch_width,
  3480. uint16_t center_freq,
  3481. bool *is_valid)
  3482. {
  3483. enum phy_ch_width agile_ch_width;
  3484. struct wlan_objmgr_pdev *pdev;
  3485. QDF_STATUS status;
  3486. if (!spectral) {
  3487. spectral_err("spectral target if object is null");
  3488. return QDF_STATUS_E_FAILURE;
  3489. }
  3490. if (!ch_width) {
  3491. spectral_err("channel width array is null");
  3492. return QDF_STATUS_E_INVAL;
  3493. }
  3494. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3495. if (!is_valid) {
  3496. spectral_err("is_valid argument is null");
  3497. return QDF_STATUS_E_FAILURE;
  3498. }
  3499. pdev = spectral->pdev_obj;
  3500. if (agile_ch_width == CH_WIDTH_20MHZ) {
  3501. status = target_if_is_center_freq_of_any_chan
  3502. (pdev, center_freq, is_valid);
  3503. if (QDF_IS_STATUS_ERROR(status))
  3504. return QDF_STATUS_E_FAILURE;
  3505. } else {
  3506. uint16_t start_freq;
  3507. uint16_t end_freq;
  3508. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3509. bool is_chan;
  3510. status = target_if_is_center_freq_of_any_chan
  3511. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  3512. &is_chan);
  3513. if (QDF_IS_STATUS_ERROR(status))
  3514. return QDF_STATUS_E_FAILURE;
  3515. if (is_chan) {
  3516. uint32_t calulated_center_freq;
  3517. enum channel_state st;
  3518. st = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  3519. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  3520. agile_ch_width,
  3521. &bonded_chan_ptr,
  3522. REG_CURRENT_PWR_MODE);
  3523. if (st == CHANNEL_STATE_DISABLE ||
  3524. st == CHANNEL_STATE_INVALID) {
  3525. spectral_err("Channel state disable/invalid");
  3526. return QDF_STATUS_E_FAILURE;
  3527. }
  3528. if (!bonded_chan_ptr) {
  3529. spectral_err("Bonded channel is not found");
  3530. return QDF_STATUS_E_FAILURE;
  3531. }
  3532. start_freq = bonded_chan_ptr->start_freq;
  3533. end_freq = bonded_chan_ptr->end_freq;
  3534. calulated_center_freq = (start_freq + end_freq) >> 1;
  3535. *is_valid = (center_freq == calulated_center_freq);
  3536. } else {
  3537. *is_valid = false;
  3538. }
  3539. }
  3540. return QDF_STATUS_SUCCESS;
  3541. }
  3542. /**
  3543. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  3544. * check whether agile span overlaps with current operating band.
  3545. *
  3546. * @spectral: Pointer to Spectral object
  3547. * @ch_width: Channel width array
  3548. * @center_freq: Agile span center frequency
  3549. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  3550. *
  3551. * Helper routine to check whether agile span overlaps with current
  3552. * operating band.
  3553. *
  3554. * Return: QDF_STATUS
  3555. */
  3556. static QDF_STATUS
  3557. target_if_is_agile_span_overlap_with_operating_span
  3558. (struct target_if_spectral *spectral,
  3559. enum phy_ch_width *ch_width,
  3560. struct spectral_config_frequency *center_freq,
  3561. bool *is_overlapping)
  3562. {
  3563. enum phy_ch_width op_ch_width;
  3564. enum phy_ch_width agile_ch_width;
  3565. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3566. struct wlan_objmgr_vdev *vdev;
  3567. struct wlan_objmgr_pdev *pdev;
  3568. int16_t chan_freq;
  3569. uint32_t op_start_freq;
  3570. uint32_t op_end_freq;
  3571. uint32_t agile_start_freq;
  3572. uint32_t agile_end_freq;
  3573. uint32_t cfreq2;
  3574. if (!spectral) {
  3575. spectral_err("Spectral object is NULL");
  3576. return QDF_STATUS_E_FAILURE;
  3577. }
  3578. pdev = spectral->pdev_obj;
  3579. if (!pdev) {
  3580. spectral_err("pdev object is NULL");
  3581. return QDF_STATUS_E_FAILURE;
  3582. }
  3583. if (!ch_width) {
  3584. spectral_err("channel width array is null");
  3585. return QDF_STATUS_E_FAILURE;
  3586. }
  3587. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  3588. if (op_ch_width == CH_WIDTH_INVALID) {
  3589. spectral_err("Invalid channel width");
  3590. return QDF_STATUS_E_INVAL;
  3591. }
  3592. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3593. if (agile_ch_width == CH_WIDTH_INVALID) {
  3594. spectral_err("Invalid channel width");
  3595. return QDF_STATUS_E_INVAL;
  3596. }
  3597. if (!is_overlapping) {
  3598. spectral_err("Argument(is_overlapping) is NULL");
  3599. return QDF_STATUS_E_FAILURE;
  3600. }
  3601. *is_overlapping = false;
  3602. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  3603. if (!vdev) {
  3604. spectral_err("vdev is NULL");
  3605. return QDF_STATUS_E_FAILURE;
  3606. }
  3607. chan_freq = target_if_vdev_get_chan_freq(vdev);
  3608. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  3609. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3610. if (cfreq2 < 0) {
  3611. spectral_err("cfreq2 is invalid");
  3612. return QDF_STATUS_E_FAILURE;
  3613. }
  3614. if (op_ch_width == CH_WIDTH_20MHZ) {
  3615. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  3616. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  3617. } else {
  3618. enum channel_state state;
  3619. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  3620. (pdev, chan_freq, op_ch_width, &bonded_chan_ptr,
  3621. REG_CURRENT_PWR_MODE);
  3622. if (state == CHANNEL_STATE_DISABLE ||
  3623. state == CHANNEL_STATE_INVALID) {
  3624. spectral_err("Channel state is disable or invalid");
  3625. return QDF_STATUS_E_FAILURE;
  3626. }
  3627. if (!bonded_chan_ptr) {
  3628. spectral_err("Bonded channel is not found");
  3629. return QDF_STATUS_E_FAILURE;
  3630. }
  3631. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  3632. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  3633. }
  3634. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3635. agile_start_freq = center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3636. agile_end_freq = center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3637. if (agile_end_freq > op_start_freq &&
  3638. op_end_freq > agile_start_freq)
  3639. *is_overlapping = true;
  3640. agile_start_freq = center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3641. agile_end_freq = center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3642. if (agile_end_freq > op_start_freq &&
  3643. op_end_freq > agile_start_freq)
  3644. *is_overlapping = true;
  3645. } else {
  3646. agile_start_freq = center_freq->cfreq1 -
  3647. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3648. agile_end_freq = center_freq->cfreq1 +
  3649. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3650. if (agile_end_freq > op_start_freq &&
  3651. op_end_freq > agile_start_freq)
  3652. *is_overlapping = true;
  3653. }
  3654. if (op_ch_width == CH_WIDTH_80P80MHZ) {
  3655. uint32_t sec80_start_feq;
  3656. uint32_t sec80_end_freq;
  3657. sec80_start_feq = cfreq2 - FREQ_OFFSET_40MHZ;
  3658. sec80_end_freq = cfreq2 + FREQ_OFFSET_40MHZ;
  3659. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3660. agile_start_freq =
  3661. center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3662. agile_end_freq =
  3663. center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3664. if (agile_end_freq > sec80_start_feq &&
  3665. sec80_end_freq > agile_start_freq)
  3666. *is_overlapping = true;
  3667. agile_start_freq =
  3668. center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3669. agile_end_freq =
  3670. center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3671. if (agile_end_freq > sec80_start_feq &&
  3672. sec80_end_freq > agile_start_freq)
  3673. *is_overlapping = true;
  3674. } else {
  3675. agile_start_freq = center_freq->cfreq1 -
  3676. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3677. agile_end_freq = center_freq->cfreq1 +
  3678. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3679. if (agile_end_freq > sec80_start_feq &&
  3680. sec80_end_freq > agile_start_freq)
  3681. *is_overlapping = true;
  3682. }
  3683. }
  3684. return QDF_STATUS_SUCCESS;
  3685. }
  3686. /**
  3687. * target_if_spectral_populate_chwidth() - Helper routine to
  3688. * populate channel width for different Spectral modes
  3689. *
  3690. * @spectral: Pointer to Spectral object
  3691. * @ch_width: Channel width array
  3692. * @is_80_80_agile: Indicates whether 80+80 agile scan is requested
  3693. *
  3694. * Helper routine to populate channel width for different Spectral modes
  3695. *
  3696. * Return: QDF_STATUS
  3697. */
  3698. static QDF_STATUS
  3699. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral,
  3700. enum phy_ch_width *ch_width,
  3701. bool is_80_80_agile)
  3702. {
  3703. enum spectral_scan_mode smode;
  3704. qdf_assert_always(spectral);
  3705. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3706. for (; smode < SPECTRAL_SCAN_MODE_MAX; ++smode) {
  3707. /* If user has configured sscan bandwidth, use it */
  3708. if (spectral->sscan_width_configured[smode]) {
  3709. ch_width[smode] = spectral->params[smode].ss_bandwidth;
  3710. } else {
  3711. /* Otherwise, derive the default sscan bandwidth */
  3712. ch_width[smode] = get_default_sscan_bw(spectral, smode,
  3713. is_80_80_agile);
  3714. if (ch_width[smode] >= CH_WIDTH_INVALID) {
  3715. spectral_err("Invalid sscan BW %u",
  3716. ch_width[smode]);
  3717. return QDF_STATUS_E_FAILURE;
  3718. }
  3719. spectral->params[smode].ss_bandwidth = ch_width[smode];
  3720. }
  3721. }
  3722. return QDF_STATUS_SUCCESS;
  3723. }
  3724. /**
  3725. * target_if_spectral_is_valid_80p80_freq() - API to check whether given
  3726. * (cfreq1, cfreq2) pair forms a valid 80+80 combination
  3727. * @pdev: pointer to pdev
  3728. * @cfreq1: center frequency 1
  3729. * @cfreq2: center frequency 2
  3730. *
  3731. * API to check whether given (cfreq1, cfreq2) pair forms a valid 80+80
  3732. * combination
  3733. *
  3734. * Return: true or false
  3735. */
  3736. static bool
  3737. target_if_spectral_is_valid_80p80_freq(struct wlan_objmgr_pdev *pdev,
  3738. uint32_t cfreq1, uint32_t cfreq2)
  3739. {
  3740. struct ch_params ch_params;
  3741. enum channel_state chan_state1;
  3742. enum channel_state chan_state2;
  3743. struct wlan_objmgr_psoc *psoc;
  3744. qdf_assert_always(pdev);
  3745. psoc = wlan_pdev_get_psoc(pdev);
  3746. qdf_assert_always(psoc);
  3747. /* In restricted 80P80 MHz enabled, only one 80+80 MHz
  3748. * channel is supported with cfreq=5690 and cfreq=5775.
  3749. */
  3750. if (wlan_psoc_nif_fw_ext_cap_get(
  3751. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  3752. return CHAN_WITHIN_RESTRICTED_80P80(cfreq1, cfreq2);
  3753. ch_params.center_freq_seg1 = wlan_reg_freq_to_chan(pdev, cfreq2);
  3754. ch_params.mhz_freq_seg1 = cfreq2;
  3755. ch_params.ch_width = CH_WIDTH_80P80MHZ;
  3756. wlan_reg_set_channel_params_for_freq(pdev, cfreq1 - FREQ_OFFSET_10MHZ,
  3757. 0, &ch_params,
  3758. REG_CURRENT_PWR_MODE);
  3759. if (ch_params.ch_width != CH_WIDTH_80P80MHZ)
  3760. return false;
  3761. if (ch_params.mhz_freq_seg0 != cfreq1 ||
  3762. ch_params.mhz_freq_seg1 != cfreq2)
  3763. return false;
  3764. chan_state1 = wlan_reg_get_5g_bonded_channel_state_for_freq(
  3765. pdev,
  3766. ch_params.mhz_freq_seg0 - FREQ_OFFSET_10MHZ,
  3767. CH_WIDTH_80MHZ,
  3768. REG_CURRENT_PWR_MODE);
  3769. if ((chan_state1 == CHANNEL_STATE_DISABLE) ||
  3770. (chan_state1 == CHANNEL_STATE_INVALID))
  3771. return false;
  3772. chan_state2 = wlan_reg_get_5g_bonded_channel_state_for_freq(
  3773. pdev,
  3774. ch_params.mhz_freq_seg1 - FREQ_OFFSET_10MHZ,
  3775. CH_WIDTH_80MHZ,
  3776. REG_CURRENT_PWR_MODE);
  3777. if ((chan_state2 == CHANNEL_STATE_DISABLE) ||
  3778. (chan_state2 == CHANNEL_STATE_INVALID))
  3779. return false;
  3780. if (abs(ch_params.mhz_freq_seg0 - ch_params.mhz_freq_seg1) <=
  3781. FREQ_OFFSET_80MHZ)
  3782. return false;
  3783. return true;
  3784. }
  3785. /**
  3786. * _target_if_set_spectral_config() - Set spectral config
  3787. * @spectral: Pointer to spectral object
  3788. * @param: Spectral parameter id and value
  3789. * @smode: Spectral scan mode
  3790. * @err: Spectral error code
  3791. *
  3792. * API to set spectral configurations
  3793. *
  3794. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3795. */
  3796. static QDF_STATUS
  3797. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  3798. const struct spectral_cp_param *param,
  3799. const enum spectral_scan_mode smode,
  3800. enum spectral_cp_error_code *err)
  3801. {
  3802. struct spectral_config params;
  3803. struct target_if_spectral_ops *p_sops;
  3804. struct spectral_config *sparams;
  3805. QDF_STATUS status;
  3806. bool is_overlapping;
  3807. uint16_t agile_cfreq;
  3808. bool is_valid_chan;
  3809. struct spectral_param_min_max *param_min_max;
  3810. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  3811. enum spectral_scan_mode m;
  3812. struct spectral_config_frequency center_freq = {0};
  3813. bool is_bw_supported;
  3814. struct wlan_objmgr_vdev *vdev;
  3815. enum phy_ch_width op_bw;
  3816. if (!err) {
  3817. spectral_err("Error code argument is null");
  3818. QDF_ASSERT(0);
  3819. return QDF_STATUS_E_FAILURE;
  3820. }
  3821. *err = SPECTRAL_SCAN_ERR_INVALID;
  3822. if (!param) {
  3823. spectral_err("Parameter object is null");
  3824. return QDF_STATUS_E_FAILURE;
  3825. }
  3826. if (!spectral) {
  3827. spectral_err("spectral object is NULL");
  3828. return QDF_STATUS_E_FAILURE;
  3829. }
  3830. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3831. param_min_max = &spectral->param_min_max;
  3832. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3833. spectral_err("Invalid Spectral mode %u", smode);
  3834. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3835. return QDF_STATUS_E_FAILURE;
  3836. }
  3837. sparams = &spectral->params[smode];
  3838. m = SPECTRAL_SCAN_MODE_NORMAL;
  3839. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  3840. ch_width[m] = CH_WIDTH_INVALID;
  3841. if (!spectral->params_valid[smode]) {
  3842. target_if_spectral_info_read(spectral,
  3843. smode,
  3844. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3845. &spectral->params[smode],
  3846. sizeof(spectral->params[smode]));
  3847. spectral->params_valid[smode] = true;
  3848. }
  3849. switch (param->id) {
  3850. case SPECTRAL_PARAM_FFT_PERIOD:
  3851. sparams->ss_fft_period = param->value;
  3852. break;
  3853. case SPECTRAL_PARAM_SCAN_PERIOD:
  3854. sparams->ss_period = param->value;
  3855. break;
  3856. case SPECTRAL_PARAM_SCAN_COUNT:
  3857. sparams->ss_count = param->value;
  3858. break;
  3859. case SPECTRAL_PARAM_SHORT_REPORT:
  3860. sparams->ss_short_report = (!!param->value) ? true : false;
  3861. break;
  3862. case SPECTRAL_PARAM_SPECT_PRI:
  3863. sparams->ss_spectral_pri = (!!param->value) ? true : false;
  3864. break;
  3865. case SPECTRAL_PARAM_FFT_SIZE:
  3866. status = target_if_spectral_populate_chwidth
  3867. (spectral, ch_width, spectral->params
  3868. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  3869. if (QDF_IS_STATUS_ERROR(status))
  3870. return QDF_STATUS_E_FAILURE;
  3871. if ((param->value < param_min_max->fft_size_min) ||
  3872. (param->value > param_min_max->fft_size_max
  3873. [ch_width[smode]])) {
  3874. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3875. return QDF_STATUS_E_FAILURE;
  3876. }
  3877. sparams->ss_fft_size = param->value;
  3878. break;
  3879. case SPECTRAL_PARAM_GC_ENA:
  3880. sparams->ss_gc_ena = !!param->value;
  3881. break;
  3882. case SPECTRAL_PARAM_RESTART_ENA:
  3883. sparams->ss_restart_ena = !!param->value;
  3884. break;
  3885. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  3886. sparams->ss_noise_floor_ref = param->value;
  3887. break;
  3888. case SPECTRAL_PARAM_INIT_DELAY:
  3889. sparams->ss_init_delay = param->value;
  3890. break;
  3891. case SPECTRAL_PARAM_NB_TONE_THR:
  3892. sparams->ss_nb_tone_thr = param->value;
  3893. break;
  3894. case SPECTRAL_PARAM_STR_BIN_THR:
  3895. sparams->ss_str_bin_thr = param->value;
  3896. break;
  3897. case SPECTRAL_PARAM_WB_RPT_MODE:
  3898. sparams->ss_wb_rpt_mode = !!param->value;
  3899. break;
  3900. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  3901. sparams->ss_rssi_rpt_mode = !!param->value;
  3902. break;
  3903. case SPECTRAL_PARAM_RSSI_THR:
  3904. sparams->ss_rssi_thr = param->value;
  3905. break;
  3906. case SPECTRAL_PARAM_PWR_FORMAT:
  3907. sparams->ss_pwr_format = !!param->value;
  3908. break;
  3909. case SPECTRAL_PARAM_RPT_MODE:
  3910. if ((param->value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  3911. (param->value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  3912. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3913. return QDF_STATUS_E_FAILURE;
  3914. }
  3915. sparams->ss_rpt_mode = param->value;
  3916. break;
  3917. case SPECTRAL_PARAM_BIN_SCALE:
  3918. sparams->ss_bin_scale = param->value;
  3919. break;
  3920. case SPECTRAL_PARAM_DBM_ADJ:
  3921. sparams->ss_dbm_adj = !!param->value;
  3922. break;
  3923. case SPECTRAL_PARAM_CHN_MASK:
  3924. sparams->ss_chn_mask = param->value;
  3925. break;
  3926. case SPECTRAL_PARAM_FREQUENCY:
  3927. status = target_if_spectral_populate_chwidth(
  3928. spectral, ch_width, param->freq.cfreq2 > 0);
  3929. if (QDF_IS_STATUS_ERROR(status)) {
  3930. spectral_err("Failed to populate channel width");
  3931. return QDF_STATUS_E_FAILURE;
  3932. }
  3933. if (ch_width[smode] != CH_WIDTH_80P80MHZ &&
  3934. param->freq.cfreq2) {
  3935. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3936. spectral_err("Non zero cfreq2 expected for 80p80 only");
  3937. return QDF_STATUS_E_INVAL;
  3938. }
  3939. if (ch_width[smode] == CH_WIDTH_80P80MHZ &&
  3940. !param->freq.cfreq2) {
  3941. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3942. spectral_err("Non zero cfreq2 expected for 80p80");
  3943. return QDF_STATUS_E_INVAL;
  3944. }
  3945. status = target_if_is_center_freq_of_any_chan
  3946. (spectral->pdev_obj, param->freq.cfreq1,
  3947. &is_valid_chan);
  3948. if (QDF_IS_STATUS_ERROR(status))
  3949. return QDF_STATUS_E_FAILURE;
  3950. if (is_valid_chan) {
  3951. status = target_if_calculate_center_freq(
  3952. spectral, ch_width,
  3953. param->freq.cfreq1,
  3954. &agile_cfreq);
  3955. if (QDF_IS_STATUS_ERROR(status)) {
  3956. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3957. return QDF_STATUS_E_FAILURE;
  3958. }
  3959. } else {
  3960. bool is_valid_agile_cfreq;
  3961. status = target_if_validate_center_freq
  3962. (spectral, ch_width, param->freq.cfreq1,
  3963. &is_valid_agile_cfreq);
  3964. if (QDF_IS_STATUS_ERROR(status))
  3965. return QDF_STATUS_E_FAILURE;
  3966. if (!is_valid_agile_cfreq) {
  3967. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3968. spectral_err("Invalid agile center frequency");
  3969. return QDF_STATUS_E_FAILURE;
  3970. }
  3971. agile_cfreq = param->freq.cfreq1;
  3972. }
  3973. center_freq.cfreq1 = agile_cfreq;
  3974. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  3975. status = target_if_is_center_freq_of_any_chan
  3976. (spectral->pdev_obj, param->freq.cfreq2,
  3977. &is_valid_chan);
  3978. if (QDF_IS_STATUS_ERROR(status))
  3979. return QDF_STATUS_E_FAILURE;
  3980. if (is_valid_chan) {
  3981. status = target_if_calculate_center_freq(
  3982. spectral, ch_width,
  3983. param->freq.cfreq2,
  3984. &agile_cfreq);
  3985. if (QDF_IS_STATUS_ERROR(status)) {
  3986. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3987. return QDF_STATUS_E_FAILURE;
  3988. }
  3989. } else {
  3990. bool is_valid_agile_cfreq;
  3991. status = target_if_validate_center_freq
  3992. (spectral, ch_width, param->freq.cfreq2,
  3993. &is_valid_agile_cfreq);
  3994. if (QDF_IS_STATUS_ERROR(status))
  3995. return QDF_STATUS_E_FAILURE;
  3996. if (!is_valid_agile_cfreq) {
  3997. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3998. spectral_err("Invalid agile center frequency");
  3999. return QDF_STATUS_E_FAILURE;
  4000. }
  4001. agile_cfreq = param->freq.cfreq2;
  4002. }
  4003. center_freq.cfreq2 = agile_cfreq;
  4004. }
  4005. status = target_if_is_agile_span_overlap_with_operating_span
  4006. (spectral, ch_width,
  4007. &center_freq, &is_overlapping);
  4008. if (QDF_IS_STATUS_ERROR(status))
  4009. return QDF_STATUS_E_FAILURE;
  4010. if (is_overlapping) {
  4011. spectral_err("Agile freq %u, %u overlaps with operating span",
  4012. center_freq.cfreq1, center_freq.cfreq2);
  4013. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4014. return QDF_STATUS_E_FAILURE;
  4015. }
  4016. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  4017. bool is_valid_80p80;
  4018. is_valid_80p80 = target_if_spectral_is_valid_80p80_freq(
  4019. spectral->pdev_obj,
  4020. center_freq.cfreq1,
  4021. center_freq.cfreq2);
  4022. if (!is_valid_80p80) {
  4023. spectral_err("Agile freq %u, %u is invalid 80+80 combination",
  4024. center_freq.cfreq1,
  4025. center_freq.cfreq2);
  4026. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4027. return QDF_STATUS_E_FAILURE;
  4028. }
  4029. }
  4030. sparams->ss_frequency.cfreq1 = center_freq.cfreq1;
  4031. sparams->ss_frequency.cfreq2 = center_freq.cfreq2;
  4032. break;
  4033. case SPECTRAL_PARAM_CHAN_WIDTH:
  4034. if (param->value >= CH_WIDTH_INVALID) {
  4035. spectral_err("invalid sscan width: %u", param->value);
  4036. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4037. return QDF_STATUS_E_FAILURE;
  4038. }
  4039. vdev = target_if_spectral_get_vdev(spectral, smode);
  4040. if (!vdev) {
  4041. spectral_err("vdev is null");
  4042. return QDF_STATUS_E_NULL_VALUE;
  4043. }
  4044. op_bw = target_if_vdev_get_ch_width(vdev);
  4045. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4046. /* Validate the bandwidth */
  4047. status = target_if_is_sscan_bw_supported(
  4048. spectral, smode,
  4049. param->value, op_bw, &is_bw_supported,
  4050. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  4051. ss_frequency.cfreq2 > 0);
  4052. if (QDF_IS_STATUS_ERROR(status)) {
  4053. spectral_err("Unable to check if given sscan_bw is supported");
  4054. return QDF_STATUS_E_FAILURE;
  4055. }
  4056. if (!is_bw_supported) {
  4057. spectral_err("sscan bw(%u) is not supported for the current operating width(%u) and sscan mode(%u)",
  4058. param->value, op_bw, smode);
  4059. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4060. return QDF_STATUS_E_FAILURE;
  4061. }
  4062. sparams->ss_bandwidth = param->value;
  4063. spectral->sscan_width_configured[smode] = true;
  4064. break;
  4065. }
  4066. p_sops->configure_spectral(spectral, sparams, smode);
  4067. /* only to validate the writes */
  4068. p_sops->get_spectral_config(spectral, &params, smode);
  4069. return QDF_STATUS_SUCCESS;
  4070. }
  4071. QDF_STATUS
  4072. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  4073. const struct spectral_cp_param *param,
  4074. const enum spectral_scan_mode smode,
  4075. enum spectral_cp_error_code *err)
  4076. {
  4077. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  4078. struct target_if_spectral *spectral;
  4079. QDF_STATUS status;
  4080. if (!err) {
  4081. spectral_err("Error code argument is null");
  4082. QDF_ASSERT(0);
  4083. return QDF_STATUS_E_FAILURE;
  4084. }
  4085. *err = SPECTRAL_SCAN_ERR_INVALID;
  4086. if (!pdev) {
  4087. spectral_err("pdev object is NULL");
  4088. return QDF_STATUS_E_FAILURE;
  4089. }
  4090. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4091. if (!spectral) {
  4092. spectral_err("spectral object is NULL");
  4093. return QDF_STATUS_E_FAILURE;
  4094. }
  4095. if (!param) {
  4096. spectral_err("parameter object is NULL");
  4097. return QDF_STATUS_E_FAILURE;
  4098. }
  4099. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4100. spectral_err("Invalid Spectral mode %u", smode);
  4101. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4102. return QDF_STATUS_E_FAILURE;
  4103. }
  4104. if (!spectral->properties[smode][param->id].supported) {
  4105. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  4106. param->id, smode);
  4107. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  4108. return QDF_STATUS_E_FAILURE;
  4109. }
  4110. if (spectral->properties[smode][param->id].common_all_modes) {
  4111. spectral_warn("Setting Spectral parameter %u for all modes",
  4112. param->id);
  4113. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  4114. status = _target_if_set_spectral_config
  4115. (spectral, param, mode, err);
  4116. if (QDF_IS_STATUS_ERROR(status))
  4117. return QDF_STATUS_E_FAILURE;
  4118. }
  4119. return QDF_STATUS_SUCCESS;
  4120. }
  4121. return _target_if_set_spectral_config(spectral, param, smode, err);
  4122. }
  4123. /**
  4124. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  4125. * @fft_len: FFT length
  4126. * @pdev: Pointer to pdev object
  4127. *
  4128. * API to get fft bin count for a given fft length
  4129. *
  4130. * Return: FFt bin count
  4131. */
  4132. static int
  4133. target_if_get_fft_bin_count(int fft_len)
  4134. {
  4135. int bin_count = 0;
  4136. switch (fft_len) {
  4137. case 5:
  4138. bin_count = 16;
  4139. break;
  4140. case 6:
  4141. bin_count = 32;
  4142. break;
  4143. case 7:
  4144. bin_count = 64;
  4145. break;
  4146. case 8:
  4147. bin_count = 128;
  4148. break;
  4149. case 9:
  4150. bin_count = 256;
  4151. break;
  4152. default:
  4153. break;
  4154. }
  4155. return bin_count;
  4156. }
  4157. /**
  4158. * target_if_init_upper_lower_flags() - Initializes control and extension
  4159. * segment flags
  4160. * @spectral: pointer to target if spectral object
  4161. * @smode: Spectral scan mode
  4162. *
  4163. * API to initialize the control and extension flags with the lower/upper
  4164. * segment based on the HT mode
  4165. *
  4166. * Return: FFt bin count
  4167. */
  4168. static void
  4169. target_if_init_upper_lower_flags(struct target_if_spectral *spectral,
  4170. enum spectral_scan_mode smode)
  4171. {
  4172. int current_channel = 0;
  4173. int ext_channel = 0;
  4174. struct target_if_spectral_ops *p_sops =
  4175. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4176. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4177. spectral_err("Invalid Spectral mode %u", smode);
  4178. return;
  4179. }
  4180. current_channel = p_sops->get_current_channel(spectral, smode);
  4181. ext_channel = p_sops->get_extension_channel(spectral, smode);
  4182. if ((current_channel == 0) || (ext_channel == 0))
  4183. return;
  4184. if (spectral->sc_spectral_20_40_mode) {
  4185. /* HT40 mode */
  4186. if (ext_channel < current_channel) {
  4187. spectral->lower_is_extension = 1;
  4188. spectral->upper_is_control = 1;
  4189. spectral->lower_is_control = 0;
  4190. spectral->upper_is_extension = 0;
  4191. } else {
  4192. spectral->lower_is_extension = 0;
  4193. spectral->upper_is_control = 0;
  4194. spectral->lower_is_control = 1;
  4195. spectral->upper_is_extension = 1;
  4196. }
  4197. } else {
  4198. /* HT20 mode, lower is always control */
  4199. spectral->lower_is_extension = 0;
  4200. spectral->upper_is_control = 0;
  4201. spectral->lower_is_control = 1;
  4202. spectral->upper_is_extension = 0;
  4203. }
  4204. }
  4205. /**
  4206. * target_if_get_spectral_config() - Get spectral configuration
  4207. * @pdev: Pointer to pdev object
  4208. * @param: Pointer to spectral_config structure in which the configuration
  4209. * should be returned
  4210. * @smode: Spectral scan mode
  4211. *
  4212. * API to get the current spectral configuration
  4213. *
  4214. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4215. */
  4216. QDF_STATUS
  4217. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  4218. struct spectral_config *param,
  4219. enum spectral_scan_mode smode)
  4220. {
  4221. struct target_if_spectral_ops *p_sops = NULL;
  4222. struct target_if_spectral *spectral = NULL;
  4223. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4224. if (!spectral) {
  4225. spectral_err("SPECTRAL : Module doesn't exist");
  4226. return QDF_STATUS_E_FAILURE;
  4227. }
  4228. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4229. if (!p_sops) {
  4230. spectral_err("p_sops is null");
  4231. return QDF_STATUS_E_FAILURE;
  4232. }
  4233. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4234. spectral_err("Invalid Spectral mode %u", smode);
  4235. return QDF_STATUS_E_FAILURE;
  4236. }
  4237. qdf_mem_zero(param, sizeof(struct spectral_config));
  4238. p_sops->get_spectral_config(spectral, param, smode);
  4239. return QDF_STATUS_SUCCESS;
  4240. }
  4241. #ifdef WLAN_FEATURE_11BE
  4242. /**
  4243. * target_if_spectral_get_num_detectors_for_higher_bws() - Get number of
  4244. * Spectral detectors for higher bandwidths
  4245. * @spectral: Pointer to target if Spectral object
  4246. * @ch_width: channel width
  4247. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  4248. *
  4249. * API to get number of Spectral detectors used for scan in the given channel
  4250. * width.
  4251. *
  4252. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  4253. */
  4254. static QDF_STATUS
  4255. target_if_spectral_get_num_detectors_for_higher_bws(
  4256. struct target_if_spectral *spectral,
  4257. enum phy_ch_width ch_width,
  4258. uint32_t *num_detectors)
  4259. {
  4260. switch (ch_width) {
  4261. case CH_WIDTH_320MHZ:
  4262. *num_detectors = spectral->capability.num_detectors_320mhz;
  4263. break;
  4264. default:
  4265. spectral_err("Unsupported channel width %d", ch_width);
  4266. return QDF_STATUS_E_INVAL;
  4267. }
  4268. return QDF_STATUS_SUCCESS;
  4269. }
  4270. #else
  4271. static QDF_STATUS
  4272. target_if_spectral_get_num_detectors_for_higher_bws(
  4273. struct target_if_spectral *spectral,
  4274. enum phy_ch_width ch_width,
  4275. uint32_t *num_detectors)
  4276. {
  4277. spectral_err("Unsupported channel width %d", ch_width);
  4278. return QDF_STATUS_E_INVAL;
  4279. }
  4280. #endif
  4281. /**
  4282. * target_if_spectral_get_num_detectors() - Get number of Spectral detectors
  4283. * @spectral: Pointer to target if Spectral object
  4284. * @ch_width: channel width
  4285. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  4286. *
  4287. * API to get number of Spectral detectors used for scan in the given channel
  4288. * width.
  4289. *
  4290. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  4291. */
  4292. static QDF_STATUS
  4293. target_if_spectral_get_num_detectors(struct target_if_spectral *spectral,
  4294. enum phy_ch_width ch_width,
  4295. uint32_t *num_detectors)
  4296. {
  4297. if (!spectral) {
  4298. spectral_err("target if spectral object is null");
  4299. return QDF_STATUS_E_INVAL;
  4300. }
  4301. if (ch_width >= CH_WIDTH_INVALID) {
  4302. spectral_err("Invalid channel width %d", ch_width);
  4303. return QDF_STATUS_E_INVAL;
  4304. }
  4305. if (!num_detectors) {
  4306. spectral_err("Invalid argument, number of detectors");
  4307. return QDF_STATUS_E_INVAL;
  4308. }
  4309. switch (ch_width) {
  4310. case CH_WIDTH_20MHZ:
  4311. *num_detectors = spectral->capability.num_detectors_20mhz;
  4312. break;
  4313. case CH_WIDTH_40MHZ:
  4314. *num_detectors = spectral->capability.num_detectors_40mhz;
  4315. break;
  4316. case CH_WIDTH_80MHZ:
  4317. *num_detectors = spectral->capability.num_detectors_80mhz;
  4318. break;
  4319. case CH_WIDTH_160MHZ:
  4320. *num_detectors = spectral->capability.num_detectors_160mhz;
  4321. break;
  4322. case CH_WIDTH_80P80MHZ:
  4323. *num_detectors = spectral->capability.num_detectors_80p80mhz;
  4324. break;
  4325. default:
  4326. return target_if_spectral_get_num_detectors_for_higher_bws(
  4327. spectral, ch_width, num_detectors);
  4328. }
  4329. return QDF_STATUS_SUCCESS;
  4330. }
  4331. /**
  4332. * target_if_spectral_finite_scan_init() - Initializations required for finite
  4333. * Spectral scan
  4334. * @spectral: Pointer to target of Spctral object
  4335. * @smode: Spectral scan mode
  4336. *
  4337. * This routine initializes the finite Spectral scan. Finite Spectral scan is
  4338. * triggered by configuring a non zero scan count.
  4339. *
  4340. * Return: QDF_STATUS_SUCCESS on success
  4341. */
  4342. static QDF_STATUS
  4343. target_if_spectral_finite_scan_init(struct target_if_spectral *spectral,
  4344. enum spectral_scan_mode smode)
  4345. {
  4346. struct target_if_finite_spectral_scan_params *finite_scan;
  4347. enum phy_ch_width ch_width;
  4348. uint32_t num_detectors;
  4349. QDF_STATUS status;
  4350. uint16_t sscan_count;
  4351. if (!spectral) {
  4352. spectral_err("target if spectral object is null");
  4353. return QDF_STATUS_E_INVAL;
  4354. }
  4355. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4356. spectral_err("Invalid Spectral mode");
  4357. return QDF_STATUS_E_INVAL;
  4358. }
  4359. ch_width = spectral->ch_width[smode];
  4360. status = target_if_spectral_get_num_detectors(spectral, ch_width,
  4361. &num_detectors);
  4362. if (QDF_IS_STATUS_ERROR(status)) {
  4363. spectral_err("Failed to get number of detectors");
  4364. return QDF_STATUS_E_FAILURE;
  4365. }
  4366. finite_scan = &spectral->finite_scan[smode];
  4367. sscan_count = spectral->params[smode].ss_count;
  4368. finite_scan->finite_spectral_scan = true;
  4369. finite_scan->num_reports_expected = num_detectors * sscan_count;
  4370. return QDF_STATUS_SUCCESS;
  4371. }
  4372. /**
  4373. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  4374. * parameters
  4375. * @spectral: Pointer to Spectral target_if internal private data
  4376. * @spectral_params: Pointer to Spectral parameters
  4377. * @smode: Spectral scan mode
  4378. * @err: Spectral error code
  4379. *
  4380. * Enable use of desired Spectral parameters by configuring them into HW, and
  4381. * starting Spectral scan
  4382. *
  4383. * Return: 0 on success, 1 on failure
  4384. */
  4385. int
  4386. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  4387. struct spectral_config *spectral_params,
  4388. enum spectral_scan_mode smode,
  4389. enum spectral_cp_error_code *err)
  4390. {
  4391. int extension_channel = 0;
  4392. int current_channel = 0;
  4393. struct target_if_spectral_ops *p_sops = NULL;
  4394. QDF_STATUS status;
  4395. struct wlan_objmgr_pdev *pdev;
  4396. struct wlan_objmgr_psoc *psoc;
  4397. if (!spectral) {
  4398. spectral_err("Spectral LMAC object is NULL");
  4399. return 1;
  4400. }
  4401. pdev = spectral->pdev_obj;
  4402. if (!pdev) {
  4403. spectral_err("pdev is null");
  4404. return QDF_STATUS_E_INVAL;
  4405. }
  4406. psoc = wlan_pdev_get_psoc(pdev);
  4407. if (!psoc) {
  4408. spectral_err("psoc is null");
  4409. return QDF_STATUS_E_INVAL;
  4410. }
  4411. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4412. spectral_err("Invalid Spectral mode %u", smode);
  4413. return 1;
  4414. }
  4415. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4416. if (!p_sops) {
  4417. spectral_err("p_sops is NULL");
  4418. return 1;
  4419. }
  4420. spectral->sc_spectral_noise_pwr_cal =
  4421. spectral_params->ss_spectral_pri ? 1 : 0;
  4422. /* check if extension channel is present */
  4423. extension_channel = p_sops->get_extension_channel(spectral, smode);
  4424. current_channel = p_sops->get_current_channel(spectral, smode);
  4425. if (spectral->capability.advncd_spectral_cap) {
  4426. spectral->lb_edge_extrabins = 0;
  4427. spectral->rb_edge_extrabins = 0;
  4428. if (spectral->is_lb_edge_extrabins_format &&
  4429. spectral->params[smode].ss_rpt_mode == 2) {
  4430. spectral->lb_edge_extrabins = 4;
  4431. }
  4432. if (spectral->is_rb_edge_extrabins_format &&
  4433. spectral->params[smode].ss_rpt_mode == 2) {
  4434. spectral->rb_edge_extrabins = 4;
  4435. }
  4436. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  4437. spectral->sc_spectral_20_40_mode = 0;
  4438. spectral->spectral_numbins =
  4439. target_if_get_fft_bin_count(
  4440. spectral->params[smode].ss_fft_size);
  4441. spectral->spectral_fft_len =
  4442. target_if_get_fft_bin_count(
  4443. spectral->params[smode].ss_fft_size);
  4444. spectral->spectral_data_len =
  4445. target_if_get_fft_bin_count(
  4446. spectral->params[smode].ss_fft_size);
  4447. /*
  4448. * Initialize classifier params to be sent to user
  4449. * space classifier
  4450. */
  4451. spectral->classifier_params.lower_chan_in_mhz =
  4452. current_channel;
  4453. spectral->classifier_params.upper_chan_in_mhz = 0;
  4454. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  4455. /* TODO : Remove this variable */
  4456. spectral->sc_spectral_20_40_mode = 1;
  4457. spectral->spectral_numbins =
  4458. target_if_get_fft_bin_count(
  4459. spectral->params[smode].ss_fft_size);
  4460. spectral->spectral_fft_len =
  4461. target_if_get_fft_bin_count(
  4462. spectral->params[smode].ss_fft_size);
  4463. spectral->spectral_data_len =
  4464. target_if_get_fft_bin_count(
  4465. spectral->params[smode].ss_fft_size);
  4466. /*
  4467. * Initialize classifier params to be sent to user
  4468. * space classifier
  4469. */
  4470. if (extension_channel < current_channel) {
  4471. spectral->classifier_params.lower_chan_in_mhz =
  4472. extension_channel;
  4473. spectral->classifier_params.upper_chan_in_mhz =
  4474. current_channel;
  4475. } else {
  4476. spectral->classifier_params.lower_chan_in_mhz =
  4477. current_channel;
  4478. spectral->classifier_params.upper_chan_in_mhz =
  4479. extension_channel;
  4480. }
  4481. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  4482. /* Set the FFT Size */
  4483. /* TODO : Remove this variable */
  4484. spectral->sc_spectral_20_40_mode = 0;
  4485. spectral->spectral_numbins =
  4486. target_if_get_fft_bin_count(
  4487. spectral->params[smode].ss_fft_size);
  4488. spectral->spectral_fft_len =
  4489. target_if_get_fft_bin_count(
  4490. spectral->params[smode].ss_fft_size);
  4491. spectral->spectral_data_len =
  4492. target_if_get_fft_bin_count(
  4493. spectral->params[smode].ss_fft_size);
  4494. /*
  4495. * Initialize classifier params to be sent to user
  4496. * space classifier
  4497. */
  4498. spectral->classifier_params.lower_chan_in_mhz =
  4499. current_channel;
  4500. spectral->classifier_params.upper_chan_in_mhz = 0;
  4501. /*
  4502. * Initialize classifier params to be sent to user
  4503. * space classifier
  4504. */
  4505. if (extension_channel < current_channel) {
  4506. spectral->classifier_params.lower_chan_in_mhz =
  4507. extension_channel;
  4508. spectral->classifier_params.upper_chan_in_mhz =
  4509. current_channel;
  4510. } else {
  4511. spectral->classifier_params.lower_chan_in_mhz =
  4512. current_channel;
  4513. spectral->classifier_params.upper_chan_in_mhz =
  4514. extension_channel;
  4515. }
  4516. } else if (is_ch_width_160_or_80p80(
  4517. spectral->ch_width[smode])) {
  4518. /* Set the FFT Size */
  4519. /* The below applies to both 160 and 80+80 cases */
  4520. /* TODO : Remove this variable */
  4521. spectral->sc_spectral_20_40_mode = 0;
  4522. spectral->spectral_numbins =
  4523. target_if_get_fft_bin_count(
  4524. spectral->params[smode].ss_fft_size);
  4525. spectral->spectral_fft_len =
  4526. target_if_get_fft_bin_count(
  4527. spectral->params[smode].ss_fft_size);
  4528. spectral->spectral_data_len =
  4529. target_if_get_fft_bin_count(
  4530. spectral->params[smode].ss_fft_size);
  4531. /*
  4532. * Initialize classifier params to be sent to user
  4533. * space classifier
  4534. */
  4535. spectral->classifier_params.lower_chan_in_mhz =
  4536. current_channel;
  4537. spectral->classifier_params.upper_chan_in_mhz = 0;
  4538. /*
  4539. * Initialize classifier params to be sent to user
  4540. * space classifier
  4541. */
  4542. if (extension_channel < current_channel) {
  4543. spectral->classifier_params.lower_chan_in_mhz =
  4544. extension_channel;
  4545. spectral->classifier_params.upper_chan_in_mhz =
  4546. current_channel;
  4547. } else {
  4548. spectral->classifier_params.lower_chan_in_mhz =
  4549. current_channel;
  4550. spectral->classifier_params.upper_chan_in_mhz =
  4551. extension_channel;
  4552. }
  4553. }
  4554. if (spectral->spectral_numbins) {
  4555. spectral->spectral_numbins +=
  4556. spectral->lb_edge_extrabins;
  4557. spectral->spectral_numbins +=
  4558. spectral->rb_edge_extrabins;
  4559. }
  4560. if (spectral->spectral_fft_len) {
  4561. spectral->spectral_fft_len +=
  4562. spectral->lb_edge_extrabins;
  4563. spectral->spectral_fft_len +=
  4564. spectral->rb_edge_extrabins;
  4565. }
  4566. if (spectral->spectral_data_len) {
  4567. spectral->spectral_data_len +=
  4568. spectral->lb_edge_extrabins;
  4569. spectral->spectral_data_len +=
  4570. spectral->rb_edge_extrabins;
  4571. }
  4572. } else {
  4573. /*
  4574. * The decision to find 20/40 mode is found based on the
  4575. * presence of extension channel
  4576. * instead of channel width, as the channel width can
  4577. * dynamically change
  4578. */
  4579. if (extension_channel == 0) {
  4580. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  4581. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  4582. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  4583. spectral->spectral_data_len =
  4584. SPECTRAL_HT20_TOTAL_DATA_LEN;
  4585. /* only valid in 20-40 mode */
  4586. spectral->spectral_lower_max_index_offset = -1;
  4587. /* only valid in 20-40 mode */
  4588. spectral->spectral_upper_max_index_offset = -1;
  4589. spectral->spectral_max_index_offset =
  4590. spectral->spectral_fft_len + 2;
  4591. spectral->sc_spectral_20_40_mode = 0;
  4592. /*
  4593. * Initialize classifier params to be sent to user
  4594. * space classifier
  4595. */
  4596. spectral->classifier_params.lower_chan_in_mhz =
  4597. current_channel;
  4598. spectral->classifier_params.upper_chan_in_mhz = 0;
  4599. } else {
  4600. spectral->spectral_numbins =
  4601. SPECTRAL_HT40_TOTAL_NUM_BINS;
  4602. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  4603. spectral->spectral_data_len =
  4604. SPECTRAL_HT40_TOTAL_DATA_LEN;
  4605. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  4606. /* only valid in 20 mode */
  4607. spectral->spectral_max_index_offset = -1;
  4608. spectral->spectral_lower_max_index_offset =
  4609. spectral->spectral_fft_len + 2;
  4610. spectral->spectral_upper_max_index_offset =
  4611. spectral->spectral_fft_len + 5;
  4612. spectral->sc_spectral_20_40_mode = 1;
  4613. /*
  4614. * Initialize classifier params to be sent to user
  4615. * space classifier
  4616. */
  4617. if (extension_channel < current_channel) {
  4618. spectral->classifier_params.lower_chan_in_mhz =
  4619. extension_channel;
  4620. spectral->classifier_params.upper_chan_in_mhz =
  4621. current_channel;
  4622. } else {
  4623. spectral->classifier_params.lower_chan_in_mhz =
  4624. current_channel;
  4625. spectral->classifier_params.upper_chan_in_mhz =
  4626. extension_channel;
  4627. }
  4628. }
  4629. }
  4630. spectral->send_single_packet = 0;
  4631. spectral->classifier_params.spectral_20_40_mode =
  4632. spectral->sc_spectral_20_40_mode;
  4633. spectral->classifier_params.spectral_dc_index =
  4634. spectral->spectral_dc_index;
  4635. spectral->spectral_sent_msg = 0;
  4636. spectral->classify_scan = 0;
  4637. spectral->num_spectral_data = 0;
  4638. if (!p_sops->is_spectral_active(spectral, smode)) {
  4639. p_sops->configure_spectral(spectral, spectral_params, smode);
  4640. spectral->rparams.marker[smode].is_valid = false;
  4641. if (spectral->params[smode].ss_count) {
  4642. status = target_if_spectral_finite_scan_init(spectral,
  4643. smode);
  4644. if (QDF_IS_STATUS_ERROR(status)) {
  4645. spectral_err("Failed to init finite scan");
  4646. return 1;
  4647. }
  4648. }
  4649. p_sops->start_spectral_scan(spectral, smode, err);
  4650. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  4651. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  4652. }
  4653. /* get current spectral configuration */
  4654. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  4655. target_if_init_upper_lower_flags(spectral, smode);
  4656. return 0;
  4657. }
  4658. /**
  4659. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  4660. * Agile DFS
  4661. * @psoc: Pointer to psoc
  4662. * @object: Pointer to pdev
  4663. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  4664. *
  4665. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  4666. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  4667. *
  4668. * Return: void
  4669. */
  4670. static void
  4671. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  4672. void *object, void *arg)
  4673. {
  4674. bool *is_aspectral_prohibited = arg;
  4675. struct wlan_objmgr_pdev *cur_pdev = object;
  4676. bool is_agile_precac_enabled_cur_pdev = false;
  4677. bool is_agile_rcac_enabled_cur_pdev = false;
  4678. QDF_STATUS status;
  4679. qdf_assert_always(is_aspectral_prohibited);
  4680. if (*is_aspectral_prohibited)
  4681. return;
  4682. qdf_assert_always(psoc);
  4683. qdf_assert_always(cur_pdev);
  4684. status = ucfg_dfs_get_agile_precac_enable
  4685. (cur_pdev,
  4686. &is_agile_precac_enabled_cur_pdev);
  4687. if (QDF_IS_STATUS_ERROR(status)) {
  4688. spectral_err("Get agile precac failed, prohibiting aSpectral");
  4689. *is_aspectral_prohibited = true;
  4690. return;
  4691. }
  4692. status = ucfg_dfs_get_rcac_enable(cur_pdev,
  4693. &is_agile_rcac_enabled_cur_pdev);
  4694. if (QDF_IS_STATUS_ERROR(status)) {
  4695. spectral_err("Get agile RCAC failed, prohibiting aSpectral");
  4696. *is_aspectral_prohibited = true;
  4697. return;
  4698. }
  4699. if (is_agile_precac_enabled_cur_pdev) {
  4700. spectral_err("aDFS preCAC is in progress on one of the pdevs");
  4701. *is_aspectral_prohibited = true;
  4702. } else if (is_agile_rcac_enabled_cur_pdev) {
  4703. spectral_err("aDFS RCAC is in progress on one of the pdevs");
  4704. *is_aspectral_prohibited = true;
  4705. }
  4706. }
  4707. /**
  4708. * target_if_get_curr_band() - Get current operating band of pdev
  4709. *
  4710. * @pdev: pointer to pdev object
  4711. *
  4712. * API to get current operating band of a given pdev.
  4713. *
  4714. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  4715. */
  4716. static enum reg_wifi_band
  4717. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id)
  4718. {
  4719. struct wlan_objmgr_vdev *vdev;
  4720. int16_t chan_freq;
  4721. enum reg_wifi_band cur_band;
  4722. if (!pdev) {
  4723. spectral_err("pdev is NULL");
  4724. return REG_BAND_UNKNOWN;
  4725. }
  4726. if (vdev_id == WLAN_INVALID_VDEV_ID)
  4727. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  4728. else
  4729. vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, vdev_id,
  4730. WLAN_SPECTRAL_ID);
  4731. if (!vdev) {
  4732. spectral_debug("vdev is NULL");
  4733. return REG_BAND_UNKNOWN;
  4734. }
  4735. chan_freq = target_if_vdev_get_chan_freq(vdev);
  4736. cur_band = wlan_reg_freq_to_band(chan_freq);
  4737. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4738. return cur_band;
  4739. }
  4740. /**
  4741. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  4742. * any of the 5G pdevs
  4743. * @psoc: Pointer to psoc
  4744. * @object: Pointer to pdev
  4745. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  4746. * progress in any 5G pdevs
  4747. *
  4748. * Return: void
  4749. */
  4750. static void
  4751. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  4752. void *object, void *arg)
  4753. {
  4754. enum reg_wifi_band band;
  4755. bool *is_agile_scan_inprog_5g_pdev = arg;
  4756. struct target_if_spectral *spectral;
  4757. struct wlan_objmgr_pdev *cur_pdev = object;
  4758. struct target_if_spectral_ops *p_sops;
  4759. if (*is_agile_scan_inprog_5g_pdev)
  4760. return;
  4761. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  4762. if (!spectral) {
  4763. spectral_err("target if spectral handle is NULL");
  4764. return;
  4765. }
  4766. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4767. band = target_if_get_curr_band(
  4768. cur_pdev, spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE]);
  4769. if (band == REG_BAND_UNKNOWN) {
  4770. spectral_debug("Failed to get current band");
  4771. return;
  4772. }
  4773. if (band == REG_BAND_5G &&
  4774. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  4775. *is_agile_scan_inprog_5g_pdev = true;
  4776. }
  4777. /**
  4778. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  4779. * for current vdev rx chainmask.
  4780. *
  4781. * @spectral: Pointer to Spectral object
  4782. * @is_supported: Pointer to is_supported
  4783. *
  4784. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4785. */
  4786. static QDF_STATUS
  4787. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  4788. bool *is_supported)
  4789. {
  4790. struct wlan_objmgr_vdev *vdev;
  4791. uint8_t vdev_rxchainmask;
  4792. struct wlan_objmgr_psoc *psoc;
  4793. struct wlan_objmgr_pdev *pdev;
  4794. struct target_psoc_info *tgt_psoc_info;
  4795. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  4796. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  4797. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  4798. struct wlan_psoc_host_chainmask_table *table;
  4799. int j;
  4800. uint32_t table_id;
  4801. enum phy_ch_width ch_width;
  4802. uint8_t pdev_id;
  4803. if (!spectral) {
  4804. spectral_err("spectral target if object is null");
  4805. return QDF_STATUS_E_FAILURE;
  4806. }
  4807. if (!is_supported) {
  4808. spectral_err("is supported argument is null");
  4809. return QDF_STATUS_E_FAILURE;
  4810. }
  4811. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  4812. spectral_err("HW Agile mode is not supported up to gen 2");
  4813. return QDF_STATUS_E_FAILURE;
  4814. }
  4815. pdev = spectral->pdev_obj;
  4816. if (!pdev) {
  4817. spectral_err("pdev is null");
  4818. return QDF_STATUS_E_FAILURE;
  4819. }
  4820. psoc = wlan_pdev_get_psoc(pdev);
  4821. if (!psoc) {
  4822. spectral_err("psoc is null");
  4823. return QDF_STATUS_E_FAILURE;
  4824. }
  4825. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  4826. if (!vdev) {
  4827. spectral_err("First vdev is NULL");
  4828. return QDF_STATUS_E_FAILURE;
  4829. }
  4830. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  4831. if (!vdev_rxchainmask) {
  4832. spectral_err("vdev rx chainmask is zero");
  4833. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4834. return QDF_STATUS_E_FAILURE;
  4835. }
  4836. ch_width = target_if_vdev_get_ch_width(vdev);
  4837. if (ch_width == CH_WIDTH_INVALID) {
  4838. spectral_err("Invalid channel width");
  4839. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4840. return QDF_STATUS_E_FAILURE;
  4841. }
  4842. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4843. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  4844. if (!tgt_psoc_info) {
  4845. spectral_err("target_psoc_info is null");
  4846. return QDF_STATUS_E_FAILURE;
  4847. }
  4848. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  4849. if (!ext_svc_param) {
  4850. spectral_err("Extended service ready param null");
  4851. return QDF_STATUS_E_FAILURE;
  4852. }
  4853. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  4854. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  4855. if (!mac_phy_cap_arr) {
  4856. spectral_err("mac phy cap array is null");
  4857. return QDF_STATUS_E_FAILURE;
  4858. }
  4859. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  4860. if (!mac_phy_cap) {
  4861. spectral_err("mac phy cap is null");
  4862. return QDF_STATUS_E_FAILURE;
  4863. }
  4864. table_id = mac_phy_cap->chainmask_table_id;
  4865. table = &ext_svc_param->chainmask_table[table_id];
  4866. if (!table) {
  4867. spectral_err("chainmask table not found");
  4868. return QDF_STATUS_E_FAILURE;
  4869. }
  4870. for (j = 0; j < table->num_valid_chainmasks; j++) {
  4871. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  4872. if (ch_width <= CH_WIDTH_80MHZ)
  4873. *is_supported =
  4874. table->cap_list[j].supports_aSpectral;
  4875. else
  4876. *is_supported =
  4877. table->cap_list[j].supports_aSpectral_160;
  4878. break;
  4879. }
  4880. }
  4881. if (j == table->num_valid_chainmasks) {
  4882. spectral_err("vdev rx chainmask %u not found in table id = %u",
  4883. vdev_rxchainmask, table_id);
  4884. return QDF_STATUS_E_FAILURE;
  4885. }
  4886. return QDF_STATUS_SUCCESS;
  4887. }
  4888. #define INVALID_SPAN_NUM (-1)
  4889. /**
  4890. * target_if_spectral_get_num_spans() - Get number of spans for a given sscan_bw
  4891. * @pdev: Pointer to pdev object
  4892. * @sscan_bw: Spectral scan bandwidth
  4893. *
  4894. * Return: Number of spans on success, INVALID_SPAN_NUM on failure
  4895. */
  4896. static int
  4897. target_if_spectral_get_num_spans(
  4898. struct wlan_objmgr_pdev *pdev,
  4899. enum phy_ch_width sscan_bw)
  4900. {
  4901. struct wlan_objmgr_psoc *psoc;
  4902. int num_spans;
  4903. if (!pdev) {
  4904. spectral_err_rl("pdev is null");
  4905. return INVALID_SPAN_NUM;
  4906. }
  4907. psoc = wlan_pdev_get_psoc(pdev);
  4908. if (!psoc) {
  4909. spectral_err_rl("psoc is null");
  4910. return INVALID_SPAN_NUM;
  4911. }
  4912. if (sscan_bw == CH_WIDTH_80P80MHZ) {
  4913. num_spans = 2;
  4914. if (wlan_psoc_nif_fw_ext_cap_get(
  4915. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  4916. /* 5 MHz frequency span in restricted 80p80 case */
  4917. num_spans += 1;
  4918. } else {
  4919. num_spans = 1;
  4920. }
  4921. return num_spans;
  4922. }
  4923. #ifdef OPTIMIZED_SAMP_MESSAGE
  4924. /**
  4925. * target_if_spectral_populate_session_report_info() - Populate per-session
  4926. * report level information.
  4927. *
  4928. * @spectral: Pointer to Spectral object
  4929. * @smode: Spectral scan mode
  4930. *
  4931. * Return: Success/Failure
  4932. */
  4933. static QDF_STATUS
  4934. target_if_spectral_populate_session_report_info(
  4935. struct target_if_spectral *spectral,
  4936. enum spectral_scan_mode smode)
  4937. {
  4938. struct per_session_report_info *rpt_info;
  4939. if (!spectral) {
  4940. spectral_err_rl("Spectral LMAC object is null");
  4941. return QDF_STATUS_E_NULL_VALUE;
  4942. }
  4943. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  4944. spectral_err_rl("Invalid Spectral scan mode");
  4945. return QDF_STATUS_E_FAILURE;
  4946. }
  4947. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  4948. /* Fill per-session report information, based on the spectral mode */
  4949. rpt_info = &spectral->report_info[smode];
  4950. rpt_info->operating_bw = spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  4951. rpt_info->sscan_bw = spectral->ch_width[smode];
  4952. rpt_info->sscan_cfreq1 = spectral->params[smode].ss_frequency.cfreq1;
  4953. rpt_info->sscan_cfreq2 = spectral->params[smode].ss_frequency.cfreq2;
  4954. rpt_info->num_spans = target_if_spectral_get_num_spans(
  4955. spectral->pdev_obj,
  4956. rpt_info->sscan_bw);
  4957. qdf_assert_always(rpt_info->num_spans != INVALID_SPAN_NUM);
  4958. rpt_info->valid = true;
  4959. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  4960. return QDF_STATUS_SUCCESS;
  4961. }
  4962. /**
  4963. * target_if_spectral_populate_session_det_host_info() - Populate per-session
  4964. * detector level information that is known to the Host
  4965. *
  4966. * @spectral: Pointer to Spectral object
  4967. * @smode: Spectral scan mode
  4968. *
  4969. * Return: Success/Failure
  4970. */
  4971. static QDF_STATUS
  4972. target_if_spectral_populate_session_det_host_info(
  4973. struct target_if_spectral *spectral,
  4974. enum spectral_scan_mode smode)
  4975. {
  4976. struct per_session_report_info *rpt_info;
  4977. struct sscan_detector_list *detector_list;
  4978. struct wlan_objmgr_psoc *psoc;
  4979. uint16_t dest_det_idx = 0;
  4980. uint16_t dest_span_idx = 0;
  4981. bool is_sec80 = false;
  4982. uint8_t det, dest_det;
  4983. if (!spectral) {
  4984. spectral_err_rl("Spectral LMAC object is null");
  4985. return QDF_STATUS_E_NULL_VALUE;
  4986. }
  4987. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  4988. spectral_err_rl("Invalid Spectral scan mode");
  4989. return QDF_STATUS_E_FAILURE;
  4990. }
  4991. if (!spectral->pdev_obj) {
  4992. spectral_err_rl("Spectral PDEV is null");
  4993. return QDF_STATUS_E_NULL_VALUE;
  4994. }
  4995. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  4996. if (!psoc) {
  4997. spectral_err_rl("psoc is null");
  4998. return QDF_STATUS_E_NULL_VALUE;
  4999. }
  5000. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5001. rpt_info = &spectral->report_info[smode];
  5002. qdf_spin_lock_bh(&spectral->detector_list_lock);
  5003. /* Fill per-sesion detector-level information */
  5004. detector_list = &spectral->detector_list[smode][rpt_info->sscan_bw];
  5005. for (det = 0; det < detector_list->num_detectors; det++) {
  5006. struct per_session_det_map *det_map;
  5007. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  5008. det_map = &spectral->det_map[detector_list->detectors[det]];
  5009. if (detector_list->num_detectors > 1) {
  5010. if (det == 0) {
  5011. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  5012. det_map->send_to_upper_layers = false;
  5013. } else if (det == detector_list->num_detectors - 1) {
  5014. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  5015. det_map->send_to_upper_layers = true;
  5016. } else {
  5017. /* middle fragments */
  5018. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  5019. det_map->send_to_upper_layers = false;
  5020. }
  5021. } else {
  5022. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  5023. det_map->send_to_upper_layers = true;
  5024. }
  5025. det_map->num_dest_det_info = 1;
  5026. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ &&
  5027. wlan_psoc_nif_fw_ext_cap_get(
  5028. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  5029. /**
  5030. * In 165MHz case, 1 Spectral HW detector maps to 3
  5031. * detectors in SAMP msg.
  5032. */
  5033. det_map->num_dest_det_info += 2;
  5034. }
  5035. for (dest_det = 0; dest_det < det_map->num_dest_det_info;
  5036. dest_det++) {
  5037. struct per_session_dest_det_info *map_det_info;
  5038. map_det_info = &det_map->dest_det_info[dest_det];
  5039. map_det_info->freq_span_id = dest_span_idx;
  5040. map_det_info->det_id = dest_det_idx;
  5041. map_det_info->is_sec80 = is_sec80;
  5042. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ) {
  5043. /* Increment span ID for non-contiguous modes */
  5044. dest_det_idx = 0;
  5045. dest_span_idx++;
  5046. } else {
  5047. /* Increment detector ID for contiguous modes */
  5048. dest_det_idx++;
  5049. }
  5050. is_sec80 = !is_sec80;
  5051. }
  5052. det_map->det_map_valid[smode] = true;
  5053. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  5054. }
  5055. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  5056. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5057. return QDF_STATUS_SUCCESS;
  5058. }
  5059. #else
  5060. static QDF_STATUS
  5061. target_if_spectral_populate_session_report_info(
  5062. struct target_if_spectral *spectral,
  5063. enum spectral_scan_mode smode)
  5064. {
  5065. return QDF_STATUS_SUCCESS;
  5066. }
  5067. static QDF_STATUS
  5068. target_if_spectral_populate_session_det_host_info(
  5069. struct target_if_spectral *spectral,
  5070. enum spectral_scan_mode smode)
  5071. {
  5072. return QDF_STATUS_SUCCESS;
  5073. }
  5074. #endif /* OPTIMIZED_SAMP_MESSAGE */
  5075. QDF_STATUS
  5076. spectral_is_session_info_expected_from_target(struct wlan_objmgr_pdev *pdev,
  5077. bool *is_session_info_expected)
  5078. {
  5079. struct wlan_objmgr_psoc *psoc;
  5080. struct wmi_unified *wmi_handle;
  5081. if (!pdev) {
  5082. spectral_err("pdev is null");
  5083. return QDF_STATUS_E_NULL_VALUE;
  5084. }
  5085. psoc = wlan_pdev_get_psoc(pdev);
  5086. if (!psoc) {
  5087. spectral_err("psoc is null");
  5088. return QDF_STATUS_E_NULL_VALUE;
  5089. }
  5090. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  5091. if (!wmi_handle) {
  5092. spectral_err("wmi handle is null");
  5093. return QDF_STATUS_E_NULL_VALUE;
  5094. }
  5095. *is_session_info_expected = target_if_spectral_wmi_service_enabled(
  5096. psoc, wmi_handle,
  5097. wmi_service_spectral_session_info_support);
  5098. return QDF_STATUS_SUCCESS;
  5099. }
  5100. QDF_STATUS
  5101. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  5102. uint8_t vdev_id,
  5103. const enum spectral_scan_mode smode,
  5104. enum spectral_cp_error_code *err)
  5105. {
  5106. struct target_if_spectral_ops *p_sops;
  5107. struct target_if_spectral *spectral;
  5108. struct wlan_objmgr_psoc *psoc;
  5109. enum reg_wifi_band band;
  5110. QDF_STATUS ret;
  5111. bool is_session_info_expected;
  5112. if (!err) {
  5113. spectral_err("Error code argument is null");
  5114. QDF_ASSERT(0);
  5115. return QDF_STATUS_E_FAILURE;
  5116. }
  5117. *err = SPECTRAL_SCAN_ERR_INVALID;
  5118. if (!pdev) {
  5119. spectral_err("pdev object is NUll");
  5120. return QDF_STATUS_E_FAILURE;
  5121. }
  5122. psoc = wlan_pdev_get_psoc(pdev);
  5123. if (!psoc) {
  5124. spectral_err("psoc is null");
  5125. return QDF_STATUS_E_FAILURE;
  5126. }
  5127. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5128. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5129. spectral_err("Invalid Spectral mode %u", smode);
  5130. return QDF_STATUS_E_FAILURE;
  5131. }
  5132. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5133. if (!spectral) {
  5134. spectral_err("Spectral LMAC object is NUll");
  5135. return QDF_STATUS_E_FAILURE;
  5136. }
  5137. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5138. if (!p_sops) {
  5139. spectral_err("p_sops is null");
  5140. return QDF_STATUS_E_FAILURE;
  5141. }
  5142. if (p_sops->is_spectral_active(spectral, smode)) {
  5143. spectral_err("spectral in progress in current pdev, mode %d",
  5144. smode);
  5145. return QDF_STATUS_E_FAILURE;
  5146. }
  5147. spectral->vdev_id[smode] = vdev_id;
  5148. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5149. QDF_STATUS status;
  5150. bool is_supported = false;
  5151. status = target_if_is_agile_supported_cur_chmask(spectral,
  5152. &is_supported);
  5153. if (QDF_IS_STATUS_ERROR(status)) {
  5154. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5155. return QDF_STATUS_E_FAILURE;
  5156. }
  5157. if (!is_supported) {
  5158. spectral_err("aSpectral unsupported for cur chainmask");
  5159. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5160. return QDF_STATUS_E_FAILURE;
  5161. }
  5162. }
  5163. band = target_if_get_curr_band(spectral->pdev_obj, vdev_id);
  5164. if (band == REG_BAND_UNKNOWN) {
  5165. spectral_err("Failed to get current band");
  5166. return QDF_STATUS_E_FAILURE;
  5167. }
  5168. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  5169. struct target_psoc_info *tgt_hdl;
  5170. enum wmi_host_hw_mode_config_type mode;
  5171. bool is_agile_scan_inprog_5g_pdev;
  5172. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  5173. if (!tgt_hdl) {
  5174. target_if_err("target_psoc_info is null");
  5175. return QDF_STATUS_E_FAILURE;
  5176. }
  5177. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  5178. switch (mode) {
  5179. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  5180. case WMI_HOST_HW_MODE_SBS:
  5181. case WMI_HOST_HW_MODE_DBS_SBS:
  5182. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  5183. is_agile_scan_inprog_5g_pdev = false;
  5184. wlan_objmgr_iterate_obj_list
  5185. (psoc, WLAN_PDEV_OP,
  5186. target_if_is_agile_scan_active_in_5g,
  5187. &is_agile_scan_inprog_5g_pdev, 0,
  5188. WLAN_SPECTRAL_ID);
  5189. break;
  5190. default:
  5191. is_agile_scan_inprog_5g_pdev = false;
  5192. break;
  5193. }
  5194. if (is_agile_scan_inprog_5g_pdev) {
  5195. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  5196. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5197. return QDF_STATUS_E_FAILURE;
  5198. }
  5199. }
  5200. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5201. bool is_aspectral_prohibited = false;
  5202. QDF_STATUS status;
  5203. status = wlan_objmgr_iterate_obj_list
  5204. (psoc, WLAN_PDEV_OP,
  5205. target_if_is_aspectral_prohibited_by_adfs,
  5206. &is_aspectral_prohibited, 0,
  5207. WLAN_SPECTRAL_ID);
  5208. if (QDF_IS_STATUS_ERROR(status)) {
  5209. spectral_err("Failed to iterate over pdevs");
  5210. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5211. return QDF_STATUS_E_FAILURE;
  5212. }
  5213. if (is_aspectral_prohibited) {
  5214. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5215. return QDF_STATUS_E_FAILURE;
  5216. }
  5217. }
  5218. if (!spectral->params_valid[smode]) {
  5219. target_if_spectral_info_read(spectral,
  5220. smode,
  5221. TARGET_IF_SPECTRAL_INFO_PARAMS,
  5222. &spectral->params[smode],
  5223. sizeof(spectral->params[smode]));
  5224. spectral->params_valid[smode] = true;
  5225. }
  5226. qdf_spin_lock_bh(&spectral->spectral_lock);
  5227. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5228. QDF_STATUS status;
  5229. bool is_overlapping;
  5230. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  5231. enum spectral_scan_mode m;
  5232. enum phy_ch_width op_ch_width;
  5233. enum phy_ch_width agile_ch_width;
  5234. m = SPECTRAL_SCAN_MODE_NORMAL;
  5235. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  5236. ch_width[m] = CH_WIDTH_INVALID;
  5237. status = target_if_spectral_populate_chwidth
  5238. (spectral, ch_width, spectral->params
  5239. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  5240. if (QDF_IS_STATUS_ERROR(status)) {
  5241. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5242. spectral_err("Failed to populate channel width");
  5243. return QDF_STATUS_E_FAILURE;
  5244. }
  5245. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  5246. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  5247. if (!spectral->params[smode].ss_frequency.cfreq1) {
  5248. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  5249. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5250. spectral_err("Agile Spectral cfreq1 is 0");
  5251. return QDF_STATUS_E_FAILURE;
  5252. } else if (agile_ch_width == CH_WIDTH_80P80MHZ &&
  5253. !spectral->params[smode].ss_frequency.cfreq2) {
  5254. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  5255. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5256. spectral_err("Agile Spectral cfreq2 is 0");
  5257. return QDF_STATUS_E_FAILURE;
  5258. }
  5259. status = target_if_is_agile_span_overlap_with_operating_span
  5260. (spectral, ch_width,
  5261. &spectral->params[smode].ss_frequency,
  5262. &is_overlapping);
  5263. if (QDF_IS_STATUS_ERROR(status)) {
  5264. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5265. return QDF_STATUS_E_FAILURE;
  5266. }
  5267. if (is_overlapping) {
  5268. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  5269. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5270. return QDF_STATUS_E_FAILURE;
  5271. }
  5272. }
  5273. /* Populate detectot list first */
  5274. ret = target_if_spectral_detector_list_init(spectral);
  5275. if (QDF_IS_STATUS_ERROR(ret)) {
  5276. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5277. spectral_err("Failed to initialize detector list");
  5278. return ret;
  5279. }
  5280. ret = target_if_spectral_populate_chwidth(
  5281. spectral, spectral->ch_width,
  5282. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  5283. ss_frequency.cfreq2 > 0);
  5284. if (QDF_IS_STATUS_ERROR(ret)) {
  5285. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5286. spectral_err("Failed to get channel widths");
  5287. return ret;
  5288. }
  5289. ret = spectral_is_session_info_expected_from_target(
  5290. spectral->pdev_obj,
  5291. &is_session_info_expected);
  5292. if (QDF_IS_STATUS_ERROR(ret)) {
  5293. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5294. spectral_err("Failed to check if session info is expected");
  5295. return ret;
  5296. }
  5297. /* If FW doesn't send session info, populate it */
  5298. if (!is_session_info_expected) {
  5299. ret = target_if_spectral_populate_session_report_info(spectral,
  5300. smode);
  5301. if (QDF_IS_STATUS_ERROR(ret)) {
  5302. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5303. spectral_err("Failed to populate per-session report info");
  5304. return QDF_STATUS_E_FAILURE;
  5305. }
  5306. ret = target_if_spectral_populate_session_det_host_info(
  5307. spectral, smode);
  5308. if (QDF_IS_STATUS_ERROR(ret)) {
  5309. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5310. spectral_err("Failed to populate per-session detector info");
  5311. return QDF_STATUS_E_FAILURE;
  5312. }
  5313. }
  5314. target_if_spectral_scan_enable_params(spectral,
  5315. &spectral->params[smode], smode,
  5316. err);
  5317. spectral->sscan_width_configured[smode] = false;
  5318. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5319. return QDF_STATUS_SUCCESS;
  5320. }
  5321. QDF_STATUS
  5322. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  5323. const enum spectral_scan_mode smode,
  5324. enum spectral_cp_error_code *err)
  5325. {
  5326. struct target_if_spectral_ops *p_sops;
  5327. struct target_if_spectral *spectral;
  5328. uint8_t det;
  5329. if (!pdev) {
  5330. spectral_err("pdev object is NULL");
  5331. return QDF_STATUS_E_INVAL;
  5332. }
  5333. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  5334. spectral_info("Spectral feature is disabled");
  5335. return QDF_STATUS_COMP_DISABLED;
  5336. }
  5337. if (!err) {
  5338. spectral_err("Error code argument is null");
  5339. QDF_ASSERT(0);
  5340. return QDF_STATUS_E_FAILURE;
  5341. }
  5342. *err = SPECTRAL_SCAN_ERR_INVALID;
  5343. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5344. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5345. spectral_err("Invalid Spectral mode %u", smode);
  5346. return QDF_STATUS_E_FAILURE;
  5347. }
  5348. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5349. if (!spectral) {
  5350. spectral_err("Spectral LMAC object is NUll ");
  5351. return QDF_STATUS_E_FAILURE;
  5352. }
  5353. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5354. qdf_spin_lock_bh(&spectral->spectral_lock);
  5355. p_sops->stop_spectral_scan(spectral, smode);
  5356. if (spectral->classify_scan) {
  5357. /* TODO : Check if this logic is necessary */
  5358. spectral->detects_control_channel = 0;
  5359. spectral->detects_extension_channel = 0;
  5360. spectral->detects_above_dc = 0;
  5361. spectral->detects_below_dc = 0;
  5362. spectral->classify_scan = 0;
  5363. }
  5364. spectral->send_single_packet = 0;
  5365. spectral->sc_spectral_scan = 0;
  5366. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  5367. for (det = 0; det < MAX_DETECTORS_PER_PDEV; det++)
  5368. spectral->det_map[det].det_map_valid[smode] = false;
  5369. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  5370. /* Mark report info as invalid */
  5371. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5372. spectral->report_info[smode].valid = false;
  5373. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5374. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5375. return QDF_STATUS_SUCCESS;
  5376. }
  5377. /**
  5378. * target_if_is_spectral_active() - Get whether Spectral is active
  5379. * @pdev: Pointer to pdev object
  5380. * @smode: Spectral scan mode
  5381. *
  5382. * API to get whether Spectral is active
  5383. *
  5384. * Return: True if Spectral is active, false if Spectral is not active
  5385. */
  5386. bool
  5387. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  5388. const enum spectral_scan_mode smode)
  5389. {
  5390. struct target_if_spectral *spectral = NULL;
  5391. struct target_if_spectral_ops *p_sops = NULL;
  5392. if (!pdev) {
  5393. spectral_err("pdev is null");
  5394. return false;
  5395. }
  5396. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  5397. spectral_info("Spectral feature is disabled");
  5398. return false;
  5399. }
  5400. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5401. if (!spectral) {
  5402. spectral_err("SPECTRAL : Module doesn't exist");
  5403. return false;
  5404. }
  5405. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5406. if (!p_sops) {
  5407. spectral_err("p_sops is null");
  5408. return false;
  5409. }
  5410. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5411. spectral_err("Invalid Spectral mode %u", smode);
  5412. return false;
  5413. }
  5414. return p_sops->is_spectral_active(spectral, smode);
  5415. }
  5416. /**
  5417. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  5418. * @pdev: Pointer to pdev object
  5419. * @smode: Spectral scan mode
  5420. *
  5421. * API to get whether Spectral is enabled
  5422. *
  5423. * Return: True if Spectral is enabled, false if Spectral is not enabled
  5424. */
  5425. bool
  5426. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  5427. enum spectral_scan_mode smode)
  5428. {
  5429. struct target_if_spectral *spectral = NULL;
  5430. struct target_if_spectral_ops *p_sops = NULL;
  5431. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5432. if (!spectral) {
  5433. spectral_err("SPECTRAL : Module doesn't exist");
  5434. return false;
  5435. }
  5436. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5437. if (!p_sops) {
  5438. spectral_err("p_sops is null");
  5439. return false;
  5440. }
  5441. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5442. spectral_err("Invalid Spectral mode %u", smode);
  5443. return false;
  5444. }
  5445. return p_sops->is_spectral_enabled(spectral, smode);
  5446. }
  5447. #ifdef DIRECT_BUF_RX_DEBUG
  5448. /**
  5449. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  5450. * @pdev: Pointer to pdev object
  5451. * @enable: Enable/Disable Spectral DMA ring debug
  5452. *
  5453. * Start/stop Spectral DMA ring debug based on @enable.
  5454. * Also save the state for future use.
  5455. *
  5456. * Return: QDF_STATUS of operation
  5457. */
  5458. static QDF_STATUS
  5459. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  5460. {
  5461. struct target_if_spectral *spectral;
  5462. struct wlan_lmac_if_tx_ops *tx_ops;
  5463. struct wlan_objmgr_psoc *psoc;
  5464. if (!pdev)
  5465. return QDF_STATUS_E_FAILURE;
  5466. psoc = wlan_pdev_get_psoc(pdev);
  5467. if (!psoc) {
  5468. spectral_err("psoc is null");
  5469. return QDF_STATUS_E_INVAL;
  5470. }
  5471. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5472. if (!tx_ops) {
  5473. spectral_err("tx_ops is NULL");
  5474. return QDF_STATUS_E_INVAL;
  5475. }
  5476. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5477. if (!spectral) {
  5478. spectral_err("Spectal LMAC object is NULL");
  5479. return QDF_STATUS_E_INVAL;
  5480. }
  5481. /* Save the state */
  5482. spectral->dbr_ring_debug = enable;
  5483. if (enable)
  5484. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  5485. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  5486. else
  5487. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  5488. pdev, 0);
  5489. return QDF_STATUS_SUCCESS;
  5490. }
  5491. /**
  5492. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  5493. * @pdev: Pointer to pdev object
  5494. * @enable: Enable/Disable Spectral DMA buffer debug
  5495. *
  5496. * Start/stop Spectral DMA buffer debug based on @enable.
  5497. * Also save the state for future use.
  5498. *
  5499. * Return: QDF_STATUS of operation
  5500. */
  5501. static QDF_STATUS
  5502. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  5503. {
  5504. struct target_if_spectral *spectral;
  5505. struct wlan_lmac_if_tx_ops *tx_ops;
  5506. struct wlan_objmgr_psoc *psoc;
  5507. if (!pdev)
  5508. return QDF_STATUS_E_FAILURE;
  5509. psoc = wlan_pdev_get_psoc(pdev);
  5510. if (!psoc) {
  5511. spectral_err("psoc is null");
  5512. return QDF_STATUS_E_INVAL;
  5513. }
  5514. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5515. if (!tx_ops) {
  5516. spectral_err("tx_ops is NULL");
  5517. return QDF_STATUS_E_INVAL;
  5518. }
  5519. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5520. if (!spectral) {
  5521. spectral_err("Spectal LMAC object is NULL");
  5522. return QDF_STATUS_E_INVAL;
  5523. }
  5524. /* Save the state */
  5525. spectral->dbr_buff_debug = enable;
  5526. if (enable)
  5527. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  5528. pdev, 0, MEM_POISON_SIGNATURE);
  5529. else
  5530. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  5531. pdev, 0);
  5532. }
  5533. /**
  5534. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  5535. * debug based on the previous state
  5536. * @pdev: Pointer to pdev object
  5537. *
  5538. * Return: QDF_STATUS of operation
  5539. */
  5540. static QDF_STATUS
  5541. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  5542. {
  5543. struct target_if_spectral *spectral;
  5544. if (!pdev) {
  5545. spectral_err("pdev is NULL!");
  5546. return QDF_STATUS_E_FAILURE;
  5547. }
  5548. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5549. if (!spectral) {
  5550. spectral_err("Spectal LMAC object is NULL");
  5551. return QDF_STATUS_E_INVAL;
  5552. }
  5553. if (spectral->dbr_buff_debug)
  5554. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  5555. else
  5556. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  5557. }
  5558. /**
  5559. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  5560. * debug based on the previous state
  5561. * @pdev: Pointer to pdev object
  5562. *
  5563. * Return: QDF_STATUS of operation
  5564. */
  5565. static QDF_STATUS
  5566. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  5567. {
  5568. struct target_if_spectral *spectral;
  5569. if (!pdev) {
  5570. spectral_err("pdev is NULL!");
  5571. return QDF_STATUS_E_FAILURE;
  5572. }
  5573. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5574. if (!spectral) {
  5575. spectral_err("Spectal LMAC object is NULL");
  5576. return QDF_STATUS_E_INVAL;
  5577. }
  5578. if (spectral->dbr_ring_debug)
  5579. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  5580. else
  5581. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  5582. }
  5583. /**
  5584. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  5585. * @pdev: Pointer to pdev object
  5586. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  5587. * @debug_value: Value to be set for @dma_debug_type
  5588. *
  5589. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  5590. * based on @debug_value
  5591. *
  5592. * Return: QDF_STATUS of operation
  5593. */
  5594. static QDF_STATUS
  5595. target_if_spectral_set_dma_debug(
  5596. struct wlan_objmgr_pdev *pdev,
  5597. enum spectral_dma_debug dma_debug_type,
  5598. bool debug_value)
  5599. {
  5600. struct target_if_spectral_ops *p_sops;
  5601. struct wlan_objmgr_psoc *psoc;
  5602. struct wlan_lmac_if_tx_ops *tx_ops;
  5603. struct target_if_spectral *spectral;
  5604. if (!pdev)
  5605. return QDF_STATUS_E_FAILURE;
  5606. psoc = wlan_pdev_get_psoc(pdev);
  5607. if (!psoc) {
  5608. spectral_err("psoc is null");
  5609. return QDF_STATUS_E_INVAL;
  5610. }
  5611. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5612. if (!tx_ops) {
  5613. spectral_err("tx_ops is NULL");
  5614. return QDF_STATUS_E_FAILURE;
  5615. }
  5616. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  5617. spectral_err("Unable to fetch target type");
  5618. return QDF_STATUS_E_FAILURE;
  5619. }
  5620. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5621. if (!spectral) {
  5622. spectral_err("Spectal LMAC object is NULL");
  5623. return QDF_STATUS_E_INVAL;
  5624. }
  5625. if (spectral->direct_dma_support) {
  5626. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5627. if (p_sops->is_spectral_active(spectral,
  5628. SPECTRAL_SCAN_MODE_NORMAL) ||
  5629. p_sops->is_spectral_active(spectral,
  5630. SPECTRAL_SCAN_MODE_AGILE)) {
  5631. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  5632. return QDF_STATUS_E_FAILURE;
  5633. }
  5634. switch (dma_debug_type) {
  5635. case SPECTRAL_DMA_RING_DEBUG:
  5636. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  5637. break;
  5638. case SPECTRAL_DMA_BUFFER_DEBUG:
  5639. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  5640. break;
  5641. default:
  5642. spectral_err("Unsupported DMA debug type : %d",
  5643. dma_debug_type);
  5644. return QDF_STATUS_E_FAILURE;
  5645. }
  5646. }
  5647. return QDF_STATUS_SUCCESS;
  5648. }
  5649. #endif /* DIRECT_BUF_RX_DEBUG */
  5650. /**
  5651. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  5652. * @pdev: Pointer to pdev object
  5653. *
  5654. * Return: Whether Direct-DMA is supported on this radio
  5655. */
  5656. static bool
  5657. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  5658. {
  5659. struct target_if_spectral *spectral;
  5660. if (!pdev) {
  5661. spectral_err("pdev is NULL!");
  5662. return false;
  5663. }
  5664. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5665. if (!spectral) {
  5666. spectral_err("Spectral LMAC object is NULL");
  5667. return false;
  5668. }
  5669. return spectral->direct_dma_support;
  5670. }
  5671. /**
  5672. * target_if_set_debug_level() - Set debug level for Spectral
  5673. * @pdev: Pointer to pdev object
  5674. * @debug_level: Debug level
  5675. *
  5676. * API to set the debug level for Spectral
  5677. *
  5678. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5679. */
  5680. QDF_STATUS
  5681. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  5682. {
  5683. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  5684. return QDF_STATUS_SUCCESS;
  5685. }
  5686. /**
  5687. * target_if_get_debug_level() - Get debug level for Spectral
  5688. * @pdev: Pointer to pdev object
  5689. *
  5690. * API to get the debug level for Spectral
  5691. *
  5692. * Return: Current debug level
  5693. */
  5694. uint32_t
  5695. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  5696. {
  5697. return spectral_debug_level;
  5698. }
  5699. /**
  5700. * target_if_get_spectral_capinfo() - Get Spectral capability information
  5701. * @pdev: Pointer to pdev object
  5702. * @scaps: Buffer into which data should be copied
  5703. *
  5704. * API to get the spectral capability information
  5705. *
  5706. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5707. */
  5708. QDF_STATUS
  5709. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  5710. struct spectral_caps *scaps)
  5711. {
  5712. struct target_if_spectral *spectral = NULL;
  5713. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5714. if (!spectral) {
  5715. spectral_err("SPECTRAL : Module doesn't exist");
  5716. return QDF_STATUS_E_FAILURE;
  5717. }
  5718. qdf_mem_copy(scaps, &spectral->capability,
  5719. sizeof(struct spectral_caps));
  5720. return QDF_STATUS_SUCCESS;
  5721. }
  5722. /**
  5723. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  5724. * @pdev: Pointer to pdev object
  5725. * @stats: Buffer into which data should be copied
  5726. *
  5727. * API to get the spectral diagnostic statistics
  5728. *
  5729. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5730. */
  5731. QDF_STATUS
  5732. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  5733. struct spectral_diag_stats *stats)
  5734. {
  5735. struct target_if_spectral *spectral = NULL;
  5736. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5737. if (!spectral) {
  5738. spectral_err("SPECTRAL : Module doesn't exist");
  5739. return QDF_STATUS_E_FAILURE;
  5740. }
  5741. qdf_mem_copy(stats, &spectral->diag_stats,
  5742. sizeof(struct spectral_diag_stats));
  5743. return QDF_STATUS_SUCCESS;
  5744. }
  5745. /**
  5746. * target_if_register_spectral_wmi_ops() - Register Spectral WMI operations
  5747. * @psoc: Pointer to psoc object
  5748. * @wmi_ops: Pointer to the structure having Spectral WMI operations
  5749. *
  5750. * API for registering Spectral WMI operations in
  5751. * spectral internal data structure
  5752. *
  5753. * Return: QDF_STATUS
  5754. */
  5755. static QDF_STATUS
  5756. target_if_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
  5757. struct spectral_wmi_ops *wmi_ops)
  5758. {
  5759. struct target_if_psoc_spectral *psoc_spectral;
  5760. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5761. if (!psoc_spectral) {
  5762. spectral_err("Spectral LMAC object is null");
  5763. return QDF_STATUS_E_INVAL;
  5764. }
  5765. psoc_spectral->wmi_ops = *wmi_ops;
  5766. return QDF_STATUS_SUCCESS;
  5767. }
  5768. /**
  5769. * target_if_register_spectral_tgt_ops() - Register Spectral target operations
  5770. * @psoc: Pointer to psoc object
  5771. * @tgt_ops: Pointer to the structure having Spectral target operations
  5772. *
  5773. * API for registering Spectral target operations in
  5774. * spectral internal data structure
  5775. *
  5776. * Return: QDF_STATUS
  5777. */
  5778. static QDF_STATUS
  5779. target_if_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
  5780. struct spectral_tgt_ops *tgt_ops)
  5781. {
  5782. if (!psoc) {
  5783. spectral_err("psoc is null");
  5784. return QDF_STATUS_E_INVAL;
  5785. }
  5786. ops_tgt = *tgt_ops;
  5787. return QDF_STATUS_SUCCESS;
  5788. }
  5789. /**
  5790. * target_if_register_netlink_cb() - Register Netlink callbacks
  5791. * @pdev: Pointer to pdev object
  5792. * @nl_cb: Netlink callbacks to register
  5793. *
  5794. * Return: void
  5795. */
  5796. static void
  5797. target_if_register_netlink_cb(
  5798. struct wlan_objmgr_pdev *pdev,
  5799. struct spectral_nl_cb *nl_cb)
  5800. {
  5801. struct target_if_spectral *spectral = NULL;
  5802. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5803. if (!spectral) {
  5804. spectral_err("SPECTRAL : Module doesn't exist");
  5805. return;
  5806. }
  5807. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  5808. if (spectral->use_nl_bcast)
  5809. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  5810. else
  5811. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  5812. }
  5813. /**
  5814. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  5815. * Netlink messages to the application layer
  5816. * @pdev: Pointer to pdev object
  5817. *
  5818. * Return: true for broadcast, false for unicast
  5819. */
  5820. static bool
  5821. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  5822. {
  5823. struct target_if_spectral *spectral = NULL;
  5824. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5825. if (!spectral) {
  5826. spectral_err("SPECTRAL : Module doesn't exist");
  5827. return false;
  5828. }
  5829. return spectral->use_nl_bcast;
  5830. }
  5831. /**
  5832. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  5833. * @pdev: Pointer to pdev object
  5834. *
  5835. * Return: void
  5836. */
  5837. static void
  5838. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  5839. {
  5840. struct target_if_spectral *spectral = NULL;
  5841. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5842. if (!spectral) {
  5843. spectral_err("SPECTRAL : Module doesn't exist");
  5844. return;
  5845. }
  5846. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  5847. }
  5848. static int
  5849. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  5850. void *payload)
  5851. {
  5852. struct target_if_spectral *spectral = NULL;
  5853. struct target_if_spectral_ops *p_sops = NULL;
  5854. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5855. if (!spectral) {
  5856. spectral_err("SPECTRAL : Module doesn't exist");
  5857. return -EPERM;
  5858. }
  5859. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5860. if (!p_sops) {
  5861. spectral_err("p_sops is null");
  5862. return -EPERM;
  5863. }
  5864. return p_sops->process_spectral_report(pdev, payload);
  5865. }
  5866. #ifdef DIRECT_BUF_RX_DEBUG
  5867. static inline void
  5868. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5869. {
  5870. if (!tx_ops) {
  5871. spectral_err("tx_ops is NULL");
  5872. return;
  5873. }
  5874. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  5875. target_if_spectral_set_dma_debug;
  5876. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  5877. target_if_spectral_check_and_do_dbr_ring_debug;
  5878. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  5879. target_if_spectral_check_and_do_dbr_buff_debug;
  5880. }
  5881. #else
  5882. static inline void
  5883. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5884. {
  5885. }
  5886. #endif
  5887. #if defined(WLAN_CONV_SPECTRAL_ENABLE) && defined(SPECTRAL_MODULIZED_ENABLE)
  5888. /**
  5889. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  5890. * register WMI event handler
  5891. * @psoc: Pointer to psoc object
  5892. * @event_id: Event id
  5893. * @handler_func: Handler function
  5894. * @rx_ctx: Context of WMI event processing
  5895. *
  5896. * Wrapper function to register WMI event handler
  5897. *
  5898. * Return: 0 for success else failure
  5899. */
  5900. static int
  5901. target_if_spectral_wmi_unified_register_event_handler(
  5902. struct wlan_objmgr_psoc *psoc,
  5903. wmi_conv_event_id event_id,
  5904. wmi_unified_event_handler handler_func,
  5905. uint8_t rx_ctx)
  5906. {
  5907. wmi_unified_t wmi_handle;
  5908. struct target_if_psoc_spectral *psoc_spectral;
  5909. QDF_STATUS ret;
  5910. if (!psoc) {
  5911. spectral_err("psoc is null");
  5912. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5913. }
  5914. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5915. if (!wmi_handle) {
  5916. spectral_err("WMI handle is null");
  5917. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5918. }
  5919. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5920. if (!psoc_spectral) {
  5921. spectral_err("spectral object is null");
  5922. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5923. }
  5924. ret = psoc_spectral->wmi_ops.wmi_unified_register_event_handler(
  5925. wmi_handle, event_id, handler_func, rx_ctx);
  5926. return qdf_status_to_os_return(ret);
  5927. }
  5928. /**
  5929. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  5930. * to unregister WMI event handler
  5931. * @psoc: Pointer to psoc object
  5932. * @event_id: Event id
  5933. *
  5934. * Wrapper function to unregister WMI event handler
  5935. *
  5936. * Return: 0 for success else failure
  5937. */
  5938. static int
  5939. target_if_spectral_wmi_unified_unregister_event_handler(
  5940. struct wlan_objmgr_psoc *psoc,
  5941. wmi_conv_event_id event_id)
  5942. {
  5943. wmi_unified_t wmi_handle;
  5944. struct target_if_psoc_spectral *psoc_spectral;
  5945. QDF_STATUS ret;
  5946. if (!psoc) {
  5947. spectral_err("psoc is null");
  5948. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5949. }
  5950. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5951. if (!wmi_handle) {
  5952. spectral_err("WMI handle is null");
  5953. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5954. }
  5955. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5956. if (!psoc_spectral) {
  5957. spectral_err("spectral object is null");
  5958. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5959. }
  5960. ret = psoc_spectral->wmi_ops.wmi_unified_unregister_event_handler(
  5961. wmi_handle, event_id);
  5962. return qdf_status_to_os_return(ret);
  5963. }
  5964. /**
  5965. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  5966. * function to extract fixed parameters from start scan response event
  5967. * @psoc: Pointer to psoc object
  5968. * @evt_buf: Event buffer
  5969. * @param: Start scan response parameters
  5970. *
  5971. * Wrapper function to extract fixed parameters from start scan response event
  5972. *
  5973. * Return: QDF_STATUS
  5974. */
  5975. static QDF_STATUS
  5976. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  5977. struct wlan_objmgr_psoc *psoc,
  5978. uint8_t *evt_buf,
  5979. struct spectral_startscan_resp_params *param)
  5980. {
  5981. wmi_unified_t wmi_handle;
  5982. struct target_if_psoc_spectral *psoc_spectral;
  5983. if (!psoc) {
  5984. spectral_err("psoc is null");
  5985. return QDF_STATUS_E_INVAL;
  5986. }
  5987. if (!evt_buf) {
  5988. spectral_err("WMI event buffer is null");
  5989. return QDF_STATUS_E_INVAL;
  5990. }
  5991. if (!param) {
  5992. spectral_err("Spectral startscan response parameters is null");
  5993. return QDF_STATUS_E_INVAL;
  5994. }
  5995. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5996. if (!wmi_handle) {
  5997. spectral_err("WMI handle is null");
  5998. return QDF_STATUS_E_INVAL;
  5999. }
  6000. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6001. if (!psoc_spectral) {
  6002. spectral_err("spectral object is null");
  6003. return QDF_STATUS_E_FAILURE;
  6004. }
  6005. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6006. wmi_handle, evt_buf, param);
  6007. }
  6008. /**
  6009. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  6010. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  6011. * secondary 80 MHz FFT bins
  6012. * @psoc: Pointer to psoc object
  6013. * @evt_buf: Event buffer
  6014. * @param: FFT bin start and end indices
  6015. *
  6016. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  6017. * and secondary 80 MHz FFT bins
  6018. *
  6019. * Return: QDF_STATUS
  6020. */
  6021. static QDF_STATUS
  6022. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6023. struct wlan_objmgr_psoc *psoc,
  6024. uint8_t *evt_buf,
  6025. struct spectral_fft_bin_markers_160_165mhz *param)
  6026. {
  6027. wmi_unified_t wmi_handle;
  6028. struct target_if_psoc_spectral *psoc_spectral;
  6029. if (!psoc) {
  6030. spectral_err("psoc is null");
  6031. return QDF_STATUS_E_INVAL;
  6032. }
  6033. if (!evt_buf) {
  6034. spectral_err("WMI event buffer is null");
  6035. return QDF_STATUS_E_INVAL;
  6036. }
  6037. if (!param) {
  6038. spectral_err("Spectral FFT bin markers is null");
  6039. return QDF_STATUS_E_INVAL;
  6040. }
  6041. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6042. if (!wmi_handle) {
  6043. spectral_err("WMI handle is null");
  6044. return QDF_STATUS_E_INVAL;
  6045. }
  6046. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6047. if (!psoc_spectral) {
  6048. spectral_err("spectral object is null");
  6049. return QDF_STATUS_E_FAILURE;
  6050. }
  6051. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fft_bin_index(
  6052. wmi_handle, evt_buf, param);
  6053. }
  6054. /**
  6055. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  6056. * object from scn handle
  6057. * @scn: scn handle
  6058. *
  6059. * Wrapper function to get psoc object from scn handle
  6060. *
  6061. * Return: Pointer to psoc object
  6062. */
  6063. static struct wlan_objmgr_psoc *
  6064. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  6065. {
  6066. if (!scn) {
  6067. spectral_err("scn is null");
  6068. return NULL;
  6069. }
  6070. return ops_tgt.tgt_get_psoc_from_scn_hdl(scn);
  6071. }
  6072. /**
  6073. * target_if_extract_pdev_spectral_session_chan_info() - Wrapper
  6074. * function to extract channel information for a spectral scan session
  6075. * @psoc: Pointer to psoc object
  6076. * @evt_buf: Event buffer
  6077. * @chan_info: Spectral session channel information data structure to be filled
  6078. * by this API
  6079. *
  6080. * Return: QDF_STATUS of operation
  6081. */
  6082. static QDF_STATUS
  6083. target_if_extract_pdev_spectral_session_chan_info(
  6084. struct wlan_objmgr_psoc *psoc,
  6085. void *evt_buf,
  6086. struct spectral_session_chan_info *chan_info)
  6087. {
  6088. wmi_unified_t wmi_handle;
  6089. struct target_if_psoc_spectral *psoc_spectral;
  6090. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6091. if (!wmi_handle) {
  6092. spectral_err("WMI handle is null");
  6093. return QDF_STATUS_E_NULL_VALUE;
  6094. }
  6095. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6096. if (!psoc_spectral) {
  6097. spectral_err("spectral object is null");
  6098. return QDF_STATUS_E_NULL_VALUE;
  6099. }
  6100. return psoc_spectral->wmi_ops.extract_pdev_spectral_session_chan_info(
  6101. wmi_handle, evt_buf, chan_info);
  6102. }
  6103. /**
  6104. * target_if_extract_pdev_spectral_session_detector_info() - Wrapper
  6105. * function to extract detector information for a spectral scan session
  6106. * @psoc: Pointer to psoc object
  6107. * @evt_buf: Event buffer
  6108. * @det_info: Spectral session detector information data structure to be filled
  6109. * by this API
  6110. * @det_info_idx: index in the array of spectral scan detector info TLVs
  6111. *
  6112. * Return: QDF_STATUS of operation
  6113. */
  6114. static QDF_STATUS
  6115. target_if_extract_pdev_spectral_session_detector_info(
  6116. struct wlan_objmgr_psoc *psoc, void *evt_buf,
  6117. struct spectral_session_det_info *det_info,
  6118. uint8_t det_info_idx)
  6119. {
  6120. wmi_unified_t wmi_handle;
  6121. struct target_if_psoc_spectral *psoc_spectral;
  6122. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6123. if (!wmi_handle) {
  6124. spectral_err("WMI handle is null");
  6125. return QDF_STATUS_E_NULL_VALUE;
  6126. }
  6127. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6128. if (!psoc_spectral) {
  6129. spectral_err("spectral object is null");
  6130. return QDF_STATUS_E_NULL_VALUE;
  6131. }
  6132. return psoc_spectral->wmi_ops.
  6133. extract_pdev_spectral_session_detector_info(
  6134. wmi_handle, evt_buf, det_info, det_info_idx);
  6135. }
  6136. /**
  6137. * target_if_wmi_extract_spectral_caps_fixed_param() - Wrapper function to
  6138. * extract fixed params from Spectral capabilities WMI event
  6139. * @psoc: Pointer to psoc object
  6140. * @evt_buf: Event buffer
  6141. * @param: Spectral capabilities event parameters data structure to be filled
  6142. * by this API
  6143. *
  6144. * Return: QDF_STATUS of operation
  6145. */
  6146. QDF_STATUS
  6147. target_if_wmi_extract_spectral_caps_fixed_param(
  6148. struct wlan_objmgr_psoc *psoc,
  6149. uint8_t *evt_buf,
  6150. struct spectral_capabilities_event_params *param)
  6151. {
  6152. struct target_if_psoc_spectral *psoc_spectral;
  6153. wmi_unified_t wmi_handle;
  6154. if (!psoc) {
  6155. spectral_err("psoc is null");
  6156. return QDF_STATUS_E_NULL_VALUE;
  6157. }
  6158. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6159. if (!wmi_handle) {
  6160. spectral_err("WMI handle is null");
  6161. return QDF_STATUS_E_NULL_VALUE;
  6162. }
  6163. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6164. if (!psoc_spectral) {
  6165. spectral_err("spectral object is null");
  6166. return QDF_STATUS_E_FAILURE;
  6167. }
  6168. return psoc_spectral->wmi_ops.extract_spectral_caps_fixed_param(
  6169. wmi_handle, evt_buf, param);
  6170. }
  6171. /**
  6172. * target_if_wmi_extract_spectral_scan_bw_caps() - Wrapper function to
  6173. * extract bandwidth capabilities from Spectral capabilities WMI event
  6174. * @psoc: Pointer to psoc object
  6175. * @evt_buf: Event buffer
  6176. * @bw_caps: Data structure to be filled by this API after extraction
  6177. *
  6178. * Return: QDF_STATUS of operation
  6179. */
  6180. QDF_STATUS
  6181. target_if_wmi_extract_spectral_scan_bw_caps(
  6182. struct wlan_objmgr_psoc *psoc,
  6183. uint8_t *evt_buf,
  6184. struct spectral_scan_bw_capabilities *bw_caps)
  6185. {
  6186. struct target_if_psoc_spectral *psoc_spectral;
  6187. wmi_unified_t wmi_handle;
  6188. if (!psoc) {
  6189. spectral_err("psoc is null");
  6190. return QDF_STATUS_E_INVAL;
  6191. }
  6192. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6193. if (!wmi_handle) {
  6194. spectral_err("WMI handle is null");
  6195. return QDF_STATUS_E_INVAL;
  6196. }
  6197. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6198. if (!psoc_spectral) {
  6199. spectral_err("spectral object is null");
  6200. return QDF_STATUS_E_FAILURE;
  6201. }
  6202. return psoc_spectral->wmi_ops.extract_spectral_scan_bw_caps(
  6203. wmi_handle, evt_buf, bw_caps);
  6204. }
  6205. /**
  6206. * target_if_wmi_extract_spectral_fft_size_caps() - Wrapper function to
  6207. * extract fft size capabilities from Spectral capabilities WMI event
  6208. * @psoc: Pointer to psoc object
  6209. * @evt_buf: Event buffer
  6210. * @fft_size_caps: Data structure to be filled by this API after extraction
  6211. *
  6212. * Return: QDF_STATUS of operation
  6213. */
  6214. QDF_STATUS
  6215. target_if_wmi_extract_spectral_fft_size_caps(
  6216. struct wlan_objmgr_psoc *psoc,
  6217. uint8_t *evt_buf,
  6218. struct spectral_fft_size_capabilities *fft_size_caps)
  6219. {
  6220. struct target_if_psoc_spectral *psoc_spectral;
  6221. wmi_unified_t wmi_handle;
  6222. if (!psoc) {
  6223. spectral_err("psoc is null");
  6224. return QDF_STATUS_E_INVAL;
  6225. }
  6226. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6227. if (!wmi_handle) {
  6228. spectral_err("WMI handle is null");
  6229. return QDF_STATUS_E_INVAL;
  6230. }
  6231. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6232. if (!psoc_spectral) {
  6233. spectral_err("spectral object is null");
  6234. return QDF_STATUS_E_FAILURE;
  6235. }
  6236. return psoc_spectral->wmi_ops.extract_spectral_fft_size_caps(
  6237. wmi_handle, evt_buf, fft_size_caps);
  6238. }
  6239. #else
  6240. /**
  6241. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  6242. * register WMI event handler
  6243. * @psoc: Pointer to psoc object
  6244. * @event_id: Event id
  6245. * @handler_func: Handler function
  6246. * @rx_ctx: Context of WMI event processing
  6247. *
  6248. * Wrapper function to register WMI event handler
  6249. *
  6250. * Return: 0 for success else failure
  6251. */
  6252. static int
  6253. target_if_spectral_wmi_unified_register_event_handler(
  6254. struct wlan_objmgr_psoc *psoc,
  6255. wmi_conv_event_id event_id,
  6256. wmi_unified_event_handler handler_func,
  6257. uint8_t rx_ctx)
  6258. {
  6259. wmi_unified_t wmi_handle;
  6260. QDF_STATUS ret;
  6261. if (!psoc) {
  6262. spectral_err("psoc is null");
  6263. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6264. }
  6265. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6266. if (!wmi_handle) {
  6267. spectral_err("WMI handle is null");
  6268. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6269. }
  6270. ret = wmi_unified_register_event_handler(wmi_handle, event_id,
  6271. handler_func, rx_ctx);
  6272. return qdf_status_to_os_return(ret);
  6273. }
  6274. /**
  6275. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  6276. * to unregister WMI event handler
  6277. * @psoc: Pointer to psoc object
  6278. * @event_id: Event id
  6279. *
  6280. * Wrapper function to unregister WMI event handler
  6281. *
  6282. * Return: 0 for success else failure
  6283. */
  6284. static int
  6285. target_if_spectral_wmi_unified_unregister_event_handler(
  6286. struct wlan_objmgr_psoc *psoc,
  6287. wmi_conv_event_id event_id)
  6288. {
  6289. wmi_unified_t wmi_handle;
  6290. QDF_STATUS ret;
  6291. if (!psoc) {
  6292. spectral_err("psoc is null");
  6293. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6294. }
  6295. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6296. if (!wmi_handle) {
  6297. spectral_err("WMI handle is null");
  6298. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6299. }
  6300. ret = wmi_unified_unregister_event_handler(wmi_handle, event_id);
  6301. return qdf_status_to_os_return(ret);
  6302. }
  6303. /**
  6304. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  6305. * function to extract fixed parameters from start scan response event
  6306. * @psoc: Pointer to psoc object
  6307. * @evt_buf: Event buffer
  6308. * @param: Start scan response parameters
  6309. *
  6310. * Wrapper function to extract fixed parameters from start scan response event
  6311. *
  6312. * Return: QDF_STATUS
  6313. */
  6314. static QDF_STATUS
  6315. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6316. struct wlan_objmgr_psoc *psoc,
  6317. uint8_t *evt_buf,
  6318. struct spectral_startscan_resp_params *param)
  6319. {
  6320. wmi_unified_t wmi_handle;
  6321. if (!psoc) {
  6322. spectral_err("psoc is null");
  6323. return QDF_STATUS_E_INVAL;
  6324. }
  6325. if (!evt_buf) {
  6326. spectral_err("WMI event buffer is null");
  6327. return QDF_STATUS_E_INVAL;
  6328. }
  6329. if (!param) {
  6330. spectral_err("Spectral startscan response parameters is null");
  6331. return QDF_STATUS_E_INVAL;
  6332. }
  6333. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6334. if (!wmi_handle) {
  6335. spectral_err("WMI handle is null");
  6336. return QDF_STATUS_E_INVAL;
  6337. }
  6338. return wmi_extract_pdev_sscan_fw_cmd_fixed_param(wmi_handle, evt_buf,
  6339. param);
  6340. }
  6341. /**
  6342. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  6343. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  6344. * secondary 80 MHz FFT bins
  6345. * @psoc: Pointer to psoc object
  6346. * @evt_buf: Event buffer
  6347. * @param: FFT bin start and end indices
  6348. *
  6349. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  6350. * and secondary 80 MHz FFT bins
  6351. *
  6352. * Return: QDF_STATUS
  6353. */
  6354. static QDF_STATUS
  6355. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6356. struct wlan_objmgr_psoc *psoc,
  6357. uint8_t *evt_buf,
  6358. struct spectral_fft_bin_markers_160_165mhz *param)
  6359. {
  6360. wmi_unified_t wmi_handle;
  6361. if (!psoc) {
  6362. spectral_err("psoc is null");
  6363. return QDF_STATUS_E_INVAL;
  6364. }
  6365. if (!evt_buf) {
  6366. spectral_err("WMI event buffer is null");
  6367. return QDF_STATUS_E_INVAL;
  6368. }
  6369. if (!param) {
  6370. spectral_err("Spectral FFT bin markers is null");
  6371. return QDF_STATUS_E_INVAL;
  6372. }
  6373. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6374. if (!wmi_handle) {
  6375. spectral_err("WMI handle is null");
  6376. return QDF_STATUS_E_INVAL;
  6377. }
  6378. return wmi_extract_pdev_sscan_fft_bin_index(wmi_handle, evt_buf, param);
  6379. }
  6380. /**
  6381. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  6382. * object from scn handle
  6383. * @scn: scn handle
  6384. *
  6385. * Wrapper function to get psoc object from scn handle
  6386. *
  6387. * Return: Pointer to psoc object
  6388. */
  6389. static struct wlan_objmgr_psoc *
  6390. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  6391. {
  6392. if (!scn) {
  6393. spectral_err("scn is null");
  6394. return NULL;
  6395. }
  6396. return target_if_get_psoc_from_scn_hdl(scn);
  6397. }
  6398. /**
  6399. * target_if_extract_pdev_spectral_session_chan_info() - Wrapper
  6400. * function to extract channel information for a spectral scan session
  6401. * @psoc: Pointer to psoc object
  6402. * @evt_buf: Event buffer
  6403. * @chan_info: Spectral session channel information data structure to be fille
  6404. * by this API
  6405. *
  6406. * Return: QDF_STATUS of operation
  6407. */
  6408. static QDF_STATUS
  6409. target_if_extract_pdev_spectral_session_chan_info(
  6410. struct wlan_objmgr_psoc *psoc,
  6411. void *evt_buf,
  6412. struct spectral_session_chan_info *chan_info)
  6413. {
  6414. wmi_unified_t wmi_handle;
  6415. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6416. if (!wmi_handle) {
  6417. spectral_err("WMI handle is null");
  6418. return QDF_STATUS_E_NULL_VALUE;
  6419. }
  6420. return wmi_extract_pdev_spectral_session_chan_info(
  6421. wmi_handle, evt_buf, chan_info);
  6422. }
  6423. /**
  6424. * target_if_extract_pdev_spectral_session_detector_info() - Wrapper
  6425. * function to extract detector information for a spectral scan session
  6426. * @psoc: Pointer to psoc object
  6427. * @evt_buf: Event buffer
  6428. * @det_info: Spectral session detector information data structure to be filled
  6429. * by this API
  6430. * @det_info_idx: index in the array of spectral scan detector info TLVs
  6431. *
  6432. * Return: QDF_STATUS of operation
  6433. */
  6434. static QDF_STATUS
  6435. target_if_extract_pdev_spectral_session_detector_info(
  6436. struct wlan_objmgr_psoc *psoc, void *evt_buf,
  6437. struct spectral_session_det_info *det_info,
  6438. uint8_t det_info_idx)
  6439. {
  6440. wmi_unified_t wmi_handle;
  6441. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6442. if (!wmi_handle) {
  6443. spectral_err("WMI handle is null");
  6444. return QDF_STATUS_E_NULL_VALUE;
  6445. }
  6446. return wmi_extract_pdev_spectral_session_detector_info(
  6447. wmi_handle, evt_buf, det_info, det_info_idx);
  6448. }
  6449. QDF_STATUS
  6450. target_if_wmi_extract_spectral_caps_fixed_param(
  6451. struct wlan_objmgr_psoc *psoc,
  6452. uint8_t *evt_buf,
  6453. struct spectral_capabilities_event_params *param)
  6454. {
  6455. wmi_unified_t wmi_handle;
  6456. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6457. if (!wmi_handle) {
  6458. spectral_err("WMI handle is null");
  6459. return QDF_STATUS_E_INVAL;
  6460. }
  6461. return wmi_extract_spectral_caps_fixed_param(wmi_handle, evt_buf,
  6462. param);
  6463. }
  6464. QDF_STATUS
  6465. target_if_wmi_extract_spectral_scan_bw_caps(
  6466. struct wlan_objmgr_psoc *psoc,
  6467. uint8_t *evt_buf,
  6468. struct spectral_scan_bw_capabilities *bw_caps)
  6469. {
  6470. wmi_unified_t wmi_handle;
  6471. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6472. if (!wmi_handle) {
  6473. spectral_err("WMI handle is null");
  6474. return QDF_STATUS_E_INVAL;
  6475. }
  6476. return wmi_extract_spectral_scan_bw_caps(wmi_handle, evt_buf, bw_caps);
  6477. }
  6478. QDF_STATUS
  6479. target_if_wmi_extract_spectral_fft_size_caps(
  6480. struct wlan_objmgr_psoc *psoc,
  6481. uint8_t *evt_buf,
  6482. struct spectral_fft_size_capabilities *fft_size_caps)
  6483. {
  6484. wmi_unified_t wmi_handle;
  6485. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6486. if (!wmi_handle) {
  6487. spectral_err("WMI handle is null");
  6488. return QDF_STATUS_E_INVAL;
  6489. }
  6490. return wmi_extract_spectral_fft_size_caps(wmi_handle, evt_buf,
  6491. fft_size_caps);
  6492. }
  6493. #endif
  6494. /**
  6495. * target_if_update_det_info_in_spectral_session() - Update detector
  6496. * information in spectral scan session
  6497. * @spectral: Spectral LMAC object
  6498. * @det_info: Pointer to spectral session detector information
  6499. *
  6500. * Return: QDF_STATUS of operation
  6501. */
  6502. static QDF_STATUS
  6503. target_if_update_det_info_in_spectral_session(
  6504. struct target_if_spectral *spectral,
  6505. const struct spectral_session_det_info *det_info)
  6506. {
  6507. struct per_session_det_map *det_map;
  6508. struct per_session_dest_det_info *dest_det_info;
  6509. if (!spectral) {
  6510. spectral_err_rl("Spectral LMAC object is null");
  6511. return QDF_STATUS_E_NULL_VALUE;
  6512. }
  6513. qdf_assert_always(det_info->det_id < MAX_DETECTORS_PER_PDEV);
  6514. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  6515. det_map = &spectral->det_map[det_info->det_id];
  6516. dest_det_info = &det_map->dest_det_info[0];
  6517. dest_det_info->start_freq = det_info->start_freq;
  6518. dest_det_info->end_freq = det_info->end_freq;
  6519. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  6520. return QDF_STATUS_SUCCESS;
  6521. }
  6522. /**
  6523. * target_if_update_chan_info_in_spectral_session() - Update channel information
  6524. * in spectral scan session
  6525. * @spectral: Spectral LMAC object
  6526. * @chan_info: Pointer to spectral session channel information
  6527. * @smode: Spectral scan mode
  6528. *
  6529. * Return: QDF_STATUS of operation
  6530. */
  6531. static QDF_STATUS
  6532. target_if_update_chan_info_in_spectral_session(
  6533. struct target_if_spectral *spectral,
  6534. const struct spectral_session_chan_info *chan_info,
  6535. enum spectral_scan_mode smode)
  6536. {
  6537. struct per_session_report_info *rpt_info;
  6538. if (!spectral) {
  6539. spectral_err_rl("Spectral LMAC object is null");
  6540. return QDF_STATUS_E_NULL_VALUE;
  6541. }
  6542. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6543. spectral_err_rl("Invalid Spectral scan mode :%u", smode);
  6544. return QDF_STATUS_E_FAILURE;
  6545. }
  6546. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  6547. rpt_info = &spectral->report_info[smode];
  6548. /* Update per-session report info */
  6549. rpt_info->pri20_freq = chan_info->operating_pri20_freq;
  6550. rpt_info->cfreq1 = chan_info->operating_cfreq1;
  6551. rpt_info->cfreq2 = chan_info->operating_cfreq2;
  6552. rpt_info->operating_bw = chan_info->operating_bw;
  6553. rpt_info->sscan_cfreq1 = chan_info->sscan_cfreq1;
  6554. rpt_info->sscan_cfreq2 = chan_info->sscan_cfreq2;
  6555. rpt_info->sscan_bw = chan_info->sscan_bw;
  6556. /* num_spans depends on sscan_bw, update it */
  6557. rpt_info->num_spans = target_if_spectral_get_num_spans(
  6558. spectral->pdev_obj,
  6559. rpt_info->sscan_bw);
  6560. qdf_assert_always(rpt_info->num_spans != INVALID_SPAN_NUM);
  6561. rpt_info->valid = true;
  6562. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  6563. return QDF_STATUS_SUCCESS;
  6564. }
  6565. /**
  6566. * target_if_spectral_fw_param_event_handler() - WMI event handler to
  6567. * process start scan response event
  6568. * @scn: Pointer to scn object
  6569. * @data_buf: Pointer to event buffer
  6570. * @data_len: Length of event buffer
  6571. *
  6572. * Return: 0 for success, else failure
  6573. */
  6574. static int
  6575. target_if_spectral_fw_param_event_handler(ol_scn_t scn, uint8_t *data_buf,
  6576. uint32_t data_len)
  6577. {
  6578. QDF_STATUS status;
  6579. struct wlan_objmgr_psoc *psoc;
  6580. struct wlan_objmgr_pdev *pdev;
  6581. struct wmi_unified *wmi_handle;
  6582. struct spectral_startscan_resp_params event_params = {0};
  6583. struct target_if_psoc_spectral *psoc_spectral;
  6584. struct target_if_spectral *spectral;
  6585. bool is_session_info_expected;
  6586. if (!scn) {
  6587. spectral_err("scn handle is null");
  6588. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6589. }
  6590. if (!data_buf) {
  6591. spectral_err("WMI event buffer null");
  6592. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6593. }
  6594. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  6595. if (!psoc) {
  6596. spectral_err("psoc is null");
  6597. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6598. }
  6599. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6600. if (!psoc_spectral) {
  6601. spectral_err("spectral object is null");
  6602. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6603. }
  6604. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6605. if (!wmi_handle) {
  6606. spectral_err("WMI handle is null");
  6607. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6608. }
  6609. status = target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6610. psoc, data_buf, &event_params);
  6611. if (QDF_IS_STATUS_ERROR(status)) {
  6612. spectral_err("unable to extract sscan fw fixed params");
  6613. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6614. }
  6615. if (event_params.smode >= SPECTRAL_SCAN_MODE_MAX ||
  6616. event_params.smode < SPECTRAL_SCAN_MODE_NORMAL) {
  6617. spectral_err("Invalid smode %d", event_params.smode);
  6618. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6619. }
  6620. pdev = wlan_objmgr_get_pdev_by_id(psoc, event_params.pdev_id,
  6621. WLAN_SPECTRAL_ID);
  6622. if (!pdev) {
  6623. spectral_err("pdev is null");
  6624. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6625. }
  6626. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  6627. if (!spectral) {
  6628. spectral_err("spectral object is null");
  6629. status = QDF_STATUS_E_FAILURE;
  6630. goto release_pdev_ref;
  6631. }
  6632. if (event_params.num_fft_bin_index == 1) {
  6633. status =
  6634. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6635. psoc, data_buf,
  6636. &spectral->rparams.marker[event_params.smode]);
  6637. if (QDF_IS_STATUS_ERROR(status)) {
  6638. spectral_err("unable to extract sscan fw fixed params");
  6639. goto release_pdev_ref;
  6640. }
  6641. } else {
  6642. spectral->rparams.marker[event_params.smode].is_valid = false;
  6643. }
  6644. status = spectral_is_session_info_expected_from_target(
  6645. pdev, &is_session_info_expected);
  6646. if (QDF_IS_STATUS_ERROR(status)) {
  6647. spectral_err("Failed to check if session info is expected");
  6648. goto release_pdev_ref;
  6649. }
  6650. if (is_session_info_expected) {
  6651. struct spectral_session_chan_info chan_info;
  6652. uint8_t det_info_idx = 0;
  6653. status = target_if_extract_pdev_spectral_session_chan_info(
  6654. psoc, data_buf, &chan_info);
  6655. if (QDF_IS_STATUS_ERROR(status)) {
  6656. spectral_err("Unable to extract spectral session channel info");
  6657. goto release_pdev_ref;
  6658. }
  6659. status = target_if_update_chan_info_in_spectral_session(
  6660. spectral, &chan_info, event_params.smode);
  6661. if (QDF_IS_STATUS_ERROR(status)) {
  6662. spectral_err("Unable to update channel info");
  6663. goto release_pdev_ref;
  6664. }
  6665. /* FFT bins info depends upon sscan_bw, update it */
  6666. status = target_if_populate_fft_bins_info(spectral,
  6667. event_params.smode);
  6668. if (QDF_IS_STATUS_ERROR(status)) {
  6669. spectral_err("Failed to populate FFT bins info");
  6670. goto release_pdev_ref;
  6671. }
  6672. /**
  6673. * per-session det info that depends on sscan_bw needs to be
  6674. * updated here
  6675. */
  6676. status = target_if_spectral_populate_session_det_host_info(
  6677. spectral, event_params.smode);
  6678. if (QDF_IS_STATUS_ERROR(status)) {
  6679. spectral_err("Failed to populate per-session det info");
  6680. goto release_pdev_ref;
  6681. }
  6682. for (; det_info_idx < event_params.num_det_info;
  6683. ++det_info_idx) {
  6684. struct spectral_session_det_info det_info;
  6685. status =
  6686. target_if_extract_pdev_spectral_session_detector_info
  6687. (psoc, data_buf, &det_info, det_info_idx);
  6688. if (QDF_IS_STATUS_ERROR(status)) {
  6689. spectral_err("Unable to extract spectral session detector info for %u",
  6690. det_info_idx);
  6691. goto release_pdev_ref;
  6692. }
  6693. status = target_if_update_det_info_in_spectral_session(
  6694. spectral, &det_info);
  6695. if (QDF_IS_STATUS_ERROR(status)) {
  6696. spectral_err("Unable to update detector info");
  6697. goto release_pdev_ref;
  6698. }
  6699. }
  6700. }
  6701. status = QDF_STATUS_SUCCESS;
  6702. release_pdev_ref:
  6703. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  6704. return qdf_status_to_os_return(status);
  6705. }
  6706. static QDF_STATUS
  6707. target_if_spectral_register_events(struct wlan_objmgr_psoc *psoc)
  6708. {
  6709. int ret;
  6710. if (!psoc) {
  6711. spectral_err("psoc is null");
  6712. return QDF_STATUS_E_INVAL;
  6713. }
  6714. ret = target_if_spectral_wmi_unified_register_event_handler(
  6715. psoc,
  6716. wmi_pdev_sscan_fw_param_eventid,
  6717. target_if_spectral_fw_param_event_handler,
  6718. WMI_RX_UMAC_CTX);
  6719. if (ret)
  6720. spectral_debug("event handler not supported, ret=%d", ret);
  6721. return QDF_STATUS_SUCCESS;
  6722. }
  6723. static QDF_STATUS
  6724. target_if_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
  6725. {
  6726. int ret;
  6727. if (!psoc) {
  6728. spectral_err("psoc is null");
  6729. return QDF_STATUS_E_INVAL;
  6730. }
  6731. ret = target_if_spectral_wmi_unified_unregister_event_handler(
  6732. psoc, wmi_pdev_sscan_fw_param_eventid);
  6733. if (ret)
  6734. spectral_debug("Unregister WMI event handler failed, ret = %d",
  6735. ret);
  6736. return QDF_STATUS_SUCCESS;
  6737. }
  6738. void
  6739. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  6740. {
  6741. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  6742. target_if_pdev_spectral_init;
  6743. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  6744. target_if_pdev_spectral_deinit;
  6745. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init =
  6746. target_if_psoc_spectral_init;
  6747. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit =
  6748. target_if_psoc_spectral_deinit;
  6749. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  6750. target_if_set_spectral_config;
  6751. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  6752. target_if_get_spectral_config;
  6753. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  6754. target_if_start_spectral_scan;
  6755. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  6756. target_if_stop_spectral_scan;
  6757. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  6758. target_if_is_spectral_active;
  6759. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  6760. target_if_is_spectral_enabled;
  6761. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  6762. target_if_set_debug_level;
  6763. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  6764. target_if_get_debug_level;
  6765. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  6766. target_if_get_spectral_capinfo;
  6767. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  6768. target_if_get_spectral_diagstats;
  6769. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_wmi_ops =
  6770. target_if_register_spectral_wmi_ops;
  6771. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_tgt_ops =
  6772. target_if_register_spectral_tgt_ops;
  6773. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  6774. target_if_register_netlink_cb;
  6775. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  6776. target_if_use_nl_bcast;
  6777. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  6778. target_if_deregister_netlink_cb;
  6779. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  6780. target_if_process_spectral_report;
  6781. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  6782. target_if_spectral_direct_dma_support;
  6783. tx_ops->sptrl_tx_ops.sptrlto_register_events =
  6784. target_if_spectral_register_events;
  6785. tx_ops->sptrl_tx_ops.sptrlto_unregister_events =
  6786. target_if_spectral_unregister_events;
  6787. tx_ops->sptrl_tx_ops.sptrlto_init_pdev_feature_caps =
  6788. target_if_spectral_init_pdev_feature_caps;
  6789. target_if_sptrl_debug_register_tx_ops(tx_ops);
  6790. }
  6791. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  6792. void
  6793. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  6794. uint16_t cw_int, uint32_t dcs_enabled)
  6795. {
  6796. struct spectral_samp_msg *msg = NULL;
  6797. struct target_if_spectral_ops *p_sops = NULL;
  6798. struct target_if_spectral *spectral = NULL;
  6799. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  6800. if (!spectral) {
  6801. spectral_err("SPECTRAL : Module doesn't exist");
  6802. return;
  6803. }
  6804. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  6805. if (!p_sops) {
  6806. spectral_err("p_sops is null");
  6807. return;
  6808. }
  6809. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  6810. spectral->pdev_obj,
  6811. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  6812. SPECTRAL_MSG_BUF_NEW);
  6813. if (msg) {
  6814. msg->int_type = cw_int ?
  6815. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  6816. msg->dcs_enabled = dcs_enabled;
  6817. msg->signature = SPECTRAL_SIGNATURE;
  6818. p_sops->get_mac_address(spectral, msg->macaddr);
  6819. if (spectral->send_phy_data
  6820. (pdev,
  6821. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  6822. spectral->spectral_sent_msg++;
  6823. }
  6824. }
  6825. qdf_export_symbol(target_if_spectral_send_intf_found_msg);
  6826. QDF_STATUS
  6827. target_if_spectral_is_finite_scan(struct target_if_spectral *spectral,
  6828. enum spectral_scan_mode smode,
  6829. bool *finite_spectral_scan)
  6830. {
  6831. struct target_if_finite_spectral_scan_params *finite_scan;
  6832. if (!spectral) {
  6833. spectral_err_rl("target if spectral object is null");
  6834. return QDF_STATUS_E_INVAL;
  6835. }
  6836. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6837. spectral_err_rl("invalid spectral mode %d", smode);
  6838. return QDF_STATUS_E_INVAL;
  6839. }
  6840. if (!finite_spectral_scan) {
  6841. spectral_err_rl("Invalid pointer");
  6842. return QDF_STATUS_E_INVAL;
  6843. }
  6844. finite_scan = &spectral->finite_scan[smode];
  6845. *finite_spectral_scan = finite_scan->finite_spectral_scan;
  6846. return QDF_STATUS_SUCCESS;
  6847. }
  6848. QDF_STATUS
  6849. target_if_spectral_finite_scan_update(struct target_if_spectral *spectral,
  6850. enum spectral_scan_mode smode)
  6851. {
  6852. struct target_if_finite_spectral_scan_params *finite_scan;
  6853. if (!spectral) {
  6854. spectral_err_rl("target if spectral object is null");
  6855. return QDF_STATUS_E_INVAL;
  6856. }
  6857. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6858. spectral_err_rl("Invalid Spectral mode");
  6859. return QDF_STATUS_E_INVAL;
  6860. }
  6861. finite_scan = &spectral->finite_scan[smode];
  6862. if (!finite_scan->num_reports_expected) {
  6863. spectral_err_rl("Error, No reports expected");
  6864. return QDF_STATUS_E_FAILURE;
  6865. }
  6866. finite_scan->num_reports_expected--;
  6867. if (!finite_scan->num_reports_expected) {
  6868. QDF_STATUS status;
  6869. enum spectral_cp_error_code err;
  6870. /* received expected number of reports from target, stop scan */
  6871. status = target_if_stop_spectral_scan(spectral->pdev_obj, smode,
  6872. &err);
  6873. if (QDF_IS_STATUS_ERROR(status)) {
  6874. spectral_err_rl("Failed to stop finite Spectral scan");
  6875. return QDF_STATUS_E_FAILURE;
  6876. }
  6877. finite_scan->finite_spectral_scan = false;
  6878. }
  6879. return QDF_STATUS_SUCCESS;
  6880. }