target_if_spectral.c 221 KB

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