target_if_spectral.c 219 KB

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