target_if_spectral.c 152 KB

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