target_if_spectral.c 159 KB

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