target_if_spectral.c 149 KB

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