target_if_spectral.c 109 KB

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