target_if_spectral.c 167 KB

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