target_if_spectral.c 151 KB

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