target_if_spectral.c 223 KB

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