target_if_spectral.c 184 KB

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