target_if_spectral.c 160 KB

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