target_if_spectral.c 159 KB

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