target_if_spectral.c 132 KB

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