target_if_spectral.c 183 KB

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