target_if_spectral.c 116 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249
  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. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1881. spectral->last_fft_timestamp[smode] = 0;
  1882. spectral->timestamp_war_offset[smode] = 0;
  1883. spectral->params_valid[smode] = false;
  1884. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  1885. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  1886. }
  1887. target_if_spectral_register_funcs(spectral, &spectral_ops);
  1888. if (target_if_spectral_check_hw_capability(spectral) == false) {
  1889. target_if_spectral_detach(spectral);
  1890. spectral = NULL;
  1891. } else {
  1892. /*
  1893. * TODO: Once the driver architecture transitions to chipset
  1894. * versioning based checks, reflect this here.
  1895. */
  1896. spectral->is_160_format = false;
  1897. spectral->is_lb_edge_extrabins_format = false;
  1898. spectral->is_rb_edge_extrabins_format = false;
  1899. if (target_type == TARGET_TYPE_QCA9984 ||
  1900. target_type == TARGET_TYPE_QCA9888) {
  1901. spectral->is_160_format = true;
  1902. spectral->is_lb_edge_extrabins_format = true;
  1903. spectral->is_rb_edge_extrabins_format = true;
  1904. } else if ((target_type == TARGET_TYPE_AR900B) &&
  1905. (target_revision == AR900B_REV_2)) {
  1906. spectral->is_rb_edge_extrabins_format = true;
  1907. }
  1908. if (target_type == TARGET_TYPE_QCA9984 ||
  1909. target_type == TARGET_TYPE_QCA9888)
  1910. spectral->is_sec80_rssi_war_required = true;
  1911. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  1912. if (spectral->spectral_gen == SPECTRAL_GEN3)
  1913. init_160mhz_delivery_state_machine(spectral);
  1914. }
  1915. return spectral;
  1916. }
  1917. /**
  1918. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  1919. * functionality for the given pdev
  1920. * @pdev: Pointer to pdev object
  1921. *
  1922. * Function to de-initialize pointer to spectral target_if internal private data
  1923. *
  1924. * Return: None
  1925. */
  1926. void
  1927. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  1928. {
  1929. struct target_if_spectral *spectral = NULL;
  1930. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1931. if (!spectral) {
  1932. spectral_err("SPECTRAL : Module doesn't exist");
  1933. return;
  1934. }
  1935. target_if_spectral_detach(spectral);
  1936. return;
  1937. }
  1938. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  1939. * corresponding translation for Agile channel width.
  1940. * Translation schema of different operating modes:
  1941. * 20 -> 20, 40 -> 40, (80 & 160 & 80_80) -> 80.
  1942. * @chwidth: Channel width enum.
  1943. *
  1944. * Return: The translated channel width enum.
  1945. */
  1946. static enum phy_ch_width
  1947. target_if_spectral_find_agile_width(enum phy_ch_width chwidth)
  1948. {
  1949. switch (chwidth) {
  1950. case CH_WIDTH_20MHZ:
  1951. return CH_WIDTH_20MHZ;
  1952. case CH_WIDTH_40MHZ:
  1953. return CH_WIDTH_40MHZ;
  1954. case CH_WIDTH_80MHZ:
  1955. case CH_WIDTH_80P80MHZ:
  1956. case CH_WIDTH_160MHZ:
  1957. return CH_WIDTH_80MHZ;
  1958. default:
  1959. spectral_err("Invalid chwidth enum %d", chwidth);
  1960. return CH_WIDTH_INVALID;
  1961. }
  1962. }
  1963. /**
  1964. * target_if_calculate_center_freq() - Helper routine to
  1965. * check whether given frequency is center frequency of a
  1966. * WLAN channel
  1967. *
  1968. * @spectral: Pointer to Spectral object
  1969. * @chan_freq: Center frequency of a WLAN channel
  1970. * @is_valid: Indicates whether given frequency is valid
  1971. *
  1972. * Return: QDF_STATUS
  1973. */
  1974. static QDF_STATUS
  1975. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  1976. uint32_t chan_freq,
  1977. bool *is_valid)
  1978. {
  1979. struct regulatory_channel *cur_chan_list;
  1980. int i;
  1981. if (!pdev) {
  1982. spectral_err("pdev object is null");
  1983. return QDF_STATUS_E_FAILURE;
  1984. }
  1985. if (!is_valid) {
  1986. spectral_err("is valid argument is null");
  1987. return QDF_STATUS_E_FAILURE;
  1988. }
  1989. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  1990. if (!cur_chan_list)
  1991. return QDF_STATUS_E_FAILURE;
  1992. if (wlan_reg_get_current_chan_list(
  1993. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  1994. spectral_err("Failed to get cur_chan list");
  1995. qdf_mem_free(cur_chan_list);
  1996. return QDF_STATUS_E_FAILURE;
  1997. }
  1998. *is_valid = false;
  1999. for (i = 0; i < NUM_CHANNELS; i++) {
  2000. uint32_t flags;
  2001. uint32_t center_freq;
  2002. flags = cur_chan_list[i].chan_flags;
  2003. center_freq = cur_chan_list[i].center_freq;
  2004. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  2005. (center_freq == chan_freq)) {
  2006. *is_valid = true;
  2007. break;
  2008. }
  2009. }
  2010. qdf_mem_free(cur_chan_list);
  2011. return QDF_STATUS_SUCCESS;
  2012. }
  2013. /**
  2014. * target_if_calculate_center_freq() - Helper routine to
  2015. * find the center frequency of the agile span from a
  2016. * WLAN channel center frequency
  2017. *
  2018. * @spectral: Pointer to Spectral object
  2019. * @chan_freq: Center frequency of a WLAN channel
  2020. * @center_freq: Pointer to center frequency
  2021. *
  2022. * Return: QDF_STATUS
  2023. */
  2024. static QDF_STATUS
  2025. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  2026. uint16_t chan_freq,
  2027. uint16_t *center_freq)
  2028. {
  2029. struct wlan_objmgr_vdev *vdev;
  2030. enum phy_ch_width ch_width;
  2031. enum phy_ch_width agile_ch_width;
  2032. uint16_t chan_num;
  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. chan_num = wlan_reg_freq_to_chan(spectral->pdev_obj, chan_freq);
  2042. vdev = target_if_spectral_get_vdev(spectral);
  2043. if (!vdev) {
  2044. spectral_err("vdev is NULL");
  2045. return QDF_STATUS_E_FAILURE;
  2046. }
  2047. ch_width = target_if_vdev_get_ch_width(vdev);
  2048. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2049. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2050. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2051. *center_freq = chan_freq;
  2052. } else {
  2053. uint16_t start_freq;
  2054. uint16_t end_freq;
  2055. const struct bonded_channel *bonded_chan_ptr = NULL;
  2056. wlan_reg_get_5g_bonded_channel_and_state
  2057. (spectral->pdev_obj, chan_num, agile_ch_width,
  2058. &bonded_chan_ptr);
  2059. if (!bonded_chan_ptr) {
  2060. spectral_err("Bonded channel is not found");
  2061. return QDF_STATUS_E_FAILURE;
  2062. }
  2063. start_freq = wlan_reg_chan_to_freq(spectral->pdev_obj,
  2064. bonded_chan_ptr->start_ch);
  2065. end_freq = wlan_reg_chan_to_freq(spectral->pdev_obj,
  2066. bonded_chan_ptr->end_ch);
  2067. *center_freq = (start_freq + end_freq) >> 1;
  2068. }
  2069. return QDF_STATUS_SUCCESS;
  2070. }
  2071. /**
  2072. * target_if_validate_center_freq() - Helper routine to
  2073. * validate user provided agile center frequency
  2074. *
  2075. * @spectral: Pointer to Spectral object
  2076. * @center_freq: User provided agile span center frequency
  2077. * @is_valid: Indicates whether agile span center frequency is valid
  2078. *
  2079. * Return: QDF_STATUS
  2080. */
  2081. static QDF_STATUS
  2082. target_if_validate_center_freq(struct target_if_spectral *spectral,
  2083. uint16_t center_freq,
  2084. bool *is_valid)
  2085. {
  2086. struct wlan_objmgr_vdev *vdev;
  2087. enum phy_ch_width ch_width;
  2088. enum phy_ch_width agile_ch_width;
  2089. uint16_t chan_num;
  2090. struct wlan_objmgr_pdev *pdev;
  2091. QDF_STATUS status;
  2092. if (!spectral) {
  2093. spectral_err("spectral target if object is null");
  2094. return QDF_STATUS_E_FAILURE;
  2095. }
  2096. if (!is_valid) {
  2097. spectral_err("is_valid argument is null");
  2098. return QDF_STATUS_E_FAILURE;
  2099. }
  2100. pdev = spectral->pdev_obj;
  2101. vdev = target_if_spectral_get_vdev(spectral);
  2102. if (!vdev) {
  2103. spectral_err("vdev is NULL");
  2104. return QDF_STATUS_E_FAILURE;
  2105. }
  2106. ch_width = target_if_vdev_get_ch_width(vdev);
  2107. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2108. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2109. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2110. status = target_if_is_center_freq_of_any_chan
  2111. (pdev, center_freq, is_valid);
  2112. if (QDF_IS_STATUS_ERROR(status))
  2113. return QDF_STATUS_E_FAILURE;
  2114. } else {
  2115. uint16_t start_freq;
  2116. uint16_t end_freq;
  2117. const struct bonded_channel *bonded_chan_ptr = NULL;
  2118. bool is_chan;
  2119. status = target_if_is_center_freq_of_any_chan
  2120. (pdev, center_freq + 10, &is_chan);
  2121. if (QDF_IS_STATUS_ERROR(status))
  2122. return QDF_STATUS_E_FAILURE;
  2123. if (is_chan) {
  2124. uint32_t calulated_center_freq;
  2125. chan_num = wlan_reg_freq_to_chan(pdev,
  2126. center_freq + 10);
  2127. wlan_reg_get_5g_bonded_channel_and_state
  2128. (pdev, chan_num, agile_ch_width,
  2129. &bonded_chan_ptr);
  2130. if (!bonded_chan_ptr) {
  2131. spectral_err("Bonded channel is not found");
  2132. return QDF_STATUS_E_FAILURE;
  2133. }
  2134. start_freq = wlan_reg_chan_to_freq
  2135. (pdev, bonded_chan_ptr->start_ch);
  2136. end_freq = wlan_reg_chan_to_freq
  2137. (pdev, bonded_chan_ptr->end_ch);
  2138. calulated_center_freq = (start_freq + end_freq) >> 1;
  2139. *is_valid = (center_freq == calulated_center_freq);
  2140. } else {
  2141. *is_valid = false;
  2142. }
  2143. }
  2144. return QDF_STATUS_SUCCESS;
  2145. }
  2146. /**
  2147. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  2148. * check whether agile span overlaps with current operating band.
  2149. *
  2150. * @spectral: Pointer to Spectral object
  2151. * @ss_frequency: Agile span center frequency
  2152. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  2153. *
  2154. * Helper routine to check whether agile span overlaps with current
  2155. * operating band.
  2156. *
  2157. * Return: QDF_STATUS
  2158. */
  2159. static QDF_STATUS
  2160. target_if_is_agile_span_overlap_with_operating_span
  2161. (struct target_if_spectral *spectral,
  2162. uint32_t ss_frequency,
  2163. bool *is_overlapping)
  2164. {
  2165. uint32_t chan_num;
  2166. enum phy_ch_width ch_width;
  2167. enum phy_ch_width agile_ch_width;
  2168. const struct bonded_channel *bonded_chan_ptr = NULL;
  2169. struct wlan_objmgr_vdev *vdev;
  2170. struct wlan_objmgr_pdev *pdev;
  2171. int16_t chan_freq;
  2172. uint32_t op_start_freq;
  2173. uint32_t op_end_freq;
  2174. uint32_t agile_start_freq;
  2175. uint32_t agile_end_freq;
  2176. uint32_t cfreq2;
  2177. if (!spectral) {
  2178. spectral_err("Spectral object is NULL");
  2179. return QDF_STATUS_E_FAILURE;
  2180. }
  2181. pdev = spectral->pdev_obj;
  2182. if (!pdev) {
  2183. spectral_err("pdev object is NULL");
  2184. return QDF_STATUS_E_FAILURE;
  2185. }
  2186. if (!is_overlapping) {
  2187. spectral_err("Argument(is_overlapping) is NULL");
  2188. return QDF_STATUS_E_FAILURE;
  2189. }
  2190. vdev = target_if_spectral_get_vdev(spectral);
  2191. if (!vdev) {
  2192. spectral_err("vdev is NULL");
  2193. return QDF_STATUS_E_FAILURE;
  2194. }
  2195. ch_width = target_if_vdev_get_ch_width(vdev);
  2196. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2197. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2198. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2199. if (cfreq2 < 0)
  2200. return QDF_STATUS_E_FAILURE;
  2201. chan_num = wlan_reg_freq_to_chan(pdev, chan_freq);
  2202. if (ch_width == CH_WIDTH_20MHZ) {
  2203. op_start_freq = chan_freq - 10;
  2204. op_end_freq = chan_freq + 10;
  2205. } else {
  2206. wlan_reg_get_5g_bonded_channel_and_state
  2207. (pdev, chan_num, ch_width, &bonded_chan_ptr);
  2208. if (!bonded_chan_ptr) {
  2209. spectral_err("Bonded channel is not found");
  2210. return QDF_STATUS_E_FAILURE;
  2211. }
  2212. op_start_freq =
  2213. wlan_reg_chan_to_freq(pdev,
  2214. bonded_chan_ptr->start_ch) - 10;
  2215. op_end_freq =
  2216. wlan_reg_chan_to_freq(pdev,
  2217. bonded_chan_ptr->end_ch) + 10;
  2218. }
  2219. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2220. if (agile_ch_width == CH_WIDTH_INVALID)
  2221. return QDF_STATUS_E_FAILURE;
  2222. agile_start_freq = ss_frequency -
  2223. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2224. agile_end_freq = ss_frequency +
  2225. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2226. if (agile_end_freq <= op_start_freq || op_end_freq <= agile_start_freq)
  2227. *is_overlapping = false;
  2228. else
  2229. *is_overlapping = true;
  2230. /* Use non zero cfreq2 to identify 80p80 */
  2231. if (cfreq2) {
  2232. uint32_t sec80_start_feq;
  2233. uint32_t sec80_end_freq;
  2234. sec80_start_feq = cfreq2 - 40;
  2235. sec80_end_freq = cfreq2 + 40;
  2236. if ((agile_end_freq > sec80_start_feq) &&
  2237. (sec80_end_freq > agile_start_freq))
  2238. *is_overlapping = true;
  2239. }
  2240. return QDF_STATUS_SUCCESS;
  2241. }
  2242. /**
  2243. * _target_if_set_spectral_config() - Set spectral config
  2244. * @spectral: Pointer to spectral object
  2245. * @threshtype: config type
  2246. * @value: config value
  2247. * @smode: Spectral scan mode
  2248. * @err: Spectral error code
  2249. *
  2250. * API to set spectral configurations
  2251. *
  2252. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2253. */
  2254. static QDF_STATUS
  2255. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  2256. const uint32_t threshtype, const uint32_t value,
  2257. const enum spectral_scan_mode smode,
  2258. enum spectral_cp_error_code *err)
  2259. {
  2260. struct spectral_config params;
  2261. struct target_if_spectral_ops *p_sops;
  2262. struct spectral_config *sparams;
  2263. QDF_STATUS status;
  2264. bool is_overlapping;
  2265. uint16_t agile_cfreq;
  2266. bool is_valid_chan;
  2267. if (!err) {
  2268. spectral_err("Error code argument is null");
  2269. QDF_ASSERT(0);
  2270. }
  2271. *err = SPECTRAL_SCAN_ERR_INVALID;
  2272. if (!spectral) {
  2273. spectral_err("spectral object is NULL");
  2274. return QDF_STATUS_E_FAILURE;
  2275. }
  2276. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2277. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2278. spectral_err("Invalid Spectral mode %u", smode);
  2279. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2280. return QDF_STATUS_E_FAILURE;
  2281. }
  2282. sparams = &spectral->params[smode];
  2283. if (!spectral->params_valid[smode]) {
  2284. target_if_spectral_info_read(spectral,
  2285. smode,
  2286. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2287. &spectral->params[smode],
  2288. sizeof(spectral->params[smode]));
  2289. spectral->params_valid[smode] = true;
  2290. }
  2291. switch (threshtype) {
  2292. case SPECTRAL_PARAM_FFT_PERIOD:
  2293. sparams->ss_fft_period = value;
  2294. break;
  2295. case SPECTRAL_PARAM_SCAN_PERIOD:
  2296. sparams->ss_period = value;
  2297. break;
  2298. case SPECTRAL_PARAM_SCAN_COUNT:
  2299. sparams->ss_count = value;
  2300. break;
  2301. case SPECTRAL_PARAM_SHORT_REPORT:
  2302. sparams->ss_short_report = (!!value) ? true : false;
  2303. break;
  2304. case SPECTRAL_PARAM_SPECT_PRI:
  2305. sparams->ss_spectral_pri = (!!value) ? true : false;
  2306. break;
  2307. case SPECTRAL_PARAM_FFT_SIZE:
  2308. if ((value < spectral->fft_size_min) ||
  2309. (value > spectral->fft_size_max)) {
  2310. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2311. return QDF_STATUS_E_FAILURE;
  2312. }
  2313. sparams->ss_fft_size = value;
  2314. break;
  2315. case SPECTRAL_PARAM_GC_ENA:
  2316. sparams->ss_gc_ena = !!value;
  2317. break;
  2318. case SPECTRAL_PARAM_RESTART_ENA:
  2319. sparams->ss_restart_ena = !!value;
  2320. break;
  2321. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  2322. sparams->ss_noise_floor_ref = value;
  2323. break;
  2324. case SPECTRAL_PARAM_INIT_DELAY:
  2325. sparams->ss_init_delay = value;
  2326. break;
  2327. case SPECTRAL_PARAM_NB_TONE_THR:
  2328. sparams->ss_nb_tone_thr = value;
  2329. break;
  2330. case SPECTRAL_PARAM_STR_BIN_THR:
  2331. sparams->ss_str_bin_thr = value;
  2332. break;
  2333. case SPECTRAL_PARAM_WB_RPT_MODE:
  2334. sparams->ss_wb_rpt_mode = !!value;
  2335. break;
  2336. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  2337. sparams->ss_rssi_rpt_mode = !!value;
  2338. break;
  2339. case SPECTRAL_PARAM_RSSI_THR:
  2340. sparams->ss_rssi_thr = value;
  2341. break;
  2342. case SPECTRAL_PARAM_PWR_FORMAT:
  2343. sparams->ss_pwr_format = !!value;
  2344. break;
  2345. case SPECTRAL_PARAM_RPT_MODE:
  2346. if ((value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  2347. (value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  2348. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2349. return QDF_STATUS_E_FAILURE;
  2350. }
  2351. sparams->ss_rpt_mode = value;
  2352. break;
  2353. case SPECTRAL_PARAM_BIN_SCALE:
  2354. sparams->ss_bin_scale = value;
  2355. break;
  2356. case SPECTRAL_PARAM_DBM_ADJ:
  2357. sparams->ss_dbm_adj = !!value;
  2358. break;
  2359. case SPECTRAL_PARAM_CHN_MASK:
  2360. sparams->ss_chn_mask = value;
  2361. break;
  2362. case SPECTRAL_PARAM_FREQUENCY:
  2363. status = target_if_is_center_freq_of_any_chan
  2364. (spectral->pdev_obj, value, &is_valid_chan);
  2365. if (QDF_IS_STATUS_ERROR(status))
  2366. return QDF_STATUS_E_FAILURE;
  2367. if (is_valid_chan) {
  2368. status = target_if_calculate_center_freq(spectral,
  2369. value,
  2370. &agile_cfreq);
  2371. if (QDF_IS_STATUS_ERROR(status)) {
  2372. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2373. return QDF_STATUS_E_FAILURE;
  2374. }
  2375. } else {
  2376. bool is_valid_agile_cfreq;
  2377. status = target_if_validate_center_freq
  2378. (spectral, value, &is_valid_agile_cfreq);
  2379. if (QDF_IS_STATUS_ERROR(status))
  2380. return QDF_STATUS_E_FAILURE;
  2381. if (!is_valid_agile_cfreq) {
  2382. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2383. spectral_err("Invalid agile center frequency");
  2384. return QDF_STATUS_E_FAILURE;
  2385. }
  2386. agile_cfreq = value;
  2387. }
  2388. status = target_if_is_agile_span_overlap_with_operating_span
  2389. (spectral, agile_cfreq, &is_overlapping);
  2390. if (QDF_IS_STATUS_ERROR(status))
  2391. return QDF_STATUS_E_FAILURE;
  2392. if (is_overlapping) {
  2393. spectral_err("Agile span overlapping with current BW");
  2394. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2395. return QDF_STATUS_E_FAILURE;
  2396. }
  2397. sparams->ss_frequency = agile_cfreq;
  2398. break;
  2399. }
  2400. p_sops->configure_spectral(spectral, sparams, smode);
  2401. /* only to validate the writes */
  2402. p_sops->get_spectral_config(spectral, &params, smode);
  2403. return QDF_STATUS_SUCCESS;
  2404. }
  2405. QDF_STATUS
  2406. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  2407. const uint32_t threshtype, const uint32_t value,
  2408. const enum spectral_scan_mode smode,
  2409. enum spectral_cp_error_code *err)
  2410. {
  2411. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  2412. struct target_if_spectral *spectral;
  2413. QDF_STATUS status;
  2414. if (!err) {
  2415. spectral_err("Error code argument is null");
  2416. QDF_ASSERT(0);
  2417. }
  2418. *err = SPECTRAL_SCAN_ERR_INVALID;
  2419. if (!pdev) {
  2420. spectral_err("pdev object is NULL");
  2421. return QDF_STATUS_E_FAILURE;
  2422. }
  2423. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2424. if (!spectral) {
  2425. spectral_err("spectral object is NULL");
  2426. return QDF_STATUS_E_FAILURE;
  2427. }
  2428. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2429. spectral_err("Invalid Spectral mode %u", smode);
  2430. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2431. return QDF_STATUS_E_FAILURE;
  2432. }
  2433. if (!spectral->properties[smode][threshtype].supported) {
  2434. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  2435. threshtype, smode);
  2436. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  2437. return QDF_STATUS_E_FAILURE;
  2438. }
  2439. if (spectral->properties[smode][threshtype].common_all_modes) {
  2440. spectral_warn("Setting Spectral parameter %u for all modes",
  2441. threshtype);
  2442. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  2443. status = _target_if_set_spectral_config
  2444. (spectral, threshtype, value,
  2445. mode, err);
  2446. if (QDF_IS_STATUS_ERROR(status))
  2447. return QDF_STATUS_E_FAILURE;
  2448. }
  2449. return QDF_STATUS_SUCCESS;
  2450. }
  2451. return _target_if_set_spectral_config(spectral, threshtype,
  2452. value, smode, err);
  2453. }
  2454. /**
  2455. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  2456. * @fft_len: FFT length
  2457. * @pdev: Pointer to pdev object
  2458. *
  2459. * API to get fft bin count for a given fft length
  2460. *
  2461. * Return: FFt bin count
  2462. */
  2463. static int
  2464. target_if_get_fft_bin_count(int fft_len)
  2465. {
  2466. int bin_count = 0;
  2467. switch (fft_len) {
  2468. case 5:
  2469. bin_count = 16;
  2470. break;
  2471. case 6:
  2472. bin_count = 32;
  2473. break;
  2474. case 7:
  2475. bin_count = 64;
  2476. break;
  2477. case 8:
  2478. bin_count = 128;
  2479. break;
  2480. case 9:
  2481. bin_count = 256;
  2482. break;
  2483. default:
  2484. break;
  2485. }
  2486. return bin_count;
  2487. }
  2488. /**
  2489. * target_if_init_upper_lower_flags() - Initializes control and extension
  2490. * segment flags
  2491. * @fft_len: FFT length
  2492. * @pdev: Pointer to pdev object
  2493. *
  2494. * API to initialize the control and extension flags with the lower/upper
  2495. * segment based on the HT mode
  2496. *
  2497. * Return: FFt bin count
  2498. */
  2499. static void
  2500. target_if_init_upper_lower_flags(struct target_if_spectral *spectral)
  2501. {
  2502. int current_channel = 0;
  2503. int ext_channel = 0;
  2504. struct target_if_spectral_ops *p_sops =
  2505. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2506. current_channel = p_sops->get_current_channel(spectral);
  2507. ext_channel = p_sops->get_extension_channel(spectral);
  2508. if ((current_channel == 0) || (ext_channel == 0))
  2509. return;
  2510. if (spectral->sc_spectral_20_40_mode) {
  2511. /* HT40 mode */
  2512. if (ext_channel < current_channel) {
  2513. spectral->lower_is_extension = 1;
  2514. spectral->upper_is_control = 1;
  2515. spectral->lower_is_control = 0;
  2516. spectral->upper_is_extension = 0;
  2517. } else {
  2518. spectral->lower_is_extension = 0;
  2519. spectral->upper_is_control = 0;
  2520. spectral->lower_is_control = 1;
  2521. spectral->upper_is_extension = 1;
  2522. }
  2523. } else {
  2524. /* HT20 mode, lower is always control */
  2525. spectral->lower_is_extension = 0;
  2526. spectral->upper_is_control = 0;
  2527. spectral->lower_is_control = 1;
  2528. spectral->upper_is_extension = 0;
  2529. }
  2530. }
  2531. /**
  2532. * target_if_get_spectral_config() - Get spectral configuration
  2533. * @pdev: Pointer to pdev object
  2534. * @param: Pointer to spectral_config structure in which the configuration
  2535. * should be returned
  2536. * @smode: Spectral scan mode
  2537. *
  2538. * API to get the current spectral configuration
  2539. *
  2540. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2541. */
  2542. QDF_STATUS
  2543. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  2544. struct spectral_config *param,
  2545. enum spectral_scan_mode smode)
  2546. {
  2547. struct target_if_spectral_ops *p_sops = NULL;
  2548. struct target_if_spectral *spectral = NULL;
  2549. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2550. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2551. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2552. spectral_err("Invalid Spectral mode %u", smode);
  2553. return QDF_STATUS_E_FAILURE;
  2554. }
  2555. qdf_mem_zero(param, sizeof(struct spectral_config));
  2556. p_sops->get_spectral_config(spectral, param, smode);
  2557. return QDF_STATUS_SUCCESS;
  2558. }
  2559. /**
  2560. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  2561. * parameters
  2562. * @spectral: Pointer to Spectral target_if internal private data
  2563. * @spectral_params: Pointer to Spectral parameters
  2564. * @smode: Spectral scan mode
  2565. * @err: Spectral error code
  2566. *
  2567. * Enable use of desired Spectral parameters by configuring them into HW, and
  2568. * starting Spectral scan
  2569. *
  2570. * Return: 0 on success, 1 on failure
  2571. */
  2572. int
  2573. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  2574. struct spectral_config *spectral_params,
  2575. enum spectral_scan_mode smode,
  2576. enum spectral_cp_error_code *err)
  2577. {
  2578. int extension_channel = 0;
  2579. int current_channel = 0;
  2580. struct target_if_spectral_ops *p_sops = NULL;
  2581. struct wlan_objmgr_vdev *vdev = NULL;
  2582. if (!spectral) {
  2583. spectral_err("Spectral LMAC object is NULL");
  2584. return 1;
  2585. }
  2586. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2587. spectral_err("Invalid Spectral mode %u", smode);
  2588. return 1;
  2589. }
  2590. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2591. if (!p_sops) {
  2592. spectral_err("p_sops is NULL");
  2593. return 1;
  2594. }
  2595. spectral->sc_spectral_noise_pwr_cal =
  2596. spectral_params->ss_spectral_pri ? 1 : 0;
  2597. /* check if extension channel is present */
  2598. extension_channel = p_sops->get_extension_channel(spectral);
  2599. current_channel = p_sops->get_current_channel(spectral);
  2600. vdev = target_if_spectral_get_vdev(spectral);
  2601. if (!vdev)
  2602. return 1;
  2603. spectral->ch_width = target_if_vdev_get_ch_width(vdev);
  2604. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2605. if (spectral->ch_width == CH_WIDTH_INVALID)
  2606. return 1;
  2607. if (spectral->capability.advncd_spectral_cap) {
  2608. spectral->lb_edge_extrabins = 0;
  2609. spectral->rb_edge_extrabins = 0;
  2610. if (spectral->is_lb_edge_extrabins_format &&
  2611. spectral->params[smode].ss_rpt_mode == 2) {
  2612. spectral->lb_edge_extrabins = 4;
  2613. }
  2614. if (spectral->is_rb_edge_extrabins_format &&
  2615. spectral->params[smode].ss_rpt_mode == 2) {
  2616. spectral->rb_edge_extrabins = 4;
  2617. }
  2618. if (spectral->ch_width == CH_WIDTH_20MHZ) {
  2619. spectral->sc_spectral_20_40_mode = 0;
  2620. spectral->spectral_numbins =
  2621. target_if_get_fft_bin_count(
  2622. spectral->params[smode].ss_fft_size);
  2623. spectral->spectral_fft_len =
  2624. target_if_get_fft_bin_count(
  2625. spectral->params[smode].ss_fft_size);
  2626. spectral->spectral_data_len =
  2627. target_if_get_fft_bin_count(
  2628. spectral->params[smode].ss_fft_size);
  2629. /*
  2630. * Initialize classifier params to be sent to user
  2631. * space classifier
  2632. */
  2633. spectral->classifier_params.lower_chan_in_mhz =
  2634. current_channel;
  2635. spectral->classifier_params.upper_chan_in_mhz = 0;
  2636. } else if (spectral->ch_width == CH_WIDTH_40MHZ) {
  2637. /* TODO : Remove this variable */
  2638. spectral->sc_spectral_20_40_mode = 1;
  2639. spectral->spectral_numbins =
  2640. target_if_get_fft_bin_count(
  2641. spectral->params[smode].ss_fft_size);
  2642. spectral->spectral_fft_len =
  2643. target_if_get_fft_bin_count(
  2644. spectral->params[smode].ss_fft_size);
  2645. spectral->spectral_data_len =
  2646. target_if_get_fft_bin_count(
  2647. spectral->params[smode].ss_fft_size);
  2648. /*
  2649. * Initialize classifier params to be sent to user
  2650. * space classifier
  2651. */
  2652. if (extension_channel < current_channel) {
  2653. spectral->classifier_params.lower_chan_in_mhz =
  2654. extension_channel;
  2655. spectral->classifier_params.upper_chan_in_mhz =
  2656. current_channel;
  2657. } else {
  2658. spectral->classifier_params.lower_chan_in_mhz =
  2659. current_channel;
  2660. spectral->classifier_params.upper_chan_in_mhz =
  2661. extension_channel;
  2662. }
  2663. } else if (spectral->ch_width == CH_WIDTH_80MHZ) {
  2664. /* Set the FFT Size */
  2665. /* TODO : Remove this variable */
  2666. spectral->sc_spectral_20_40_mode = 0;
  2667. spectral->spectral_numbins =
  2668. target_if_get_fft_bin_count(
  2669. spectral->params[smode].ss_fft_size);
  2670. spectral->spectral_fft_len =
  2671. target_if_get_fft_bin_count(
  2672. spectral->params[smode].ss_fft_size);
  2673. spectral->spectral_data_len =
  2674. target_if_get_fft_bin_count(
  2675. spectral->params[smode].ss_fft_size);
  2676. /*
  2677. * Initialize classifier params to be sent to user
  2678. * space classifier
  2679. */
  2680. spectral->classifier_params.lower_chan_in_mhz =
  2681. current_channel;
  2682. spectral->classifier_params.upper_chan_in_mhz = 0;
  2683. /*
  2684. * Initialize classifier params to be sent to user
  2685. * space classifier
  2686. */
  2687. if (extension_channel < current_channel) {
  2688. spectral->classifier_params.lower_chan_in_mhz =
  2689. extension_channel;
  2690. spectral->classifier_params.upper_chan_in_mhz =
  2691. current_channel;
  2692. } else {
  2693. spectral->classifier_params.lower_chan_in_mhz =
  2694. current_channel;
  2695. spectral->classifier_params.upper_chan_in_mhz =
  2696. extension_channel;
  2697. }
  2698. } else if (spectral->ch_width == CH_WIDTH_160MHZ) {
  2699. /* Set the FFT Size */
  2700. /* The below applies to both 160 and 80+80 cases */
  2701. /* TODO : Remove this variable */
  2702. spectral->sc_spectral_20_40_mode = 0;
  2703. spectral->spectral_numbins =
  2704. target_if_get_fft_bin_count(
  2705. spectral->params[smode].ss_fft_size);
  2706. spectral->spectral_fft_len =
  2707. target_if_get_fft_bin_count(
  2708. spectral->params[smode].ss_fft_size);
  2709. spectral->spectral_data_len =
  2710. target_if_get_fft_bin_count(
  2711. spectral->params[smode].ss_fft_size);
  2712. /*
  2713. * Initialize classifier params to be sent to user
  2714. * space classifier
  2715. */
  2716. spectral->classifier_params.lower_chan_in_mhz =
  2717. current_channel;
  2718. spectral->classifier_params.upper_chan_in_mhz = 0;
  2719. /*
  2720. * Initialize classifier params to be sent to user
  2721. * space classifier
  2722. */
  2723. if (extension_channel < current_channel) {
  2724. spectral->classifier_params.lower_chan_in_mhz =
  2725. extension_channel;
  2726. spectral->classifier_params.upper_chan_in_mhz =
  2727. current_channel;
  2728. } else {
  2729. spectral->classifier_params.lower_chan_in_mhz =
  2730. current_channel;
  2731. spectral->classifier_params.upper_chan_in_mhz =
  2732. extension_channel;
  2733. }
  2734. }
  2735. if (spectral->spectral_numbins) {
  2736. spectral->spectral_numbins +=
  2737. spectral->lb_edge_extrabins;
  2738. spectral->spectral_numbins +=
  2739. spectral->rb_edge_extrabins;
  2740. }
  2741. if (spectral->spectral_fft_len) {
  2742. spectral->spectral_fft_len +=
  2743. spectral->lb_edge_extrabins;
  2744. spectral->spectral_fft_len +=
  2745. spectral->rb_edge_extrabins;
  2746. }
  2747. if (spectral->spectral_data_len) {
  2748. spectral->spectral_data_len +=
  2749. spectral->lb_edge_extrabins;
  2750. spectral->spectral_data_len +=
  2751. spectral->rb_edge_extrabins;
  2752. }
  2753. } else {
  2754. /*
  2755. * The decision to find 20/40 mode is found based on the
  2756. * presence of extension channel
  2757. * instead of channel width, as the channel width can
  2758. * dynamically change
  2759. */
  2760. if (extension_channel == 0) {
  2761. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  2762. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  2763. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  2764. spectral->spectral_data_len =
  2765. SPECTRAL_HT20_TOTAL_DATA_LEN;
  2766. /* only valid in 20-40 mode */
  2767. spectral->spectral_lower_max_index_offset = -1;
  2768. /* only valid in 20-40 mode */
  2769. spectral->spectral_upper_max_index_offset = -1;
  2770. spectral->spectral_max_index_offset =
  2771. spectral->spectral_fft_len + 2;
  2772. spectral->sc_spectral_20_40_mode = 0;
  2773. /*
  2774. * Initialize classifier params to be sent to user
  2775. * space classifier
  2776. */
  2777. spectral->classifier_params.lower_chan_in_mhz =
  2778. current_channel;
  2779. spectral->classifier_params.upper_chan_in_mhz = 0;
  2780. } else {
  2781. spectral->spectral_numbins =
  2782. SPECTRAL_HT40_TOTAL_NUM_BINS;
  2783. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  2784. spectral->spectral_data_len =
  2785. SPECTRAL_HT40_TOTAL_DATA_LEN;
  2786. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  2787. /* only valid in 20 mode */
  2788. spectral->spectral_max_index_offset = -1;
  2789. spectral->spectral_lower_max_index_offset =
  2790. spectral->spectral_fft_len + 2;
  2791. spectral->spectral_upper_max_index_offset =
  2792. spectral->spectral_fft_len + 5;
  2793. spectral->sc_spectral_20_40_mode = 1;
  2794. /*
  2795. * Initialize classifier params to be sent to user
  2796. * space classifier
  2797. */
  2798. if (extension_channel < current_channel) {
  2799. spectral->classifier_params.lower_chan_in_mhz =
  2800. extension_channel;
  2801. spectral->classifier_params.upper_chan_in_mhz =
  2802. current_channel;
  2803. } else {
  2804. spectral->classifier_params.lower_chan_in_mhz =
  2805. current_channel;
  2806. spectral->classifier_params.upper_chan_in_mhz =
  2807. extension_channel;
  2808. }
  2809. }
  2810. }
  2811. spectral->send_single_packet = 0;
  2812. spectral->classifier_params.spectral_20_40_mode =
  2813. spectral->sc_spectral_20_40_mode;
  2814. spectral->classifier_params.spectral_dc_index =
  2815. spectral->spectral_dc_index;
  2816. spectral->spectral_sent_msg = 0;
  2817. spectral->classify_scan = 0;
  2818. spectral->num_spectral_data = 0;
  2819. if (!p_sops->is_spectral_active(spectral, smode)) {
  2820. p_sops->configure_spectral(spectral, spectral_params, smode);
  2821. p_sops->start_spectral_scan(spectral, smode, err);
  2822. spectral->timestamp_war_offset[smode] = 0;
  2823. spectral->last_fft_timestamp[smode] = 0;
  2824. }
  2825. /* get current spectral configuration */
  2826. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  2827. target_if_init_upper_lower_flags(spectral);
  2828. return 0;
  2829. }
  2830. /**
  2831. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  2832. * Agile DFS
  2833. * @psoc: Pointer to psoc
  2834. * @object: Pointer to pdev
  2835. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  2836. *
  2837. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  2838. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  2839. *
  2840. * Return: void
  2841. */
  2842. static void
  2843. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  2844. void *object, void *arg)
  2845. {
  2846. bool *is_aspectral_prohibited = arg;
  2847. struct wlan_objmgr_pdev *cur_pdev = object;
  2848. bool is_agile_dfs_enabled_cur_pdev = false;
  2849. QDF_STATUS status;
  2850. qdf_assert_always(is_aspectral_prohibited);
  2851. if (*is_aspectral_prohibited)
  2852. return;
  2853. qdf_assert_always(psoc);
  2854. qdf_assert_always(cur_pdev);
  2855. status = ucfg_dfs_get_agile_precac_enable
  2856. (cur_pdev,
  2857. &is_agile_dfs_enabled_cur_pdev);
  2858. if (QDF_IS_STATUS_ERROR(status)) {
  2859. spectral_err("Get agile precac failed, prohibiting aSpectral");
  2860. *is_aspectral_prohibited = true;
  2861. return;
  2862. }
  2863. if (is_agile_dfs_enabled_cur_pdev) {
  2864. spectral_err("aDFS is in progress on one of the pdevs");
  2865. *is_aspectral_prohibited = true;
  2866. }
  2867. }
  2868. /**
  2869. * target_if_get_curr_band() - Get current operating band of pdev
  2870. *
  2871. * @spectral: pointer to spectral object
  2872. *
  2873. * API to get current operating band of a given pdev.
  2874. *
  2875. * Return: if success enum band_info, BAND_UNKNOWN in case of failure
  2876. */
  2877. static enum band_info
  2878. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev)
  2879. {
  2880. struct wlan_objmgr_vdev *vdev;
  2881. int16_t chan_freq;
  2882. enum band_info cur_band;
  2883. uint32_t chan_num;
  2884. if (!pdev) {
  2885. spectral_err("pdev is NULL");
  2886. return BAND_UNKNOWN;
  2887. }
  2888. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  2889. if (!vdev) {
  2890. spectral_debug("vdev is NULL");
  2891. return BAND_UNKNOWN;
  2892. }
  2893. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2894. chan_num = wlan_reg_freq_to_chan(pdev, chan_freq);
  2895. cur_band = wlan_reg_chan_to_band(chan_num);
  2896. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2897. return cur_band;
  2898. }
  2899. /**
  2900. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  2901. * any of the 5G pdevs
  2902. * @psoc: Pointer to psoc
  2903. * @object: Pointer to pdev
  2904. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  2905. * progress in any 5G pdevs
  2906. *
  2907. * Return: void
  2908. */
  2909. static void
  2910. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  2911. void *object, void *arg)
  2912. {
  2913. enum band_info band;
  2914. bool *is_agile_scan_inprog_5g_pdev = arg;
  2915. struct target_if_spectral *spectral;
  2916. struct wlan_objmgr_pdev *cur_pdev = object;
  2917. struct target_if_spectral_ops *p_sops;
  2918. if (*is_agile_scan_inprog_5g_pdev)
  2919. return;
  2920. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  2921. if (!spectral) {
  2922. spectral_err("target if spectral handle is NULL");
  2923. return;
  2924. }
  2925. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2926. band = target_if_get_curr_band(cur_pdev);
  2927. if (band == BAND_UNKNOWN) {
  2928. spectral_debug("Failed to get current band");
  2929. return;
  2930. }
  2931. if (band == BAND_5G &&
  2932. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  2933. *is_agile_scan_inprog_5g_pdev = true;
  2934. }
  2935. /**
  2936. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  2937. * for current vdev rx chainmask.
  2938. *
  2939. * @spectral: Pointer to Spectral object
  2940. * @is_supported: Pointer to is_supported
  2941. *
  2942. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2943. */
  2944. static QDF_STATUS
  2945. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  2946. bool *is_supported)
  2947. {
  2948. struct wlan_objmgr_vdev *vdev;
  2949. uint8_t vdev_rxchainmask;
  2950. struct wlan_objmgr_psoc *psoc;
  2951. struct wlan_objmgr_pdev *pdev;
  2952. struct target_psoc_info *tgt_psoc_info;
  2953. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  2954. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  2955. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  2956. struct wlan_psoc_host_chainmask_table *table;
  2957. int j;
  2958. uint32_t table_id;
  2959. enum phy_ch_width ch_width;
  2960. uint8_t pdev_id;
  2961. if (!spectral) {
  2962. spectral_err("spectral target if object is null");
  2963. return QDF_STATUS_E_FAILURE;
  2964. }
  2965. if (!is_supported) {
  2966. spectral_err("is supported argument is null");
  2967. return QDF_STATUS_E_FAILURE;
  2968. }
  2969. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  2970. spectral_err("HW Agile mode is not supported up to gen 2");
  2971. return QDF_STATUS_E_FAILURE;
  2972. }
  2973. pdev = spectral->pdev_obj;
  2974. if (!pdev) {
  2975. spectral_err("pdev is null");
  2976. return QDF_STATUS_E_FAILURE;
  2977. }
  2978. psoc = wlan_pdev_get_psoc(pdev);
  2979. if (!psoc) {
  2980. spectral_err("psoc is null");
  2981. return QDF_STATUS_E_FAILURE;
  2982. }
  2983. vdev = target_if_spectral_get_vdev(spectral);
  2984. if (!vdev) {
  2985. spectral_err("First vdev is NULL");
  2986. return QDF_STATUS_E_FAILURE;
  2987. }
  2988. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  2989. if (!vdev_rxchainmask) {
  2990. spectral_err("vdev rx chainmask is zero");
  2991. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2992. return QDF_STATUS_E_FAILURE;
  2993. }
  2994. ch_width = target_if_vdev_get_ch_width(vdev);
  2995. if (ch_width == CH_WIDTH_INVALID) {
  2996. spectral_err("Invalid channel width");
  2997. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2998. return QDF_STATUS_E_FAILURE;
  2999. }
  3000. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3001. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  3002. if (!tgt_psoc_info) {
  3003. spectral_err("target_psoc_info is null");
  3004. return QDF_STATUS_E_FAILURE;
  3005. }
  3006. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  3007. if (!ext_svc_param) {
  3008. spectral_err("Extended service ready param null");
  3009. return QDF_STATUS_E_FAILURE;
  3010. }
  3011. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  3012. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  3013. if (!mac_phy_cap_arr) {
  3014. spectral_err("mac phy cap array is null");
  3015. return QDF_STATUS_E_FAILURE;
  3016. }
  3017. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  3018. if (!mac_phy_cap) {
  3019. spectral_err("mac phy cap is null");
  3020. return QDF_STATUS_E_FAILURE;
  3021. }
  3022. table_id = mac_phy_cap->chainmask_table_id;
  3023. table = &ext_svc_param->chainmask_table[table_id];
  3024. if (!table) {
  3025. spectral_err("chainmask table not found");
  3026. return QDF_STATUS_E_FAILURE;
  3027. }
  3028. for (j = 0; j < table->num_valid_chainmasks; j++) {
  3029. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  3030. if (ch_width <= CH_WIDTH_80MHZ)
  3031. *is_supported =
  3032. table->cap_list[j].supports_aSpectral;
  3033. else
  3034. *is_supported =
  3035. table->cap_list[j].supports_aSpectral_160;
  3036. break;
  3037. }
  3038. }
  3039. if (j == table->num_valid_chainmasks) {
  3040. spectral_err("vdev rx chainmask %u not found in table id = %u",
  3041. vdev_rxchainmask, table_id);
  3042. return QDF_STATUS_E_FAILURE;
  3043. }
  3044. return QDF_STATUS_SUCCESS;
  3045. }
  3046. QDF_STATUS
  3047. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3048. const enum spectral_scan_mode smode,
  3049. enum spectral_cp_error_code *err)
  3050. {
  3051. struct target_if_spectral_ops *p_sops;
  3052. struct target_if_spectral *spectral;
  3053. struct wlan_objmgr_psoc *psoc;
  3054. enum band_info band;
  3055. if (!err) {
  3056. spectral_err("Error code argument is null");
  3057. QDF_ASSERT(0);
  3058. }
  3059. *err = SPECTRAL_SCAN_ERR_INVALID;
  3060. psoc = wlan_pdev_get_psoc(pdev);
  3061. if (!psoc) {
  3062. spectral_err("psoc is null");
  3063. return QDF_STATUS_E_FAILURE;
  3064. }
  3065. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3066. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3067. spectral_err("Invalid Spectral mode %u", smode);
  3068. return QDF_STATUS_E_FAILURE;
  3069. }
  3070. if (!pdev) {
  3071. spectral_err("pdev object is NUll");
  3072. return QDF_STATUS_E_FAILURE;
  3073. }
  3074. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3075. if (!spectral) {
  3076. spectral_err("Spectral LMAC object is NUll");
  3077. return QDF_STATUS_E_FAILURE;
  3078. }
  3079. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3080. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3081. QDF_STATUS status;
  3082. bool is_supported = false;
  3083. status = target_if_is_agile_supported_cur_chmask(spectral,
  3084. &is_supported);
  3085. if (QDF_IS_STATUS_ERROR(status)) {
  3086. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3087. return QDF_STATUS_E_FAILURE;
  3088. }
  3089. if (!is_supported) {
  3090. spectral_err("aSpectral unsupported for cur chainmask");
  3091. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3092. return QDF_STATUS_E_FAILURE;
  3093. }
  3094. }
  3095. band = target_if_get_curr_band(spectral->pdev_obj);
  3096. if (band == BAND_UNKNOWN) {
  3097. spectral_err("Failed to get current band");
  3098. return QDF_STATUS_E_FAILURE;
  3099. }
  3100. if ((band == BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  3101. struct target_psoc_info *tgt_hdl;
  3102. enum wmi_host_hw_mode_config_type mode;
  3103. bool is_agile_scan_inprog_5g_pdev;
  3104. if (p_sops->is_spectral_active(spectral,
  3105. SPECTRAL_SCAN_MODE_AGILE)) {
  3106. spectral_err("Agile Scan in progress in current pdev");
  3107. return QDF_STATUS_E_FAILURE;
  3108. }
  3109. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  3110. if (!tgt_hdl) {
  3111. target_if_err("target_psoc_info is null");
  3112. return QDF_STATUS_E_FAILURE;
  3113. }
  3114. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  3115. switch (mode) {
  3116. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  3117. case WMI_HOST_HW_MODE_SBS:
  3118. case WMI_HOST_HW_MODE_DBS_SBS:
  3119. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  3120. is_agile_scan_inprog_5g_pdev = false;
  3121. wlan_objmgr_iterate_obj_list
  3122. (psoc, WLAN_PDEV_OP,
  3123. target_if_is_agile_scan_active_in_5g,
  3124. &is_agile_scan_inprog_5g_pdev, 0,
  3125. WLAN_SPECTRAL_ID);
  3126. break;
  3127. default:
  3128. is_agile_scan_inprog_5g_pdev = false;
  3129. break;
  3130. }
  3131. if (is_agile_scan_inprog_5g_pdev) {
  3132. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  3133. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3134. return QDF_STATUS_E_FAILURE;
  3135. }
  3136. }
  3137. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3138. bool is_aspectral_prohibited = false;
  3139. QDF_STATUS status;
  3140. status = wlan_objmgr_iterate_obj_list
  3141. (psoc, WLAN_PDEV_OP,
  3142. target_if_is_aspectral_prohibited_by_adfs,
  3143. &is_aspectral_prohibited, 0,
  3144. WLAN_SPECTRAL_ID);
  3145. if (QDF_IS_STATUS_ERROR(status)) {
  3146. spectral_err("Failed to iterate over pdevs");
  3147. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3148. return QDF_STATUS_E_FAILURE;
  3149. }
  3150. if (is_aspectral_prohibited) {
  3151. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3152. return QDF_STATUS_E_FAILURE;
  3153. }
  3154. }
  3155. if (!spectral->params_valid[smode]) {
  3156. target_if_spectral_info_read(spectral,
  3157. smode,
  3158. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3159. &spectral->params[smode],
  3160. sizeof(spectral->params[smode]));
  3161. spectral->params_valid[smode] = true;
  3162. }
  3163. qdf_spin_lock(&spectral->spectral_lock);
  3164. if (smode == SPECTRAL_SCAN_MODE_AGILE &&
  3165. !spectral->params[smode].ss_frequency) {
  3166. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  3167. qdf_spin_unlock(&spectral->spectral_lock);
  3168. return QDF_STATUS_E_FAILURE;
  3169. }
  3170. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3171. QDF_STATUS status;
  3172. bool is_overlapping;
  3173. status = target_if_is_agile_span_overlap_with_operating_span
  3174. (spectral,
  3175. spectral->params[smode].ss_frequency,
  3176. &is_overlapping);
  3177. if (QDF_IS_STATUS_ERROR(status)) {
  3178. qdf_spin_unlock(&spectral->spectral_lock);
  3179. return QDF_STATUS_E_FAILURE;
  3180. }
  3181. if (is_overlapping) {
  3182. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3183. qdf_spin_unlock(&spectral->spectral_lock);
  3184. return QDF_STATUS_E_FAILURE;
  3185. }
  3186. }
  3187. target_if_spectral_scan_enable_params(spectral,
  3188. &spectral->params[smode], smode,
  3189. err);
  3190. qdf_spin_unlock(&spectral->spectral_lock);
  3191. return QDF_STATUS_SUCCESS;
  3192. }
  3193. QDF_STATUS
  3194. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3195. const enum spectral_scan_mode smode,
  3196. enum spectral_cp_error_code *err)
  3197. {
  3198. struct target_if_spectral_ops *p_sops;
  3199. struct target_if_spectral *spectral;
  3200. if (!err) {
  3201. spectral_err("Error code argument is null");
  3202. QDF_ASSERT(0);
  3203. }
  3204. *err = SPECTRAL_SCAN_ERR_INVALID;
  3205. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3206. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3207. spectral_err("Invalid Spectral mode %u", smode);
  3208. return QDF_STATUS_E_FAILURE;
  3209. }
  3210. if (!pdev) {
  3211. spectral_err("pdev object is NUll ");
  3212. return QDF_STATUS_E_FAILURE;
  3213. }
  3214. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3215. if (!spectral) {
  3216. spectral_err("Spectral LMAC object is NUll ");
  3217. return QDF_STATUS_E_FAILURE;
  3218. }
  3219. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3220. qdf_spin_lock(&spectral->spectral_lock);
  3221. p_sops->stop_spectral_scan(spectral, smode);
  3222. if (spectral->classify_scan) {
  3223. /* TODO : Check if this logic is necessary */
  3224. spectral->detects_control_channel = 0;
  3225. spectral->detects_extension_channel = 0;
  3226. spectral->detects_above_dc = 0;
  3227. spectral->detects_below_dc = 0;
  3228. spectral->classify_scan = 0;
  3229. }
  3230. spectral->send_single_packet = 0;
  3231. spectral->sc_spectral_scan = 0;
  3232. qdf_spin_unlock(&spectral->spectral_lock);
  3233. return QDF_STATUS_SUCCESS;
  3234. }
  3235. /**
  3236. * target_if_is_spectral_active() - Get whether Spectral is active
  3237. * @pdev: Pointer to pdev object
  3238. * @smode: Spectral scan mode
  3239. *
  3240. * API to get whether Spectral is active
  3241. *
  3242. * Return: True if Spectral is active, false if Spectral is not active
  3243. */
  3244. bool
  3245. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  3246. const enum spectral_scan_mode smode)
  3247. {
  3248. struct target_if_spectral *spectral = NULL;
  3249. struct target_if_spectral_ops *p_sops = NULL;
  3250. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3251. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3252. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3253. spectral_err("Invalid Spectral mode %u", smode);
  3254. return QDF_STATUS_E_FAILURE;
  3255. }
  3256. return p_sops->is_spectral_active(spectral, smode);
  3257. }
  3258. /**
  3259. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  3260. * @pdev: Pointer to pdev object
  3261. * @smode: Spectral scan mode
  3262. *
  3263. * API to get whether Spectral is enabled
  3264. *
  3265. * Return: True if Spectral is enabled, false if Spectral is not enabled
  3266. */
  3267. bool
  3268. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  3269. enum spectral_scan_mode smode)
  3270. {
  3271. struct target_if_spectral *spectral = NULL;
  3272. struct target_if_spectral_ops *p_sops = NULL;
  3273. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3274. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3275. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3276. spectral_err("Invalid Spectral mode %u", smode);
  3277. return QDF_STATUS_E_FAILURE;
  3278. }
  3279. return p_sops->is_spectral_enabled(spectral, smode);
  3280. }
  3281. #ifdef DIRECT_BUF_RX_DEBUG
  3282. /**
  3283. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  3284. * @pdev: Pointer to pdev object
  3285. * @enable: Enable/Disable Spectral DMA ring debug
  3286. *
  3287. * Start/stop Spectral DMA ring debug based on @enable.
  3288. * Also save the state for future use.
  3289. *
  3290. * Return: QDF_STATUS of operation
  3291. */
  3292. static QDF_STATUS
  3293. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3294. {
  3295. struct target_if_spectral *spectral;
  3296. struct wlan_lmac_if_tx_ops *tx_ops;
  3297. struct wlan_objmgr_psoc *psoc;
  3298. if (!pdev)
  3299. return QDF_STATUS_E_FAILURE;
  3300. psoc = wlan_pdev_get_psoc(pdev);
  3301. if (!psoc) {
  3302. spectral_err("psoc is null");
  3303. return QDF_STATUS_E_INVAL;
  3304. }
  3305. tx_ops = &psoc->soc_cb.tx_ops;
  3306. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3307. if (!spectral) {
  3308. spectral_err("Spectal LMAC object is NULL");
  3309. return QDF_STATUS_E_INVAL;
  3310. }
  3311. /* Save the state */
  3312. spectral->dbr_ring_debug = enable;
  3313. if (enable)
  3314. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  3315. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  3316. else
  3317. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  3318. pdev, 0);
  3319. return QDF_STATUS_SUCCESS;
  3320. }
  3321. /**
  3322. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  3323. * @pdev: Pointer to pdev object
  3324. * @enable: Enable/Disable Spectral DMA buffer debug
  3325. *
  3326. * Start/stop Spectral DMA buffer debug based on @enable.
  3327. * Also save the state for future use.
  3328. *
  3329. * Return: QDF_STATUS of operation
  3330. */
  3331. static QDF_STATUS
  3332. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3333. {
  3334. struct target_if_spectral *spectral;
  3335. struct wlan_lmac_if_tx_ops *tx_ops;
  3336. struct wlan_objmgr_psoc *psoc;
  3337. if (!pdev)
  3338. return QDF_STATUS_E_FAILURE;
  3339. psoc = wlan_pdev_get_psoc(pdev);
  3340. if (!psoc) {
  3341. spectral_err("psoc is null");
  3342. return QDF_STATUS_E_INVAL;
  3343. }
  3344. tx_ops = &psoc->soc_cb.tx_ops;
  3345. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3346. if (!spectral) {
  3347. spectral_err("Spectal LMAC object is NULL");
  3348. return QDF_STATUS_E_INVAL;
  3349. }
  3350. /* Save the state */
  3351. spectral->dbr_buff_debug = enable;
  3352. if (enable)
  3353. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  3354. pdev, 0, MEM_POISON_SIGNATURE);
  3355. else
  3356. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  3357. pdev, 0);
  3358. }
  3359. /**
  3360. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  3361. * debug based on the previous state
  3362. * @pdev: Pointer to pdev object
  3363. *
  3364. * Return: QDF_STATUS of operation
  3365. */
  3366. static QDF_STATUS
  3367. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  3368. {
  3369. struct target_if_spectral *spectral;
  3370. if (!pdev) {
  3371. spectral_err("pdev is NULL!");
  3372. return QDF_STATUS_E_FAILURE;
  3373. }
  3374. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3375. if (!spectral) {
  3376. spectral_err("Spectal LMAC object is NULL");
  3377. return QDF_STATUS_E_INVAL;
  3378. }
  3379. if (spectral->dbr_buff_debug)
  3380. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  3381. else
  3382. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  3383. }
  3384. /**
  3385. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  3386. * debug based on the previous state
  3387. * @pdev: Pointer to pdev object
  3388. *
  3389. * Return: QDF_STATUS of operation
  3390. */
  3391. static QDF_STATUS
  3392. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  3393. {
  3394. struct target_if_spectral *spectral;
  3395. if (!pdev) {
  3396. spectral_err("pdev is NULL!");
  3397. return QDF_STATUS_E_FAILURE;
  3398. }
  3399. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3400. if (!spectral) {
  3401. spectral_err("Spectal LMAC object is NULL");
  3402. return QDF_STATUS_E_INVAL;
  3403. }
  3404. if (spectral->dbr_ring_debug)
  3405. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  3406. else
  3407. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  3408. }
  3409. /**
  3410. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  3411. * @pdev: Pointer to pdev object
  3412. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  3413. * @debug_value: Value to be set for @dma_debug_type
  3414. *
  3415. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  3416. * based on @debug_value
  3417. *
  3418. * Return: QDF_STATUS of operation
  3419. */
  3420. static QDF_STATUS
  3421. target_if_spectral_set_dma_debug(
  3422. struct wlan_objmgr_pdev *pdev,
  3423. enum spectral_dma_debug dma_debug_type,
  3424. bool debug_value)
  3425. {
  3426. struct target_if_spectral_ops *p_sops;
  3427. struct wlan_objmgr_psoc *psoc;
  3428. struct wlan_lmac_if_tx_ops *tx_ops;
  3429. struct target_if_spectral *spectral;
  3430. if (!pdev)
  3431. return QDF_STATUS_E_FAILURE;
  3432. psoc = wlan_pdev_get_psoc(pdev);
  3433. if (!psoc) {
  3434. spectral_err("psoc is null");
  3435. return QDF_STATUS_E_INVAL;
  3436. }
  3437. tx_ops = &psoc->soc_cb.tx_ops;
  3438. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  3439. spectral_err("Unable to fetch target type");
  3440. return QDF_STATUS_E_FAILURE;
  3441. }
  3442. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3443. if (!spectral) {
  3444. spectral_err("Spectal LMAC object is NULL");
  3445. return QDF_STATUS_E_INVAL;
  3446. }
  3447. if (spectral->direct_dma_support) {
  3448. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3449. if (p_sops->is_spectral_active(spectral,
  3450. SPECTRAL_SCAN_MODE_NORMAL) ||
  3451. p_sops->is_spectral_active(spectral,
  3452. SPECTRAL_SCAN_MODE_AGILE)) {
  3453. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  3454. return QDF_STATUS_E_FAILURE;
  3455. }
  3456. switch (dma_debug_type) {
  3457. case SPECTRAL_DMA_RING_DEBUG:
  3458. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  3459. break;
  3460. case SPECTRAL_DMA_BUFFER_DEBUG:
  3461. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  3462. break;
  3463. default:
  3464. spectral_err("Unsupported DMA debug type : %d",
  3465. dma_debug_type);
  3466. return QDF_STATUS_E_FAILURE;
  3467. }
  3468. }
  3469. return QDF_STATUS_SUCCESS;
  3470. }
  3471. #endif /* DIRECT_BUF_RX_DEBUG */
  3472. /**
  3473. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  3474. * @pdev: Pointer to pdev object
  3475. *
  3476. * Return: Whether Direct-DMA is supported on this radio
  3477. */
  3478. static bool
  3479. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  3480. {
  3481. struct target_if_spectral *spectral;
  3482. if (!pdev) {
  3483. spectral_err("pdev is NULL!");
  3484. return false;
  3485. }
  3486. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3487. if (!spectral) {
  3488. spectral_err("Spectral LMAC object is NULL");
  3489. return false;
  3490. }
  3491. return spectral->direct_dma_support;
  3492. }
  3493. /**
  3494. * target_if_set_debug_level() - Set debug level for Spectral
  3495. * @pdev: Pointer to pdev object
  3496. * @debug_level: Debug level
  3497. *
  3498. * API to set the debug level for Spectral
  3499. *
  3500. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3501. */
  3502. QDF_STATUS
  3503. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  3504. {
  3505. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  3506. return QDF_STATUS_SUCCESS;
  3507. }
  3508. /**
  3509. * target_if_get_debug_level() - Get debug level for Spectral
  3510. * @pdev: Pointer to pdev object
  3511. *
  3512. * API to get the debug level for Spectral
  3513. *
  3514. * Return: Current debug level
  3515. */
  3516. uint32_t
  3517. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  3518. {
  3519. return spectral_debug_level;
  3520. }
  3521. /**
  3522. * target_if_get_spectral_capinfo() - Get Spectral capability information
  3523. * @pdev: Pointer to pdev object
  3524. * @scaps: Buffer into which data should be copied
  3525. *
  3526. * API to get the spectral capability information
  3527. *
  3528. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3529. */
  3530. QDF_STATUS
  3531. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  3532. struct spectral_caps *scaps)
  3533. {
  3534. struct target_if_spectral *spectral = NULL;
  3535. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3536. qdf_mem_copy(scaps, &spectral->capability,
  3537. sizeof(struct spectral_caps));
  3538. return QDF_STATUS_SUCCESS;
  3539. }
  3540. /**
  3541. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  3542. * @pdev: Pointer to pdev object
  3543. * @stats: Buffer into which data should be copied
  3544. *
  3545. * API to get the spectral diagnostic statistics
  3546. *
  3547. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3548. */
  3549. QDF_STATUS
  3550. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  3551. struct spectral_diag_stats *stats)
  3552. {
  3553. struct target_if_spectral *spectral = NULL;
  3554. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3555. qdf_mem_copy(stats, &spectral->diag_stats,
  3556. sizeof(struct spectral_diag_stats));
  3557. return QDF_STATUS_SUCCESS;
  3558. }
  3559. /**
  3560. * target_if_register_wmi_spectral_cmd_ops() - Register wmi_spectral_cmd_ops
  3561. * @cmd_ops: Pointer to the structure having wmi_spectral_cmd function pointers
  3562. * @pdev: Pointer to pdev object
  3563. *
  3564. * API for register wmi_spectral_cmd_ops in spectral internal data structure
  3565. *
  3566. * Return: void
  3567. */
  3568. void
  3569. target_if_register_wmi_spectral_cmd_ops(struct wlan_objmgr_pdev *pdev,
  3570. struct wmi_spectral_cmd_ops *cmd_ops)
  3571. {
  3572. struct target_if_spectral *spectral =
  3573. get_target_if_spectral_handle_from_pdev(pdev);
  3574. if (!spectral) {
  3575. spectral_err("Spectral LMAC object is null");
  3576. return;
  3577. }
  3578. spectral->param_wmi_cmd_ops = *cmd_ops;
  3579. }
  3580. /**
  3581. * target_if_register_netlink_cb() - Register Netlink callbacks
  3582. * @pdev: Pointer to pdev object
  3583. * @nl_cb: Netlink callbacks to register
  3584. *
  3585. * Return: void
  3586. */
  3587. static void
  3588. target_if_register_netlink_cb(
  3589. struct wlan_objmgr_pdev *pdev,
  3590. struct spectral_nl_cb *nl_cb)
  3591. {
  3592. struct target_if_spectral *spectral = NULL;
  3593. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3594. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  3595. if (spectral->use_nl_bcast)
  3596. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  3597. else
  3598. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  3599. }
  3600. /**
  3601. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  3602. * Netlink messages to the application layer
  3603. * @pdev: Pointer to pdev object
  3604. *
  3605. * Return: true for broadcast, false for unicast
  3606. */
  3607. static bool
  3608. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  3609. {
  3610. struct target_if_spectral *spectral = NULL;
  3611. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3612. return spectral->use_nl_bcast;
  3613. }
  3614. /**
  3615. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  3616. * @pdev: Pointer to pdev object
  3617. *
  3618. * Return: void
  3619. */
  3620. static void
  3621. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  3622. {
  3623. struct target_if_spectral *spectral = NULL;
  3624. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3625. if (!spectral) {
  3626. spectral_err("SPECTRAL : Module doesn't exist");
  3627. return;
  3628. }
  3629. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  3630. }
  3631. static int
  3632. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  3633. void *payload)
  3634. {
  3635. struct target_if_spectral *spectral = NULL;
  3636. struct target_if_spectral_ops *p_sops = NULL;
  3637. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3638. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3639. return p_sops->process_spectral_report(pdev, payload);
  3640. }
  3641. #ifdef DIRECT_BUF_RX_DEBUG
  3642. static inline void
  3643. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3644. {
  3645. if (!tx_ops)
  3646. return;
  3647. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  3648. target_if_spectral_set_dma_debug;
  3649. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  3650. target_if_spectral_check_and_do_dbr_ring_debug;
  3651. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  3652. target_if_spectral_check_and_do_dbr_buff_debug;
  3653. }
  3654. #else
  3655. static inline void
  3656. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3657. {
  3658. }
  3659. #endif
  3660. void
  3661. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3662. {
  3663. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  3664. target_if_pdev_spectral_init;
  3665. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  3666. target_if_pdev_spectral_deinit;
  3667. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  3668. target_if_set_spectral_config;
  3669. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  3670. target_if_get_spectral_config;
  3671. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  3672. target_if_start_spectral_scan;
  3673. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  3674. target_if_stop_spectral_scan;
  3675. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  3676. target_if_is_spectral_active;
  3677. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  3678. target_if_is_spectral_enabled;
  3679. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  3680. target_if_set_debug_level;
  3681. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  3682. target_if_get_debug_level;
  3683. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  3684. target_if_get_spectral_capinfo;
  3685. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  3686. target_if_get_spectral_diagstats;
  3687. tx_ops->sptrl_tx_ops.sptrlto_register_wmi_spectral_cmd_ops =
  3688. target_if_register_wmi_spectral_cmd_ops;
  3689. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  3690. target_if_register_netlink_cb;
  3691. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  3692. target_if_use_nl_bcast;
  3693. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  3694. target_if_deregister_netlink_cb;
  3695. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  3696. target_if_process_spectral_report;
  3697. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  3698. target_if_spectral_direct_dma_support;
  3699. target_if_sptrl_debug_register_tx_ops(tx_ops);
  3700. }
  3701. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  3702. void
  3703. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  3704. uint16_t cw_int, uint32_t dcs_enabled)
  3705. {
  3706. struct spectral_samp_msg *msg = NULL;
  3707. struct target_if_spectral_ops *p_sops = NULL;
  3708. struct target_if_spectral *spectral = NULL;
  3709. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3710. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  3711. spectral->pdev_obj,
  3712. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  3713. SPECTRAL_MSG_BUF_NEW);
  3714. if (msg) {
  3715. msg->int_type = cw_int ?
  3716. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  3717. msg->dcs_enabled = dcs_enabled;
  3718. msg->signature = SPECTRAL_SIGNATURE;
  3719. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3720. p_sops->get_mac_address(spectral, msg->macaddr);
  3721. if (spectral->send_phy_data
  3722. (pdev,
  3723. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  3724. spectral->spectral_sent_msg++;
  3725. }
  3726. }
  3727. qdf_export_symbol(target_if_spectral_send_intf_found_msg);