target_if_spectral.c 169 KB

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