target_if_spectral.c 166 KB

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