target_if_spectral.c 194 KB

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