target_if_spectral.c 123 KB

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