target_if_spectral.c 127 KB

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