target_if_spectral.c 216 KB

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