target_if_spectral.c 221 KB

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