target_if_spectral.c 152 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592
  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. target_type == TARGET_TYPE_QCA5018 ||
  1210. target_type == TARGET_TYPE_QCA6490) {
  1211. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1212. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1213. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1214. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1215. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1216. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1217. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1218. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1219. } else {
  1220. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1221. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1222. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1223. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1224. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1225. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1226. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1227. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1228. }
  1229. break;
  1230. case SPECTRAL_GEN2:
  1231. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1232. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1233. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1234. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1235. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1236. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1237. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1238. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1239. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1240. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1241. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1242. break;
  1243. default:
  1244. spectral_err("Invalid spectral generation %d", gen);
  1245. return QDF_STATUS_E_INVAL;
  1246. }
  1247. return QDF_STATUS_SUCCESS;
  1248. }
  1249. /**
  1250. * target_if_init_spectral_param_properties() - Initialize Spectral parameter
  1251. * properties
  1252. * @spectral: Pointer to Spectral target_if internal private data
  1253. *
  1254. * Initialize Spectral parameter properties
  1255. *
  1256. * Return: QDF_STATUS
  1257. */
  1258. static QDF_STATUS
  1259. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1260. {
  1261. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1262. int param;
  1263. /* Initialize default values for properties.
  1264. * Default values are supported for all the parameters for all modes
  1265. * and allows different values for each mode for all the parameters .
  1266. */
  1267. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1268. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1269. spectral->properties[smode][param].supported = true;
  1270. spectral->properties[smode][param].common_all_modes =
  1271. false;
  1272. }
  1273. }
  1274. /* Once FW advertisement is in place remove this hard coding */
  1275. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1276. spectral->properties[SPECTRAL_SCAN_MODE_NORMAL]
  1277. [SPECTRAL_PARAM_FREQUENCY].supported = false;
  1278. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1279. spectral->properties[smode]
  1280. [SPECTRAL_PARAM_SPECT_PRI].common_all_modes = true;
  1281. spectral->properties[smode]
  1282. [SPECTRAL_PARAM_SCAN_PERIOD].common_all_modes = true;
  1283. spectral->properties[smode]
  1284. [SPECTRAL_PARAM_INIT_DELAY].common_all_modes = true;
  1285. }
  1286. return QDF_STATUS_SUCCESS;
  1287. }
  1288. QDF_STATUS
  1289. target_if_init_spectral_capability(struct target_if_spectral *spectral,
  1290. uint32_t target_type)
  1291. {
  1292. struct wlan_objmgr_psoc *psoc;
  1293. struct wlan_objmgr_pdev *pdev;
  1294. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  1295. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  1296. struct target_psoc_info *tgt_psoc_info;
  1297. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  1298. struct spectral_caps *pcap = &spectral->capability;
  1299. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  1300. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  1301. struct wlan_psoc_host_chainmask_table *table;
  1302. int j;
  1303. uint32_t table_id;
  1304. pdev = spectral->pdev_obj;
  1305. psoc = wlan_pdev_get_psoc(pdev);
  1306. if (!psoc) {
  1307. spectral_err("psoc is null");
  1308. return QDF_STATUS_E_FAILURE;
  1309. }
  1310. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  1311. if (!tgt_psoc_info) {
  1312. spectral_err("target_psoc_info is null");
  1313. return QDF_STATUS_E_FAILURE;
  1314. }
  1315. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  1316. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  1317. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  1318. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  1319. /* XXX : Workaround: Set Spectral capability */
  1320. pcap = &spectral->capability;
  1321. pcap->phydiag_cap = 1;
  1322. pcap->radar_cap = 1;
  1323. pcap->spectral_cap = 1;
  1324. pcap->advncd_spectral_cap = 1;
  1325. pcap->hw_gen = spectral->spectral_gen;
  1326. if (spectral->spectral_gen >= SPECTRAL_GEN3) {
  1327. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  1328. if (!mac_phy_cap_arr) {
  1329. spectral_err("mac phy cap array is null");
  1330. return QDF_STATUS_E_FAILURE;
  1331. }
  1332. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  1333. if (!mac_phy_cap) {
  1334. spectral_err("mac phy cap is null");
  1335. return QDF_STATUS_E_FAILURE;
  1336. }
  1337. table_id = mac_phy_cap->chainmask_table_id;
  1338. table = &ext_svc_param->chainmask_table[table_id];
  1339. if (!table) {
  1340. spectral_err("chainmask table not found");
  1341. return QDF_STATUS_E_FAILURE;
  1342. }
  1343. for (j = 0; j < table->num_valid_chainmasks; j++) {
  1344. pcap->agile_spectral_cap |=
  1345. table->cap_list[j].supports_aSpectral;
  1346. pcap->agile_spectral_cap_160 |=
  1347. table->cap_list[j].supports_aSpectral_160;
  1348. }
  1349. pcap->agile_spectral_cap_80p80 = pcap->agile_spectral_cap_160;
  1350. } else {
  1351. pcap->agile_spectral_cap = false;
  1352. pcap->agile_spectral_cap_160 = false;
  1353. pcap->agile_spectral_cap_80p80 = false;
  1354. }
  1355. if (scaling_params) {
  1356. for (param_idx = 0; param_idx < num_bin_scaling_params;
  1357. param_idx++) {
  1358. if (scaling_params[param_idx].pdev_id == pdev_id) {
  1359. pcap->is_scaling_params_populated = true;
  1360. pcap->formula_id =
  1361. scaling_params[param_idx].formula_id;
  1362. pcap->low_level_offset =
  1363. scaling_params[param_idx].low_level_offset;
  1364. pcap->high_level_offset =
  1365. scaling_params[param_idx].high_level_offset;
  1366. pcap->rssi_thr =
  1367. scaling_params[param_idx].rssi_thr;
  1368. pcap->default_agc_max_gain =
  1369. scaling_params[param_idx].default_agc_max_gain;
  1370. break;
  1371. }
  1372. }
  1373. }
  1374. pcap->num_detectors_20mhz = 1;
  1375. pcap->num_detectors_40mhz = 1;
  1376. pcap->num_detectors_80mhz = 1;
  1377. if (target_type == TARGET_TYPE_QCN9000 ||
  1378. target_type == TARGET_TYPE_QCA6490) {
  1379. pcap->num_detectors_160mhz = 1;
  1380. pcap->num_detectors_80p80mhz = 1;
  1381. } else {
  1382. pcap->num_detectors_160mhz = 2;
  1383. pcap->num_detectors_80p80mhz = 2;
  1384. }
  1385. return QDF_STATUS_SUCCESS;
  1386. }
  1387. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1388. /**
  1389. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1390. * internal operations with functions related to spectral simulation
  1391. * @p_sops: spectral low level ops table
  1392. *
  1393. * Initialize spectral target_if internal operations with functions
  1394. * related to spectral simulation
  1395. *
  1396. * Return: None
  1397. */
  1398. static void
  1399. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1400. {
  1401. /*
  1402. * Spectral simulation is currently intended for platform transitions
  1403. * where underlying HW support may not be available for some time.
  1404. * Hence, we do not currently provide a runtime switch to turn the
  1405. * simulation on or off.
  1406. * In case of future requirements where runtime switches are required,
  1407. * this can be added. But it is suggested to use application layer
  1408. * simulation as far as possible in such cases, since the main
  1409. * use of record and replay of samples would concern higher
  1410. * level sample processing rather than lower level delivery.
  1411. */
  1412. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  1413. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  1414. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  1415. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  1416. p_sops->configure_spectral =
  1417. target_if_spectral_sops_sim_configure_params;
  1418. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  1419. }
  1420. #else
  1421. /**
  1422. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1423. * internal operations
  1424. * @p_sops: spectral low level ops table
  1425. *
  1426. * Return: None
  1427. */
  1428. static void
  1429. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1430. {
  1431. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  1432. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  1433. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  1434. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  1435. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  1436. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  1437. }
  1438. #endif
  1439. /**
  1440. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  1441. * operations common to all Spectral chipset generations
  1442. *
  1443. * Initializes target_if_spectral_ops common to all chipset generations
  1444. *
  1445. * Return: None
  1446. */
  1447. static void
  1448. target_if_init_spectral_ops_common(void)
  1449. {
  1450. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1451. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  1452. p_sops->get_capability = target_if_spectral_get_capability;
  1453. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  1454. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  1455. target_if_init_spectral_simulation_ops(p_sops);
  1456. p_sops->get_extension_channel =
  1457. target_if_spectral_get_extension_channel;
  1458. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  1459. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  1460. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  1461. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  1462. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  1463. p_sops->reset_hw = target_if_spectral_reset_hw;
  1464. p_sops->get_chain_noise_floor =
  1465. target_if_spectral_get_chain_noise_floor;
  1466. }
  1467. /**
  1468. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  1469. * operations specific to Spectral chipset generation 2.
  1470. *
  1471. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  1472. *
  1473. * Return: None
  1474. */
  1475. static void
  1476. target_if_init_spectral_ops_gen2(void)
  1477. {
  1478. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1479. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  1480. }
  1481. /**
  1482. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  1483. * operations specific to Spectral chipset generation 3.
  1484. *
  1485. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  1486. *
  1487. * Return: None
  1488. */
  1489. static void
  1490. target_if_init_spectral_ops_gen3(void)
  1491. {
  1492. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1493. p_sops->process_spectral_report =
  1494. target_if_spectral_process_report_gen3;
  1495. return;
  1496. }
  1497. /**
  1498. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  1499. * operations.
  1500. * @spectral: Pointer to Spectral target_if internal private data
  1501. *
  1502. * Initializes all function pointers in target_if_spectral_ops for
  1503. * all generations
  1504. *
  1505. * Return: None
  1506. */
  1507. static void
  1508. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  1509. {
  1510. target_if_init_spectral_ops_common();
  1511. if (spectral->spectral_gen == SPECTRAL_GEN2)
  1512. target_if_init_spectral_ops_gen2();
  1513. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  1514. target_if_init_spectral_ops_gen3();
  1515. else
  1516. spectral_err("Invalid Spectral generation");
  1517. }
  1518. /*
  1519. * Dummy Functions:
  1520. * These functions are initially registered to avoid any crashes due to
  1521. * invocation of spectral functions before they are registered.
  1522. */
  1523. static uint64_t
  1524. null_get_tsf64(void *arg)
  1525. {
  1526. spectral_ops_not_registered("get_tsf64");
  1527. return 0;
  1528. }
  1529. static uint32_t
  1530. null_get_capability(void *arg, enum spectral_capability_type type)
  1531. {
  1532. /*
  1533. * TODO : We should have conditional compilation to get the capability
  1534. * : We have not yet attahced ATH layer here, so there is no
  1535. * : way to check the HAL capbalities
  1536. */
  1537. spectral_ops_not_registered("get_capability");
  1538. /* TODO : For the time being, we are returning TRUE */
  1539. return true;
  1540. }
  1541. static uint32_t
  1542. null_set_rxfilter(void *arg, int rxfilter)
  1543. {
  1544. spectral_ops_not_registered("set_rxfilter");
  1545. return 1;
  1546. }
  1547. static uint32_t
  1548. null_get_rxfilter(void *arg)
  1549. {
  1550. spectral_ops_not_registered("get_rxfilter");
  1551. return 0;
  1552. }
  1553. static uint32_t
  1554. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  1555. {
  1556. spectral_ops_not_registered("is_spectral_active");
  1557. return 1;
  1558. }
  1559. static uint32_t
  1560. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  1561. {
  1562. spectral_ops_not_registered("is_spectral_enabled");
  1563. return 1;
  1564. }
  1565. static uint32_t
  1566. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  1567. enum spectral_cp_error_code *err)
  1568. {
  1569. spectral_ops_not_registered("start_spectral_scan");
  1570. return 1;
  1571. }
  1572. static uint32_t
  1573. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  1574. {
  1575. spectral_ops_not_registered("stop_spectral_scan");
  1576. return 1;
  1577. }
  1578. static uint32_t
  1579. null_get_extension_channel(void *arg)
  1580. {
  1581. spectral_ops_not_registered("get_extension_channel");
  1582. return 1;
  1583. }
  1584. static int8_t
  1585. null_get_ctl_noisefloor(void *arg)
  1586. {
  1587. spectral_ops_not_registered("get_ctl_noisefloor");
  1588. return 1;
  1589. }
  1590. static int8_t
  1591. null_get_ext_noisefloor(void *arg)
  1592. {
  1593. spectral_ops_not_registered("get_ext_noisefloor");
  1594. return 0;
  1595. }
  1596. static uint32_t
  1597. null_configure_spectral(void *arg, struct spectral_config *params,
  1598. enum spectral_scan_mode smode)
  1599. {
  1600. spectral_ops_not_registered("configure_spectral");
  1601. return 0;
  1602. }
  1603. static uint32_t
  1604. null_get_spectral_config(void *arg, struct spectral_config *params,
  1605. enum spectral_scan_mode smode)
  1606. {
  1607. spectral_ops_not_registered("get_spectral_config");
  1608. return 0;
  1609. }
  1610. static uint32_t
  1611. null_get_ent_spectral_mask(void *arg)
  1612. {
  1613. spectral_ops_not_registered("get_ent_spectral_mask");
  1614. return 0;
  1615. }
  1616. static uint32_t
  1617. null_get_mac_address(void *arg, char *addr)
  1618. {
  1619. spectral_ops_not_registered("get_mac_address");
  1620. return 0;
  1621. }
  1622. static uint32_t
  1623. null_get_current_channel(void *arg)
  1624. {
  1625. spectral_ops_not_registered("get_current_channel");
  1626. return 0;
  1627. }
  1628. static uint32_t
  1629. null_reset_hw(void *arg)
  1630. {
  1631. spectral_ops_not_registered("get_current_channel");
  1632. return 0;
  1633. }
  1634. static uint32_t
  1635. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1636. {
  1637. spectral_ops_not_registered("get_chain_noise_floor");
  1638. return 0;
  1639. }
  1640. static int
  1641. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  1642. uint8_t *data,
  1643. uint32_t datalen,
  1644. struct target_if_spectral_rfqual_info *p_rfqual,
  1645. struct target_if_spectral_chan_info *p_chaninfo,
  1646. uint64_t tsf64,
  1647. struct target_if_spectral_acs_stats *acs_stats)
  1648. {
  1649. spectral_ops_not_registered("spectral_process_phyerr");
  1650. return 0;
  1651. }
  1652. static int
  1653. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  1654. void *payload)
  1655. {
  1656. spectral_ops_not_registered("process_spectral_report");
  1657. return 0;
  1658. }
  1659. /**
  1660. * target_if_spectral_init_dummy_function_table() -
  1661. * Initialize target_if internal
  1662. * Spectral operations to dummy functions
  1663. * @ps: Pointer to Spectral target_if internal private data
  1664. *
  1665. * Initialize all the function pointers in target_if_spectral_ops with
  1666. * dummy functions.
  1667. *
  1668. * Return: None
  1669. */
  1670. static void
  1671. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  1672. {
  1673. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  1674. p_sops->get_tsf64 = null_get_tsf64;
  1675. p_sops->get_capability = null_get_capability;
  1676. p_sops->set_rxfilter = null_set_rxfilter;
  1677. p_sops->get_rxfilter = null_get_rxfilter;
  1678. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  1679. p_sops->is_spectral_active = null_is_spectral_active;
  1680. p_sops->start_spectral_scan = null_start_spectral_scan;
  1681. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  1682. p_sops->get_extension_channel = null_get_extension_channel;
  1683. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  1684. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  1685. p_sops->configure_spectral = null_configure_spectral;
  1686. p_sops->get_spectral_config = null_get_spectral_config;
  1687. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  1688. p_sops->get_mac_address = null_get_mac_address;
  1689. p_sops->get_current_channel = null_get_current_channel;
  1690. p_sops->reset_hw = null_reset_hw;
  1691. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  1692. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  1693. p_sops->process_spectral_report = null_process_spectral_report;
  1694. }
  1695. /**
  1696. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  1697. * operations
  1698. * @spectral: Pointer to Spectral target_if internal private data
  1699. * @p: Pointer to Spectral function table
  1700. *
  1701. * Return: None
  1702. */
  1703. static void
  1704. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  1705. struct target_if_spectral_ops *p)
  1706. {
  1707. struct target_if_spectral_ops *p_sops =
  1708. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1709. p_sops->get_tsf64 = p->get_tsf64;
  1710. p_sops->get_capability = p->get_capability;
  1711. p_sops->set_rxfilter = p->set_rxfilter;
  1712. p_sops->get_rxfilter = p->get_rxfilter;
  1713. p_sops->is_spectral_enabled = p->is_spectral_enabled;
  1714. p_sops->is_spectral_active = p->is_spectral_active;
  1715. p_sops->start_spectral_scan = p->start_spectral_scan;
  1716. p_sops->stop_spectral_scan = p->stop_spectral_scan;
  1717. p_sops->get_extension_channel = p->get_extension_channel;
  1718. p_sops->get_ctl_noisefloor = p->get_ctl_noisefloor;
  1719. p_sops->get_ext_noisefloor = p->get_ext_noisefloor;
  1720. p_sops->configure_spectral = p->configure_spectral;
  1721. p_sops->get_spectral_config = p->get_spectral_config;
  1722. p_sops->get_ent_spectral_mask = p->get_ent_spectral_mask;
  1723. p_sops->get_mac_address = p->get_mac_address;
  1724. p_sops->get_current_channel = p->get_current_channel;
  1725. p_sops->reset_hw = p->reset_hw;
  1726. p_sops->get_chain_noise_floor = p->get_chain_noise_floor;
  1727. p_sops->spectral_process_phyerr = p->spectral_process_phyerr;
  1728. p_sops->process_spectral_report = p->process_spectral_report;
  1729. }
  1730. /**
  1731. * target_if_spectral_clear_stats() - Clear Spectral stats
  1732. * @spectral: Pointer to Spectral target_if internal private data
  1733. *
  1734. * Function to clear spectral stats
  1735. *
  1736. * Return: None
  1737. */
  1738. static void
  1739. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  1740. {
  1741. struct target_if_spectral_ops *p_sops =
  1742. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1743. qdf_mem_zero(&spectral->spectral_stats,
  1744. sizeof(struct target_if_spectral_stats));
  1745. spectral->spectral_stats.last_reset_tstamp =
  1746. p_sops->get_tsf64(spectral);
  1747. }
  1748. /**
  1749. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  1750. * @spectral: Pointer to Spectral target_if internal private data
  1751. *
  1752. * Function to check whether hardware supports spectral
  1753. *
  1754. * Return: True if HW supports Spectral, false if HW does not support Spectral
  1755. */
  1756. static int
  1757. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  1758. {
  1759. struct target_if_spectral_ops *p_sops = NULL;
  1760. struct spectral_caps *pcap = NULL;
  1761. int is_spectral_supported = true;
  1762. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1763. pcap = &spectral->capability;
  1764. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  1765. is_spectral_supported = false;
  1766. spectral_info("SPECTRAL : No PHYDIAG support");
  1767. return is_spectral_supported;
  1768. }
  1769. pcap->phydiag_cap = 1;
  1770. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  1771. is_spectral_supported = false;
  1772. spectral_info("SPECTRAL : No RADAR support");
  1773. return is_spectral_supported;
  1774. }
  1775. pcap->radar_cap = 1;
  1776. if (p_sops->get_capability(spectral,
  1777. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  1778. is_spectral_supported = false;
  1779. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  1780. return is_spectral_supported;
  1781. }
  1782. pcap->spectral_cap = 1;
  1783. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  1784. == false) {
  1785. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  1786. } else {
  1787. pcap->advncd_spectral_cap = 1;
  1788. }
  1789. return is_spectral_supported;
  1790. }
  1791. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1792. /**
  1793. * target_if_spectral_detach_simulation() - De-initialize Spectral
  1794. * Simulation functionality
  1795. * @spectral: Pointer to Spectral target_if internal private data
  1796. *
  1797. * Function to de-initialize Spectral Simulation functionality
  1798. *
  1799. * Return: None
  1800. */
  1801. static void
  1802. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1803. {
  1804. target_if_spectral_sim_detach(spectral);
  1805. }
  1806. #else
  1807. static void
  1808. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1809. {
  1810. }
  1811. #endif
  1812. /**
  1813. * target_if_spectral_detach() - De-initialize target_if Spectral
  1814. * @pdev: Pointer to pdev object
  1815. *
  1816. * Function to detach target_if spectral
  1817. *
  1818. * Return: None
  1819. */
  1820. static void
  1821. target_if_spectral_detach(struct target_if_spectral *spectral)
  1822. {
  1823. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1824. spectral_info("spectral detach");
  1825. if (spectral) {
  1826. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1827. qdf_spinlock_destroy
  1828. (&spectral->param_info[smode].osps_lock);
  1829. target_if_spectral_detach_simulation(spectral);
  1830. qdf_spinlock_destroy(&spectral->spectral_lock);
  1831. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  1832. qdf_mem_free(spectral);
  1833. spectral = NULL;
  1834. }
  1835. }
  1836. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1837. /**
  1838. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  1839. * functionality
  1840. * @spectral: Pointer to Spectral target_if internal private data
  1841. *
  1842. * Function to initialize spectral simulation functionality
  1843. *
  1844. * Return: 0 on success, negative error code on failure
  1845. */
  1846. static int
  1847. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1848. {
  1849. if (target_if_spectral_sim_attach(spectral)) {
  1850. qdf_mem_free(spectral);
  1851. return -EPERM;
  1852. }
  1853. return 0;
  1854. }
  1855. #else
  1856. static int
  1857. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1858. {
  1859. return 0;
  1860. }
  1861. #endif
  1862. /**
  1863. * target_if_spectral_len_adj_swar_init() - Initialize FFT bin length adjustment
  1864. * related info
  1865. * @swar: Pointer to Spectral FFT bin length adjustment SWAR params
  1866. * @target_type: Target type
  1867. *
  1868. * Function to Initialize parameters related to Spectral FFT bin
  1869. * length adjustment SWARs.
  1870. *
  1871. * Return: void
  1872. */
  1873. static void
  1874. target_if_spectral_len_adj_swar_init(struct spectral_fft_bin_len_adj_swar *swar,
  1875. uint32_t target_type)
  1876. {
  1877. if (target_type == TARGET_TYPE_QCA8074V2 ||
  1878. target_type == TARGET_TYPE_QCN9000 ||
  1879. target_type == TARGET_TYPE_QCA5018 ||
  1880. target_type == TARGET_TYPE_QCA6750 ||
  1881. target_type == TARGET_TYPE_QCA6490)
  1882. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  1883. else if (target_type == TARGET_TYPE_QCA8074 ||
  1884. target_type == TARGET_TYPE_QCA6018 ||
  1885. target_type == TARGET_TYPE_QCA6390)
  1886. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  1887. else
  1888. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  1889. if (target_type == TARGET_TYPE_QCA8074 ||
  1890. target_type == TARGET_TYPE_QCA8074V2 ||
  1891. target_type == TARGET_TYPE_QCA6018 ||
  1892. target_type == TARGET_TYPE_QCA5018 ||
  1893. target_type == TARGET_TYPE_QCN9000 ||
  1894. target_type == TARGET_TYPE_QCA6490) {
  1895. swar->inband_fftbin_size_adj = 1;
  1896. swar->null_fftbin_adj = 1;
  1897. } else {
  1898. swar->inband_fftbin_size_adj = 0;
  1899. swar->null_fftbin_adj = 0;
  1900. }
  1901. if (target_type == TARGET_TYPE_QCA8074V2)
  1902. swar->packmode_fftbin_size_adj = 1;
  1903. else
  1904. swar->packmode_fftbin_size_adj = 0;
  1905. }
  1906. /**
  1907. * target_if_spectral_report_params_init() - Initialize parameters which
  1908. * describes the structure of Spectral reports
  1909. *
  1910. * @rparams: Pointer to Spectral report parameter object
  1911. * @target_type: target type
  1912. *
  1913. * Function to Initialize parameters related to the structure of Spectral
  1914. * reports.
  1915. *
  1916. * Return: void
  1917. */
  1918. static void
  1919. target_if_spectral_report_params_init(
  1920. struct spectral_report_params *rparams,
  1921. uint32_t target_type)
  1922. {
  1923. enum spectral_scan_mode smode;
  1924. /* This entries are currently used by gen3 chipsets only. Hence
  1925. * initialization is done for gen3 alone. In future if other generations
  1926. * needs to use them they have to add proper initial values.
  1927. */
  1928. if (target_type == TARGET_TYPE_QCN9000 ||
  1929. target_type == TARGET_TYPE_QCA5018 ||
  1930. target_type == TARGET_TYPE_QCA6750 ||
  1931. target_type == TARGET_TYPE_QCA6490) {
  1932. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_2;
  1933. rparams->num_spectral_detectors =
  1934. NUM_SPECTRAL_DETECTORS_GEN3_V2;
  1935. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1936. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1937. rparams->fragmentation_160[smode] = false;
  1938. rparams->max_agile_ch_width = CH_WIDTH_80P80MHZ;
  1939. } else {
  1940. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_1;
  1941. rparams->num_spectral_detectors =
  1942. NUM_SPECTRAL_DETECTORS_GEN3_V1;
  1943. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1944. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1945. rparams->fragmentation_160[smode] = true;
  1946. rparams->max_agile_ch_width = CH_WIDTH_80MHZ;
  1947. }
  1948. switch (rparams->version) {
  1949. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1950. rparams->ssumaary_padding_bytes =
  1951. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1;
  1952. rparams->fft_report_hdr_len =
  1953. FFT_REPORT_HEADER_LENGTH_GEN3_V1;
  1954. break;
  1955. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1956. rparams->ssumaary_padding_bytes =
  1957. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2;
  1958. rparams->fft_report_hdr_len =
  1959. FFT_REPORT_HEADER_LENGTH_GEN3_V2;
  1960. break;
  1961. default:
  1962. qdf_assert_always(0);
  1963. }
  1964. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_0] =
  1965. SPECTRAL_SCAN_MODE_NORMAL;
  1966. if (target_type == TARGET_TYPE_QCN9000 ||
  1967. target_type == TARGET_TYPE_QCA6490) {
  1968. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  1969. SPECTRAL_SCAN_MODE_AGILE;
  1970. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  1971. SPECTRAL_SCAN_MODE_INVALID;
  1972. } else {
  1973. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  1974. SPECTRAL_SCAN_MODE_NORMAL;
  1975. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  1976. SPECTRAL_SCAN_MODE_AGILE;
  1977. }
  1978. }
  1979. /**
  1980. * target_if_spectral_timestamp_war_init() - Initialize Spectral timestamp WAR
  1981. * related info
  1982. * @twar: Pointer to Spectral timstamp WAR related info
  1983. *
  1984. * Function to Initialize parameters related to Spectral timestamp WAR
  1985. *
  1986. * Return: void
  1987. */
  1988. static void
  1989. target_if_spectral_timestamp_war_init(struct spectral_timestamp_war *twar)
  1990. {
  1991. enum spectral_scan_mode smode;
  1992. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1993. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1994. twar->last_fft_timestamp[smode] = 0;
  1995. twar->timestamp_war_offset[smode] = 0;
  1996. }
  1997. twar->target_reset_count = 0;
  1998. }
  1999. /**
  2000. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  2001. * functionality for the given pdev
  2002. * @pdev: Pointer to pdev object
  2003. *
  2004. * Function to initialize pointer to spectral target_if internal private data
  2005. *
  2006. * Return: On success, pointer to Spectral target_if internal private data, on
  2007. * failure, NULL
  2008. */
  2009. void *
  2010. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  2011. {
  2012. struct target_if_spectral_ops *p_sops = NULL;
  2013. struct target_if_spectral *spectral = NULL;
  2014. uint32_t target_type;
  2015. uint32_t target_revision;
  2016. struct wlan_objmgr_psoc *psoc;
  2017. struct wlan_lmac_if_target_tx_ops *tgt_tx_ops;
  2018. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  2019. QDF_STATUS status;
  2020. struct wlan_lmac_if_tx_ops *tx_ops;
  2021. if (!pdev) {
  2022. spectral_err("SPECTRAL: pdev is NULL!");
  2023. return NULL;
  2024. }
  2025. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  2026. sizeof(struct target_if_spectral));
  2027. if (!spectral)
  2028. return spectral;
  2029. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  2030. /* Store pdev in Spectral */
  2031. spectral->pdev_obj = pdev;
  2032. psoc = wlan_pdev_get_psoc(pdev);
  2033. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  2034. if (!tx_ops) {
  2035. spectral_err("tx_ops is NULL");
  2036. qdf_mem_free(spectral);
  2037. return NULL;
  2038. }
  2039. tgt_tx_ops = &tx_ops->target_tx_ops;
  2040. if (tgt_tx_ops->tgt_get_tgt_type) {
  2041. target_type = tgt_tx_ops->tgt_get_tgt_type(psoc);
  2042. } else {
  2043. qdf_mem_free(spectral);
  2044. return NULL;
  2045. }
  2046. if (tgt_tx_ops->tgt_get_tgt_revision) {
  2047. target_revision = tgt_tx_ops->tgt_get_tgt_revision(psoc);
  2048. } else {
  2049. qdf_mem_free(spectral);
  2050. return NULL;
  2051. }
  2052. /* init the function ptr table */
  2053. target_if_spectral_init_dummy_function_table(spectral);
  2054. /* get spectral function table */
  2055. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2056. /* TODO : Should this be called here of after ath_attach ? */
  2057. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  2058. spectral_info("HAL_CAP_PHYDIAG : Capable");
  2059. /* TODO: Need to fix the capablity check for RADAR */
  2060. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  2061. spectral_info("HAL_CAP_RADAR : Capable");
  2062. /* TODO : Need to fix the capablity check for SPECTRAL */
  2063. /* TODO : Should this be called here of after ath_attach ? */
  2064. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  2065. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  2066. qdf_spinlock_create(&spectral->spectral_lock);
  2067. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  2068. target_if_spectral_clear_stats(spectral);
  2069. if (target_type == TARGET_TYPE_QCA8074 ||
  2070. target_type == TARGET_TYPE_QCA8074V2 ||
  2071. target_type == TARGET_TYPE_QCA6018 ||
  2072. target_type == TARGET_TYPE_QCA5018 ||
  2073. target_type == TARGET_TYPE_QCA6390 ||
  2074. target_type == TARGET_TYPE_QCA6490 ||
  2075. target_type == TARGET_TYPE_QCN9000 ||
  2076. target_type == TARGET_TYPE_QCA6750)
  2077. spectral->direct_dma_support = true;
  2078. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  2079. target_type);
  2080. target_if_spectral_report_params_init(&spectral->rparams, target_type);
  2081. if ((target_type == TARGET_TYPE_QCA8074) ||
  2082. (target_type == TARGET_TYPE_QCA8074V2) ||
  2083. (target_type == TARGET_TYPE_QCA6018) ||
  2084. (target_type == TARGET_TYPE_QCA5018) ||
  2085. (target_type == TARGET_TYPE_QCN9000) ||
  2086. (target_type == TARGET_TYPE_QCA6290) ||
  2087. (target_type == TARGET_TYPE_QCA6390) ||
  2088. (target_type == TARGET_TYPE_QCA6490) ||
  2089. (target_type == TARGET_TYPE_QCA6750)) {
  2090. spectral->spectral_gen = SPECTRAL_GEN3;
  2091. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  2092. spectral->tag_sscan_summary_exp =
  2093. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  2094. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  2095. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  2096. } else {
  2097. spectral->spectral_gen = SPECTRAL_GEN2;
  2098. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  2099. spectral->tag_sscan_summary_exp =
  2100. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  2101. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  2102. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  2103. }
  2104. status = target_if_init_spectral_param_min_max(
  2105. &spectral->param_min_max,
  2106. spectral->spectral_gen, target_type);
  2107. if (QDF_IS_STATUS_ERROR(status)) {
  2108. spectral_err("Failed to initialize parameter min max values");
  2109. goto fail;
  2110. }
  2111. target_if_init_spectral_param_properties(spectral);
  2112. /* Init spectral capability */
  2113. if (target_if_init_spectral_capability(spectral, target_type) !=
  2114. QDF_STATUS_SUCCESS) {
  2115. qdf_mem_free(spectral);
  2116. return NULL;
  2117. }
  2118. if (target_if_spectral_attach_simulation(spectral) < 0)
  2119. return NULL;
  2120. target_if_init_spectral_ops(spectral);
  2121. target_if_spectral_timestamp_war_init(&spectral->timestamp_war);
  2122. /* Spectral mode specific init */
  2123. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2124. spectral->params_valid[smode] = false;
  2125. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  2126. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  2127. }
  2128. target_if_spectral_register_funcs(spectral, &spectral_ops);
  2129. if (target_if_spectral_check_hw_capability(spectral) == false) {
  2130. goto fail;
  2131. } else {
  2132. /*
  2133. * TODO: Once the driver architecture transitions to chipset
  2134. * versioning based checks, reflect this here.
  2135. */
  2136. spectral->is_160_format = false;
  2137. spectral->is_lb_edge_extrabins_format = false;
  2138. spectral->is_rb_edge_extrabins_format = false;
  2139. if (target_type == TARGET_TYPE_QCA9984 ||
  2140. target_type == TARGET_TYPE_QCA9888) {
  2141. spectral->is_160_format = true;
  2142. spectral->is_lb_edge_extrabins_format = true;
  2143. spectral->is_rb_edge_extrabins_format = true;
  2144. } else if ((target_type == TARGET_TYPE_AR900B) &&
  2145. (target_revision == AR900B_REV_2)) {
  2146. spectral->is_rb_edge_extrabins_format = true;
  2147. }
  2148. if (target_type == TARGET_TYPE_QCA9984 ||
  2149. target_type == TARGET_TYPE_QCA9888)
  2150. spectral->is_sec80_rssi_war_required = true;
  2151. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  2152. if (spectral->spectral_gen == SPECTRAL_GEN3)
  2153. init_160mhz_delivery_state_machine(spectral);
  2154. }
  2155. return spectral;
  2156. fail:
  2157. target_if_spectral_detach(spectral);
  2158. return NULL;
  2159. }
  2160. /**
  2161. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  2162. * functionality for the given pdev
  2163. * @pdev: Pointer to pdev object
  2164. *
  2165. * Function to de-initialize pointer to spectral target_if internal private data
  2166. *
  2167. * Return: None
  2168. */
  2169. void
  2170. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  2171. {
  2172. struct target_if_spectral *spectral = NULL;
  2173. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2174. if (!spectral) {
  2175. spectral_err("SPECTRAL : Module doesn't exist");
  2176. return;
  2177. }
  2178. target_if_spectral_detach(spectral);
  2179. return;
  2180. }
  2181. /**
  2182. * target_if_psoc_spectral_deinit() - De-initialize target_if Spectral
  2183. * functionality for the given psoc
  2184. * @psoc: Pointer to psoc object
  2185. *
  2186. * Function to de-initialize pointer to psoc spectral target_if internal
  2187. * private data
  2188. *
  2189. * Return: None
  2190. */
  2191. static void
  2192. target_if_psoc_spectral_deinit(struct wlan_objmgr_psoc *psoc)
  2193. {
  2194. struct target_if_psoc_spectral *psoc_spectral;
  2195. if (!psoc) {
  2196. spectral_err("psoc is null");
  2197. return;
  2198. }
  2199. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  2200. if (!psoc_spectral) {
  2201. spectral_err("Spectral target_if psoc object is null");
  2202. return;
  2203. }
  2204. qdf_mem_free(psoc_spectral);
  2205. }
  2206. /**
  2207. * target_if_psoc_spectral_init() - Initialize target_if Spectral
  2208. * functionality for the given psoc
  2209. * @psoc: Pointer to psoc object
  2210. *
  2211. * Function to initialize pointer to psoc spectral target_if internal
  2212. * private data
  2213. *
  2214. * Return: On success, pointer to Spectral psoc target_if internal
  2215. * private data, on failure, NULL
  2216. */
  2217. static void *
  2218. target_if_psoc_spectral_init(struct wlan_objmgr_psoc *psoc)
  2219. {
  2220. struct target_if_psoc_spectral *psoc_spectral = NULL;
  2221. if (!psoc) {
  2222. spectral_err("psoc is null");
  2223. goto fail;
  2224. }
  2225. psoc_spectral = (struct target_if_psoc_spectral *)qdf_mem_malloc(
  2226. sizeof(struct target_if_psoc_spectral));
  2227. if (!psoc_spectral) {
  2228. spectral_err("Spectral lmac psoc object allocation failed");
  2229. goto fail;
  2230. }
  2231. psoc_spectral->psoc_obj = psoc;
  2232. return psoc_spectral;
  2233. fail:
  2234. if (psoc_spectral)
  2235. target_if_psoc_spectral_deinit(psoc);
  2236. return psoc_spectral;
  2237. }
  2238. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  2239. * corresponding translation for Agile channel width.
  2240. * @spectral: pointer to Spectral object
  2241. * @chwidth: operating channel width
  2242. * @is_80_80_agile: Indicates an 80+80 agile Scan request
  2243. *
  2244. * Return: The translated channel width enum.
  2245. */
  2246. static enum phy_ch_width
  2247. target_if_spectral_find_agile_width(struct target_if_spectral *spectral,
  2248. enum phy_ch_width chwidth,
  2249. bool is_80_80_agile)
  2250. {
  2251. enum phy_ch_width agile_width;
  2252. struct wlan_objmgr_pdev *pdev;
  2253. struct wlan_objmgr_psoc *psoc;
  2254. if (!spectral) {
  2255. spectral_err("Spectral object is null");
  2256. return CH_WIDTH_INVALID;
  2257. }
  2258. pdev = spectral->pdev_obj;
  2259. if (!pdev) {
  2260. spectral_err("pdev is null");
  2261. return CH_WIDTH_INVALID;
  2262. }
  2263. psoc = wlan_pdev_get_psoc(pdev);
  2264. if (!psoc) {
  2265. spectral_err("psoc is null");
  2266. return CH_WIDTH_INVALID;
  2267. }
  2268. switch (chwidth) {
  2269. case CH_WIDTH_20MHZ:
  2270. agile_width = CH_WIDTH_20MHZ;
  2271. break;
  2272. case CH_WIDTH_40MHZ:
  2273. agile_width = CH_WIDTH_40MHZ;
  2274. break;
  2275. case CH_WIDTH_80MHZ:
  2276. agile_width = CH_WIDTH_80MHZ;
  2277. break;
  2278. case CH_WIDTH_80P80MHZ:
  2279. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  2280. WLAN_SOC_RESTRICTED_80P80_SUPPORT) && !is_80_80_agile)
  2281. agile_width = CH_WIDTH_160MHZ;
  2282. else
  2283. agile_width = CH_WIDTH_80P80MHZ;
  2284. if (agile_width > spectral->rparams.max_agile_ch_width)
  2285. agile_width = spectral->rparams.max_agile_ch_width;
  2286. break;
  2287. case CH_WIDTH_160MHZ:
  2288. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  2289. WLAN_SOC_RESTRICTED_80P80_SUPPORT) && is_80_80_agile)
  2290. agile_width = CH_WIDTH_80P80MHZ;
  2291. else
  2292. agile_width = CH_WIDTH_160MHZ;
  2293. if (agile_width > spectral->rparams.max_agile_ch_width)
  2294. agile_width = spectral->rparams.max_agile_ch_width;
  2295. break;
  2296. default:
  2297. spectral_err("Invalid channel width %d", chwidth);
  2298. agile_width = CH_WIDTH_INVALID;
  2299. break;
  2300. }
  2301. return agile_width;
  2302. }
  2303. /**
  2304. * target_if_calculate_center_freq() - Helper routine to
  2305. * check whether given frequency is center frequency of a
  2306. * WLAN channel
  2307. *
  2308. * @spectral: Pointer to Spectral object
  2309. * @chan_freq: Center frequency of a WLAN channel
  2310. * @is_valid: Indicates whether given frequency is valid
  2311. *
  2312. * Return: QDF_STATUS
  2313. */
  2314. static QDF_STATUS
  2315. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  2316. uint32_t chan_freq,
  2317. bool *is_valid)
  2318. {
  2319. struct regulatory_channel *cur_chan_list;
  2320. int i;
  2321. if (!pdev) {
  2322. spectral_err("pdev object is null");
  2323. return QDF_STATUS_E_FAILURE;
  2324. }
  2325. if (!is_valid) {
  2326. spectral_err("is valid argument is null");
  2327. return QDF_STATUS_E_FAILURE;
  2328. }
  2329. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  2330. if (!cur_chan_list)
  2331. return QDF_STATUS_E_FAILURE;
  2332. if (wlan_reg_get_current_chan_list(
  2333. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  2334. spectral_err("Failed to get cur_chan list");
  2335. qdf_mem_free(cur_chan_list);
  2336. return QDF_STATUS_E_FAILURE;
  2337. }
  2338. *is_valid = false;
  2339. for (i = 0; i < NUM_CHANNELS; i++) {
  2340. uint32_t flags;
  2341. uint32_t center_freq;
  2342. flags = cur_chan_list[i].chan_flags;
  2343. center_freq = cur_chan_list[i].center_freq;
  2344. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  2345. (center_freq == chan_freq)) {
  2346. *is_valid = true;
  2347. break;
  2348. }
  2349. }
  2350. qdf_mem_free(cur_chan_list);
  2351. return QDF_STATUS_SUCCESS;
  2352. }
  2353. /**
  2354. * target_if_calculate_center_freq() - Helper routine to
  2355. * find the center frequency of the agile span from a
  2356. * WLAN channel center frequency
  2357. *
  2358. * @spectral: Pointer to Spectral object
  2359. * @ch_width: Channel width array
  2360. * @chan_freq: Center frequency of a WLAN channel
  2361. * @center_freq: Pointer to center frequency
  2362. *
  2363. * Return: QDF_STATUS
  2364. */
  2365. static QDF_STATUS
  2366. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  2367. enum phy_ch_width *ch_width,
  2368. uint16_t chan_freq,
  2369. uint16_t *center_freq)
  2370. {
  2371. enum phy_ch_width agile_ch_width;
  2372. if (!spectral) {
  2373. spectral_err("spectral target if object is null");
  2374. return QDF_STATUS_E_FAILURE;
  2375. }
  2376. if (!ch_width) {
  2377. spectral_err("Channel width array is null");
  2378. return QDF_STATUS_E_INVAL;
  2379. }
  2380. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2381. if (!center_freq) {
  2382. spectral_err("center_freq argument is null");
  2383. return QDF_STATUS_E_FAILURE;
  2384. }
  2385. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2386. *center_freq = chan_freq;
  2387. } else {
  2388. uint16_t start_freq;
  2389. uint16_t end_freq;
  2390. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2391. enum channel_state state;
  2392. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2393. (spectral->pdev_obj, chan_freq, agile_ch_width,
  2394. &bonded_chan_ptr);
  2395. if (state == CHANNEL_STATE_DISABLE ||
  2396. state == CHANNEL_STATE_INVALID) {
  2397. spectral_err("Channel state is disable or invalid");
  2398. return QDF_STATUS_E_FAILURE;
  2399. }
  2400. if (!bonded_chan_ptr) {
  2401. spectral_err("Bonded channel is not found");
  2402. return QDF_STATUS_E_FAILURE;
  2403. }
  2404. start_freq = bonded_chan_ptr->start_freq;
  2405. end_freq = bonded_chan_ptr->end_freq;
  2406. *center_freq = (start_freq + end_freq) >> 1;
  2407. }
  2408. return QDF_STATUS_SUCCESS;
  2409. }
  2410. /**
  2411. * target_if_validate_center_freq() - Helper routine to
  2412. * validate user provided agile center frequency
  2413. *
  2414. * @spectral: Pointer to Spectral object
  2415. * @ch_width: Channel width array
  2416. * @center_freq: User provided agile span center frequency
  2417. * @is_valid: Indicates whether agile span center frequency is valid
  2418. *
  2419. * Return: QDF_STATUS
  2420. */
  2421. static QDF_STATUS
  2422. target_if_validate_center_freq(struct target_if_spectral *spectral,
  2423. enum phy_ch_width *ch_width,
  2424. uint16_t center_freq,
  2425. bool *is_valid)
  2426. {
  2427. enum phy_ch_width agile_ch_width;
  2428. struct wlan_objmgr_pdev *pdev;
  2429. QDF_STATUS status;
  2430. if (!spectral) {
  2431. spectral_err("spectral target if object is null");
  2432. return QDF_STATUS_E_FAILURE;
  2433. }
  2434. if (!ch_width) {
  2435. spectral_err("channel width array is null");
  2436. return QDF_STATUS_E_INVAL;
  2437. }
  2438. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2439. if (!is_valid) {
  2440. spectral_err("is_valid argument is null");
  2441. return QDF_STATUS_E_FAILURE;
  2442. }
  2443. pdev = spectral->pdev_obj;
  2444. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2445. status = target_if_is_center_freq_of_any_chan
  2446. (pdev, center_freq, is_valid);
  2447. if (QDF_IS_STATUS_ERROR(status))
  2448. return QDF_STATUS_E_FAILURE;
  2449. } else {
  2450. uint16_t start_freq;
  2451. uint16_t end_freq;
  2452. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2453. bool is_chan;
  2454. status = target_if_is_center_freq_of_any_chan
  2455. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2456. &is_chan);
  2457. if (QDF_IS_STATUS_ERROR(status))
  2458. return QDF_STATUS_E_FAILURE;
  2459. if (is_chan) {
  2460. uint32_t calulated_center_freq;
  2461. enum channel_state st;
  2462. st = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2463. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2464. agile_ch_width,
  2465. &bonded_chan_ptr);
  2466. if (st == CHANNEL_STATE_DISABLE ||
  2467. st == CHANNEL_STATE_INVALID) {
  2468. spectral_err("Channel state disable/invalid");
  2469. return QDF_STATUS_E_FAILURE;
  2470. }
  2471. if (!bonded_chan_ptr) {
  2472. spectral_err("Bonded channel is not found");
  2473. return QDF_STATUS_E_FAILURE;
  2474. }
  2475. start_freq = bonded_chan_ptr->start_freq;
  2476. end_freq = bonded_chan_ptr->end_freq;
  2477. calulated_center_freq = (start_freq + end_freq) >> 1;
  2478. *is_valid = (center_freq == calulated_center_freq);
  2479. } else {
  2480. *is_valid = false;
  2481. }
  2482. }
  2483. return QDF_STATUS_SUCCESS;
  2484. }
  2485. /**
  2486. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  2487. * check whether agile span overlaps with current operating band.
  2488. *
  2489. * @spectral: Pointer to Spectral object
  2490. * @ch_width: Channel width array
  2491. * @center_freq: Agile span center frequency
  2492. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  2493. *
  2494. * Helper routine to check whether agile span overlaps with current
  2495. * operating band.
  2496. *
  2497. * Return: QDF_STATUS
  2498. */
  2499. static QDF_STATUS
  2500. target_if_is_agile_span_overlap_with_operating_span
  2501. (struct target_if_spectral *spectral,
  2502. enum phy_ch_width *ch_width,
  2503. struct spectral_config_frequency *center_freq,
  2504. bool *is_overlapping)
  2505. {
  2506. enum phy_ch_width op_ch_width;
  2507. enum phy_ch_width agile_ch_width;
  2508. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2509. struct wlan_objmgr_vdev *vdev;
  2510. struct wlan_objmgr_pdev *pdev;
  2511. int16_t chan_freq;
  2512. uint32_t op_start_freq;
  2513. uint32_t op_end_freq;
  2514. uint32_t agile_start_freq;
  2515. uint32_t agile_end_freq;
  2516. uint32_t cfreq2;
  2517. if (!spectral) {
  2518. spectral_err("Spectral object is NULL");
  2519. return QDF_STATUS_E_FAILURE;
  2520. }
  2521. pdev = spectral->pdev_obj;
  2522. if (!pdev) {
  2523. spectral_err("pdev object is NULL");
  2524. return QDF_STATUS_E_FAILURE;
  2525. }
  2526. if (!ch_width) {
  2527. spectral_err("channel width array is null");
  2528. return QDF_STATUS_E_FAILURE;
  2529. }
  2530. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  2531. if (op_ch_width == CH_WIDTH_INVALID) {
  2532. spectral_err("Invalid channel width");
  2533. return QDF_STATUS_E_INVAL;
  2534. }
  2535. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2536. if (agile_ch_width == CH_WIDTH_INVALID) {
  2537. spectral_err("Invalid channel width");
  2538. return QDF_STATUS_E_INVAL;
  2539. }
  2540. if (!is_overlapping) {
  2541. spectral_err("Argument(is_overlapping) is NULL");
  2542. return QDF_STATUS_E_FAILURE;
  2543. }
  2544. *is_overlapping = false;
  2545. vdev = target_if_spectral_get_vdev(spectral);
  2546. if (!vdev) {
  2547. spectral_err("vdev is NULL");
  2548. return QDF_STATUS_E_FAILURE;
  2549. }
  2550. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2551. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2552. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2553. if (cfreq2 < 0) {
  2554. spectral_err("cfreq2 is invalid");
  2555. return QDF_STATUS_E_FAILURE;
  2556. }
  2557. if (op_ch_width == CH_WIDTH_20MHZ) {
  2558. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  2559. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  2560. } else {
  2561. enum channel_state state;
  2562. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2563. (pdev, chan_freq, op_ch_width, &bonded_chan_ptr);
  2564. if (state == CHANNEL_STATE_DISABLE ||
  2565. state == CHANNEL_STATE_INVALID) {
  2566. spectral_err("Channel state is disable or invalid");
  2567. return QDF_STATUS_E_FAILURE;
  2568. }
  2569. if (!bonded_chan_ptr) {
  2570. spectral_err("Bonded channel is not found");
  2571. return QDF_STATUS_E_FAILURE;
  2572. }
  2573. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  2574. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  2575. }
  2576. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  2577. agile_start_freq = center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  2578. agile_end_freq = center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  2579. if (agile_end_freq > op_start_freq &&
  2580. op_end_freq > agile_start_freq)
  2581. *is_overlapping = true;
  2582. agile_start_freq = center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  2583. agile_end_freq = center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  2584. if (agile_end_freq > op_start_freq &&
  2585. op_end_freq > agile_start_freq)
  2586. *is_overlapping = true;
  2587. } else {
  2588. agile_start_freq = center_freq->cfreq1 -
  2589. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2590. agile_end_freq = center_freq->cfreq1 +
  2591. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2592. if (agile_end_freq > op_start_freq &&
  2593. op_end_freq > agile_start_freq)
  2594. *is_overlapping = true;
  2595. }
  2596. if (op_ch_width == CH_WIDTH_80P80MHZ) {
  2597. uint32_t sec80_start_feq;
  2598. uint32_t sec80_end_freq;
  2599. sec80_start_feq = cfreq2 - FREQ_OFFSET_40MHZ;
  2600. sec80_end_freq = cfreq2 + FREQ_OFFSET_40MHZ;
  2601. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  2602. agile_start_freq =
  2603. center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  2604. agile_end_freq =
  2605. center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  2606. if (agile_end_freq > sec80_start_feq &&
  2607. sec80_end_freq > agile_start_freq)
  2608. *is_overlapping = true;
  2609. agile_start_freq =
  2610. center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  2611. agile_end_freq =
  2612. center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  2613. if (agile_end_freq > sec80_start_feq &&
  2614. sec80_end_freq > agile_start_freq)
  2615. *is_overlapping = true;
  2616. } else {
  2617. agile_start_freq = center_freq->cfreq1 -
  2618. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2619. agile_end_freq = center_freq->cfreq1 +
  2620. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2621. if (agile_end_freq > sec80_start_feq &&
  2622. sec80_end_freq > agile_start_freq)
  2623. *is_overlapping = true;
  2624. }
  2625. }
  2626. return QDF_STATUS_SUCCESS;
  2627. }
  2628. /**
  2629. * target_if_spectral_populate_chwidth() - Helper routine to
  2630. * populate channel width for different Spectral modes
  2631. *
  2632. * @spectral: Pointer to Spectral object
  2633. * @ch_width: Channel width array
  2634. * @is_80_80_agile: Indicates whether 80+80 agile scan is requested
  2635. *
  2636. * Helper routine to populate channel width for different Spectral modes
  2637. *
  2638. * Return: QDF_STATUS
  2639. */
  2640. static QDF_STATUS
  2641. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral,
  2642. enum phy_ch_width *ch_width,
  2643. bool is_80_80_agile) {
  2644. struct wlan_objmgr_vdev *vdev;
  2645. enum spectral_scan_mode smode;
  2646. enum phy_ch_width vdev_ch_width;
  2647. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2648. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2649. ch_width[smode] = CH_WIDTH_INVALID;
  2650. if (!spectral) {
  2651. spectral_err("Spectral object is null");
  2652. return QDF_STATUS_E_INVAL;
  2653. }
  2654. vdev = target_if_spectral_get_vdev(spectral);
  2655. if (!vdev) {
  2656. spectral_err("vdev is null");
  2657. return QDF_STATUS_E_FAILURE;
  2658. }
  2659. vdev_ch_width = target_if_vdev_get_ch_width(vdev);
  2660. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2661. if (vdev_ch_width == CH_WIDTH_INVALID) {
  2662. spectral_err("Invalid channel width %d", vdev_ch_width);
  2663. return QDF_STATUS_E_FAILURE;
  2664. }
  2665. ch_width[SPECTRAL_SCAN_MODE_NORMAL] = vdev_ch_width;
  2666. ch_width[SPECTRAL_SCAN_MODE_AGILE] =
  2667. target_if_spectral_find_agile_width(spectral, vdev_ch_width,
  2668. is_80_80_agile);
  2669. return QDF_STATUS_SUCCESS;
  2670. }
  2671. /**
  2672. * target_if_spectral_is_valid_80p80_freq() - API to check whether given
  2673. * (cfreq1, cfreq2) pair forms a valid 80+80 combination
  2674. * @pdev: pointer to pdev
  2675. * @cfreq1: center frequency 1
  2676. * @cfreq2: center frequency 2
  2677. *
  2678. * API to check whether given (cfreq1, cfreq2) pair forms a valid 80+80
  2679. * combination
  2680. *
  2681. * Return: true or false
  2682. */
  2683. static bool
  2684. target_if_spectral_is_valid_80p80_freq(struct wlan_objmgr_pdev *pdev,
  2685. uint32_t cfreq1, uint32_t cfreq2)
  2686. {
  2687. struct ch_params ch_params;
  2688. enum channel_state chan_state1;
  2689. enum channel_state chan_state2;
  2690. struct wlan_objmgr_psoc *psoc;
  2691. qdf_assert_always(pdev);
  2692. psoc = wlan_pdev_get_psoc(pdev);
  2693. qdf_assert_always(psoc);
  2694. /* In restricted 80P80 MHz enabled, only one 80+80 MHz
  2695. * channel is supported with cfreq=5690 and cfreq=5775.
  2696. */
  2697. if (wlan_psoc_nif_fw_ext_cap_get(
  2698. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  2699. return CHAN_WITHIN_RESTRICTED_80P80(cfreq1, cfreq2);
  2700. ch_params.center_freq_seg1 = wlan_reg_freq_to_chan(pdev, cfreq2);
  2701. ch_params.mhz_freq_seg1 = cfreq2;
  2702. ch_params.ch_width = CH_WIDTH_80P80MHZ;
  2703. wlan_reg_set_channel_params_for_freq(pdev, cfreq1 - FREQ_OFFSET_10MHZ,
  2704. 0, &ch_params);
  2705. if (ch_params.ch_width != CH_WIDTH_80P80MHZ)
  2706. return false;
  2707. if (ch_params.mhz_freq_seg0 != cfreq1 ||
  2708. ch_params.mhz_freq_seg1 != cfreq2)
  2709. return false;
  2710. chan_state1 = wlan_reg_get_5g_bonded_channel_state_for_freq(
  2711. pdev,
  2712. ch_params.mhz_freq_seg0 - FREQ_OFFSET_10MHZ,
  2713. CH_WIDTH_80MHZ);
  2714. if ((chan_state1 == CHANNEL_STATE_DISABLE) ||
  2715. (chan_state1 == CHANNEL_STATE_INVALID))
  2716. return false;
  2717. chan_state2 = wlan_reg_get_5g_bonded_channel_state_for_freq(
  2718. pdev,
  2719. ch_params.mhz_freq_seg1 - FREQ_OFFSET_10MHZ,
  2720. CH_WIDTH_80MHZ);
  2721. if ((chan_state2 == CHANNEL_STATE_DISABLE) ||
  2722. (chan_state2 == CHANNEL_STATE_INVALID))
  2723. return false;
  2724. if (abs(ch_params.mhz_freq_seg0 - ch_params.mhz_freq_seg1) <=
  2725. FREQ_OFFSET_80MHZ)
  2726. return false;
  2727. return true;
  2728. }
  2729. /**
  2730. * _target_if_set_spectral_config() - Set spectral config
  2731. * @spectral: Pointer to spectral object
  2732. * @param: Spectral parameter id and value
  2733. * @smode: Spectral scan mode
  2734. * @err: Spectral error code
  2735. *
  2736. * API to set spectral configurations
  2737. *
  2738. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2739. */
  2740. static QDF_STATUS
  2741. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  2742. const struct spectral_cp_param *param,
  2743. const enum spectral_scan_mode smode,
  2744. enum spectral_cp_error_code *err)
  2745. {
  2746. struct spectral_config params;
  2747. struct target_if_spectral_ops *p_sops;
  2748. struct spectral_config *sparams;
  2749. QDF_STATUS status;
  2750. bool is_overlapping;
  2751. uint16_t agile_cfreq;
  2752. bool is_valid_chan;
  2753. struct spectral_param_min_max *param_min_max;
  2754. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  2755. enum spectral_scan_mode m;
  2756. struct spectral_config_frequency center_freq = {0};
  2757. if (!err) {
  2758. spectral_err("Error code argument is null");
  2759. QDF_ASSERT(0);
  2760. return QDF_STATUS_E_FAILURE;
  2761. }
  2762. *err = SPECTRAL_SCAN_ERR_INVALID;
  2763. if (!param) {
  2764. spectral_err("Parameter object is null");
  2765. return QDF_STATUS_E_FAILURE;
  2766. }
  2767. if (!spectral) {
  2768. spectral_err("spectral object is NULL");
  2769. return QDF_STATUS_E_FAILURE;
  2770. }
  2771. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2772. param_min_max = &spectral->param_min_max;
  2773. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2774. spectral_err("Invalid Spectral mode %u", smode);
  2775. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2776. return QDF_STATUS_E_FAILURE;
  2777. }
  2778. sparams = &spectral->params[smode];
  2779. m = SPECTRAL_SCAN_MODE_NORMAL;
  2780. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  2781. ch_width[m] = CH_WIDTH_INVALID;
  2782. if (!spectral->params_valid[smode]) {
  2783. target_if_spectral_info_read(spectral,
  2784. smode,
  2785. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2786. &spectral->params[smode],
  2787. sizeof(spectral->params[smode]));
  2788. spectral->params_valid[smode] = true;
  2789. }
  2790. switch (param->id) {
  2791. case SPECTRAL_PARAM_FFT_PERIOD:
  2792. sparams->ss_fft_period = param->value;
  2793. break;
  2794. case SPECTRAL_PARAM_SCAN_PERIOD:
  2795. sparams->ss_period = param->value;
  2796. break;
  2797. case SPECTRAL_PARAM_SCAN_COUNT:
  2798. sparams->ss_count = param->value;
  2799. break;
  2800. case SPECTRAL_PARAM_SHORT_REPORT:
  2801. sparams->ss_short_report = (!!param->value) ? true : false;
  2802. break;
  2803. case SPECTRAL_PARAM_SPECT_PRI:
  2804. sparams->ss_spectral_pri = (!!param->value) ? true : false;
  2805. break;
  2806. case SPECTRAL_PARAM_FFT_SIZE:
  2807. status = target_if_spectral_populate_chwidth
  2808. (spectral, ch_width, spectral->params
  2809. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  2810. if (QDF_IS_STATUS_ERROR(status))
  2811. return QDF_STATUS_E_FAILURE;
  2812. if ((param->value < param_min_max->fft_size_min) ||
  2813. (param->value > param_min_max->fft_size_max
  2814. [ch_width[smode]])) {
  2815. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2816. return QDF_STATUS_E_FAILURE;
  2817. }
  2818. sparams->ss_fft_size = param->value;
  2819. break;
  2820. case SPECTRAL_PARAM_GC_ENA:
  2821. sparams->ss_gc_ena = !!param->value;
  2822. break;
  2823. case SPECTRAL_PARAM_RESTART_ENA:
  2824. sparams->ss_restart_ena = !!param->value;
  2825. break;
  2826. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  2827. sparams->ss_noise_floor_ref = param->value;
  2828. break;
  2829. case SPECTRAL_PARAM_INIT_DELAY:
  2830. sparams->ss_init_delay = param->value;
  2831. break;
  2832. case SPECTRAL_PARAM_NB_TONE_THR:
  2833. sparams->ss_nb_tone_thr = param->value;
  2834. break;
  2835. case SPECTRAL_PARAM_STR_BIN_THR:
  2836. sparams->ss_str_bin_thr = param->value;
  2837. break;
  2838. case SPECTRAL_PARAM_WB_RPT_MODE:
  2839. sparams->ss_wb_rpt_mode = !!param->value;
  2840. break;
  2841. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  2842. sparams->ss_rssi_rpt_mode = !!param->value;
  2843. break;
  2844. case SPECTRAL_PARAM_RSSI_THR:
  2845. sparams->ss_rssi_thr = param->value;
  2846. break;
  2847. case SPECTRAL_PARAM_PWR_FORMAT:
  2848. sparams->ss_pwr_format = !!param->value;
  2849. break;
  2850. case SPECTRAL_PARAM_RPT_MODE:
  2851. if ((param->value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  2852. (param->value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  2853. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2854. return QDF_STATUS_E_FAILURE;
  2855. }
  2856. sparams->ss_rpt_mode = param->value;
  2857. break;
  2858. case SPECTRAL_PARAM_BIN_SCALE:
  2859. sparams->ss_bin_scale = param->value;
  2860. break;
  2861. case SPECTRAL_PARAM_DBM_ADJ:
  2862. sparams->ss_dbm_adj = !!param->value;
  2863. break;
  2864. case SPECTRAL_PARAM_CHN_MASK:
  2865. sparams->ss_chn_mask = param->value;
  2866. break;
  2867. case SPECTRAL_PARAM_FREQUENCY:
  2868. status = target_if_spectral_populate_chwidth(
  2869. spectral, ch_width, param->freq.cfreq2 > 0);
  2870. if (QDF_IS_STATUS_ERROR(status)) {
  2871. spectral_err("Failed to populate channel width");
  2872. return QDF_STATUS_E_FAILURE;
  2873. }
  2874. if (ch_width[smode] != CH_WIDTH_80P80MHZ &&
  2875. param->freq.cfreq2) {
  2876. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2877. spectral_err("Non zero cfreq2 expected for 80p80 only");
  2878. return QDF_STATUS_E_INVAL;
  2879. }
  2880. if (ch_width[smode] == CH_WIDTH_80P80MHZ &&
  2881. !param->freq.cfreq2) {
  2882. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2883. spectral_err("Non zero cfreq2 expected for 80p80");
  2884. return QDF_STATUS_E_INVAL;
  2885. }
  2886. status = target_if_is_center_freq_of_any_chan
  2887. (spectral->pdev_obj, param->freq.cfreq1,
  2888. &is_valid_chan);
  2889. if (QDF_IS_STATUS_ERROR(status))
  2890. return QDF_STATUS_E_FAILURE;
  2891. if (is_valid_chan) {
  2892. status = target_if_calculate_center_freq(
  2893. spectral, ch_width,
  2894. param->freq.cfreq1,
  2895. &agile_cfreq);
  2896. if (QDF_IS_STATUS_ERROR(status)) {
  2897. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2898. return QDF_STATUS_E_FAILURE;
  2899. }
  2900. } else {
  2901. bool is_valid_agile_cfreq;
  2902. status = target_if_validate_center_freq
  2903. (spectral, ch_width, param->freq.cfreq1,
  2904. &is_valid_agile_cfreq);
  2905. if (QDF_IS_STATUS_ERROR(status))
  2906. return QDF_STATUS_E_FAILURE;
  2907. if (!is_valid_agile_cfreq) {
  2908. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2909. spectral_err("Invalid agile center frequency");
  2910. return QDF_STATUS_E_FAILURE;
  2911. }
  2912. agile_cfreq = param->freq.cfreq1;
  2913. }
  2914. center_freq.cfreq1 = agile_cfreq;
  2915. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  2916. status = target_if_is_center_freq_of_any_chan
  2917. (spectral->pdev_obj, param->freq.cfreq2,
  2918. &is_valid_chan);
  2919. if (QDF_IS_STATUS_ERROR(status))
  2920. return QDF_STATUS_E_FAILURE;
  2921. if (is_valid_chan) {
  2922. status = target_if_calculate_center_freq(
  2923. spectral, ch_width,
  2924. param->freq.cfreq2,
  2925. &agile_cfreq);
  2926. if (QDF_IS_STATUS_ERROR(status)) {
  2927. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2928. return QDF_STATUS_E_FAILURE;
  2929. }
  2930. } else {
  2931. bool is_valid_agile_cfreq;
  2932. status = target_if_validate_center_freq
  2933. (spectral, ch_width, param->freq.cfreq2,
  2934. &is_valid_agile_cfreq);
  2935. if (QDF_IS_STATUS_ERROR(status))
  2936. return QDF_STATUS_E_FAILURE;
  2937. if (!is_valid_agile_cfreq) {
  2938. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2939. spectral_err("Invalid agile center frequency");
  2940. return QDF_STATUS_E_FAILURE;
  2941. }
  2942. agile_cfreq = param->freq.cfreq2;
  2943. }
  2944. center_freq.cfreq2 = agile_cfreq;
  2945. }
  2946. status = target_if_is_agile_span_overlap_with_operating_span
  2947. (spectral, ch_width,
  2948. &center_freq, &is_overlapping);
  2949. if (QDF_IS_STATUS_ERROR(status))
  2950. return QDF_STATUS_E_FAILURE;
  2951. if (is_overlapping) {
  2952. spectral_err("Agile freq %u, %u overlaps with operating span",
  2953. center_freq.cfreq1, center_freq.cfreq2);
  2954. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2955. return QDF_STATUS_E_FAILURE;
  2956. }
  2957. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  2958. bool is_valid_80p80;
  2959. is_valid_80p80 = target_if_spectral_is_valid_80p80_freq(
  2960. spectral->pdev_obj,
  2961. center_freq.cfreq1,
  2962. center_freq.cfreq2);
  2963. if (!is_valid_80p80) {
  2964. spectral_err("Agile freq %u, %u is invalid 80+80 combination",
  2965. center_freq.cfreq1,
  2966. center_freq.cfreq2);
  2967. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2968. return QDF_STATUS_E_FAILURE;
  2969. }
  2970. }
  2971. sparams->ss_frequency.cfreq1 = center_freq.cfreq1;
  2972. sparams->ss_frequency.cfreq2 = center_freq.cfreq2;
  2973. break;
  2974. }
  2975. p_sops->configure_spectral(spectral, sparams, smode);
  2976. /* only to validate the writes */
  2977. p_sops->get_spectral_config(spectral, &params, smode);
  2978. return QDF_STATUS_SUCCESS;
  2979. }
  2980. QDF_STATUS
  2981. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  2982. const struct spectral_cp_param *param,
  2983. const enum spectral_scan_mode smode,
  2984. enum spectral_cp_error_code *err)
  2985. {
  2986. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  2987. struct target_if_spectral *spectral;
  2988. QDF_STATUS status;
  2989. if (!err) {
  2990. spectral_err("Error code argument is null");
  2991. QDF_ASSERT(0);
  2992. return QDF_STATUS_E_FAILURE;
  2993. }
  2994. *err = SPECTRAL_SCAN_ERR_INVALID;
  2995. if (!pdev) {
  2996. spectral_err("pdev object is NULL");
  2997. return QDF_STATUS_E_FAILURE;
  2998. }
  2999. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3000. if (!spectral) {
  3001. spectral_err("spectral object is NULL");
  3002. return QDF_STATUS_E_FAILURE;
  3003. }
  3004. if (!param) {
  3005. spectral_err("parameter object is NULL");
  3006. return QDF_STATUS_E_FAILURE;
  3007. }
  3008. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3009. spectral_err("Invalid Spectral mode %u", smode);
  3010. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3011. return QDF_STATUS_E_FAILURE;
  3012. }
  3013. if (!spectral->properties[smode][param->id].supported) {
  3014. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  3015. param->id, smode);
  3016. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  3017. return QDF_STATUS_E_FAILURE;
  3018. }
  3019. if (spectral->properties[smode][param->id].common_all_modes) {
  3020. spectral_warn("Setting Spectral parameter %u for all modes",
  3021. param->id);
  3022. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  3023. status = _target_if_set_spectral_config
  3024. (spectral, param, mode, err);
  3025. if (QDF_IS_STATUS_ERROR(status))
  3026. return QDF_STATUS_E_FAILURE;
  3027. }
  3028. return QDF_STATUS_SUCCESS;
  3029. }
  3030. return _target_if_set_spectral_config(spectral, param, smode, err);
  3031. }
  3032. /**
  3033. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  3034. * @fft_len: FFT length
  3035. * @pdev: Pointer to pdev object
  3036. *
  3037. * API to get fft bin count for a given fft length
  3038. *
  3039. * Return: FFt bin count
  3040. */
  3041. static int
  3042. target_if_get_fft_bin_count(int fft_len)
  3043. {
  3044. int bin_count = 0;
  3045. switch (fft_len) {
  3046. case 5:
  3047. bin_count = 16;
  3048. break;
  3049. case 6:
  3050. bin_count = 32;
  3051. break;
  3052. case 7:
  3053. bin_count = 64;
  3054. break;
  3055. case 8:
  3056. bin_count = 128;
  3057. break;
  3058. case 9:
  3059. bin_count = 256;
  3060. break;
  3061. default:
  3062. break;
  3063. }
  3064. return bin_count;
  3065. }
  3066. /**
  3067. * target_if_init_upper_lower_flags() - Initializes control and extension
  3068. * segment flags
  3069. * @fft_len: FFT length
  3070. * @pdev: Pointer to pdev object
  3071. *
  3072. * API to initialize the control and extension flags with the lower/upper
  3073. * segment based on the HT mode
  3074. *
  3075. * Return: FFt bin count
  3076. */
  3077. static void
  3078. target_if_init_upper_lower_flags(struct target_if_spectral *spectral)
  3079. {
  3080. int current_channel = 0;
  3081. int ext_channel = 0;
  3082. struct target_if_spectral_ops *p_sops =
  3083. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3084. current_channel = p_sops->get_current_channel(spectral);
  3085. ext_channel = p_sops->get_extension_channel(spectral);
  3086. if ((current_channel == 0) || (ext_channel == 0))
  3087. return;
  3088. if (spectral->sc_spectral_20_40_mode) {
  3089. /* HT40 mode */
  3090. if (ext_channel < current_channel) {
  3091. spectral->lower_is_extension = 1;
  3092. spectral->upper_is_control = 1;
  3093. spectral->lower_is_control = 0;
  3094. spectral->upper_is_extension = 0;
  3095. } else {
  3096. spectral->lower_is_extension = 0;
  3097. spectral->upper_is_control = 0;
  3098. spectral->lower_is_control = 1;
  3099. spectral->upper_is_extension = 1;
  3100. }
  3101. } else {
  3102. /* HT20 mode, lower is always control */
  3103. spectral->lower_is_extension = 0;
  3104. spectral->upper_is_control = 0;
  3105. spectral->lower_is_control = 1;
  3106. spectral->upper_is_extension = 0;
  3107. }
  3108. }
  3109. /**
  3110. * target_if_get_spectral_config() - Get spectral configuration
  3111. * @pdev: Pointer to pdev object
  3112. * @param: Pointer to spectral_config structure in which the configuration
  3113. * should be returned
  3114. * @smode: Spectral scan mode
  3115. *
  3116. * API to get the current spectral configuration
  3117. *
  3118. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3119. */
  3120. QDF_STATUS
  3121. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  3122. struct spectral_config *param,
  3123. enum spectral_scan_mode smode)
  3124. {
  3125. struct target_if_spectral_ops *p_sops = NULL;
  3126. struct target_if_spectral *spectral = NULL;
  3127. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3128. if (!spectral) {
  3129. spectral_err("SPECTRAL : Module doesn't exist");
  3130. return QDF_STATUS_E_FAILURE;
  3131. }
  3132. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3133. if (!p_sops) {
  3134. spectral_err("p_sops is null");
  3135. return QDF_STATUS_E_FAILURE;
  3136. }
  3137. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3138. spectral_err("Invalid Spectral mode %u", smode);
  3139. return QDF_STATUS_E_FAILURE;
  3140. }
  3141. qdf_mem_zero(param, sizeof(struct spectral_config));
  3142. p_sops->get_spectral_config(spectral, param, smode);
  3143. return QDF_STATUS_SUCCESS;
  3144. }
  3145. /**
  3146. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  3147. * parameters
  3148. * @spectral: Pointer to Spectral target_if internal private data
  3149. * @spectral_params: Pointer to Spectral parameters
  3150. * @smode: Spectral scan mode
  3151. * @err: Spectral error code
  3152. *
  3153. * Enable use of desired Spectral parameters by configuring them into HW, and
  3154. * starting Spectral scan
  3155. *
  3156. * Return: 0 on success, 1 on failure
  3157. */
  3158. int
  3159. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  3160. struct spectral_config *spectral_params,
  3161. enum spectral_scan_mode smode,
  3162. enum spectral_cp_error_code *err)
  3163. {
  3164. int extension_channel = 0;
  3165. int current_channel = 0;
  3166. struct target_if_spectral_ops *p_sops = NULL;
  3167. QDF_STATUS status;
  3168. struct wlan_objmgr_pdev *pdev;
  3169. struct wlan_objmgr_psoc *psoc;
  3170. if (!spectral) {
  3171. spectral_err("Spectral LMAC object is NULL");
  3172. return 1;
  3173. }
  3174. pdev = spectral->pdev_obj;
  3175. if (!pdev) {
  3176. spectral_err("pdev is null");
  3177. return QDF_STATUS_E_INVAL;
  3178. }
  3179. psoc = wlan_pdev_get_psoc(pdev);
  3180. if (!psoc) {
  3181. spectral_err("psoc is null");
  3182. return QDF_STATUS_E_INVAL;
  3183. }
  3184. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3185. spectral_err("Invalid Spectral mode %u", smode);
  3186. return 1;
  3187. }
  3188. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3189. if (!p_sops) {
  3190. spectral_err("p_sops is NULL");
  3191. return 1;
  3192. }
  3193. spectral->sc_spectral_noise_pwr_cal =
  3194. spectral_params->ss_spectral_pri ? 1 : 0;
  3195. /* check if extension channel is present */
  3196. extension_channel = p_sops->get_extension_channel(spectral);
  3197. current_channel = p_sops->get_current_channel(spectral);
  3198. status = target_if_spectral_populate_chwidth(
  3199. spectral, spectral->ch_width,
  3200. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  3201. ss_frequency.cfreq2 > 0);
  3202. if (QDF_IS_STATUS_ERROR(status)) {
  3203. spectral_err("Failed to get channel widths");
  3204. return 1;
  3205. }
  3206. if (spectral->capability.advncd_spectral_cap) {
  3207. spectral->lb_edge_extrabins = 0;
  3208. spectral->rb_edge_extrabins = 0;
  3209. if (spectral->is_lb_edge_extrabins_format &&
  3210. spectral->params[smode].ss_rpt_mode == 2) {
  3211. spectral->lb_edge_extrabins = 4;
  3212. }
  3213. if (spectral->is_rb_edge_extrabins_format &&
  3214. spectral->params[smode].ss_rpt_mode == 2) {
  3215. spectral->rb_edge_extrabins = 4;
  3216. }
  3217. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  3218. spectral->sc_spectral_20_40_mode = 0;
  3219. spectral->spectral_numbins =
  3220. target_if_get_fft_bin_count(
  3221. spectral->params[smode].ss_fft_size);
  3222. spectral->spectral_fft_len =
  3223. target_if_get_fft_bin_count(
  3224. spectral->params[smode].ss_fft_size);
  3225. spectral->spectral_data_len =
  3226. target_if_get_fft_bin_count(
  3227. spectral->params[smode].ss_fft_size);
  3228. /*
  3229. * Initialize classifier params to be sent to user
  3230. * space classifier
  3231. */
  3232. spectral->classifier_params.lower_chan_in_mhz =
  3233. current_channel;
  3234. spectral->classifier_params.upper_chan_in_mhz = 0;
  3235. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  3236. /* TODO : Remove this variable */
  3237. spectral->sc_spectral_20_40_mode = 1;
  3238. spectral->spectral_numbins =
  3239. target_if_get_fft_bin_count(
  3240. spectral->params[smode].ss_fft_size);
  3241. spectral->spectral_fft_len =
  3242. target_if_get_fft_bin_count(
  3243. spectral->params[smode].ss_fft_size);
  3244. spectral->spectral_data_len =
  3245. target_if_get_fft_bin_count(
  3246. spectral->params[smode].ss_fft_size);
  3247. /*
  3248. * Initialize classifier params to be sent to user
  3249. * space classifier
  3250. */
  3251. if (extension_channel < current_channel) {
  3252. spectral->classifier_params.lower_chan_in_mhz =
  3253. extension_channel;
  3254. spectral->classifier_params.upper_chan_in_mhz =
  3255. current_channel;
  3256. } else {
  3257. spectral->classifier_params.lower_chan_in_mhz =
  3258. current_channel;
  3259. spectral->classifier_params.upper_chan_in_mhz =
  3260. extension_channel;
  3261. }
  3262. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  3263. /* Set the FFT Size */
  3264. /* TODO : Remove this variable */
  3265. spectral->sc_spectral_20_40_mode = 0;
  3266. spectral->spectral_numbins =
  3267. target_if_get_fft_bin_count(
  3268. spectral->params[smode].ss_fft_size);
  3269. spectral->spectral_fft_len =
  3270. target_if_get_fft_bin_count(
  3271. spectral->params[smode].ss_fft_size);
  3272. spectral->spectral_data_len =
  3273. target_if_get_fft_bin_count(
  3274. spectral->params[smode].ss_fft_size);
  3275. /*
  3276. * Initialize classifier params to be sent to user
  3277. * space classifier
  3278. */
  3279. spectral->classifier_params.lower_chan_in_mhz =
  3280. current_channel;
  3281. spectral->classifier_params.upper_chan_in_mhz = 0;
  3282. /*
  3283. * Initialize classifier params to be sent to user
  3284. * space classifier
  3285. */
  3286. if (extension_channel < current_channel) {
  3287. spectral->classifier_params.lower_chan_in_mhz =
  3288. extension_channel;
  3289. spectral->classifier_params.upper_chan_in_mhz =
  3290. current_channel;
  3291. } else {
  3292. spectral->classifier_params.lower_chan_in_mhz =
  3293. current_channel;
  3294. spectral->classifier_params.upper_chan_in_mhz =
  3295. extension_channel;
  3296. }
  3297. } else if (is_ch_width_160_or_80p80(
  3298. spectral->ch_width[smode])) {
  3299. /* Set the FFT Size */
  3300. /* The below applies to both 160 and 80+80 cases */
  3301. /* TODO : Remove this variable */
  3302. spectral->sc_spectral_20_40_mode = 0;
  3303. spectral->spectral_numbins =
  3304. target_if_get_fft_bin_count(
  3305. spectral->params[smode].ss_fft_size);
  3306. spectral->spectral_fft_len =
  3307. target_if_get_fft_bin_count(
  3308. spectral->params[smode].ss_fft_size);
  3309. spectral->spectral_data_len =
  3310. target_if_get_fft_bin_count(
  3311. spectral->params[smode].ss_fft_size);
  3312. /*
  3313. * Initialize classifier params to be sent to user
  3314. * space classifier
  3315. */
  3316. spectral->classifier_params.lower_chan_in_mhz =
  3317. current_channel;
  3318. spectral->classifier_params.upper_chan_in_mhz = 0;
  3319. /*
  3320. * Initialize classifier params to be sent to user
  3321. * space classifier
  3322. */
  3323. if (extension_channel < current_channel) {
  3324. spectral->classifier_params.lower_chan_in_mhz =
  3325. extension_channel;
  3326. spectral->classifier_params.upper_chan_in_mhz =
  3327. current_channel;
  3328. } else {
  3329. spectral->classifier_params.lower_chan_in_mhz =
  3330. current_channel;
  3331. spectral->classifier_params.upper_chan_in_mhz =
  3332. extension_channel;
  3333. }
  3334. }
  3335. if (spectral->spectral_numbins) {
  3336. spectral->spectral_numbins +=
  3337. spectral->lb_edge_extrabins;
  3338. spectral->spectral_numbins +=
  3339. spectral->rb_edge_extrabins;
  3340. }
  3341. if (spectral->spectral_fft_len) {
  3342. spectral->spectral_fft_len +=
  3343. spectral->lb_edge_extrabins;
  3344. spectral->spectral_fft_len +=
  3345. spectral->rb_edge_extrabins;
  3346. }
  3347. if (spectral->spectral_data_len) {
  3348. spectral->spectral_data_len +=
  3349. spectral->lb_edge_extrabins;
  3350. spectral->spectral_data_len +=
  3351. spectral->rb_edge_extrabins;
  3352. }
  3353. } else {
  3354. /*
  3355. * The decision to find 20/40 mode is found based on the
  3356. * presence of extension channel
  3357. * instead of channel width, as the channel width can
  3358. * dynamically change
  3359. */
  3360. if (extension_channel == 0) {
  3361. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  3362. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  3363. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  3364. spectral->spectral_data_len =
  3365. SPECTRAL_HT20_TOTAL_DATA_LEN;
  3366. /* only valid in 20-40 mode */
  3367. spectral->spectral_lower_max_index_offset = -1;
  3368. /* only valid in 20-40 mode */
  3369. spectral->spectral_upper_max_index_offset = -1;
  3370. spectral->spectral_max_index_offset =
  3371. spectral->spectral_fft_len + 2;
  3372. spectral->sc_spectral_20_40_mode = 0;
  3373. /*
  3374. * Initialize classifier params to be sent to user
  3375. * space classifier
  3376. */
  3377. spectral->classifier_params.lower_chan_in_mhz =
  3378. current_channel;
  3379. spectral->classifier_params.upper_chan_in_mhz = 0;
  3380. } else {
  3381. spectral->spectral_numbins =
  3382. SPECTRAL_HT40_TOTAL_NUM_BINS;
  3383. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  3384. spectral->spectral_data_len =
  3385. SPECTRAL_HT40_TOTAL_DATA_LEN;
  3386. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  3387. /* only valid in 20 mode */
  3388. spectral->spectral_max_index_offset = -1;
  3389. spectral->spectral_lower_max_index_offset =
  3390. spectral->spectral_fft_len + 2;
  3391. spectral->spectral_upper_max_index_offset =
  3392. spectral->spectral_fft_len + 5;
  3393. spectral->sc_spectral_20_40_mode = 1;
  3394. /*
  3395. * Initialize classifier params to be sent to user
  3396. * space classifier
  3397. */
  3398. if (extension_channel < current_channel) {
  3399. spectral->classifier_params.lower_chan_in_mhz =
  3400. extension_channel;
  3401. spectral->classifier_params.upper_chan_in_mhz =
  3402. current_channel;
  3403. } else {
  3404. spectral->classifier_params.lower_chan_in_mhz =
  3405. current_channel;
  3406. spectral->classifier_params.upper_chan_in_mhz =
  3407. extension_channel;
  3408. }
  3409. }
  3410. }
  3411. spectral->send_single_packet = 0;
  3412. spectral->classifier_params.spectral_20_40_mode =
  3413. spectral->sc_spectral_20_40_mode;
  3414. spectral->classifier_params.spectral_dc_index =
  3415. spectral->spectral_dc_index;
  3416. spectral->spectral_sent_msg = 0;
  3417. spectral->classify_scan = 0;
  3418. spectral->num_spectral_data = 0;
  3419. if (!p_sops->is_spectral_active(spectral, smode)) {
  3420. p_sops->configure_spectral(spectral, spectral_params, smode);
  3421. spectral->rparams.marker[smode].is_valid = false;
  3422. p_sops->start_spectral_scan(spectral, smode, err);
  3423. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  3424. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  3425. }
  3426. /* get current spectral configuration */
  3427. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  3428. target_if_init_upper_lower_flags(spectral);
  3429. return 0;
  3430. }
  3431. /**
  3432. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  3433. * Agile DFS
  3434. * @psoc: Pointer to psoc
  3435. * @object: Pointer to pdev
  3436. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  3437. *
  3438. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  3439. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  3440. *
  3441. * Return: void
  3442. */
  3443. static void
  3444. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  3445. void *object, void *arg)
  3446. {
  3447. bool *is_aspectral_prohibited = arg;
  3448. struct wlan_objmgr_pdev *cur_pdev = object;
  3449. bool is_agile_dfs_enabled_cur_pdev = false;
  3450. QDF_STATUS status;
  3451. qdf_assert_always(is_aspectral_prohibited);
  3452. if (*is_aspectral_prohibited)
  3453. return;
  3454. qdf_assert_always(psoc);
  3455. qdf_assert_always(cur_pdev);
  3456. status = ucfg_dfs_get_agile_precac_enable
  3457. (cur_pdev,
  3458. &is_agile_dfs_enabled_cur_pdev);
  3459. if (QDF_IS_STATUS_ERROR(status)) {
  3460. spectral_err("Get agile precac failed, prohibiting aSpectral");
  3461. *is_aspectral_prohibited = true;
  3462. return;
  3463. }
  3464. if (is_agile_dfs_enabled_cur_pdev) {
  3465. spectral_err("aDFS is in progress on one of the pdevs");
  3466. *is_aspectral_prohibited = true;
  3467. }
  3468. }
  3469. /**
  3470. * target_if_get_curr_band() - Get current operating band of pdev
  3471. *
  3472. * @spectral: pointer to spectral object
  3473. *
  3474. * API to get current operating band of a given pdev.
  3475. *
  3476. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  3477. */
  3478. static enum reg_wifi_band
  3479. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev)
  3480. {
  3481. struct wlan_objmgr_vdev *vdev;
  3482. int16_t chan_freq;
  3483. enum reg_wifi_band cur_band;
  3484. if (!pdev) {
  3485. spectral_err("pdev is NULL");
  3486. return REG_BAND_UNKNOWN;
  3487. }
  3488. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  3489. if (!vdev) {
  3490. spectral_debug("vdev is NULL");
  3491. return REG_BAND_UNKNOWN;
  3492. }
  3493. chan_freq = target_if_vdev_get_chan_freq(vdev);
  3494. cur_band = wlan_reg_freq_to_band(chan_freq);
  3495. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3496. return cur_band;
  3497. }
  3498. /**
  3499. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  3500. * any of the 5G pdevs
  3501. * @psoc: Pointer to psoc
  3502. * @object: Pointer to pdev
  3503. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  3504. * progress in any 5G pdevs
  3505. *
  3506. * Return: void
  3507. */
  3508. static void
  3509. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  3510. void *object, void *arg)
  3511. {
  3512. enum reg_wifi_band band;
  3513. bool *is_agile_scan_inprog_5g_pdev = arg;
  3514. struct target_if_spectral *spectral;
  3515. struct wlan_objmgr_pdev *cur_pdev = object;
  3516. struct target_if_spectral_ops *p_sops;
  3517. if (*is_agile_scan_inprog_5g_pdev)
  3518. return;
  3519. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  3520. if (!spectral) {
  3521. spectral_err("target if spectral handle is NULL");
  3522. return;
  3523. }
  3524. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3525. band = target_if_get_curr_band(cur_pdev);
  3526. if (band == REG_BAND_UNKNOWN) {
  3527. spectral_debug("Failed to get current band");
  3528. return;
  3529. }
  3530. if (band == REG_BAND_5G &&
  3531. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  3532. *is_agile_scan_inprog_5g_pdev = true;
  3533. }
  3534. /**
  3535. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  3536. * for current vdev rx chainmask.
  3537. *
  3538. * @spectral: Pointer to Spectral object
  3539. * @is_supported: Pointer to is_supported
  3540. *
  3541. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3542. */
  3543. static QDF_STATUS
  3544. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  3545. bool *is_supported)
  3546. {
  3547. struct wlan_objmgr_vdev *vdev;
  3548. uint8_t vdev_rxchainmask;
  3549. struct wlan_objmgr_psoc *psoc;
  3550. struct wlan_objmgr_pdev *pdev;
  3551. struct target_psoc_info *tgt_psoc_info;
  3552. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  3553. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  3554. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  3555. struct wlan_psoc_host_chainmask_table *table;
  3556. int j;
  3557. uint32_t table_id;
  3558. enum phy_ch_width ch_width;
  3559. uint8_t pdev_id;
  3560. if (!spectral) {
  3561. spectral_err("spectral target if object is null");
  3562. return QDF_STATUS_E_FAILURE;
  3563. }
  3564. if (!is_supported) {
  3565. spectral_err("is supported argument is null");
  3566. return QDF_STATUS_E_FAILURE;
  3567. }
  3568. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  3569. spectral_err("HW Agile mode is not supported up to gen 2");
  3570. return QDF_STATUS_E_FAILURE;
  3571. }
  3572. pdev = spectral->pdev_obj;
  3573. if (!pdev) {
  3574. spectral_err("pdev is null");
  3575. return QDF_STATUS_E_FAILURE;
  3576. }
  3577. psoc = wlan_pdev_get_psoc(pdev);
  3578. if (!psoc) {
  3579. spectral_err("psoc is null");
  3580. return QDF_STATUS_E_FAILURE;
  3581. }
  3582. vdev = target_if_spectral_get_vdev(spectral);
  3583. if (!vdev) {
  3584. spectral_err("First vdev is NULL");
  3585. return QDF_STATUS_E_FAILURE;
  3586. }
  3587. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  3588. if (!vdev_rxchainmask) {
  3589. spectral_err("vdev rx chainmask is zero");
  3590. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3591. return QDF_STATUS_E_FAILURE;
  3592. }
  3593. ch_width = target_if_vdev_get_ch_width(vdev);
  3594. if (ch_width == CH_WIDTH_INVALID) {
  3595. spectral_err("Invalid channel width");
  3596. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3597. return QDF_STATUS_E_FAILURE;
  3598. }
  3599. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3600. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  3601. if (!tgt_psoc_info) {
  3602. spectral_err("target_psoc_info is null");
  3603. return QDF_STATUS_E_FAILURE;
  3604. }
  3605. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  3606. if (!ext_svc_param) {
  3607. spectral_err("Extended service ready param null");
  3608. return QDF_STATUS_E_FAILURE;
  3609. }
  3610. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  3611. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  3612. if (!mac_phy_cap_arr) {
  3613. spectral_err("mac phy cap array is null");
  3614. return QDF_STATUS_E_FAILURE;
  3615. }
  3616. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  3617. if (!mac_phy_cap) {
  3618. spectral_err("mac phy cap is null");
  3619. return QDF_STATUS_E_FAILURE;
  3620. }
  3621. table_id = mac_phy_cap->chainmask_table_id;
  3622. table = &ext_svc_param->chainmask_table[table_id];
  3623. if (!table) {
  3624. spectral_err("chainmask table not found");
  3625. return QDF_STATUS_E_FAILURE;
  3626. }
  3627. for (j = 0; j < table->num_valid_chainmasks; j++) {
  3628. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  3629. if (ch_width <= CH_WIDTH_80MHZ)
  3630. *is_supported =
  3631. table->cap_list[j].supports_aSpectral;
  3632. else
  3633. *is_supported =
  3634. table->cap_list[j].supports_aSpectral_160;
  3635. break;
  3636. }
  3637. }
  3638. if (j == table->num_valid_chainmasks) {
  3639. spectral_err("vdev rx chainmask %u not found in table id = %u",
  3640. vdev_rxchainmask, table_id);
  3641. return QDF_STATUS_E_FAILURE;
  3642. }
  3643. return QDF_STATUS_SUCCESS;
  3644. }
  3645. QDF_STATUS
  3646. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3647. const enum spectral_scan_mode smode,
  3648. enum spectral_cp_error_code *err)
  3649. {
  3650. struct target_if_spectral_ops *p_sops;
  3651. struct target_if_spectral *spectral;
  3652. struct wlan_objmgr_psoc *psoc;
  3653. enum reg_wifi_band band;
  3654. if (!err) {
  3655. spectral_err("Error code argument is null");
  3656. QDF_ASSERT(0);
  3657. return QDF_STATUS_E_FAILURE;
  3658. }
  3659. *err = SPECTRAL_SCAN_ERR_INVALID;
  3660. if (!pdev) {
  3661. spectral_err("pdev object is NUll");
  3662. return QDF_STATUS_E_FAILURE;
  3663. }
  3664. psoc = wlan_pdev_get_psoc(pdev);
  3665. if (!psoc) {
  3666. spectral_err("psoc is null");
  3667. return QDF_STATUS_E_FAILURE;
  3668. }
  3669. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3670. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3671. spectral_err("Invalid Spectral mode %u", smode);
  3672. return QDF_STATUS_E_FAILURE;
  3673. }
  3674. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3675. if (!spectral) {
  3676. spectral_err("Spectral LMAC object is NUll");
  3677. return QDF_STATUS_E_FAILURE;
  3678. }
  3679. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3680. if (!p_sops) {
  3681. spectral_err("p_sops is null");
  3682. return QDF_STATUS_E_FAILURE;
  3683. }
  3684. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3685. QDF_STATUS status;
  3686. bool is_supported = false;
  3687. status = target_if_is_agile_supported_cur_chmask(spectral,
  3688. &is_supported);
  3689. if (QDF_IS_STATUS_ERROR(status)) {
  3690. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3691. return QDF_STATUS_E_FAILURE;
  3692. }
  3693. if (!is_supported) {
  3694. spectral_err("aSpectral unsupported for cur chainmask");
  3695. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3696. return QDF_STATUS_E_FAILURE;
  3697. }
  3698. }
  3699. band = target_if_get_curr_band(spectral->pdev_obj);
  3700. if (band == REG_BAND_UNKNOWN) {
  3701. spectral_err("Failed to get current band");
  3702. return QDF_STATUS_E_FAILURE;
  3703. }
  3704. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  3705. struct target_psoc_info *tgt_hdl;
  3706. enum wmi_host_hw_mode_config_type mode;
  3707. bool is_agile_scan_inprog_5g_pdev;
  3708. if (p_sops->is_spectral_active(spectral,
  3709. SPECTRAL_SCAN_MODE_AGILE)) {
  3710. spectral_err("Agile Scan in progress in current pdev");
  3711. return QDF_STATUS_E_FAILURE;
  3712. }
  3713. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  3714. if (!tgt_hdl) {
  3715. target_if_err("target_psoc_info is null");
  3716. return QDF_STATUS_E_FAILURE;
  3717. }
  3718. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  3719. switch (mode) {
  3720. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  3721. case WMI_HOST_HW_MODE_SBS:
  3722. case WMI_HOST_HW_MODE_DBS_SBS:
  3723. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  3724. is_agile_scan_inprog_5g_pdev = false;
  3725. wlan_objmgr_iterate_obj_list
  3726. (psoc, WLAN_PDEV_OP,
  3727. target_if_is_agile_scan_active_in_5g,
  3728. &is_agile_scan_inprog_5g_pdev, 0,
  3729. WLAN_SPECTRAL_ID);
  3730. break;
  3731. default:
  3732. is_agile_scan_inprog_5g_pdev = false;
  3733. break;
  3734. }
  3735. if (is_agile_scan_inprog_5g_pdev) {
  3736. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  3737. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3738. return QDF_STATUS_E_FAILURE;
  3739. }
  3740. }
  3741. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3742. bool is_aspectral_prohibited = false;
  3743. QDF_STATUS status;
  3744. status = wlan_objmgr_iterate_obj_list
  3745. (psoc, WLAN_PDEV_OP,
  3746. target_if_is_aspectral_prohibited_by_adfs,
  3747. &is_aspectral_prohibited, 0,
  3748. WLAN_SPECTRAL_ID);
  3749. if (QDF_IS_STATUS_ERROR(status)) {
  3750. spectral_err("Failed to iterate over pdevs");
  3751. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3752. return QDF_STATUS_E_FAILURE;
  3753. }
  3754. if (is_aspectral_prohibited) {
  3755. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3756. return QDF_STATUS_E_FAILURE;
  3757. }
  3758. }
  3759. if (!spectral->params_valid[smode]) {
  3760. target_if_spectral_info_read(spectral,
  3761. smode,
  3762. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3763. &spectral->params[smode],
  3764. sizeof(spectral->params[smode]));
  3765. spectral->params_valid[smode] = true;
  3766. }
  3767. qdf_spin_lock(&spectral->spectral_lock);
  3768. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3769. QDF_STATUS status;
  3770. bool is_overlapping;
  3771. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  3772. enum spectral_scan_mode m;
  3773. enum phy_ch_width op_ch_width;
  3774. enum phy_ch_width agile_ch_width;
  3775. m = SPECTRAL_SCAN_MODE_NORMAL;
  3776. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  3777. ch_width[m] = CH_WIDTH_INVALID;
  3778. status = target_if_spectral_populate_chwidth
  3779. (spectral, ch_width, spectral->params
  3780. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  3781. if (QDF_IS_STATUS_ERROR(status)) {
  3782. qdf_spin_unlock(&spectral->spectral_lock);
  3783. spectral_err("Failed to populate channel width");
  3784. return QDF_STATUS_E_FAILURE;
  3785. }
  3786. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  3787. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3788. if (!spectral->params[smode].ss_frequency.cfreq1 ||
  3789. (agile_ch_width == CH_WIDTH_80P80MHZ &&
  3790. !spectral->params[smode].ss_frequency.cfreq2)) {
  3791. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  3792. qdf_spin_unlock(&spectral->spectral_lock);
  3793. return QDF_STATUS_E_FAILURE;
  3794. }
  3795. status = target_if_is_agile_span_overlap_with_operating_span
  3796. (spectral, ch_width,
  3797. &spectral->params[smode].ss_frequency,
  3798. &is_overlapping);
  3799. if (QDF_IS_STATUS_ERROR(status)) {
  3800. qdf_spin_unlock(&spectral->spectral_lock);
  3801. return QDF_STATUS_E_FAILURE;
  3802. }
  3803. if (is_overlapping) {
  3804. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3805. qdf_spin_unlock(&spectral->spectral_lock);
  3806. return QDF_STATUS_E_FAILURE;
  3807. }
  3808. }
  3809. target_if_spectral_scan_enable_params(spectral,
  3810. &spectral->params[smode], smode,
  3811. err);
  3812. qdf_spin_unlock(&spectral->spectral_lock);
  3813. return QDF_STATUS_SUCCESS;
  3814. }
  3815. QDF_STATUS
  3816. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3817. const enum spectral_scan_mode smode,
  3818. enum spectral_cp_error_code *err)
  3819. {
  3820. struct target_if_spectral_ops *p_sops;
  3821. struct target_if_spectral *spectral;
  3822. if (!err) {
  3823. spectral_err("Error code argument is null");
  3824. QDF_ASSERT(0);
  3825. return QDF_STATUS_E_FAILURE;
  3826. }
  3827. *err = SPECTRAL_SCAN_ERR_INVALID;
  3828. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3829. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3830. spectral_err("Invalid Spectral mode %u", smode);
  3831. return QDF_STATUS_E_FAILURE;
  3832. }
  3833. if (!pdev) {
  3834. spectral_err("pdev object is NUll ");
  3835. return QDF_STATUS_E_FAILURE;
  3836. }
  3837. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3838. if (!spectral) {
  3839. spectral_err("Spectral LMAC object is NUll ");
  3840. return QDF_STATUS_E_FAILURE;
  3841. }
  3842. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3843. qdf_spin_lock(&spectral->spectral_lock);
  3844. p_sops->stop_spectral_scan(spectral, smode);
  3845. if (spectral->classify_scan) {
  3846. /* TODO : Check if this logic is necessary */
  3847. spectral->detects_control_channel = 0;
  3848. spectral->detects_extension_channel = 0;
  3849. spectral->detects_above_dc = 0;
  3850. spectral->detects_below_dc = 0;
  3851. spectral->classify_scan = 0;
  3852. }
  3853. spectral->send_single_packet = 0;
  3854. spectral->sc_spectral_scan = 0;
  3855. qdf_spin_unlock(&spectral->spectral_lock);
  3856. return QDF_STATUS_SUCCESS;
  3857. }
  3858. /**
  3859. * target_if_is_spectral_active() - Get whether Spectral is active
  3860. * @pdev: Pointer to pdev object
  3861. * @smode: Spectral scan mode
  3862. *
  3863. * API to get whether Spectral is active
  3864. *
  3865. * Return: True if Spectral is active, false if Spectral is not active
  3866. */
  3867. bool
  3868. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  3869. const enum spectral_scan_mode smode)
  3870. {
  3871. struct target_if_spectral *spectral = NULL;
  3872. struct target_if_spectral_ops *p_sops = NULL;
  3873. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3874. if (!spectral) {
  3875. spectral_err("SPECTRAL : Module doesn't exist");
  3876. return QDF_STATUS_E_FAILURE;
  3877. }
  3878. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3879. if (!p_sops) {
  3880. spectral_err("p_sops is null");
  3881. return QDF_STATUS_E_FAILURE;
  3882. }
  3883. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3884. spectral_err("Invalid Spectral mode %u", smode);
  3885. return QDF_STATUS_E_FAILURE;
  3886. }
  3887. return p_sops->is_spectral_active(spectral, smode);
  3888. }
  3889. /**
  3890. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  3891. * @pdev: Pointer to pdev object
  3892. * @smode: Spectral scan mode
  3893. *
  3894. * API to get whether Spectral is enabled
  3895. *
  3896. * Return: True if Spectral is enabled, false if Spectral is not enabled
  3897. */
  3898. bool
  3899. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  3900. enum spectral_scan_mode smode)
  3901. {
  3902. struct target_if_spectral *spectral = NULL;
  3903. struct target_if_spectral_ops *p_sops = NULL;
  3904. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3905. if (!spectral) {
  3906. spectral_err("SPECTRAL : Module doesn't exist");
  3907. return QDF_STATUS_E_FAILURE;
  3908. }
  3909. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3910. if (!p_sops) {
  3911. spectral_err("p_sops is null");
  3912. return QDF_STATUS_E_FAILURE;
  3913. }
  3914. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3915. spectral_err("Invalid Spectral mode %u", smode);
  3916. return QDF_STATUS_E_FAILURE;
  3917. }
  3918. return p_sops->is_spectral_enabled(spectral, smode);
  3919. }
  3920. #ifdef DIRECT_BUF_RX_DEBUG
  3921. /**
  3922. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  3923. * @pdev: Pointer to pdev object
  3924. * @enable: Enable/Disable Spectral DMA ring debug
  3925. *
  3926. * Start/stop Spectral DMA ring debug based on @enable.
  3927. * Also save the state for future use.
  3928. *
  3929. * Return: QDF_STATUS of operation
  3930. */
  3931. static QDF_STATUS
  3932. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3933. {
  3934. struct target_if_spectral *spectral;
  3935. struct wlan_lmac_if_tx_ops *tx_ops;
  3936. struct wlan_objmgr_psoc *psoc;
  3937. if (!pdev)
  3938. return QDF_STATUS_E_FAILURE;
  3939. psoc = wlan_pdev_get_psoc(pdev);
  3940. if (!psoc) {
  3941. spectral_err("psoc is null");
  3942. return QDF_STATUS_E_INVAL;
  3943. }
  3944. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  3945. if (!tx_ops) {
  3946. spectral_err("tx_ops is NULL");
  3947. return QDF_STATUS_E_INVAL;
  3948. }
  3949. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3950. if (!spectral) {
  3951. spectral_err("Spectal LMAC object is NULL");
  3952. return QDF_STATUS_E_INVAL;
  3953. }
  3954. /* Save the state */
  3955. spectral->dbr_ring_debug = enable;
  3956. if (enable)
  3957. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  3958. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  3959. else
  3960. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  3961. pdev, 0);
  3962. return QDF_STATUS_SUCCESS;
  3963. }
  3964. /**
  3965. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  3966. * @pdev: Pointer to pdev object
  3967. * @enable: Enable/Disable Spectral DMA buffer debug
  3968. *
  3969. * Start/stop Spectral DMA buffer debug based on @enable.
  3970. * Also save the state for future use.
  3971. *
  3972. * Return: QDF_STATUS of operation
  3973. */
  3974. static QDF_STATUS
  3975. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3976. {
  3977. struct target_if_spectral *spectral;
  3978. struct wlan_lmac_if_tx_ops *tx_ops;
  3979. struct wlan_objmgr_psoc *psoc;
  3980. if (!pdev)
  3981. return QDF_STATUS_E_FAILURE;
  3982. psoc = wlan_pdev_get_psoc(pdev);
  3983. if (!psoc) {
  3984. spectral_err("psoc is null");
  3985. return QDF_STATUS_E_INVAL;
  3986. }
  3987. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  3988. if (!tx_ops) {
  3989. spectral_err("tx_ops is NULL");
  3990. return QDF_STATUS_E_INVAL;
  3991. }
  3992. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3993. if (!spectral) {
  3994. spectral_err("Spectal LMAC object is NULL");
  3995. return QDF_STATUS_E_INVAL;
  3996. }
  3997. /* Save the state */
  3998. spectral->dbr_buff_debug = enable;
  3999. if (enable)
  4000. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  4001. pdev, 0, MEM_POISON_SIGNATURE);
  4002. else
  4003. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  4004. pdev, 0);
  4005. }
  4006. /**
  4007. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  4008. * debug based on the previous state
  4009. * @pdev: Pointer to pdev object
  4010. *
  4011. * Return: QDF_STATUS of operation
  4012. */
  4013. static QDF_STATUS
  4014. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  4015. {
  4016. struct target_if_spectral *spectral;
  4017. if (!pdev) {
  4018. spectral_err("pdev is NULL!");
  4019. return QDF_STATUS_E_FAILURE;
  4020. }
  4021. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4022. if (!spectral) {
  4023. spectral_err("Spectal LMAC object is NULL");
  4024. return QDF_STATUS_E_INVAL;
  4025. }
  4026. if (spectral->dbr_buff_debug)
  4027. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  4028. else
  4029. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  4030. }
  4031. /**
  4032. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  4033. * debug based on the previous state
  4034. * @pdev: Pointer to pdev object
  4035. *
  4036. * Return: QDF_STATUS of operation
  4037. */
  4038. static QDF_STATUS
  4039. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  4040. {
  4041. struct target_if_spectral *spectral;
  4042. if (!pdev) {
  4043. spectral_err("pdev is NULL!");
  4044. return QDF_STATUS_E_FAILURE;
  4045. }
  4046. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4047. if (!spectral) {
  4048. spectral_err("Spectal LMAC object is NULL");
  4049. return QDF_STATUS_E_INVAL;
  4050. }
  4051. if (spectral->dbr_ring_debug)
  4052. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  4053. else
  4054. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  4055. }
  4056. /**
  4057. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  4058. * @pdev: Pointer to pdev object
  4059. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  4060. * @debug_value: Value to be set for @dma_debug_type
  4061. *
  4062. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  4063. * based on @debug_value
  4064. *
  4065. * Return: QDF_STATUS of operation
  4066. */
  4067. static QDF_STATUS
  4068. target_if_spectral_set_dma_debug(
  4069. struct wlan_objmgr_pdev *pdev,
  4070. enum spectral_dma_debug dma_debug_type,
  4071. bool debug_value)
  4072. {
  4073. struct target_if_spectral_ops *p_sops;
  4074. struct wlan_objmgr_psoc *psoc;
  4075. struct wlan_lmac_if_tx_ops *tx_ops;
  4076. struct target_if_spectral *spectral;
  4077. if (!pdev)
  4078. return QDF_STATUS_E_FAILURE;
  4079. psoc = wlan_pdev_get_psoc(pdev);
  4080. if (!psoc) {
  4081. spectral_err("psoc is null");
  4082. return QDF_STATUS_E_INVAL;
  4083. }
  4084. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  4085. if (!tx_ops) {
  4086. spectral_err("tx_ops is NULL");
  4087. return QDF_STATUS_E_FAILURE;
  4088. }
  4089. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  4090. spectral_err("Unable to fetch target type");
  4091. return QDF_STATUS_E_FAILURE;
  4092. }
  4093. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4094. if (!spectral) {
  4095. spectral_err("Spectal LMAC object is NULL");
  4096. return QDF_STATUS_E_INVAL;
  4097. }
  4098. if (spectral->direct_dma_support) {
  4099. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4100. if (p_sops->is_spectral_active(spectral,
  4101. SPECTRAL_SCAN_MODE_NORMAL) ||
  4102. p_sops->is_spectral_active(spectral,
  4103. SPECTRAL_SCAN_MODE_AGILE)) {
  4104. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  4105. return QDF_STATUS_E_FAILURE;
  4106. }
  4107. switch (dma_debug_type) {
  4108. case SPECTRAL_DMA_RING_DEBUG:
  4109. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  4110. break;
  4111. case SPECTRAL_DMA_BUFFER_DEBUG:
  4112. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  4113. break;
  4114. default:
  4115. spectral_err("Unsupported DMA debug type : %d",
  4116. dma_debug_type);
  4117. return QDF_STATUS_E_FAILURE;
  4118. }
  4119. }
  4120. return QDF_STATUS_SUCCESS;
  4121. }
  4122. #endif /* DIRECT_BUF_RX_DEBUG */
  4123. /**
  4124. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  4125. * @pdev: Pointer to pdev object
  4126. *
  4127. * Return: Whether Direct-DMA is supported on this radio
  4128. */
  4129. static bool
  4130. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  4131. {
  4132. struct target_if_spectral *spectral;
  4133. if (!pdev) {
  4134. spectral_err("pdev is NULL!");
  4135. return false;
  4136. }
  4137. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4138. if (!spectral) {
  4139. spectral_err("Spectral LMAC object is NULL");
  4140. return false;
  4141. }
  4142. return spectral->direct_dma_support;
  4143. }
  4144. /**
  4145. * target_if_set_debug_level() - Set debug level for Spectral
  4146. * @pdev: Pointer to pdev object
  4147. * @debug_level: Debug level
  4148. *
  4149. * API to set the debug level for Spectral
  4150. *
  4151. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4152. */
  4153. QDF_STATUS
  4154. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  4155. {
  4156. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  4157. return QDF_STATUS_SUCCESS;
  4158. }
  4159. /**
  4160. * target_if_get_debug_level() - Get debug level for Spectral
  4161. * @pdev: Pointer to pdev object
  4162. *
  4163. * API to get the debug level for Spectral
  4164. *
  4165. * Return: Current debug level
  4166. */
  4167. uint32_t
  4168. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  4169. {
  4170. return spectral_debug_level;
  4171. }
  4172. /**
  4173. * target_if_get_spectral_capinfo() - Get Spectral capability information
  4174. * @pdev: Pointer to pdev object
  4175. * @scaps: Buffer into which data should be copied
  4176. *
  4177. * API to get the spectral capability information
  4178. *
  4179. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4180. */
  4181. QDF_STATUS
  4182. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  4183. struct spectral_caps *scaps)
  4184. {
  4185. struct target_if_spectral *spectral = NULL;
  4186. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4187. if (!spectral) {
  4188. spectral_err("SPECTRAL : Module doesn't exist");
  4189. return QDF_STATUS_E_FAILURE;
  4190. }
  4191. qdf_mem_copy(scaps, &spectral->capability,
  4192. sizeof(struct spectral_caps));
  4193. return QDF_STATUS_SUCCESS;
  4194. }
  4195. /**
  4196. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  4197. * @pdev: Pointer to pdev object
  4198. * @stats: Buffer into which data should be copied
  4199. *
  4200. * API to get the spectral diagnostic statistics
  4201. *
  4202. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4203. */
  4204. QDF_STATUS
  4205. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  4206. struct spectral_diag_stats *stats)
  4207. {
  4208. struct target_if_spectral *spectral = NULL;
  4209. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4210. if (!spectral) {
  4211. spectral_err("SPECTRAL : Module doesn't exist");
  4212. return QDF_STATUS_E_FAILURE;
  4213. }
  4214. qdf_mem_copy(stats, &spectral->diag_stats,
  4215. sizeof(struct spectral_diag_stats));
  4216. return QDF_STATUS_SUCCESS;
  4217. }
  4218. /**
  4219. * target_if_register_spectral_wmi_ops() - Register Spectral WMI operations
  4220. * @psoc: Pointer to psoc object
  4221. * @wmi_ops: Pointer to the structure having Spectral WMI operations
  4222. *
  4223. * API for registering Spectral WMI operations in
  4224. * spectral internal data structure
  4225. *
  4226. * Return: QDF_STATUS
  4227. */
  4228. static QDF_STATUS
  4229. target_if_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
  4230. struct spectral_wmi_ops *wmi_ops)
  4231. {
  4232. struct target_if_psoc_spectral *psoc_spectral;
  4233. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4234. if (!psoc_spectral) {
  4235. spectral_err("Spectral LMAC object is null");
  4236. return QDF_STATUS_E_INVAL;
  4237. }
  4238. psoc_spectral->wmi_ops = *wmi_ops;
  4239. return QDF_STATUS_SUCCESS;
  4240. }
  4241. /**
  4242. * target_if_register_spectral_tgt_ops() - Register Spectral target operations
  4243. * @psoc: Pointer to psoc object
  4244. * @tgt_ops: Pointer to the structure having Spectral target operations
  4245. *
  4246. * API for registering Spectral target operations in
  4247. * spectral internal data structure
  4248. *
  4249. * Return: QDF_STATUS
  4250. */
  4251. static QDF_STATUS
  4252. target_if_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
  4253. struct spectral_tgt_ops *tgt_ops)
  4254. {
  4255. if (!psoc) {
  4256. spectral_err("psoc is null");
  4257. return QDF_STATUS_E_INVAL;
  4258. }
  4259. ops_tgt = *tgt_ops;
  4260. return QDF_STATUS_SUCCESS;
  4261. }
  4262. /**
  4263. * target_if_register_netlink_cb() - Register Netlink callbacks
  4264. * @pdev: Pointer to pdev object
  4265. * @nl_cb: Netlink callbacks to register
  4266. *
  4267. * Return: void
  4268. */
  4269. static void
  4270. target_if_register_netlink_cb(
  4271. struct wlan_objmgr_pdev *pdev,
  4272. struct spectral_nl_cb *nl_cb)
  4273. {
  4274. struct target_if_spectral *spectral = NULL;
  4275. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4276. if (!spectral) {
  4277. spectral_err("SPECTRAL : Module doesn't exist");
  4278. return;
  4279. }
  4280. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  4281. if (spectral->use_nl_bcast)
  4282. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  4283. else
  4284. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  4285. }
  4286. /**
  4287. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  4288. * Netlink messages to the application layer
  4289. * @pdev: Pointer to pdev object
  4290. *
  4291. * Return: true for broadcast, false for unicast
  4292. */
  4293. static bool
  4294. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  4295. {
  4296. struct target_if_spectral *spectral = NULL;
  4297. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4298. if (!spectral) {
  4299. spectral_err("SPECTRAL : Module doesn't exist");
  4300. return false;
  4301. }
  4302. return spectral->use_nl_bcast;
  4303. }
  4304. /**
  4305. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  4306. * @pdev: Pointer to pdev object
  4307. *
  4308. * Return: void
  4309. */
  4310. static void
  4311. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  4312. {
  4313. struct target_if_spectral *spectral = NULL;
  4314. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4315. if (!spectral) {
  4316. spectral_err("SPECTRAL : Module doesn't exist");
  4317. return;
  4318. }
  4319. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  4320. }
  4321. static int
  4322. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  4323. void *payload)
  4324. {
  4325. struct target_if_spectral *spectral = NULL;
  4326. struct target_if_spectral_ops *p_sops = NULL;
  4327. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4328. if (!spectral) {
  4329. spectral_err("SPECTRAL : Module doesn't exist");
  4330. return -EPERM;
  4331. }
  4332. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4333. if (!p_sops) {
  4334. spectral_err("p_sops is null");
  4335. return -EPERM;
  4336. }
  4337. return p_sops->process_spectral_report(pdev, payload);
  4338. }
  4339. #ifdef DIRECT_BUF_RX_DEBUG
  4340. static inline void
  4341. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4342. {
  4343. if (!tx_ops) {
  4344. spectral_err("tx_ops is NULL");
  4345. return;
  4346. }
  4347. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  4348. target_if_spectral_set_dma_debug;
  4349. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  4350. target_if_spectral_check_and_do_dbr_ring_debug;
  4351. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  4352. target_if_spectral_check_and_do_dbr_buff_debug;
  4353. }
  4354. #else
  4355. static inline void
  4356. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4357. {
  4358. }
  4359. #endif
  4360. #if defined(WLAN_CONV_SPECTRAL_ENABLE) && defined(SPECTRAL_MODULIZED_ENABLE)
  4361. /**
  4362. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  4363. * register WMI event handler
  4364. * @psoc: Pointer to psoc object
  4365. * @event_id: Event id
  4366. * @handler_func: Handler function
  4367. * @rx_ctx: Context of WMI event processing
  4368. *
  4369. * Wrapper function to register WMI event handler
  4370. *
  4371. * Return: 0 for success else failure
  4372. */
  4373. static int
  4374. target_if_spectral_wmi_unified_register_event_handler(
  4375. struct wlan_objmgr_psoc *psoc,
  4376. wmi_conv_event_id event_id,
  4377. wmi_unified_event_handler handler_func,
  4378. uint8_t rx_ctx)
  4379. {
  4380. wmi_unified_t wmi_handle;
  4381. struct target_if_psoc_spectral *psoc_spectral;
  4382. if (!psoc) {
  4383. spectral_err("psoc is null");
  4384. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4385. }
  4386. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4387. if (!wmi_handle) {
  4388. spectral_err("WMI handle is null");
  4389. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4390. }
  4391. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4392. if (!psoc_spectral) {
  4393. spectral_err("spectral object is null");
  4394. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4395. }
  4396. return psoc_spectral->wmi_ops.wmi_unified_register_event_handler(
  4397. wmi_handle, event_id, handler_func, rx_ctx);
  4398. }
  4399. /**
  4400. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  4401. * to unregister WMI event handler
  4402. * @psoc: Pointer to psoc object
  4403. * @event_id: Event id
  4404. *
  4405. * Wrapper function to unregister WMI event handler
  4406. *
  4407. * Return: 0 for success else failure
  4408. */
  4409. static int
  4410. target_if_spectral_wmi_unified_unregister_event_handler(
  4411. struct wlan_objmgr_psoc *psoc,
  4412. wmi_conv_event_id event_id)
  4413. {
  4414. wmi_unified_t wmi_handle;
  4415. struct target_if_psoc_spectral *psoc_spectral;
  4416. if (!psoc) {
  4417. spectral_err("psoc is null");
  4418. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4419. }
  4420. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4421. if (!wmi_handle) {
  4422. spectral_err("WMI handle is null");
  4423. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4424. }
  4425. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4426. if (!psoc_spectral) {
  4427. spectral_err("spectral object is null");
  4428. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4429. }
  4430. return psoc_spectral->wmi_ops.wmi_unified_unregister_event_handler(
  4431. wmi_handle, event_id);
  4432. }
  4433. /**
  4434. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  4435. * function to extract fixed parameters from start scan response event
  4436. * @psoc: Pointer to psoc object
  4437. * @evt_buf: Event buffer
  4438. * @param: Start scan response parameters
  4439. *
  4440. * Wrapper function to extract fixed parameters from start scan response event
  4441. *
  4442. * Return: QDF_STATUS
  4443. */
  4444. static QDF_STATUS
  4445. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4446. struct wlan_objmgr_psoc *psoc,
  4447. uint8_t *evt_buf,
  4448. struct spectral_startscan_resp_params *param)
  4449. {
  4450. wmi_unified_t wmi_handle;
  4451. struct target_if_psoc_spectral *psoc_spectral;
  4452. if (!psoc) {
  4453. spectral_err("psoc is null");
  4454. return QDF_STATUS_E_INVAL;
  4455. }
  4456. if (!evt_buf) {
  4457. spectral_err("WMI event buffer is null");
  4458. return QDF_STATUS_E_INVAL;
  4459. }
  4460. if (!param) {
  4461. spectral_err("Spectral startscan response parameters is null");
  4462. return QDF_STATUS_E_INVAL;
  4463. }
  4464. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4465. if (!wmi_handle) {
  4466. spectral_err("WMI handle is null");
  4467. return QDF_STATUS_E_INVAL;
  4468. }
  4469. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4470. if (!psoc_spectral) {
  4471. spectral_err("spectral object is null");
  4472. return QDF_STATUS_E_FAILURE;
  4473. }
  4474. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4475. wmi_handle, evt_buf, param);
  4476. }
  4477. /**
  4478. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  4479. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  4480. * secondary 80 MHz FFT bins
  4481. * @psoc: Pointer to psoc object
  4482. * @evt_buf: Event buffer
  4483. * @param: FFT bin start and end indices
  4484. *
  4485. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  4486. * and secondary 80 MHz FFT bins
  4487. *
  4488. * Return: QDF_STATUS
  4489. */
  4490. static QDF_STATUS
  4491. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  4492. struct wlan_objmgr_psoc *psoc,
  4493. uint8_t *evt_buf,
  4494. struct spectral_fft_bin_markers_160_165mhz *param)
  4495. {
  4496. wmi_unified_t wmi_handle;
  4497. struct target_if_psoc_spectral *psoc_spectral;
  4498. if (!psoc) {
  4499. spectral_err("psoc is null");
  4500. return QDF_STATUS_E_INVAL;
  4501. }
  4502. if (!evt_buf) {
  4503. spectral_err("WMI event buffer is null");
  4504. return QDF_STATUS_E_INVAL;
  4505. }
  4506. if (!param) {
  4507. spectral_err("Spectral FFT bin markers is null");
  4508. return QDF_STATUS_E_INVAL;
  4509. }
  4510. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4511. if (!wmi_handle) {
  4512. spectral_err("WMI handle is null");
  4513. return QDF_STATUS_E_INVAL;
  4514. }
  4515. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4516. if (!psoc_spectral) {
  4517. spectral_err("spectral object is null");
  4518. return QDF_STATUS_E_FAILURE;
  4519. }
  4520. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fft_bin_index(
  4521. wmi_handle, evt_buf, param);
  4522. }
  4523. /**
  4524. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  4525. * object from scn handle
  4526. * @scn: scn handle
  4527. *
  4528. * Wrapper function to get psoc object from scn handle
  4529. *
  4530. * Return: Pointer to psoc object
  4531. */
  4532. static struct wlan_objmgr_psoc *
  4533. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  4534. {
  4535. if (!scn) {
  4536. spectral_err("scn is null");
  4537. return NULL;
  4538. }
  4539. return ops_tgt.tgt_get_psoc_from_scn_hdl(scn);
  4540. }
  4541. #else
  4542. /**
  4543. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  4544. * register WMI event handler
  4545. * @psoc: Pointer to psoc object
  4546. * @event_id: Event id
  4547. * @handler_func: Handler function
  4548. * @rx_ctx: Context of WMI event processing
  4549. *
  4550. * Wrapper function to register WMI event handler
  4551. *
  4552. * Return: 0 for success else failure
  4553. */
  4554. static int
  4555. target_if_spectral_wmi_unified_register_event_handler(
  4556. struct wlan_objmgr_psoc *psoc,
  4557. wmi_conv_event_id event_id,
  4558. wmi_unified_event_handler handler_func,
  4559. uint8_t rx_ctx)
  4560. {
  4561. wmi_unified_t wmi_handle;
  4562. if (!psoc) {
  4563. spectral_err("psoc is null");
  4564. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4565. }
  4566. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4567. if (!wmi_handle) {
  4568. spectral_err("WMI handle is null");
  4569. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4570. }
  4571. return wmi_unified_register_event_handler(wmi_handle, event_id,
  4572. handler_func, rx_ctx);
  4573. }
  4574. /**
  4575. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  4576. * to unregister WMI event handler
  4577. * @psoc: Pointer to psoc object
  4578. * @event_id: Event id
  4579. *
  4580. * Wrapper function to unregister WMI event handler
  4581. *
  4582. * Return: 0 for success else failure
  4583. */
  4584. static int
  4585. target_if_spectral_wmi_unified_unregister_event_handler(
  4586. struct wlan_objmgr_psoc *psoc,
  4587. wmi_conv_event_id event_id)
  4588. {
  4589. wmi_unified_t wmi_handle;
  4590. if (!psoc) {
  4591. spectral_err("psoc is null");
  4592. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4593. }
  4594. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4595. if (!wmi_handle) {
  4596. spectral_err("WMI handle is null");
  4597. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4598. }
  4599. return wmi_unified_unregister_event_handler(wmi_handle, event_id);
  4600. }
  4601. /**
  4602. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  4603. * function to extract fixed parameters from start scan response event
  4604. * @psoc: Pointer to psoc object
  4605. * @evt_buf: Event buffer
  4606. * @param: Start scan response parameters
  4607. *
  4608. * Wrapper function to extract fixed parameters from start scan response event
  4609. *
  4610. * Return: QDF_STATUS
  4611. */
  4612. static QDF_STATUS
  4613. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4614. struct wlan_objmgr_psoc *psoc,
  4615. uint8_t *evt_buf,
  4616. struct spectral_startscan_resp_params *param)
  4617. {
  4618. wmi_unified_t wmi_handle;
  4619. if (!psoc) {
  4620. spectral_err("psoc is null");
  4621. return QDF_STATUS_E_INVAL;
  4622. }
  4623. if (!evt_buf) {
  4624. spectral_err("WMI event buffer is null");
  4625. return QDF_STATUS_E_INVAL;
  4626. }
  4627. if (!param) {
  4628. spectral_err("Spectral startscan response parameters is null");
  4629. return QDF_STATUS_E_INVAL;
  4630. }
  4631. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4632. if (!wmi_handle) {
  4633. spectral_err("WMI handle is null");
  4634. return QDF_STATUS_E_INVAL;
  4635. }
  4636. return wmi_extract_pdev_sscan_fw_cmd_fixed_param(wmi_handle, evt_buf,
  4637. param);
  4638. }
  4639. /**
  4640. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  4641. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  4642. * secondary 80 MHz FFT bins
  4643. * @psoc: Pointer to psoc object
  4644. * @evt_buf: Event buffer
  4645. * @param: FFT bin start and end indices
  4646. *
  4647. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  4648. * and secondary 80 MHz FFT bins
  4649. *
  4650. * Return: QDF_STATUS
  4651. */
  4652. static QDF_STATUS
  4653. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  4654. struct wlan_objmgr_psoc *psoc,
  4655. uint8_t *evt_buf,
  4656. struct spectral_fft_bin_markers_160_165mhz *param)
  4657. {
  4658. wmi_unified_t wmi_handle;
  4659. if (!psoc) {
  4660. spectral_err("psoc is null");
  4661. return QDF_STATUS_E_INVAL;
  4662. }
  4663. if (!evt_buf) {
  4664. spectral_err("WMI event buffer is null");
  4665. return QDF_STATUS_E_INVAL;
  4666. }
  4667. if (!param) {
  4668. spectral_err("Spectral FFT bin markers is null");
  4669. return QDF_STATUS_E_INVAL;
  4670. }
  4671. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4672. if (!wmi_handle) {
  4673. spectral_err("WMI handle is null");
  4674. return QDF_STATUS_E_INVAL;
  4675. }
  4676. return wmi_extract_pdev_sscan_fft_bin_index(wmi_handle, evt_buf, param);
  4677. }
  4678. /**
  4679. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  4680. * object from scn handle
  4681. * @scn: scn handle
  4682. *
  4683. * Wrapper function to get psoc object from scn handle
  4684. *
  4685. * Return: Pointer to psoc object
  4686. */
  4687. static struct wlan_objmgr_psoc *
  4688. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  4689. {
  4690. if (!scn) {
  4691. spectral_err("scn is null");
  4692. return NULL;
  4693. }
  4694. return target_if_get_psoc_from_scn_hdl(scn);
  4695. }
  4696. #endif
  4697. /**
  4698. * target_if_spectral_fw_param_event_handler() - WMI event handler to
  4699. * process start scan response event
  4700. * @scn: Pointer to scn object
  4701. * @data_buf: Pointer to event buffer
  4702. * @data_len: Length of event buffer
  4703. *
  4704. * Return: 0 for success, else failure
  4705. */
  4706. static int
  4707. target_if_spectral_fw_param_event_handler(ol_scn_t scn, uint8_t *data_buf,
  4708. uint32_t data_len)
  4709. {
  4710. QDF_STATUS status;
  4711. struct wlan_objmgr_psoc *psoc;
  4712. struct wlan_objmgr_pdev *pdev;
  4713. struct wmi_unified *wmi_handle;
  4714. struct spectral_startscan_resp_params event_params = {0};
  4715. struct target_if_psoc_spectral *psoc_spectral;
  4716. struct target_if_spectral *spectral;
  4717. if (!scn) {
  4718. spectral_err("scn handle is null");
  4719. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4720. }
  4721. if (!data_buf) {
  4722. spectral_err("WMI event buffer null");
  4723. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4724. }
  4725. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  4726. if (!psoc) {
  4727. spectral_err("psoc is null");
  4728. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4729. }
  4730. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4731. if (!psoc_spectral) {
  4732. spectral_err("spectral object is null");
  4733. return QDF_STATUS_E_FAILURE;
  4734. }
  4735. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4736. if (!wmi_handle) {
  4737. spectral_err("WMI handle is null");
  4738. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4739. }
  4740. status = target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4741. psoc, data_buf, &event_params);
  4742. if (QDF_IS_STATUS_ERROR(status)) {
  4743. spectral_err("unable to extract sscan fw fixed params");
  4744. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4745. }
  4746. pdev = wlan_objmgr_get_pdev_by_id(psoc, event_params.pdev_id,
  4747. WLAN_SPECTRAL_ID);
  4748. if (!pdev) {
  4749. spectral_err("pdev is null");
  4750. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4751. }
  4752. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4753. if (!spectral) {
  4754. spectral_err("spectral object is null");
  4755. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  4756. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4757. }
  4758. if (event_params.num_fft_bin_index == 1) {
  4759. status =
  4760. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  4761. psoc, data_buf,
  4762. &spectral->rparams.marker[event_params.smode]);
  4763. if (QDF_IS_STATUS_ERROR(status)) {
  4764. spectral_err("unable to extract sscan fw fixed params");
  4765. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  4766. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4767. }
  4768. } else {
  4769. spectral->rparams.marker[event_params.smode].is_valid = false;
  4770. }
  4771. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  4772. return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
  4773. }
  4774. static QDF_STATUS
  4775. target_if_spectral_register_events(struct wlan_objmgr_psoc *psoc)
  4776. {
  4777. int ret;
  4778. if (!psoc) {
  4779. spectral_err("psoc is null");
  4780. return QDF_STATUS_E_INVAL;
  4781. }
  4782. ret = target_if_spectral_wmi_unified_register_event_handler(
  4783. psoc,
  4784. wmi_pdev_sscan_fw_param_eventid,
  4785. target_if_spectral_fw_param_event_handler,
  4786. WMI_RX_UMAC_CTX);
  4787. if (ret)
  4788. spectral_debug("event handler not supported, ret=%d", ret);
  4789. return QDF_STATUS_SUCCESS;
  4790. }
  4791. static QDF_STATUS
  4792. target_if_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
  4793. {
  4794. int ret;
  4795. if (!psoc) {
  4796. spectral_err("psoc is null");
  4797. return QDF_STATUS_E_INVAL;
  4798. }
  4799. ret = target_if_spectral_wmi_unified_unregister_event_handler(
  4800. psoc, wmi_pdev_sscan_fw_param_eventid);
  4801. if (ret)
  4802. spectral_debug("Unregister WMI event handler failed, ret = %d",
  4803. ret);
  4804. return QDF_STATUS_SUCCESS;
  4805. }
  4806. void
  4807. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4808. {
  4809. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  4810. target_if_pdev_spectral_init;
  4811. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  4812. target_if_pdev_spectral_deinit;
  4813. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init =
  4814. target_if_psoc_spectral_init;
  4815. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit =
  4816. target_if_psoc_spectral_deinit;
  4817. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  4818. target_if_set_spectral_config;
  4819. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  4820. target_if_get_spectral_config;
  4821. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  4822. target_if_start_spectral_scan;
  4823. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  4824. target_if_stop_spectral_scan;
  4825. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  4826. target_if_is_spectral_active;
  4827. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  4828. target_if_is_spectral_enabled;
  4829. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  4830. target_if_set_debug_level;
  4831. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  4832. target_if_get_debug_level;
  4833. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  4834. target_if_get_spectral_capinfo;
  4835. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  4836. target_if_get_spectral_diagstats;
  4837. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_wmi_ops =
  4838. target_if_register_spectral_wmi_ops;
  4839. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_tgt_ops =
  4840. target_if_register_spectral_tgt_ops;
  4841. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  4842. target_if_register_netlink_cb;
  4843. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  4844. target_if_use_nl_bcast;
  4845. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  4846. target_if_deregister_netlink_cb;
  4847. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  4848. target_if_process_spectral_report;
  4849. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  4850. target_if_spectral_direct_dma_support;
  4851. tx_ops->sptrl_tx_ops.sptrlto_register_events =
  4852. target_if_spectral_register_events;
  4853. tx_ops->sptrl_tx_ops.sptrlto_unregister_events =
  4854. target_if_spectral_unregister_events;
  4855. target_if_sptrl_debug_register_tx_ops(tx_ops);
  4856. }
  4857. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  4858. void
  4859. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  4860. uint16_t cw_int, uint32_t dcs_enabled)
  4861. {
  4862. struct spectral_samp_msg *msg = NULL;
  4863. struct target_if_spectral_ops *p_sops = NULL;
  4864. struct target_if_spectral *spectral = NULL;
  4865. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4866. if (!spectral) {
  4867. spectral_err("SPECTRAL : Module doesn't exist");
  4868. return;
  4869. }
  4870. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4871. if (!p_sops) {
  4872. spectral_err("p_sops is null");
  4873. return;
  4874. }
  4875. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  4876. spectral->pdev_obj,
  4877. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  4878. SPECTRAL_MSG_BUF_NEW);
  4879. if (msg) {
  4880. msg->int_type = cw_int ?
  4881. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  4882. msg->dcs_enabled = dcs_enabled;
  4883. msg->signature = SPECTRAL_SIGNATURE;
  4884. p_sops->get_mac_address(spectral, msg->macaddr);
  4885. if (spectral->send_phy_data
  4886. (pdev,
  4887. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  4888. spectral->spectral_sent_msg++;
  4889. }
  4890. }
  4891. qdf_export_symbol(target_if_spectral_send_intf_found_msg);