target_if_spectral.c 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236
  1. /*
  2. * Copyright (c) 2011,2017-2019 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_properties() - Initialize Spectral parameter
  1157. * properties
  1158. * @spectral: Pointer to Spectral target_if internal private data
  1159. *
  1160. * Initialize Spectral parameter properties
  1161. *
  1162. * Return: QDF_STATUS
  1163. */
  1164. static QDF_STATUS
  1165. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1166. {
  1167. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1168. int param;
  1169. /* Initialize default values for properties.
  1170. * Default values are supported for all the parameters for all modes
  1171. * and allows different values for each mode for all the parameters .
  1172. */
  1173. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1174. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1175. spectral->properties[smode][param].supported = true;
  1176. spectral->properties[smode][param].common_all_modes =
  1177. false;
  1178. }
  1179. }
  1180. /* Once FW advertisement is in place remove this hard coding */
  1181. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1182. spectral->properties[SPECTRAL_SCAN_MODE_NORMAL]
  1183. [SPECTRAL_PARAM_FREQUENCY].supported = false;
  1184. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1185. spectral->properties[smode]
  1186. [SPECTRAL_PARAM_SPECT_PRI].common_all_modes = true;
  1187. spectral->properties[smode]
  1188. [SPECTRAL_PARAM_SCAN_PERIOD].common_all_modes = true;
  1189. spectral->properties[smode]
  1190. [SPECTRAL_PARAM_INIT_DELAY].common_all_modes = true;
  1191. }
  1192. return QDF_STATUS_SUCCESS;
  1193. }
  1194. /**
  1195. * target_if_init_spectral_capability() - Initialize Spectral capability
  1196. * @spectral: Pointer to Spectral target_if internal private data
  1197. *
  1198. * This is a workaround.
  1199. *
  1200. * Return: QDF_STATUS
  1201. */
  1202. QDF_STATUS
  1203. target_if_init_spectral_capability(struct target_if_spectral *spectral)
  1204. {
  1205. struct wlan_objmgr_psoc *psoc;
  1206. struct wlan_objmgr_pdev *pdev;
  1207. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  1208. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  1209. struct target_psoc_info *tgt_psoc_info;
  1210. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  1211. struct spectral_caps *pcap = &spectral->capability;
  1212. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  1213. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  1214. struct wlan_psoc_host_chainmask_table *table;
  1215. int j;
  1216. uint32_t table_id;
  1217. pdev = spectral->pdev_obj;
  1218. psoc = wlan_pdev_get_psoc(pdev);
  1219. if (!psoc) {
  1220. spectral_err("psoc is null");
  1221. return QDF_STATUS_E_FAILURE;
  1222. }
  1223. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  1224. if (!tgt_psoc_info) {
  1225. spectral_err("target_psoc_info is null");
  1226. return QDF_STATUS_E_FAILURE;
  1227. }
  1228. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  1229. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  1230. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  1231. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  1232. /* XXX : Workaround: Set Spectral capability */
  1233. pcap = &spectral->capability;
  1234. pcap->phydiag_cap = 1;
  1235. pcap->radar_cap = 1;
  1236. pcap->spectral_cap = 1;
  1237. pcap->advncd_spectral_cap = 1;
  1238. pcap->hw_gen = spectral->spectral_gen;
  1239. if (spectral->spectral_gen >= SPECTRAL_GEN3) {
  1240. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  1241. if (!mac_phy_cap_arr) {
  1242. spectral_err("mac phy cap array is null");
  1243. return QDF_STATUS_E_FAILURE;
  1244. }
  1245. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  1246. if (!mac_phy_cap) {
  1247. spectral_err("mac phy cap is null");
  1248. return QDF_STATUS_E_FAILURE;
  1249. }
  1250. table_id = mac_phy_cap->chainmask_table_id;
  1251. table = &ext_svc_param->chainmask_table[table_id];
  1252. if (!table) {
  1253. spectral_err("chainmask table not found");
  1254. return QDF_STATUS_E_FAILURE;
  1255. }
  1256. for (j = 0; j < table->num_valid_chainmasks; j++) {
  1257. pcap->agile_spectral_cap |=
  1258. table->cap_list[j].supports_aSpectral;
  1259. pcap->agile_spectral_cap_160 |=
  1260. table->cap_list[j].supports_aSpectral_160;
  1261. }
  1262. pcap->agile_spectral_cap_80p80 = pcap->agile_spectral_cap_160;
  1263. } else {
  1264. pcap->agile_spectral_cap = false;
  1265. pcap->agile_spectral_cap_160 = false;
  1266. pcap->agile_spectral_cap_80p80 = false;
  1267. }
  1268. for (param_idx = 0; param_idx < num_bin_scaling_params; param_idx++) {
  1269. if (scaling_params[param_idx].pdev_id == pdev_id) {
  1270. pcap->is_scaling_params_populated = true;
  1271. pcap->formula_id = scaling_params[param_idx].formula_id;
  1272. pcap->low_level_offset =
  1273. scaling_params[param_idx].low_level_offset;
  1274. pcap->high_level_offset =
  1275. scaling_params[param_idx].high_level_offset;
  1276. pcap->rssi_thr = scaling_params[param_idx].rssi_thr;
  1277. pcap->default_agc_max_gain =
  1278. scaling_params[param_idx].default_agc_max_gain;
  1279. break;
  1280. }
  1281. }
  1282. return QDF_STATUS_SUCCESS;
  1283. }
  1284. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1285. /**
  1286. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1287. * internal operations with functions related to spectral simulation
  1288. * @p_sops: spectral low level ops table
  1289. *
  1290. * Initialize spectral target_if internal operations with functions
  1291. * related to spectral simulation
  1292. *
  1293. * Return: None
  1294. */
  1295. static void
  1296. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1297. {
  1298. /*
  1299. * Spectral simulation is currently intended for platform transitions
  1300. * where underlying HW support may not be available for some time.
  1301. * Hence, we do not currently provide a runtime switch to turn the
  1302. * simulation on or off.
  1303. * In case of future requirements where runtime switches are required,
  1304. * this can be added. But it is suggested to use application layer
  1305. * simulation as far as possible in such cases, since the main
  1306. * use of record and replay of samples would concern higher
  1307. * level sample processing rather than lower level delivery.
  1308. */
  1309. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  1310. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  1311. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  1312. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  1313. p_sops->configure_spectral =
  1314. target_if_spectral_sops_sim_configure_params;
  1315. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  1316. }
  1317. #else
  1318. /**
  1319. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1320. * internal operations
  1321. * @p_sops: spectral low level ops table
  1322. *
  1323. * Return: None
  1324. */
  1325. static void
  1326. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1327. {
  1328. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  1329. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  1330. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  1331. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  1332. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  1333. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  1334. }
  1335. #endif
  1336. /**
  1337. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  1338. * operations common to all Spectral chipset generations
  1339. *
  1340. * Initializes target_if_spectral_ops common to all chipset generations
  1341. *
  1342. * Return: None
  1343. */
  1344. static void
  1345. target_if_init_spectral_ops_common(void)
  1346. {
  1347. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1348. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  1349. p_sops->get_capability = target_if_spectral_get_capability;
  1350. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  1351. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  1352. target_if_init_spectral_simulation_ops(p_sops);
  1353. p_sops->get_extension_channel =
  1354. target_if_spectral_get_extension_channel;
  1355. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  1356. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  1357. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  1358. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  1359. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  1360. p_sops->reset_hw = target_if_spectral_reset_hw;
  1361. p_sops->get_chain_noise_floor =
  1362. target_if_spectral_get_chain_noise_floor;
  1363. }
  1364. /**
  1365. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  1366. * operations specific to Spectral chipset generation 2.
  1367. *
  1368. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  1369. *
  1370. * Return: None
  1371. */
  1372. static void
  1373. target_if_init_spectral_ops_gen2(void)
  1374. {
  1375. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1376. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  1377. }
  1378. /**
  1379. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  1380. * operations specific to Spectral chipset generation 3.
  1381. *
  1382. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  1383. *
  1384. * Return: None
  1385. */
  1386. static void
  1387. target_if_init_spectral_ops_gen3(void)
  1388. {
  1389. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1390. p_sops->process_spectral_report =
  1391. target_if_spectral_process_report_gen3;
  1392. return;
  1393. }
  1394. /**
  1395. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  1396. * operations.
  1397. * @spectral: Pointer to Spectral target_if internal private data
  1398. *
  1399. * Initializes all function pointers in target_if_spectral_ops for
  1400. * all generations
  1401. *
  1402. * Return: None
  1403. */
  1404. static void
  1405. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  1406. {
  1407. target_if_init_spectral_ops_common();
  1408. if (spectral->spectral_gen == SPECTRAL_GEN2)
  1409. target_if_init_spectral_ops_gen2();
  1410. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  1411. target_if_init_spectral_ops_gen3();
  1412. else
  1413. spectral_err("Invalid Spectral generation");
  1414. }
  1415. /*
  1416. * Dummy Functions:
  1417. * These functions are initially registered to avoid any crashes due to
  1418. * invocation of spectral functions before they are registered.
  1419. */
  1420. static uint64_t
  1421. null_get_tsf64(void *arg)
  1422. {
  1423. spectral_ops_not_registered("get_tsf64");
  1424. return 0;
  1425. }
  1426. static uint32_t
  1427. null_get_capability(void *arg, enum spectral_capability_type type)
  1428. {
  1429. /*
  1430. * TODO : We should have conditional compilation to get the capability
  1431. * : We have not yet attahced ATH layer here, so there is no
  1432. * : way to check the HAL capbalities
  1433. */
  1434. spectral_ops_not_registered("get_capability");
  1435. /* TODO : For the time being, we are returning TRUE */
  1436. return true;
  1437. }
  1438. static uint32_t
  1439. null_set_rxfilter(void *arg, int rxfilter)
  1440. {
  1441. spectral_ops_not_registered("set_rxfilter");
  1442. return 1;
  1443. }
  1444. static uint32_t
  1445. null_get_rxfilter(void *arg)
  1446. {
  1447. spectral_ops_not_registered("get_rxfilter");
  1448. return 0;
  1449. }
  1450. static uint32_t
  1451. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  1452. {
  1453. spectral_ops_not_registered("is_spectral_active");
  1454. return 1;
  1455. }
  1456. static uint32_t
  1457. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  1458. {
  1459. spectral_ops_not_registered("is_spectral_enabled");
  1460. return 1;
  1461. }
  1462. static uint32_t
  1463. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  1464. enum spectral_cp_error_code *err)
  1465. {
  1466. spectral_ops_not_registered("start_spectral_scan");
  1467. return 1;
  1468. }
  1469. static uint32_t
  1470. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  1471. {
  1472. spectral_ops_not_registered("stop_spectral_scan");
  1473. return 1;
  1474. }
  1475. static uint32_t
  1476. null_get_extension_channel(void *arg)
  1477. {
  1478. spectral_ops_not_registered("get_extension_channel");
  1479. return 1;
  1480. }
  1481. static int8_t
  1482. null_get_ctl_noisefloor(void *arg)
  1483. {
  1484. spectral_ops_not_registered("get_ctl_noisefloor");
  1485. return 1;
  1486. }
  1487. static int8_t
  1488. null_get_ext_noisefloor(void *arg)
  1489. {
  1490. spectral_ops_not_registered("get_ext_noisefloor");
  1491. return 0;
  1492. }
  1493. static uint32_t
  1494. null_configure_spectral(void *arg, struct spectral_config *params,
  1495. enum spectral_scan_mode smode)
  1496. {
  1497. spectral_ops_not_registered("configure_spectral");
  1498. return 0;
  1499. }
  1500. static uint32_t
  1501. null_get_spectral_config(void *arg, struct spectral_config *params,
  1502. enum spectral_scan_mode smode)
  1503. {
  1504. spectral_ops_not_registered("get_spectral_config");
  1505. return 0;
  1506. }
  1507. static uint32_t
  1508. null_get_ent_spectral_mask(void *arg)
  1509. {
  1510. spectral_ops_not_registered("get_ent_spectral_mask");
  1511. return 0;
  1512. }
  1513. static uint32_t
  1514. null_get_mac_address(void *arg, char *addr)
  1515. {
  1516. spectral_ops_not_registered("get_mac_address");
  1517. return 0;
  1518. }
  1519. static uint32_t
  1520. null_get_current_channel(void *arg)
  1521. {
  1522. spectral_ops_not_registered("get_current_channel");
  1523. return 0;
  1524. }
  1525. static uint32_t
  1526. null_reset_hw(void *arg)
  1527. {
  1528. spectral_ops_not_registered("get_current_channel");
  1529. return 0;
  1530. }
  1531. static uint32_t
  1532. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1533. {
  1534. spectral_ops_not_registered("get_chain_noise_floor");
  1535. return 0;
  1536. }
  1537. static int
  1538. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  1539. uint8_t *data,
  1540. uint32_t datalen,
  1541. struct target_if_spectral_rfqual_info *p_rfqual,
  1542. struct target_if_spectral_chan_info *p_chaninfo,
  1543. uint64_t tsf64,
  1544. struct target_if_spectral_acs_stats *acs_stats)
  1545. {
  1546. spectral_ops_not_registered("spectral_process_phyerr");
  1547. return 0;
  1548. }
  1549. static int
  1550. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  1551. void *payload)
  1552. {
  1553. spectral_ops_not_registered("process_spectral_report");
  1554. return 0;
  1555. }
  1556. /**
  1557. * target_if_spectral_init_dummy_function_table() -
  1558. * Initialize target_if internal
  1559. * Spectral operations to dummy functions
  1560. * @ps: Pointer to Spectral target_if internal private data
  1561. *
  1562. * Initialize all the function pointers in target_if_spectral_ops with
  1563. * dummy functions.
  1564. *
  1565. * Return: None
  1566. */
  1567. static void
  1568. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  1569. {
  1570. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  1571. p_sops->get_tsf64 = null_get_tsf64;
  1572. p_sops->get_capability = null_get_capability;
  1573. p_sops->set_rxfilter = null_set_rxfilter;
  1574. p_sops->get_rxfilter = null_get_rxfilter;
  1575. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  1576. p_sops->is_spectral_active = null_is_spectral_active;
  1577. p_sops->start_spectral_scan = null_start_spectral_scan;
  1578. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  1579. p_sops->get_extension_channel = null_get_extension_channel;
  1580. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  1581. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  1582. p_sops->configure_spectral = null_configure_spectral;
  1583. p_sops->get_spectral_config = null_get_spectral_config;
  1584. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  1585. p_sops->get_mac_address = null_get_mac_address;
  1586. p_sops->get_current_channel = null_get_current_channel;
  1587. p_sops->reset_hw = null_reset_hw;
  1588. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  1589. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  1590. p_sops->process_spectral_report = null_process_spectral_report;
  1591. }
  1592. /**
  1593. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  1594. * operations
  1595. * @spectral: Pointer to Spectral target_if internal private data
  1596. * @p: Pointer to Spectral function table
  1597. *
  1598. * Return: None
  1599. */
  1600. static void
  1601. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  1602. struct target_if_spectral_ops *p)
  1603. {
  1604. struct target_if_spectral_ops *p_sops =
  1605. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1606. p_sops->get_tsf64 = p->get_tsf64;
  1607. p_sops->get_capability = p->get_capability;
  1608. p_sops->set_rxfilter = p->set_rxfilter;
  1609. p_sops->get_rxfilter = p->get_rxfilter;
  1610. p_sops->is_spectral_enabled = p->is_spectral_enabled;
  1611. p_sops->is_spectral_active = p->is_spectral_active;
  1612. p_sops->start_spectral_scan = p->start_spectral_scan;
  1613. p_sops->stop_spectral_scan = p->stop_spectral_scan;
  1614. p_sops->get_extension_channel = p->get_extension_channel;
  1615. p_sops->get_ctl_noisefloor = p->get_ctl_noisefloor;
  1616. p_sops->get_ext_noisefloor = p->get_ext_noisefloor;
  1617. p_sops->configure_spectral = p->configure_spectral;
  1618. p_sops->get_spectral_config = p->get_spectral_config;
  1619. p_sops->get_ent_spectral_mask = p->get_ent_spectral_mask;
  1620. p_sops->get_mac_address = p->get_mac_address;
  1621. p_sops->get_current_channel = p->get_current_channel;
  1622. p_sops->reset_hw = p->reset_hw;
  1623. p_sops->get_chain_noise_floor = p->get_chain_noise_floor;
  1624. p_sops->spectral_process_phyerr = p->spectral_process_phyerr;
  1625. p_sops->process_spectral_report = p->process_spectral_report;
  1626. }
  1627. /**
  1628. * target_if_spectral_clear_stats() - Clear Spectral stats
  1629. * @spectral: Pointer to Spectral target_if internal private data
  1630. *
  1631. * Function to clear spectral stats
  1632. *
  1633. * Return: None
  1634. */
  1635. static void
  1636. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  1637. {
  1638. struct target_if_spectral_ops *p_sops =
  1639. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1640. qdf_mem_zero(&spectral->spectral_stats,
  1641. sizeof(struct target_if_spectral_stats));
  1642. spectral->spectral_stats.last_reset_tstamp =
  1643. p_sops->get_tsf64(spectral);
  1644. }
  1645. /**
  1646. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  1647. * @spectral: Pointer to Spectral target_if internal private data
  1648. *
  1649. * Function to check whether hardware supports spectral
  1650. *
  1651. * Return: True if HW supports Spectral, false if HW does not support Spectral
  1652. */
  1653. static int
  1654. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  1655. {
  1656. struct target_if_spectral_ops *p_sops = NULL;
  1657. struct spectral_caps *pcap = NULL;
  1658. int is_spectral_supported = true;
  1659. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1660. pcap = &spectral->capability;
  1661. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  1662. is_spectral_supported = false;
  1663. spectral_info("SPECTRAL : No PHYDIAG support");
  1664. return is_spectral_supported;
  1665. }
  1666. pcap->phydiag_cap = 1;
  1667. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  1668. is_spectral_supported = false;
  1669. spectral_info("SPECTRAL : No RADAR support");
  1670. return is_spectral_supported;
  1671. }
  1672. pcap->radar_cap = 1;
  1673. if (p_sops->get_capability(spectral,
  1674. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  1675. is_spectral_supported = false;
  1676. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  1677. return is_spectral_supported;
  1678. }
  1679. pcap->spectral_cap = 1;
  1680. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  1681. == false) {
  1682. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  1683. } else {
  1684. pcap->advncd_spectral_cap = 1;
  1685. }
  1686. return is_spectral_supported;
  1687. }
  1688. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1689. /**
  1690. * target_if_spectral_detach_simulation() - De-initialize Spectral
  1691. * Simulation functionality
  1692. * @spectral: Pointer to Spectral target_if internal private data
  1693. *
  1694. * Function to de-initialize Spectral Simulation functionality
  1695. *
  1696. * Return: None
  1697. */
  1698. static void
  1699. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1700. {
  1701. target_if_spectral_sim_detach(spectral);
  1702. }
  1703. #else
  1704. static void
  1705. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1706. {
  1707. }
  1708. #endif
  1709. /**
  1710. * target_if_spectral_detach() - De-initialize target_if Spectral
  1711. * @pdev: Pointer to pdev object
  1712. *
  1713. * Function to detach target_if spectral
  1714. *
  1715. * Return: None
  1716. */
  1717. static void
  1718. target_if_spectral_detach(struct target_if_spectral *spectral)
  1719. {
  1720. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1721. spectral_info("spectral detach");
  1722. if (spectral) {
  1723. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1724. qdf_spinlock_destroy
  1725. (&spectral->param_info[smode].osps_lock);
  1726. target_if_spectral_detach_simulation(spectral);
  1727. qdf_spinlock_destroy(&spectral->spectral_lock);
  1728. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  1729. qdf_mem_free(spectral);
  1730. spectral = NULL;
  1731. }
  1732. }
  1733. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1734. /**
  1735. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  1736. * functionality
  1737. * @spectral: Pointer to Spectral target_if internal private data
  1738. *
  1739. * Function to initialize spectral simulation functionality
  1740. *
  1741. * Return: 0 on success, negative error code on failure
  1742. */
  1743. static int
  1744. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1745. {
  1746. if (target_if_spectral_sim_attach(spectral)) {
  1747. qdf_mem_free(spectral);
  1748. return -EPERM;
  1749. }
  1750. return 0;
  1751. }
  1752. #else
  1753. static int
  1754. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1755. {
  1756. return 0;
  1757. }
  1758. #endif
  1759. /**
  1760. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  1761. * functionality for the given pdev
  1762. * @pdev: Pointer to pdev object
  1763. *
  1764. * Function to initialize pointer to spectral target_if internal private data
  1765. *
  1766. * Return: On success, pointer to Spectral target_if internal private data, on
  1767. * failure, NULL
  1768. */
  1769. void *
  1770. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  1771. {
  1772. struct target_if_spectral_ops *p_sops = NULL;
  1773. struct target_if_spectral *spectral = NULL;
  1774. uint32_t target_type;
  1775. uint32_t target_revision;
  1776. struct wlan_objmgr_psoc *psoc;
  1777. struct wlan_lmac_if_target_tx_ops *tx_ops;
  1778. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1779. if (!pdev) {
  1780. spectral_err("SPECTRAL: pdev is NULL!");
  1781. return NULL;
  1782. }
  1783. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  1784. sizeof(struct target_if_spectral));
  1785. if (!spectral)
  1786. return spectral;
  1787. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  1788. /* Store pdev in Spectral */
  1789. spectral->pdev_obj = pdev;
  1790. psoc = wlan_pdev_get_psoc(pdev);
  1791. tx_ops = &psoc->soc_cb.tx_ops.target_tx_ops;
  1792. if (tx_ops->tgt_get_tgt_type) {
  1793. target_type = tx_ops->tgt_get_tgt_type(psoc);
  1794. } else {
  1795. qdf_mem_free(spectral);
  1796. return NULL;
  1797. }
  1798. if (tx_ops->tgt_get_tgt_revision) {
  1799. target_revision = tx_ops->tgt_get_tgt_revision(psoc);
  1800. } else {
  1801. qdf_mem_free(spectral);
  1802. return NULL;
  1803. }
  1804. /* init the function ptr table */
  1805. target_if_spectral_init_dummy_function_table(spectral);
  1806. /* get spectral function table */
  1807. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1808. /* TODO : Should this be called here of after ath_attach ? */
  1809. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  1810. spectral_info("HAL_CAP_PHYDIAG : Capable");
  1811. /* TODO: Need to fix the capablity check for RADAR */
  1812. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  1813. spectral_info("HAL_CAP_RADAR : Capable");
  1814. /* TODO : Need to fix the capablity check for SPECTRAL */
  1815. /* TODO : Should this be called here of after ath_attach ? */
  1816. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  1817. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  1818. qdf_spinlock_create(&spectral->spectral_lock);
  1819. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  1820. target_if_spectral_clear_stats(spectral);
  1821. if (target_type == TARGET_TYPE_QCA8074 ||
  1822. target_type == TARGET_TYPE_QCA8074V2 ||
  1823. target_type == TARGET_TYPE_QCA6018 ||
  1824. target_type == TARGET_TYPE_QCA6390)
  1825. spectral->direct_dma_support = true;
  1826. if (target_type == TARGET_TYPE_QCA8074V2)
  1827. spectral->fftbin_size_war =
  1828. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  1829. else if (target_type == TARGET_TYPE_QCA8074 ||
  1830. target_type == TARGET_TYPE_QCA6018 ||
  1831. target_type == TARGET_TYPE_QCA6390)
  1832. spectral->fftbin_size_war =
  1833. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  1834. else
  1835. spectral->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  1836. if (target_type == TARGET_TYPE_QCA8074 ||
  1837. target_type == TARGET_TYPE_QCA8074V2 ||
  1838. target_type == TARGET_TYPE_QCA6018) {
  1839. spectral->inband_fftbin_size_adj = 1;
  1840. spectral->null_fftbin_adj = 1;
  1841. } else {
  1842. spectral->inband_fftbin_size_adj = 0;
  1843. spectral->null_fftbin_adj = 0;
  1844. }
  1845. if ((target_type == TARGET_TYPE_QCA8074) ||
  1846. (target_type == TARGET_TYPE_QCA8074V2) ||
  1847. (target_type == TARGET_TYPE_QCA6018) ||
  1848. (target_type == TARGET_TYPE_QCN9000) ||
  1849. (target_type == TARGET_TYPE_QCA6290) ||
  1850. (target_type == TARGET_TYPE_QCA6390)) {
  1851. spectral->spectral_gen = SPECTRAL_GEN3;
  1852. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  1853. spectral->tag_sscan_summary_exp =
  1854. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  1855. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  1856. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  1857. spectral->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3;
  1858. spectral->fft_size_max = SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3;
  1859. } else {
  1860. spectral->spectral_gen = SPECTRAL_GEN2;
  1861. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  1862. spectral->tag_sscan_summary_exp =
  1863. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  1864. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  1865. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  1866. spectral->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1867. spectral->fft_size_max = SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1868. }
  1869. target_if_init_spectral_param_properties(spectral);
  1870. /* Init spectral capability */
  1871. if (target_if_init_spectral_capability(spectral) !=
  1872. QDF_STATUS_SUCCESS) {
  1873. qdf_mem_free(spectral);
  1874. return NULL;
  1875. }
  1876. if (target_if_spectral_attach_simulation(spectral) < 0)
  1877. return NULL;
  1878. target_if_init_spectral_ops(spectral);
  1879. /* Spectral mode specific init */
  1880. spectral->target_reset_count = 0;
  1881. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1882. spectral->last_fft_timestamp[smode] = 0;
  1883. spectral->timestamp_war_offset[smode] = 0;
  1884. spectral->params_valid[smode] = false;
  1885. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  1886. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  1887. }
  1888. target_if_spectral_register_funcs(spectral, &spectral_ops);
  1889. if (target_if_spectral_check_hw_capability(spectral) == false) {
  1890. target_if_spectral_detach(spectral);
  1891. spectral = NULL;
  1892. } else {
  1893. /*
  1894. * TODO: Once the driver architecture transitions to chipset
  1895. * versioning based checks, reflect this here.
  1896. */
  1897. spectral->is_160_format = false;
  1898. spectral->is_lb_edge_extrabins_format = false;
  1899. spectral->is_rb_edge_extrabins_format = false;
  1900. if (target_type == TARGET_TYPE_QCA9984 ||
  1901. target_type == TARGET_TYPE_QCA9888) {
  1902. spectral->is_160_format = true;
  1903. spectral->is_lb_edge_extrabins_format = true;
  1904. spectral->is_rb_edge_extrabins_format = true;
  1905. } else if ((target_type == TARGET_TYPE_AR900B) &&
  1906. (target_revision == AR900B_REV_2)) {
  1907. spectral->is_rb_edge_extrabins_format = true;
  1908. }
  1909. if (target_type == TARGET_TYPE_QCA9984 ||
  1910. target_type == TARGET_TYPE_QCA9888)
  1911. spectral->is_sec80_rssi_war_required = true;
  1912. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  1913. if (spectral->spectral_gen == SPECTRAL_GEN3)
  1914. init_160mhz_delivery_state_machine(spectral);
  1915. }
  1916. return spectral;
  1917. }
  1918. /**
  1919. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  1920. * functionality for the given pdev
  1921. * @pdev: Pointer to pdev object
  1922. *
  1923. * Function to de-initialize pointer to spectral target_if internal private data
  1924. *
  1925. * Return: None
  1926. */
  1927. void
  1928. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  1929. {
  1930. struct target_if_spectral *spectral = NULL;
  1931. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1932. if (!spectral) {
  1933. spectral_err("SPECTRAL : Module doesn't exist");
  1934. return;
  1935. }
  1936. target_if_spectral_detach(spectral);
  1937. return;
  1938. }
  1939. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  1940. * corresponding translation for Agile channel width.
  1941. * Translation schema of different operating modes:
  1942. * 20 -> 20, 40 -> 40, (80 & 160 & 80_80) -> 80.
  1943. * @chwidth: Channel width enum.
  1944. *
  1945. * Return: The translated channel width enum.
  1946. */
  1947. static enum phy_ch_width
  1948. target_if_spectral_find_agile_width(enum phy_ch_width chwidth)
  1949. {
  1950. switch (chwidth) {
  1951. case CH_WIDTH_20MHZ:
  1952. return CH_WIDTH_20MHZ;
  1953. case CH_WIDTH_40MHZ:
  1954. return CH_WIDTH_40MHZ;
  1955. case CH_WIDTH_80MHZ:
  1956. case CH_WIDTH_80P80MHZ:
  1957. case CH_WIDTH_160MHZ:
  1958. return CH_WIDTH_80MHZ;
  1959. default:
  1960. spectral_err("Invalid chwidth enum %d", chwidth);
  1961. return CH_WIDTH_INVALID;
  1962. }
  1963. }
  1964. /**
  1965. * target_if_calculate_center_freq() - Helper routine to
  1966. * check whether given frequency is center frequency of a
  1967. * WLAN channel
  1968. *
  1969. * @spectral: Pointer to Spectral object
  1970. * @chan_freq: Center frequency of a WLAN channel
  1971. * @is_valid: Indicates whether given frequency is valid
  1972. *
  1973. * Return: QDF_STATUS
  1974. */
  1975. static QDF_STATUS
  1976. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  1977. uint32_t chan_freq,
  1978. bool *is_valid)
  1979. {
  1980. struct regulatory_channel *cur_chan_list;
  1981. int i;
  1982. if (!pdev) {
  1983. spectral_err("pdev object is null");
  1984. return QDF_STATUS_E_FAILURE;
  1985. }
  1986. if (!is_valid) {
  1987. spectral_err("is valid argument is null");
  1988. return QDF_STATUS_E_FAILURE;
  1989. }
  1990. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  1991. if (!cur_chan_list)
  1992. return QDF_STATUS_E_FAILURE;
  1993. if (wlan_reg_get_current_chan_list(
  1994. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  1995. spectral_err("Failed to get cur_chan list");
  1996. qdf_mem_free(cur_chan_list);
  1997. return QDF_STATUS_E_FAILURE;
  1998. }
  1999. *is_valid = false;
  2000. for (i = 0; i < NUM_CHANNELS; i++) {
  2001. uint32_t flags;
  2002. uint32_t center_freq;
  2003. flags = cur_chan_list[i].chan_flags;
  2004. center_freq = cur_chan_list[i].center_freq;
  2005. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  2006. (center_freq == chan_freq)) {
  2007. *is_valid = true;
  2008. break;
  2009. }
  2010. }
  2011. qdf_mem_free(cur_chan_list);
  2012. return QDF_STATUS_SUCCESS;
  2013. }
  2014. /**
  2015. * target_if_calculate_center_freq() - Helper routine to
  2016. * find the center frequency of the agile span from a
  2017. * WLAN channel center frequency
  2018. *
  2019. * @spectral: Pointer to Spectral object
  2020. * @chan_freq: Center frequency of a WLAN channel
  2021. * @center_freq: Pointer to center frequency
  2022. *
  2023. * Return: QDF_STATUS
  2024. */
  2025. static QDF_STATUS
  2026. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  2027. uint16_t chan_freq,
  2028. uint16_t *center_freq)
  2029. {
  2030. struct wlan_objmgr_vdev *vdev;
  2031. enum phy_ch_width ch_width;
  2032. enum phy_ch_width agile_ch_width;
  2033. if (!spectral) {
  2034. spectral_err("spectral target if object is null");
  2035. return QDF_STATUS_E_FAILURE;
  2036. }
  2037. if (!center_freq) {
  2038. spectral_err("center_freq argument is null");
  2039. return QDF_STATUS_E_FAILURE;
  2040. }
  2041. vdev = target_if_spectral_get_vdev(spectral);
  2042. if (!vdev) {
  2043. spectral_err("vdev is NULL");
  2044. return QDF_STATUS_E_FAILURE;
  2045. }
  2046. ch_width = target_if_vdev_get_ch_width(vdev);
  2047. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2048. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2049. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2050. *center_freq = chan_freq;
  2051. } else {
  2052. uint16_t start_freq;
  2053. uint16_t end_freq;
  2054. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2055. wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2056. (spectral->pdev_obj, chan_freq, agile_ch_width,
  2057. &bonded_chan_ptr);
  2058. if (!bonded_chan_ptr) {
  2059. spectral_err("Bonded channel is not found");
  2060. return QDF_STATUS_E_FAILURE;
  2061. }
  2062. start_freq = bonded_chan_ptr->start_freq;
  2063. end_freq = bonded_chan_ptr->end_freq;
  2064. *center_freq = (start_freq + end_freq) >> 1;
  2065. }
  2066. return QDF_STATUS_SUCCESS;
  2067. }
  2068. /**
  2069. * target_if_validate_center_freq() - Helper routine to
  2070. * validate user provided agile center frequency
  2071. *
  2072. * @spectral: Pointer to Spectral object
  2073. * @center_freq: User provided agile span center frequency
  2074. * @is_valid: Indicates whether agile span center frequency is valid
  2075. *
  2076. * Return: QDF_STATUS
  2077. */
  2078. static QDF_STATUS
  2079. target_if_validate_center_freq(struct target_if_spectral *spectral,
  2080. uint16_t center_freq,
  2081. bool *is_valid)
  2082. {
  2083. struct wlan_objmgr_vdev *vdev;
  2084. enum phy_ch_width ch_width;
  2085. enum phy_ch_width agile_ch_width;
  2086. struct wlan_objmgr_pdev *pdev;
  2087. QDF_STATUS status;
  2088. if (!spectral) {
  2089. spectral_err("spectral target if object is null");
  2090. return QDF_STATUS_E_FAILURE;
  2091. }
  2092. if (!is_valid) {
  2093. spectral_err("is_valid argument is null");
  2094. return QDF_STATUS_E_FAILURE;
  2095. }
  2096. pdev = spectral->pdev_obj;
  2097. vdev = target_if_spectral_get_vdev(spectral);
  2098. if (!vdev) {
  2099. spectral_err("vdev is NULL");
  2100. return QDF_STATUS_E_FAILURE;
  2101. }
  2102. ch_width = target_if_vdev_get_ch_width(vdev);
  2103. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2104. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2105. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2106. status = target_if_is_center_freq_of_any_chan
  2107. (pdev, center_freq, is_valid);
  2108. if (QDF_IS_STATUS_ERROR(status))
  2109. return QDF_STATUS_E_FAILURE;
  2110. } else {
  2111. uint16_t start_freq;
  2112. uint16_t end_freq;
  2113. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2114. bool is_chan;
  2115. status = target_if_is_center_freq_of_any_chan
  2116. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2117. &is_chan);
  2118. if (QDF_IS_STATUS_ERROR(status))
  2119. return QDF_STATUS_E_FAILURE;
  2120. if (is_chan) {
  2121. uint32_t calulated_center_freq;
  2122. wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2123. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2124. agile_ch_width,
  2125. &bonded_chan_ptr);
  2126. if (!bonded_chan_ptr) {
  2127. spectral_err("Bonded channel is not found");
  2128. return QDF_STATUS_E_FAILURE;
  2129. }
  2130. start_freq = bonded_chan_ptr->start_freq;
  2131. end_freq = bonded_chan_ptr->end_freq;
  2132. calulated_center_freq = (start_freq + end_freq) >> 1;
  2133. *is_valid = (center_freq == calulated_center_freq);
  2134. } else {
  2135. *is_valid = false;
  2136. }
  2137. }
  2138. return QDF_STATUS_SUCCESS;
  2139. }
  2140. /**
  2141. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  2142. * check whether agile span overlaps with current operating band.
  2143. *
  2144. * @spectral: Pointer to Spectral object
  2145. * @ss_frequency: Agile span center frequency
  2146. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  2147. *
  2148. * Helper routine to check whether agile span overlaps with current
  2149. * operating band.
  2150. *
  2151. * Return: QDF_STATUS
  2152. */
  2153. static QDF_STATUS
  2154. target_if_is_agile_span_overlap_with_operating_span
  2155. (struct target_if_spectral *spectral,
  2156. uint32_t ss_frequency,
  2157. bool *is_overlapping)
  2158. {
  2159. enum phy_ch_width ch_width;
  2160. enum phy_ch_width agile_ch_width;
  2161. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2162. struct wlan_objmgr_vdev *vdev;
  2163. struct wlan_objmgr_pdev *pdev;
  2164. int16_t chan_freq;
  2165. uint32_t op_start_freq;
  2166. uint32_t op_end_freq;
  2167. uint32_t agile_start_freq;
  2168. uint32_t agile_end_freq;
  2169. uint32_t cfreq2;
  2170. if (!spectral) {
  2171. spectral_err("Spectral object is NULL");
  2172. return QDF_STATUS_E_FAILURE;
  2173. }
  2174. pdev = spectral->pdev_obj;
  2175. if (!pdev) {
  2176. spectral_err("pdev object is NULL");
  2177. return QDF_STATUS_E_FAILURE;
  2178. }
  2179. if (!is_overlapping) {
  2180. spectral_err("Argument(is_overlapping) is NULL");
  2181. return QDF_STATUS_E_FAILURE;
  2182. }
  2183. vdev = target_if_spectral_get_vdev(spectral);
  2184. if (!vdev) {
  2185. spectral_err("vdev is NULL");
  2186. return QDF_STATUS_E_FAILURE;
  2187. }
  2188. ch_width = target_if_vdev_get_ch_width(vdev);
  2189. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2190. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2191. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2192. if (cfreq2 < 0)
  2193. return QDF_STATUS_E_FAILURE;
  2194. if (ch_width == CH_WIDTH_20MHZ) {
  2195. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  2196. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  2197. } else {
  2198. wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2199. (pdev, chan_freq, ch_width, &bonded_chan_ptr);
  2200. if (!bonded_chan_ptr) {
  2201. spectral_err("Bonded channel is not found");
  2202. return QDF_STATUS_E_FAILURE;
  2203. }
  2204. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  2205. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  2206. }
  2207. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2208. if (agile_ch_width == CH_WIDTH_INVALID)
  2209. return QDF_STATUS_E_FAILURE;
  2210. agile_start_freq = ss_frequency -
  2211. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2212. agile_end_freq = ss_frequency +
  2213. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2214. if (agile_end_freq <= op_start_freq || op_end_freq <= agile_start_freq)
  2215. *is_overlapping = false;
  2216. else
  2217. *is_overlapping = true;
  2218. /* Use non zero cfreq2 to identify 80p80 */
  2219. if (cfreq2) {
  2220. uint32_t sec80_start_feq;
  2221. uint32_t sec80_end_freq;
  2222. sec80_start_feq = cfreq2 - 40;
  2223. sec80_end_freq = cfreq2 + 40;
  2224. if ((agile_end_freq > sec80_start_feq) &&
  2225. (sec80_end_freq > agile_start_freq))
  2226. *is_overlapping = true;
  2227. }
  2228. return QDF_STATUS_SUCCESS;
  2229. }
  2230. /**
  2231. * _target_if_set_spectral_config() - Set spectral config
  2232. * @spectral: Pointer to spectral object
  2233. * @threshtype: config type
  2234. * @value: config value
  2235. * @smode: Spectral scan mode
  2236. * @err: Spectral error code
  2237. *
  2238. * API to set spectral configurations
  2239. *
  2240. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2241. */
  2242. static QDF_STATUS
  2243. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  2244. const uint32_t threshtype, const uint32_t value,
  2245. const enum spectral_scan_mode smode,
  2246. enum spectral_cp_error_code *err)
  2247. {
  2248. struct spectral_config params;
  2249. struct target_if_spectral_ops *p_sops;
  2250. struct spectral_config *sparams;
  2251. QDF_STATUS status;
  2252. bool is_overlapping;
  2253. uint16_t agile_cfreq;
  2254. bool is_valid_chan;
  2255. if (!err) {
  2256. spectral_err("Error code argument is null");
  2257. QDF_ASSERT(0);
  2258. }
  2259. *err = SPECTRAL_SCAN_ERR_INVALID;
  2260. if (!spectral) {
  2261. spectral_err("spectral object is NULL");
  2262. return QDF_STATUS_E_FAILURE;
  2263. }
  2264. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2265. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2266. spectral_err("Invalid Spectral mode %u", smode);
  2267. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2268. return QDF_STATUS_E_FAILURE;
  2269. }
  2270. sparams = &spectral->params[smode];
  2271. if (!spectral->params_valid[smode]) {
  2272. target_if_spectral_info_read(spectral,
  2273. smode,
  2274. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2275. &spectral->params[smode],
  2276. sizeof(spectral->params[smode]));
  2277. spectral->params_valid[smode] = true;
  2278. }
  2279. switch (threshtype) {
  2280. case SPECTRAL_PARAM_FFT_PERIOD:
  2281. sparams->ss_fft_period = value;
  2282. break;
  2283. case SPECTRAL_PARAM_SCAN_PERIOD:
  2284. sparams->ss_period = value;
  2285. break;
  2286. case SPECTRAL_PARAM_SCAN_COUNT:
  2287. sparams->ss_count = value;
  2288. break;
  2289. case SPECTRAL_PARAM_SHORT_REPORT:
  2290. sparams->ss_short_report = (!!value) ? true : false;
  2291. break;
  2292. case SPECTRAL_PARAM_SPECT_PRI:
  2293. sparams->ss_spectral_pri = (!!value) ? true : false;
  2294. break;
  2295. case SPECTRAL_PARAM_FFT_SIZE:
  2296. if ((value < spectral->fft_size_min) ||
  2297. (value > spectral->fft_size_max)) {
  2298. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2299. return QDF_STATUS_E_FAILURE;
  2300. }
  2301. sparams->ss_fft_size = value;
  2302. break;
  2303. case SPECTRAL_PARAM_GC_ENA:
  2304. sparams->ss_gc_ena = !!value;
  2305. break;
  2306. case SPECTRAL_PARAM_RESTART_ENA:
  2307. sparams->ss_restart_ena = !!value;
  2308. break;
  2309. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  2310. sparams->ss_noise_floor_ref = value;
  2311. break;
  2312. case SPECTRAL_PARAM_INIT_DELAY:
  2313. sparams->ss_init_delay = value;
  2314. break;
  2315. case SPECTRAL_PARAM_NB_TONE_THR:
  2316. sparams->ss_nb_tone_thr = value;
  2317. break;
  2318. case SPECTRAL_PARAM_STR_BIN_THR:
  2319. sparams->ss_str_bin_thr = value;
  2320. break;
  2321. case SPECTRAL_PARAM_WB_RPT_MODE:
  2322. sparams->ss_wb_rpt_mode = !!value;
  2323. break;
  2324. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  2325. sparams->ss_rssi_rpt_mode = !!value;
  2326. break;
  2327. case SPECTRAL_PARAM_RSSI_THR:
  2328. sparams->ss_rssi_thr = value;
  2329. break;
  2330. case SPECTRAL_PARAM_PWR_FORMAT:
  2331. sparams->ss_pwr_format = !!value;
  2332. break;
  2333. case SPECTRAL_PARAM_RPT_MODE:
  2334. if ((value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  2335. (value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  2336. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2337. return QDF_STATUS_E_FAILURE;
  2338. }
  2339. sparams->ss_rpt_mode = value;
  2340. break;
  2341. case SPECTRAL_PARAM_BIN_SCALE:
  2342. sparams->ss_bin_scale = value;
  2343. break;
  2344. case SPECTRAL_PARAM_DBM_ADJ:
  2345. sparams->ss_dbm_adj = !!value;
  2346. break;
  2347. case SPECTRAL_PARAM_CHN_MASK:
  2348. sparams->ss_chn_mask = value;
  2349. break;
  2350. case SPECTRAL_PARAM_FREQUENCY:
  2351. status = target_if_is_center_freq_of_any_chan
  2352. (spectral->pdev_obj, value, &is_valid_chan);
  2353. if (QDF_IS_STATUS_ERROR(status))
  2354. return QDF_STATUS_E_FAILURE;
  2355. if (is_valid_chan) {
  2356. status = target_if_calculate_center_freq(spectral,
  2357. value,
  2358. &agile_cfreq);
  2359. if (QDF_IS_STATUS_ERROR(status)) {
  2360. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2361. return QDF_STATUS_E_FAILURE;
  2362. }
  2363. } else {
  2364. bool is_valid_agile_cfreq;
  2365. status = target_if_validate_center_freq
  2366. (spectral, value, &is_valid_agile_cfreq);
  2367. if (QDF_IS_STATUS_ERROR(status))
  2368. return QDF_STATUS_E_FAILURE;
  2369. if (!is_valid_agile_cfreq) {
  2370. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2371. spectral_err("Invalid agile center frequency");
  2372. return QDF_STATUS_E_FAILURE;
  2373. }
  2374. agile_cfreq = value;
  2375. }
  2376. status = target_if_is_agile_span_overlap_with_operating_span
  2377. (spectral, agile_cfreq, &is_overlapping);
  2378. if (QDF_IS_STATUS_ERROR(status))
  2379. return QDF_STATUS_E_FAILURE;
  2380. if (is_overlapping) {
  2381. spectral_err("Agile span overlapping with current BW");
  2382. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2383. return QDF_STATUS_E_FAILURE;
  2384. }
  2385. sparams->ss_frequency = agile_cfreq;
  2386. break;
  2387. }
  2388. p_sops->configure_spectral(spectral, sparams, smode);
  2389. /* only to validate the writes */
  2390. p_sops->get_spectral_config(spectral, &params, smode);
  2391. return QDF_STATUS_SUCCESS;
  2392. }
  2393. QDF_STATUS
  2394. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  2395. const uint32_t threshtype, const uint32_t value,
  2396. const enum spectral_scan_mode smode,
  2397. enum spectral_cp_error_code *err)
  2398. {
  2399. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  2400. struct target_if_spectral *spectral;
  2401. QDF_STATUS status;
  2402. if (!err) {
  2403. spectral_err("Error code argument is null");
  2404. QDF_ASSERT(0);
  2405. }
  2406. *err = SPECTRAL_SCAN_ERR_INVALID;
  2407. if (!pdev) {
  2408. spectral_err("pdev object is NULL");
  2409. return QDF_STATUS_E_FAILURE;
  2410. }
  2411. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2412. if (!spectral) {
  2413. spectral_err("spectral object is NULL");
  2414. return QDF_STATUS_E_FAILURE;
  2415. }
  2416. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2417. spectral_err("Invalid Spectral mode %u", smode);
  2418. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2419. return QDF_STATUS_E_FAILURE;
  2420. }
  2421. if (!spectral->properties[smode][threshtype].supported) {
  2422. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  2423. threshtype, smode);
  2424. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  2425. return QDF_STATUS_E_FAILURE;
  2426. }
  2427. if (spectral->properties[smode][threshtype].common_all_modes) {
  2428. spectral_warn("Setting Spectral parameter %u for all modes",
  2429. threshtype);
  2430. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  2431. status = _target_if_set_spectral_config
  2432. (spectral, threshtype, value,
  2433. mode, err);
  2434. if (QDF_IS_STATUS_ERROR(status))
  2435. return QDF_STATUS_E_FAILURE;
  2436. }
  2437. return QDF_STATUS_SUCCESS;
  2438. }
  2439. return _target_if_set_spectral_config(spectral, threshtype,
  2440. value, smode, err);
  2441. }
  2442. /**
  2443. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  2444. * @fft_len: FFT length
  2445. * @pdev: Pointer to pdev object
  2446. *
  2447. * API to get fft bin count for a given fft length
  2448. *
  2449. * Return: FFt bin count
  2450. */
  2451. static int
  2452. target_if_get_fft_bin_count(int fft_len)
  2453. {
  2454. int bin_count = 0;
  2455. switch (fft_len) {
  2456. case 5:
  2457. bin_count = 16;
  2458. break;
  2459. case 6:
  2460. bin_count = 32;
  2461. break;
  2462. case 7:
  2463. bin_count = 64;
  2464. break;
  2465. case 8:
  2466. bin_count = 128;
  2467. break;
  2468. case 9:
  2469. bin_count = 256;
  2470. break;
  2471. default:
  2472. break;
  2473. }
  2474. return bin_count;
  2475. }
  2476. /**
  2477. * target_if_init_upper_lower_flags() - Initializes control and extension
  2478. * segment flags
  2479. * @fft_len: FFT length
  2480. * @pdev: Pointer to pdev object
  2481. *
  2482. * API to initialize the control and extension flags with the lower/upper
  2483. * segment based on the HT mode
  2484. *
  2485. * Return: FFt bin count
  2486. */
  2487. static void
  2488. target_if_init_upper_lower_flags(struct target_if_spectral *spectral)
  2489. {
  2490. int current_channel = 0;
  2491. int ext_channel = 0;
  2492. struct target_if_spectral_ops *p_sops =
  2493. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2494. current_channel = p_sops->get_current_channel(spectral);
  2495. ext_channel = p_sops->get_extension_channel(spectral);
  2496. if ((current_channel == 0) || (ext_channel == 0))
  2497. return;
  2498. if (spectral->sc_spectral_20_40_mode) {
  2499. /* HT40 mode */
  2500. if (ext_channel < current_channel) {
  2501. spectral->lower_is_extension = 1;
  2502. spectral->upper_is_control = 1;
  2503. spectral->lower_is_control = 0;
  2504. spectral->upper_is_extension = 0;
  2505. } else {
  2506. spectral->lower_is_extension = 0;
  2507. spectral->upper_is_control = 0;
  2508. spectral->lower_is_control = 1;
  2509. spectral->upper_is_extension = 1;
  2510. }
  2511. } else {
  2512. /* HT20 mode, lower is always control */
  2513. spectral->lower_is_extension = 0;
  2514. spectral->upper_is_control = 0;
  2515. spectral->lower_is_control = 1;
  2516. spectral->upper_is_extension = 0;
  2517. }
  2518. }
  2519. /**
  2520. * target_if_get_spectral_config() - Get spectral configuration
  2521. * @pdev: Pointer to pdev object
  2522. * @param: Pointer to spectral_config structure in which the configuration
  2523. * should be returned
  2524. * @smode: Spectral scan mode
  2525. *
  2526. * API to get the current spectral configuration
  2527. *
  2528. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2529. */
  2530. QDF_STATUS
  2531. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  2532. struct spectral_config *param,
  2533. enum spectral_scan_mode smode)
  2534. {
  2535. struct target_if_spectral_ops *p_sops = NULL;
  2536. struct target_if_spectral *spectral = NULL;
  2537. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2538. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2539. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2540. spectral_err("Invalid Spectral mode %u", smode);
  2541. return QDF_STATUS_E_FAILURE;
  2542. }
  2543. qdf_mem_zero(param, sizeof(struct spectral_config));
  2544. p_sops->get_spectral_config(spectral, param, smode);
  2545. return QDF_STATUS_SUCCESS;
  2546. }
  2547. /**
  2548. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  2549. * parameters
  2550. * @spectral: Pointer to Spectral target_if internal private data
  2551. * @spectral_params: Pointer to Spectral parameters
  2552. * @smode: Spectral scan mode
  2553. * @err: Spectral error code
  2554. *
  2555. * Enable use of desired Spectral parameters by configuring them into HW, and
  2556. * starting Spectral scan
  2557. *
  2558. * Return: 0 on success, 1 on failure
  2559. */
  2560. int
  2561. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  2562. struct spectral_config *spectral_params,
  2563. enum spectral_scan_mode smode,
  2564. enum spectral_cp_error_code *err)
  2565. {
  2566. int extension_channel = 0;
  2567. int current_channel = 0;
  2568. struct target_if_spectral_ops *p_sops = NULL;
  2569. struct wlan_objmgr_vdev *vdev = NULL;
  2570. if (!spectral) {
  2571. spectral_err("Spectral LMAC object is NULL");
  2572. return 1;
  2573. }
  2574. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2575. spectral_err("Invalid Spectral mode %u", smode);
  2576. return 1;
  2577. }
  2578. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2579. if (!p_sops) {
  2580. spectral_err("p_sops is NULL");
  2581. return 1;
  2582. }
  2583. spectral->sc_spectral_noise_pwr_cal =
  2584. spectral_params->ss_spectral_pri ? 1 : 0;
  2585. /* check if extension channel is present */
  2586. extension_channel = p_sops->get_extension_channel(spectral);
  2587. current_channel = p_sops->get_current_channel(spectral);
  2588. vdev = target_if_spectral_get_vdev(spectral);
  2589. if (!vdev)
  2590. return 1;
  2591. spectral->ch_width = target_if_vdev_get_ch_width(vdev);
  2592. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2593. if (spectral->ch_width == CH_WIDTH_INVALID)
  2594. return 1;
  2595. spectral->agile_ch_width =
  2596. target_if_spectral_find_agile_width(spectral->ch_width);
  2597. if (spectral->capability.advncd_spectral_cap) {
  2598. spectral->lb_edge_extrabins = 0;
  2599. spectral->rb_edge_extrabins = 0;
  2600. if (spectral->is_lb_edge_extrabins_format &&
  2601. spectral->params[smode].ss_rpt_mode == 2) {
  2602. spectral->lb_edge_extrabins = 4;
  2603. }
  2604. if (spectral->is_rb_edge_extrabins_format &&
  2605. spectral->params[smode].ss_rpt_mode == 2) {
  2606. spectral->rb_edge_extrabins = 4;
  2607. }
  2608. if (spectral->ch_width == CH_WIDTH_20MHZ) {
  2609. spectral->sc_spectral_20_40_mode = 0;
  2610. spectral->spectral_numbins =
  2611. target_if_get_fft_bin_count(
  2612. spectral->params[smode].ss_fft_size);
  2613. spectral->spectral_fft_len =
  2614. target_if_get_fft_bin_count(
  2615. spectral->params[smode].ss_fft_size);
  2616. spectral->spectral_data_len =
  2617. target_if_get_fft_bin_count(
  2618. spectral->params[smode].ss_fft_size);
  2619. /*
  2620. * Initialize classifier params to be sent to user
  2621. * space classifier
  2622. */
  2623. spectral->classifier_params.lower_chan_in_mhz =
  2624. current_channel;
  2625. spectral->classifier_params.upper_chan_in_mhz = 0;
  2626. } else if (spectral->ch_width == CH_WIDTH_40MHZ) {
  2627. /* TODO : Remove this variable */
  2628. spectral->sc_spectral_20_40_mode = 1;
  2629. spectral->spectral_numbins =
  2630. target_if_get_fft_bin_count(
  2631. spectral->params[smode].ss_fft_size);
  2632. spectral->spectral_fft_len =
  2633. target_if_get_fft_bin_count(
  2634. spectral->params[smode].ss_fft_size);
  2635. spectral->spectral_data_len =
  2636. target_if_get_fft_bin_count(
  2637. spectral->params[smode].ss_fft_size);
  2638. /*
  2639. * Initialize classifier params to be sent to user
  2640. * space classifier
  2641. */
  2642. if (extension_channel < current_channel) {
  2643. spectral->classifier_params.lower_chan_in_mhz =
  2644. extension_channel;
  2645. spectral->classifier_params.upper_chan_in_mhz =
  2646. current_channel;
  2647. } else {
  2648. spectral->classifier_params.lower_chan_in_mhz =
  2649. current_channel;
  2650. spectral->classifier_params.upper_chan_in_mhz =
  2651. extension_channel;
  2652. }
  2653. } else if (spectral->ch_width == CH_WIDTH_80MHZ) {
  2654. /* Set the FFT Size */
  2655. /* TODO : Remove this variable */
  2656. spectral->sc_spectral_20_40_mode = 0;
  2657. spectral->spectral_numbins =
  2658. target_if_get_fft_bin_count(
  2659. spectral->params[smode].ss_fft_size);
  2660. spectral->spectral_fft_len =
  2661. target_if_get_fft_bin_count(
  2662. spectral->params[smode].ss_fft_size);
  2663. spectral->spectral_data_len =
  2664. target_if_get_fft_bin_count(
  2665. spectral->params[smode].ss_fft_size);
  2666. /*
  2667. * Initialize classifier params to be sent to user
  2668. * space classifier
  2669. */
  2670. spectral->classifier_params.lower_chan_in_mhz =
  2671. current_channel;
  2672. spectral->classifier_params.upper_chan_in_mhz = 0;
  2673. /*
  2674. * Initialize classifier params to be sent to user
  2675. * space classifier
  2676. */
  2677. if (extension_channel < current_channel) {
  2678. spectral->classifier_params.lower_chan_in_mhz =
  2679. extension_channel;
  2680. spectral->classifier_params.upper_chan_in_mhz =
  2681. current_channel;
  2682. } else {
  2683. spectral->classifier_params.lower_chan_in_mhz =
  2684. current_channel;
  2685. spectral->classifier_params.upper_chan_in_mhz =
  2686. extension_channel;
  2687. }
  2688. } else if (spectral->ch_width == CH_WIDTH_160MHZ) {
  2689. /* Set the FFT Size */
  2690. /* The below applies to both 160 and 80+80 cases */
  2691. /* TODO : Remove this variable */
  2692. spectral->sc_spectral_20_40_mode = 0;
  2693. spectral->spectral_numbins =
  2694. target_if_get_fft_bin_count(
  2695. spectral->params[smode].ss_fft_size);
  2696. spectral->spectral_fft_len =
  2697. target_if_get_fft_bin_count(
  2698. spectral->params[smode].ss_fft_size);
  2699. spectral->spectral_data_len =
  2700. target_if_get_fft_bin_count(
  2701. spectral->params[smode].ss_fft_size);
  2702. /*
  2703. * Initialize classifier params to be sent to user
  2704. * space classifier
  2705. */
  2706. spectral->classifier_params.lower_chan_in_mhz =
  2707. current_channel;
  2708. spectral->classifier_params.upper_chan_in_mhz = 0;
  2709. /*
  2710. * Initialize classifier params to be sent to user
  2711. * space classifier
  2712. */
  2713. if (extension_channel < current_channel) {
  2714. spectral->classifier_params.lower_chan_in_mhz =
  2715. extension_channel;
  2716. spectral->classifier_params.upper_chan_in_mhz =
  2717. current_channel;
  2718. } else {
  2719. spectral->classifier_params.lower_chan_in_mhz =
  2720. current_channel;
  2721. spectral->classifier_params.upper_chan_in_mhz =
  2722. extension_channel;
  2723. }
  2724. }
  2725. if (spectral->spectral_numbins) {
  2726. spectral->spectral_numbins +=
  2727. spectral->lb_edge_extrabins;
  2728. spectral->spectral_numbins +=
  2729. spectral->rb_edge_extrabins;
  2730. }
  2731. if (spectral->spectral_fft_len) {
  2732. spectral->spectral_fft_len +=
  2733. spectral->lb_edge_extrabins;
  2734. spectral->spectral_fft_len +=
  2735. spectral->rb_edge_extrabins;
  2736. }
  2737. if (spectral->spectral_data_len) {
  2738. spectral->spectral_data_len +=
  2739. spectral->lb_edge_extrabins;
  2740. spectral->spectral_data_len +=
  2741. spectral->rb_edge_extrabins;
  2742. }
  2743. } else {
  2744. /*
  2745. * The decision to find 20/40 mode is found based on the
  2746. * presence of extension channel
  2747. * instead of channel width, as the channel width can
  2748. * dynamically change
  2749. */
  2750. if (extension_channel == 0) {
  2751. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  2752. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  2753. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  2754. spectral->spectral_data_len =
  2755. SPECTRAL_HT20_TOTAL_DATA_LEN;
  2756. /* only valid in 20-40 mode */
  2757. spectral->spectral_lower_max_index_offset = -1;
  2758. /* only valid in 20-40 mode */
  2759. spectral->spectral_upper_max_index_offset = -1;
  2760. spectral->spectral_max_index_offset =
  2761. spectral->spectral_fft_len + 2;
  2762. spectral->sc_spectral_20_40_mode = 0;
  2763. /*
  2764. * Initialize classifier params to be sent to user
  2765. * space classifier
  2766. */
  2767. spectral->classifier_params.lower_chan_in_mhz =
  2768. current_channel;
  2769. spectral->classifier_params.upper_chan_in_mhz = 0;
  2770. } else {
  2771. spectral->spectral_numbins =
  2772. SPECTRAL_HT40_TOTAL_NUM_BINS;
  2773. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  2774. spectral->spectral_data_len =
  2775. SPECTRAL_HT40_TOTAL_DATA_LEN;
  2776. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  2777. /* only valid in 20 mode */
  2778. spectral->spectral_max_index_offset = -1;
  2779. spectral->spectral_lower_max_index_offset =
  2780. spectral->spectral_fft_len + 2;
  2781. spectral->spectral_upper_max_index_offset =
  2782. spectral->spectral_fft_len + 5;
  2783. spectral->sc_spectral_20_40_mode = 1;
  2784. /*
  2785. * Initialize classifier params to be sent to user
  2786. * space classifier
  2787. */
  2788. if (extension_channel < current_channel) {
  2789. spectral->classifier_params.lower_chan_in_mhz =
  2790. extension_channel;
  2791. spectral->classifier_params.upper_chan_in_mhz =
  2792. current_channel;
  2793. } else {
  2794. spectral->classifier_params.lower_chan_in_mhz =
  2795. current_channel;
  2796. spectral->classifier_params.upper_chan_in_mhz =
  2797. extension_channel;
  2798. }
  2799. }
  2800. }
  2801. spectral->send_single_packet = 0;
  2802. spectral->classifier_params.spectral_20_40_mode =
  2803. spectral->sc_spectral_20_40_mode;
  2804. spectral->classifier_params.spectral_dc_index =
  2805. spectral->spectral_dc_index;
  2806. spectral->spectral_sent_msg = 0;
  2807. spectral->classify_scan = 0;
  2808. spectral->num_spectral_data = 0;
  2809. if (!p_sops->is_spectral_active(spectral, smode)) {
  2810. p_sops->configure_spectral(spectral, spectral_params, smode);
  2811. p_sops->start_spectral_scan(spectral, smode, err);
  2812. spectral->timestamp_war_offset[smode] = 0;
  2813. spectral->last_fft_timestamp[smode] = 0;
  2814. }
  2815. /* get current spectral configuration */
  2816. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  2817. target_if_init_upper_lower_flags(spectral);
  2818. return 0;
  2819. }
  2820. /**
  2821. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  2822. * Agile DFS
  2823. * @psoc: Pointer to psoc
  2824. * @object: Pointer to pdev
  2825. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  2826. *
  2827. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  2828. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  2829. *
  2830. * Return: void
  2831. */
  2832. static void
  2833. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  2834. void *object, void *arg)
  2835. {
  2836. bool *is_aspectral_prohibited = arg;
  2837. struct wlan_objmgr_pdev *cur_pdev = object;
  2838. bool is_agile_dfs_enabled_cur_pdev = false;
  2839. QDF_STATUS status;
  2840. qdf_assert_always(is_aspectral_prohibited);
  2841. if (*is_aspectral_prohibited)
  2842. return;
  2843. qdf_assert_always(psoc);
  2844. qdf_assert_always(cur_pdev);
  2845. status = ucfg_dfs_get_agile_precac_enable
  2846. (cur_pdev,
  2847. &is_agile_dfs_enabled_cur_pdev);
  2848. if (QDF_IS_STATUS_ERROR(status)) {
  2849. spectral_err("Get agile precac failed, prohibiting aSpectral");
  2850. *is_aspectral_prohibited = true;
  2851. return;
  2852. }
  2853. if (is_agile_dfs_enabled_cur_pdev) {
  2854. spectral_err("aDFS is in progress on one of the pdevs");
  2855. *is_aspectral_prohibited = true;
  2856. }
  2857. }
  2858. /**
  2859. * target_if_get_curr_band() - Get current operating band of pdev
  2860. *
  2861. * @spectral: pointer to spectral object
  2862. *
  2863. * API to get current operating band of a given pdev.
  2864. *
  2865. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  2866. */
  2867. static enum reg_wifi_band
  2868. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev)
  2869. {
  2870. struct wlan_objmgr_vdev *vdev;
  2871. int16_t chan_freq;
  2872. enum reg_wifi_band cur_band;
  2873. if (!pdev) {
  2874. spectral_err("pdev is NULL");
  2875. return REG_BAND_UNKNOWN;
  2876. }
  2877. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  2878. if (!vdev) {
  2879. spectral_debug("vdev is NULL");
  2880. return REG_BAND_UNKNOWN;
  2881. }
  2882. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2883. cur_band = wlan_reg_freq_to_band(chan_freq);
  2884. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2885. return cur_band;
  2886. }
  2887. /**
  2888. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  2889. * any of the 5G pdevs
  2890. * @psoc: Pointer to psoc
  2891. * @object: Pointer to pdev
  2892. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  2893. * progress in any 5G pdevs
  2894. *
  2895. * Return: void
  2896. */
  2897. static void
  2898. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  2899. void *object, void *arg)
  2900. {
  2901. enum reg_wifi_band band;
  2902. bool *is_agile_scan_inprog_5g_pdev = arg;
  2903. struct target_if_spectral *spectral;
  2904. struct wlan_objmgr_pdev *cur_pdev = object;
  2905. struct target_if_spectral_ops *p_sops;
  2906. if (*is_agile_scan_inprog_5g_pdev)
  2907. return;
  2908. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  2909. if (!spectral) {
  2910. spectral_err("target if spectral handle is NULL");
  2911. return;
  2912. }
  2913. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2914. band = target_if_get_curr_band(cur_pdev);
  2915. if (band == REG_BAND_UNKNOWN) {
  2916. spectral_debug("Failed to get current band");
  2917. return;
  2918. }
  2919. if (band == REG_BAND_5G &&
  2920. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  2921. *is_agile_scan_inprog_5g_pdev = true;
  2922. }
  2923. /**
  2924. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  2925. * for current vdev rx chainmask.
  2926. *
  2927. * @spectral: Pointer to Spectral object
  2928. * @is_supported: Pointer to is_supported
  2929. *
  2930. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2931. */
  2932. static QDF_STATUS
  2933. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  2934. bool *is_supported)
  2935. {
  2936. struct wlan_objmgr_vdev *vdev;
  2937. uint8_t vdev_rxchainmask;
  2938. struct wlan_objmgr_psoc *psoc;
  2939. struct wlan_objmgr_pdev *pdev;
  2940. struct target_psoc_info *tgt_psoc_info;
  2941. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  2942. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  2943. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  2944. struct wlan_psoc_host_chainmask_table *table;
  2945. int j;
  2946. uint32_t table_id;
  2947. enum phy_ch_width ch_width;
  2948. uint8_t pdev_id;
  2949. if (!spectral) {
  2950. spectral_err("spectral target if object is null");
  2951. return QDF_STATUS_E_FAILURE;
  2952. }
  2953. if (!is_supported) {
  2954. spectral_err("is supported argument is null");
  2955. return QDF_STATUS_E_FAILURE;
  2956. }
  2957. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  2958. spectral_err("HW Agile mode is not supported up to gen 2");
  2959. return QDF_STATUS_E_FAILURE;
  2960. }
  2961. pdev = spectral->pdev_obj;
  2962. if (!pdev) {
  2963. spectral_err("pdev is null");
  2964. return QDF_STATUS_E_FAILURE;
  2965. }
  2966. psoc = wlan_pdev_get_psoc(pdev);
  2967. if (!psoc) {
  2968. spectral_err("psoc is null");
  2969. return QDF_STATUS_E_FAILURE;
  2970. }
  2971. vdev = target_if_spectral_get_vdev(spectral);
  2972. if (!vdev) {
  2973. spectral_err("First vdev is NULL");
  2974. return QDF_STATUS_E_FAILURE;
  2975. }
  2976. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  2977. if (!vdev_rxchainmask) {
  2978. spectral_err("vdev rx chainmask is zero");
  2979. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2980. return QDF_STATUS_E_FAILURE;
  2981. }
  2982. ch_width = target_if_vdev_get_ch_width(vdev);
  2983. if (ch_width == CH_WIDTH_INVALID) {
  2984. spectral_err("Invalid channel width");
  2985. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2986. return QDF_STATUS_E_FAILURE;
  2987. }
  2988. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2989. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  2990. if (!tgt_psoc_info) {
  2991. spectral_err("target_psoc_info is null");
  2992. return QDF_STATUS_E_FAILURE;
  2993. }
  2994. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  2995. if (!ext_svc_param) {
  2996. spectral_err("Extended service ready param null");
  2997. return QDF_STATUS_E_FAILURE;
  2998. }
  2999. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  3000. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  3001. if (!mac_phy_cap_arr) {
  3002. spectral_err("mac phy cap array is null");
  3003. return QDF_STATUS_E_FAILURE;
  3004. }
  3005. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  3006. if (!mac_phy_cap) {
  3007. spectral_err("mac phy cap is null");
  3008. return QDF_STATUS_E_FAILURE;
  3009. }
  3010. table_id = mac_phy_cap->chainmask_table_id;
  3011. table = &ext_svc_param->chainmask_table[table_id];
  3012. if (!table) {
  3013. spectral_err("chainmask table not found");
  3014. return QDF_STATUS_E_FAILURE;
  3015. }
  3016. for (j = 0; j < table->num_valid_chainmasks; j++) {
  3017. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  3018. if (ch_width <= CH_WIDTH_80MHZ)
  3019. *is_supported =
  3020. table->cap_list[j].supports_aSpectral;
  3021. else
  3022. *is_supported =
  3023. table->cap_list[j].supports_aSpectral_160;
  3024. break;
  3025. }
  3026. }
  3027. if (j == table->num_valid_chainmasks) {
  3028. spectral_err("vdev rx chainmask %u not found in table id = %u",
  3029. vdev_rxchainmask, table_id);
  3030. return QDF_STATUS_E_FAILURE;
  3031. }
  3032. return QDF_STATUS_SUCCESS;
  3033. }
  3034. QDF_STATUS
  3035. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3036. const enum spectral_scan_mode smode,
  3037. enum spectral_cp_error_code *err)
  3038. {
  3039. struct target_if_spectral_ops *p_sops;
  3040. struct target_if_spectral *spectral;
  3041. struct wlan_objmgr_psoc *psoc;
  3042. enum reg_wifi_band band;
  3043. if (!err) {
  3044. spectral_err("Error code argument is null");
  3045. QDF_ASSERT(0);
  3046. }
  3047. *err = SPECTRAL_SCAN_ERR_INVALID;
  3048. psoc = wlan_pdev_get_psoc(pdev);
  3049. if (!psoc) {
  3050. spectral_err("psoc is null");
  3051. return QDF_STATUS_E_FAILURE;
  3052. }
  3053. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3054. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3055. spectral_err("Invalid Spectral mode %u", smode);
  3056. return QDF_STATUS_E_FAILURE;
  3057. }
  3058. if (!pdev) {
  3059. spectral_err("pdev object is NUll");
  3060. return QDF_STATUS_E_FAILURE;
  3061. }
  3062. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3063. if (!spectral) {
  3064. spectral_err("Spectral LMAC object is NUll");
  3065. return QDF_STATUS_E_FAILURE;
  3066. }
  3067. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3068. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3069. QDF_STATUS status;
  3070. bool is_supported = false;
  3071. status = target_if_is_agile_supported_cur_chmask(spectral,
  3072. &is_supported);
  3073. if (QDF_IS_STATUS_ERROR(status)) {
  3074. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3075. return QDF_STATUS_E_FAILURE;
  3076. }
  3077. if (!is_supported) {
  3078. spectral_err("aSpectral unsupported for cur chainmask");
  3079. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3080. return QDF_STATUS_E_FAILURE;
  3081. }
  3082. }
  3083. band = target_if_get_curr_band(spectral->pdev_obj);
  3084. if (band == REG_BAND_UNKNOWN) {
  3085. spectral_err("Failed to get current band");
  3086. return QDF_STATUS_E_FAILURE;
  3087. }
  3088. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  3089. struct target_psoc_info *tgt_hdl;
  3090. enum wmi_host_hw_mode_config_type mode;
  3091. bool is_agile_scan_inprog_5g_pdev;
  3092. if (p_sops->is_spectral_active(spectral,
  3093. SPECTRAL_SCAN_MODE_AGILE)) {
  3094. spectral_err("Agile Scan in progress in current pdev");
  3095. return QDF_STATUS_E_FAILURE;
  3096. }
  3097. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  3098. if (!tgt_hdl) {
  3099. target_if_err("target_psoc_info is null");
  3100. return QDF_STATUS_E_FAILURE;
  3101. }
  3102. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  3103. switch (mode) {
  3104. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  3105. case WMI_HOST_HW_MODE_SBS:
  3106. case WMI_HOST_HW_MODE_DBS_SBS:
  3107. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  3108. is_agile_scan_inprog_5g_pdev = false;
  3109. wlan_objmgr_iterate_obj_list
  3110. (psoc, WLAN_PDEV_OP,
  3111. target_if_is_agile_scan_active_in_5g,
  3112. &is_agile_scan_inprog_5g_pdev, 0,
  3113. WLAN_SPECTRAL_ID);
  3114. break;
  3115. default:
  3116. is_agile_scan_inprog_5g_pdev = false;
  3117. break;
  3118. }
  3119. if (is_agile_scan_inprog_5g_pdev) {
  3120. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  3121. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3122. return QDF_STATUS_E_FAILURE;
  3123. }
  3124. }
  3125. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3126. bool is_aspectral_prohibited = false;
  3127. QDF_STATUS status;
  3128. status = wlan_objmgr_iterate_obj_list
  3129. (psoc, WLAN_PDEV_OP,
  3130. target_if_is_aspectral_prohibited_by_adfs,
  3131. &is_aspectral_prohibited, 0,
  3132. WLAN_SPECTRAL_ID);
  3133. if (QDF_IS_STATUS_ERROR(status)) {
  3134. spectral_err("Failed to iterate over pdevs");
  3135. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3136. return QDF_STATUS_E_FAILURE;
  3137. }
  3138. if (is_aspectral_prohibited) {
  3139. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3140. return QDF_STATUS_E_FAILURE;
  3141. }
  3142. }
  3143. if (!spectral->params_valid[smode]) {
  3144. target_if_spectral_info_read(spectral,
  3145. smode,
  3146. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3147. &spectral->params[smode],
  3148. sizeof(spectral->params[smode]));
  3149. spectral->params_valid[smode] = true;
  3150. }
  3151. qdf_spin_lock(&spectral->spectral_lock);
  3152. if (smode == SPECTRAL_SCAN_MODE_AGILE &&
  3153. !spectral->params[smode].ss_frequency) {
  3154. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  3155. qdf_spin_unlock(&spectral->spectral_lock);
  3156. return QDF_STATUS_E_FAILURE;
  3157. }
  3158. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3159. QDF_STATUS status;
  3160. bool is_overlapping;
  3161. status = target_if_is_agile_span_overlap_with_operating_span
  3162. (spectral,
  3163. spectral->params[smode].ss_frequency,
  3164. &is_overlapping);
  3165. if (QDF_IS_STATUS_ERROR(status)) {
  3166. qdf_spin_unlock(&spectral->spectral_lock);
  3167. return QDF_STATUS_E_FAILURE;
  3168. }
  3169. if (is_overlapping) {
  3170. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3171. qdf_spin_unlock(&spectral->spectral_lock);
  3172. return QDF_STATUS_E_FAILURE;
  3173. }
  3174. }
  3175. target_if_spectral_scan_enable_params(spectral,
  3176. &spectral->params[smode], smode,
  3177. err);
  3178. qdf_spin_unlock(&spectral->spectral_lock);
  3179. return QDF_STATUS_SUCCESS;
  3180. }
  3181. QDF_STATUS
  3182. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3183. const enum spectral_scan_mode smode,
  3184. enum spectral_cp_error_code *err)
  3185. {
  3186. struct target_if_spectral_ops *p_sops;
  3187. struct target_if_spectral *spectral;
  3188. if (!err) {
  3189. spectral_err("Error code argument is null");
  3190. QDF_ASSERT(0);
  3191. }
  3192. *err = SPECTRAL_SCAN_ERR_INVALID;
  3193. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3194. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3195. spectral_err("Invalid Spectral mode %u", smode);
  3196. return QDF_STATUS_E_FAILURE;
  3197. }
  3198. if (!pdev) {
  3199. spectral_err("pdev object is NUll ");
  3200. return QDF_STATUS_E_FAILURE;
  3201. }
  3202. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3203. if (!spectral) {
  3204. spectral_err("Spectral LMAC object is NUll ");
  3205. return QDF_STATUS_E_FAILURE;
  3206. }
  3207. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3208. qdf_spin_lock(&spectral->spectral_lock);
  3209. p_sops->stop_spectral_scan(spectral, smode);
  3210. if (spectral->classify_scan) {
  3211. /* TODO : Check if this logic is necessary */
  3212. spectral->detects_control_channel = 0;
  3213. spectral->detects_extension_channel = 0;
  3214. spectral->detects_above_dc = 0;
  3215. spectral->detects_below_dc = 0;
  3216. spectral->classify_scan = 0;
  3217. }
  3218. spectral->send_single_packet = 0;
  3219. spectral->sc_spectral_scan = 0;
  3220. qdf_spin_unlock(&spectral->spectral_lock);
  3221. return QDF_STATUS_SUCCESS;
  3222. }
  3223. /**
  3224. * target_if_is_spectral_active() - Get whether Spectral is active
  3225. * @pdev: Pointer to pdev object
  3226. * @smode: Spectral scan mode
  3227. *
  3228. * API to get whether Spectral is active
  3229. *
  3230. * Return: True if Spectral is active, false if Spectral is not active
  3231. */
  3232. bool
  3233. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  3234. const enum spectral_scan_mode smode)
  3235. {
  3236. struct target_if_spectral *spectral = NULL;
  3237. struct target_if_spectral_ops *p_sops = NULL;
  3238. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3239. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3240. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3241. spectral_err("Invalid Spectral mode %u", smode);
  3242. return QDF_STATUS_E_FAILURE;
  3243. }
  3244. return p_sops->is_spectral_active(spectral, smode);
  3245. }
  3246. /**
  3247. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  3248. * @pdev: Pointer to pdev object
  3249. * @smode: Spectral scan mode
  3250. *
  3251. * API to get whether Spectral is enabled
  3252. *
  3253. * Return: True if Spectral is enabled, false if Spectral is not enabled
  3254. */
  3255. bool
  3256. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  3257. enum spectral_scan_mode smode)
  3258. {
  3259. struct target_if_spectral *spectral = NULL;
  3260. struct target_if_spectral_ops *p_sops = NULL;
  3261. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3262. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3263. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3264. spectral_err("Invalid Spectral mode %u", smode);
  3265. return QDF_STATUS_E_FAILURE;
  3266. }
  3267. return p_sops->is_spectral_enabled(spectral, smode);
  3268. }
  3269. #ifdef DIRECT_BUF_RX_DEBUG
  3270. /**
  3271. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  3272. * @pdev: Pointer to pdev object
  3273. * @enable: Enable/Disable Spectral DMA ring debug
  3274. *
  3275. * Start/stop Spectral DMA ring debug based on @enable.
  3276. * Also save the state for future use.
  3277. *
  3278. * Return: QDF_STATUS of operation
  3279. */
  3280. static QDF_STATUS
  3281. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3282. {
  3283. struct target_if_spectral *spectral;
  3284. struct wlan_lmac_if_tx_ops *tx_ops;
  3285. struct wlan_objmgr_psoc *psoc;
  3286. if (!pdev)
  3287. return QDF_STATUS_E_FAILURE;
  3288. psoc = wlan_pdev_get_psoc(pdev);
  3289. if (!psoc) {
  3290. spectral_err("psoc is null");
  3291. return QDF_STATUS_E_INVAL;
  3292. }
  3293. tx_ops = &psoc->soc_cb.tx_ops;
  3294. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3295. if (!spectral) {
  3296. spectral_err("Spectal LMAC object is NULL");
  3297. return QDF_STATUS_E_INVAL;
  3298. }
  3299. /* Save the state */
  3300. spectral->dbr_ring_debug = enable;
  3301. if (enable)
  3302. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  3303. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  3304. else
  3305. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  3306. pdev, 0);
  3307. return QDF_STATUS_SUCCESS;
  3308. }
  3309. /**
  3310. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  3311. * @pdev: Pointer to pdev object
  3312. * @enable: Enable/Disable Spectral DMA buffer debug
  3313. *
  3314. * Start/stop Spectral DMA buffer debug based on @enable.
  3315. * Also save the state for future use.
  3316. *
  3317. * Return: QDF_STATUS of operation
  3318. */
  3319. static QDF_STATUS
  3320. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3321. {
  3322. struct target_if_spectral *spectral;
  3323. struct wlan_lmac_if_tx_ops *tx_ops;
  3324. struct wlan_objmgr_psoc *psoc;
  3325. if (!pdev)
  3326. return QDF_STATUS_E_FAILURE;
  3327. psoc = wlan_pdev_get_psoc(pdev);
  3328. if (!psoc) {
  3329. spectral_err("psoc is null");
  3330. return QDF_STATUS_E_INVAL;
  3331. }
  3332. tx_ops = &psoc->soc_cb.tx_ops;
  3333. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3334. if (!spectral) {
  3335. spectral_err("Spectal LMAC object is NULL");
  3336. return QDF_STATUS_E_INVAL;
  3337. }
  3338. /* Save the state */
  3339. spectral->dbr_buff_debug = enable;
  3340. if (enable)
  3341. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  3342. pdev, 0, MEM_POISON_SIGNATURE);
  3343. else
  3344. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  3345. pdev, 0);
  3346. }
  3347. /**
  3348. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  3349. * debug based on the previous state
  3350. * @pdev: Pointer to pdev object
  3351. *
  3352. * Return: QDF_STATUS of operation
  3353. */
  3354. static QDF_STATUS
  3355. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  3356. {
  3357. struct target_if_spectral *spectral;
  3358. if (!pdev) {
  3359. spectral_err("pdev is NULL!");
  3360. return QDF_STATUS_E_FAILURE;
  3361. }
  3362. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3363. if (!spectral) {
  3364. spectral_err("Spectal LMAC object is NULL");
  3365. return QDF_STATUS_E_INVAL;
  3366. }
  3367. if (spectral->dbr_buff_debug)
  3368. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  3369. else
  3370. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  3371. }
  3372. /**
  3373. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  3374. * debug based on the previous state
  3375. * @pdev: Pointer to pdev object
  3376. *
  3377. * Return: QDF_STATUS of operation
  3378. */
  3379. static QDF_STATUS
  3380. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  3381. {
  3382. struct target_if_spectral *spectral;
  3383. if (!pdev) {
  3384. spectral_err("pdev is NULL!");
  3385. return QDF_STATUS_E_FAILURE;
  3386. }
  3387. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3388. if (!spectral) {
  3389. spectral_err("Spectal LMAC object is NULL");
  3390. return QDF_STATUS_E_INVAL;
  3391. }
  3392. if (spectral->dbr_ring_debug)
  3393. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  3394. else
  3395. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  3396. }
  3397. /**
  3398. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  3399. * @pdev: Pointer to pdev object
  3400. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  3401. * @debug_value: Value to be set for @dma_debug_type
  3402. *
  3403. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  3404. * based on @debug_value
  3405. *
  3406. * Return: QDF_STATUS of operation
  3407. */
  3408. static QDF_STATUS
  3409. target_if_spectral_set_dma_debug(
  3410. struct wlan_objmgr_pdev *pdev,
  3411. enum spectral_dma_debug dma_debug_type,
  3412. bool debug_value)
  3413. {
  3414. struct target_if_spectral_ops *p_sops;
  3415. struct wlan_objmgr_psoc *psoc;
  3416. struct wlan_lmac_if_tx_ops *tx_ops;
  3417. struct target_if_spectral *spectral;
  3418. if (!pdev)
  3419. return QDF_STATUS_E_FAILURE;
  3420. psoc = wlan_pdev_get_psoc(pdev);
  3421. if (!psoc) {
  3422. spectral_err("psoc is null");
  3423. return QDF_STATUS_E_INVAL;
  3424. }
  3425. tx_ops = &psoc->soc_cb.tx_ops;
  3426. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  3427. spectral_err("Unable to fetch target type");
  3428. return QDF_STATUS_E_FAILURE;
  3429. }
  3430. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3431. if (!spectral) {
  3432. spectral_err("Spectal LMAC object is NULL");
  3433. return QDF_STATUS_E_INVAL;
  3434. }
  3435. if (spectral->direct_dma_support) {
  3436. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3437. if (p_sops->is_spectral_active(spectral,
  3438. SPECTRAL_SCAN_MODE_NORMAL) ||
  3439. p_sops->is_spectral_active(spectral,
  3440. SPECTRAL_SCAN_MODE_AGILE)) {
  3441. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  3442. return QDF_STATUS_E_FAILURE;
  3443. }
  3444. switch (dma_debug_type) {
  3445. case SPECTRAL_DMA_RING_DEBUG:
  3446. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  3447. break;
  3448. case SPECTRAL_DMA_BUFFER_DEBUG:
  3449. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  3450. break;
  3451. default:
  3452. spectral_err("Unsupported DMA debug type : %d",
  3453. dma_debug_type);
  3454. return QDF_STATUS_E_FAILURE;
  3455. }
  3456. }
  3457. return QDF_STATUS_SUCCESS;
  3458. }
  3459. #endif /* DIRECT_BUF_RX_DEBUG */
  3460. /**
  3461. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  3462. * @pdev: Pointer to pdev object
  3463. *
  3464. * Return: Whether Direct-DMA is supported on this radio
  3465. */
  3466. static bool
  3467. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  3468. {
  3469. struct target_if_spectral *spectral;
  3470. if (!pdev) {
  3471. spectral_err("pdev is NULL!");
  3472. return false;
  3473. }
  3474. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3475. if (!spectral) {
  3476. spectral_err("Spectral LMAC object is NULL");
  3477. return false;
  3478. }
  3479. return spectral->direct_dma_support;
  3480. }
  3481. /**
  3482. * target_if_set_debug_level() - Set debug level for Spectral
  3483. * @pdev: Pointer to pdev object
  3484. * @debug_level: Debug level
  3485. *
  3486. * API to set the debug level for Spectral
  3487. *
  3488. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3489. */
  3490. QDF_STATUS
  3491. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  3492. {
  3493. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  3494. return QDF_STATUS_SUCCESS;
  3495. }
  3496. /**
  3497. * target_if_get_debug_level() - Get debug level for Spectral
  3498. * @pdev: Pointer to pdev object
  3499. *
  3500. * API to get the debug level for Spectral
  3501. *
  3502. * Return: Current debug level
  3503. */
  3504. uint32_t
  3505. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  3506. {
  3507. return spectral_debug_level;
  3508. }
  3509. /**
  3510. * target_if_get_spectral_capinfo() - Get Spectral capability information
  3511. * @pdev: Pointer to pdev object
  3512. * @scaps: Buffer into which data should be copied
  3513. *
  3514. * API to get the spectral capability information
  3515. *
  3516. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3517. */
  3518. QDF_STATUS
  3519. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  3520. struct spectral_caps *scaps)
  3521. {
  3522. struct target_if_spectral *spectral = NULL;
  3523. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3524. qdf_mem_copy(scaps, &spectral->capability,
  3525. sizeof(struct spectral_caps));
  3526. return QDF_STATUS_SUCCESS;
  3527. }
  3528. /**
  3529. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  3530. * @pdev: Pointer to pdev object
  3531. * @stats: Buffer into which data should be copied
  3532. *
  3533. * API to get the spectral diagnostic statistics
  3534. *
  3535. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3536. */
  3537. QDF_STATUS
  3538. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  3539. struct spectral_diag_stats *stats)
  3540. {
  3541. struct target_if_spectral *spectral = NULL;
  3542. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3543. qdf_mem_copy(stats, &spectral->diag_stats,
  3544. sizeof(struct spectral_diag_stats));
  3545. return QDF_STATUS_SUCCESS;
  3546. }
  3547. /**
  3548. * target_if_register_wmi_spectral_cmd_ops() - Register wmi_spectral_cmd_ops
  3549. * @cmd_ops: Pointer to the structure having wmi_spectral_cmd function pointers
  3550. * @pdev: Pointer to pdev object
  3551. *
  3552. * API for register wmi_spectral_cmd_ops in spectral internal data structure
  3553. *
  3554. * Return: void
  3555. */
  3556. void
  3557. target_if_register_wmi_spectral_cmd_ops(struct wlan_objmgr_pdev *pdev,
  3558. struct wmi_spectral_cmd_ops *cmd_ops)
  3559. {
  3560. struct target_if_spectral *spectral =
  3561. get_target_if_spectral_handle_from_pdev(pdev);
  3562. if (!spectral) {
  3563. spectral_err("Spectral LMAC object is null");
  3564. return;
  3565. }
  3566. spectral->param_wmi_cmd_ops = *cmd_ops;
  3567. }
  3568. /**
  3569. * target_if_register_netlink_cb() - Register Netlink callbacks
  3570. * @pdev: Pointer to pdev object
  3571. * @nl_cb: Netlink callbacks to register
  3572. *
  3573. * Return: void
  3574. */
  3575. static void
  3576. target_if_register_netlink_cb(
  3577. struct wlan_objmgr_pdev *pdev,
  3578. struct spectral_nl_cb *nl_cb)
  3579. {
  3580. struct target_if_spectral *spectral = NULL;
  3581. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3582. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  3583. if (spectral->use_nl_bcast)
  3584. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  3585. else
  3586. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  3587. }
  3588. /**
  3589. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  3590. * Netlink messages to the application layer
  3591. * @pdev: Pointer to pdev object
  3592. *
  3593. * Return: true for broadcast, false for unicast
  3594. */
  3595. static bool
  3596. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  3597. {
  3598. struct target_if_spectral *spectral = NULL;
  3599. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3600. return spectral->use_nl_bcast;
  3601. }
  3602. /**
  3603. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  3604. * @pdev: Pointer to pdev object
  3605. *
  3606. * Return: void
  3607. */
  3608. static void
  3609. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  3610. {
  3611. struct target_if_spectral *spectral = NULL;
  3612. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3613. if (!spectral) {
  3614. spectral_err("SPECTRAL : Module doesn't exist");
  3615. return;
  3616. }
  3617. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  3618. }
  3619. static int
  3620. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  3621. void *payload)
  3622. {
  3623. struct target_if_spectral *spectral = NULL;
  3624. struct target_if_spectral_ops *p_sops = NULL;
  3625. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3626. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3627. return p_sops->process_spectral_report(pdev, payload);
  3628. }
  3629. #ifdef DIRECT_BUF_RX_DEBUG
  3630. static inline void
  3631. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3632. {
  3633. if (!tx_ops)
  3634. return;
  3635. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  3636. target_if_spectral_set_dma_debug;
  3637. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  3638. target_if_spectral_check_and_do_dbr_ring_debug;
  3639. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  3640. target_if_spectral_check_and_do_dbr_buff_debug;
  3641. }
  3642. #else
  3643. static inline void
  3644. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3645. {
  3646. }
  3647. #endif
  3648. void
  3649. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3650. {
  3651. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  3652. target_if_pdev_spectral_init;
  3653. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  3654. target_if_pdev_spectral_deinit;
  3655. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  3656. target_if_set_spectral_config;
  3657. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  3658. target_if_get_spectral_config;
  3659. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  3660. target_if_start_spectral_scan;
  3661. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  3662. target_if_stop_spectral_scan;
  3663. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  3664. target_if_is_spectral_active;
  3665. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  3666. target_if_is_spectral_enabled;
  3667. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  3668. target_if_set_debug_level;
  3669. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  3670. target_if_get_debug_level;
  3671. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  3672. target_if_get_spectral_capinfo;
  3673. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  3674. target_if_get_spectral_diagstats;
  3675. tx_ops->sptrl_tx_ops.sptrlto_register_wmi_spectral_cmd_ops =
  3676. target_if_register_wmi_spectral_cmd_ops;
  3677. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  3678. target_if_register_netlink_cb;
  3679. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  3680. target_if_use_nl_bcast;
  3681. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  3682. target_if_deregister_netlink_cb;
  3683. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  3684. target_if_process_spectral_report;
  3685. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  3686. target_if_spectral_direct_dma_support;
  3687. target_if_sptrl_debug_register_tx_ops(tx_ops);
  3688. }
  3689. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  3690. void
  3691. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  3692. uint16_t cw_int, uint32_t dcs_enabled)
  3693. {
  3694. struct spectral_samp_msg *msg = NULL;
  3695. struct target_if_spectral_ops *p_sops = NULL;
  3696. struct target_if_spectral *spectral = NULL;
  3697. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3698. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  3699. spectral->pdev_obj,
  3700. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  3701. SPECTRAL_MSG_BUF_NEW);
  3702. if (msg) {
  3703. msg->int_type = cw_int ?
  3704. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  3705. msg->dcs_enabled = dcs_enabled;
  3706. msg->signature = SPECTRAL_SIGNATURE;
  3707. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3708. p_sops->get_mac_address(spectral, msg->macaddr);
  3709. if (spectral->send_phy_data
  3710. (pdev,
  3711. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  3712. spectral->spectral_sent_msg++;
  3713. }
  3714. }
  3715. qdf_export_symbol(target_if_spectral_send_intf_found_msg);