target_if_spectral.c 149 KB

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