target_if_spectral.c 223 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191
  1. /*
  2. * Copyright (c) 2011,2017-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  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. agile_cap->agile_spectral_cap_320 = false;
  206. return QDF_STATUS_SUCCESS;
  207. }
  208. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  209. if (!tgt_psoc_info) {
  210. spectral_err("target_psoc_info is null");
  211. return QDF_STATUS_E_FAILURE;
  212. }
  213. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  214. if (!mac_phy_cap_arr) {
  215. spectral_err("mac phy cap array is null");
  216. return QDF_STATUS_E_FAILURE;
  217. }
  218. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  219. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  220. table_id = mac_phy_cap->chainmask_table_id;
  221. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  222. if (!ext_svc_param) {
  223. spectral_err("Extended service ready params null");
  224. return QDF_STATUS_E_FAILURE;
  225. }
  226. table = &ext_svc_param->chainmask_table[table_id];
  227. for (i = 0; i < table->num_valid_chainmasks; i++) {
  228. agile_cap->agile_spectral_cap |=
  229. table->cap_list[i].supports_aSpectral;
  230. agile_cap->agile_spectral_cap_160 |=
  231. table->cap_list[i].supports_aSpectral_160;
  232. agile_cap->agile_spectral_cap_320 |= 0;
  233. }
  234. agile_cap->agile_spectral_cap_80p80 = agile_cap->agile_spectral_cap_160;
  235. return QDF_STATUS_SUCCESS;
  236. }
  237. /**
  238. * target_if_spectral_init_pdev_feature_cap_per_mode() - API to initialize
  239. * Spectral scan pdev feature caps for a given Spectral mode
  240. * @pdev: pdev handle
  241. * @smode: Spectral scan mode
  242. *
  243. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE/
  244. * QDF_STATUS_E_INVAL on failure
  245. */
  246. static QDF_STATUS
  247. target_if_spectral_init_pdev_feature_cap_per_mode(struct wlan_objmgr_pdev *pdev,
  248. enum spectral_scan_mode smode)
  249. {
  250. struct wlan_objmgr_psoc *psoc;
  251. bool normal_mode_disable;
  252. struct target_if_spectral_agile_mode_cap agile_cap = { 0 };
  253. QDF_STATUS status;
  254. if (!pdev) {
  255. spectral_err("pdev is null");
  256. return QDF_STATUS_E_INVAL;
  257. }
  258. psoc = wlan_pdev_get_psoc(pdev);
  259. if (!psoc) {
  260. spectral_err("psoc is null");
  261. return QDF_STATUS_E_INVAL;
  262. }
  263. switch (smode) {
  264. case SPECTRAL_SCAN_MODE_NORMAL:
  265. if (target_if_spectral_is_feature_disabled_psoc(psoc)) {
  266. wlan_pdev_nif_feat_ext_cap_set(
  267. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  268. return QDF_STATUS_SUCCESS;
  269. }
  270. status = target_if_spectral_get_normal_mode_cap(
  271. pdev, &normal_mode_disable);
  272. if (QDF_IS_STATUS_ERROR(status)) {
  273. spectral_err("Failed to get normal spectral scan caps");
  274. return QDF_STATUS_E_FAILURE;
  275. }
  276. if (normal_mode_disable)
  277. wlan_pdev_nif_feat_ext_cap_set(
  278. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  279. else
  280. wlan_pdev_nif_feat_ext_cap_clear(
  281. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  282. break;
  283. case SPECTRAL_SCAN_MODE_AGILE:
  284. if (target_if_spectral_is_feature_disabled_psoc(psoc)) {
  285. wlan_pdev_nif_feat_ext_cap_set(
  286. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  287. wlan_pdev_nif_feat_ext_cap_set(
  288. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  289. wlan_pdev_nif_feat_ext_cap_set(
  290. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  291. wlan_pdev_nif_feat_ext_cap_set(
  292. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  293. return QDF_STATUS_SUCCESS;
  294. }
  295. status = target_if_spectral_get_agile_mode_cap(
  296. pdev, &agile_cap);
  297. if (QDF_IS_STATUS_ERROR(status)) {
  298. spectral_err("Failed to get agile Spectral capability");
  299. return QDF_STATUS_E_FAILURE;
  300. }
  301. if (!agile_cap.agile_spectral_cap)
  302. wlan_pdev_nif_feat_ext_cap_set(
  303. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  304. else
  305. wlan_pdev_nif_feat_ext_cap_clear(
  306. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  307. if (!agile_cap.agile_spectral_cap_160)
  308. wlan_pdev_nif_feat_ext_cap_set(
  309. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  310. else
  311. wlan_pdev_nif_feat_ext_cap_clear(
  312. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  313. if (!agile_cap.agile_spectral_cap_80p80)
  314. wlan_pdev_nif_feat_ext_cap_set(
  315. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  316. else
  317. wlan_pdev_nif_feat_ext_cap_clear(
  318. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  319. if (!agile_cap.agile_spectral_cap_320)
  320. wlan_pdev_nif_feat_ext_cap_set(
  321. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  322. else
  323. wlan_pdev_nif_feat_ext_cap_clear(
  324. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  325. break;
  326. default:
  327. spectral_err("Invalid Spectral scan mode %d", smode);
  328. return QDF_STATUS_E_INVAL;
  329. }
  330. return QDF_STATUS_SUCCESS;
  331. }
  332. /**
  333. * target_if_spectral_init_pdev_feature_caps() - API to initialize
  334. * Spectral scan pdev feature caps for a given pdev
  335. * @pdev: pdev handle
  336. *
  337. * API initialize normal and agile Spectral scan pdev
  338. * feature caps for a given pdev.
  339. *
  340. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  341. */
  342. static QDF_STATUS
  343. target_if_spectral_init_pdev_feature_caps(struct wlan_objmgr_pdev *pdev)
  344. {
  345. enum spectral_scan_mode smode;
  346. if (!pdev) {
  347. spectral_err("pdev is NULL!");
  348. return QDF_STATUS_E_INVAL;
  349. }
  350. smode = SPECTRAL_SCAN_MODE_NORMAL;
  351. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  352. QDF_STATUS status;
  353. status = target_if_spectral_init_pdev_feature_cap_per_mode(
  354. pdev, smode);
  355. if (QDF_IS_STATUS_ERROR(status))
  356. return QDF_STATUS_E_INVAL;
  357. }
  358. return QDF_STATUS_SUCCESS;
  359. }
  360. static void target_if_spectral_get_firstvdev_pdev(struct wlan_objmgr_pdev *pdev,
  361. void *obj, void *arg)
  362. {
  363. struct wlan_objmgr_vdev *vdev = obj;
  364. struct wlan_objmgr_vdev **first_vdev = arg;
  365. if (!(*first_vdev))
  366. *first_vdev = vdev;
  367. }
  368. struct wlan_objmgr_vdev *
  369. target_if_spectral_get_vdev(struct target_if_spectral *spectral,
  370. enum spectral_scan_mode smode)
  371. {
  372. struct wlan_objmgr_pdev *pdev = NULL;
  373. struct wlan_objmgr_vdev *first_vdev = NULL;
  374. if (!spectral) {
  375. spectral_err("spectral variable in null.");
  376. return NULL;
  377. }
  378. pdev = spectral->pdev_obj;
  379. if (!pdev) {
  380. spectral_err("pdev variable in null.");
  381. return NULL;
  382. }
  383. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  384. spectral_err("Invalid Spectral mode %u", smode);
  385. return NULL;
  386. }
  387. if (spectral->vdev_id[smode] != WLAN_INVALID_VDEV_ID) {
  388. first_vdev = wlan_objmgr_get_vdev_by_id_from_pdev(
  389. pdev, spectral->vdev_id[smode],
  390. WLAN_SPECTRAL_ID);
  391. return first_vdev;
  392. }
  393. if (wlan_objmgr_pdev_try_get_ref(pdev, WLAN_SPECTRAL_ID) !=
  394. QDF_STATUS_SUCCESS) {
  395. spectral_err("Unable to get pdev reference.");
  396. return NULL;
  397. }
  398. wlan_objmgr_pdev_iterate_obj_list(pdev, WLAN_VDEV_OP,
  399. target_if_spectral_get_firstvdev_pdev,
  400. &first_vdev, 0, WLAN_SPECTRAL_ID);
  401. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  402. if (!first_vdev)
  403. return NULL;
  404. if (wlan_objmgr_vdev_try_get_ref(first_vdev, WLAN_SPECTRAL_ID) !=
  405. QDF_STATUS_SUCCESS)
  406. first_vdev = NULL;
  407. return first_vdev;
  408. }
  409. /**
  410. * target_if_send_vdev_spectral_configure_cmd() - Send WMI command to configure
  411. * spectral parameters
  412. * @spectral: Pointer to Spectral target_if internal private data
  413. * @smode: Spectral scan mode
  414. * @param: Pointer to spectral_config giving the Spectral configuration
  415. *
  416. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  417. */
  418. static int
  419. target_if_send_vdev_spectral_configure_cmd(struct target_if_spectral *spectral,
  420. enum spectral_scan_mode smode,
  421. struct spectral_config *param)
  422. {
  423. struct vdev_spectral_configure_params sparam;
  424. struct wlan_objmgr_psoc *psoc;
  425. struct wlan_objmgr_pdev *pdev = NULL;
  426. struct wlan_objmgr_vdev *vdev = NULL;
  427. struct target_if_psoc_spectral *psoc_spectral;
  428. if (!spectral || !param || !(spectral->pdev_obj)) {
  429. spectral_err("null params: spectral %pK, spectral_config %pK, pdev: %pK.",
  430. spectral, param, pdev);
  431. return qdf_status_to_os_return(QDF_STATUS_E_NULL_VALUE);
  432. }
  433. pdev = spectral->pdev_obj;
  434. psoc = wlan_pdev_get_psoc(pdev);
  435. if (!psoc) {
  436. spectral_err("psoc is null");
  437. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  438. }
  439. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  440. if (!psoc_spectral) {
  441. spectral_err("psoc spectral object is null");
  442. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  443. }
  444. vdev = target_if_spectral_get_vdev(spectral, smode);
  445. if (!vdev)
  446. return QDF_STATUS_E_NOENT;
  447. qdf_mem_zero(&sparam, sizeof(sparam));
  448. sparam.vdev_id = wlan_vdev_get_id(vdev);
  449. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  450. sparam.count = param->ss_count;
  451. sparam.period = param->ss_period;
  452. sparam.fft_recap = param->ss_recapture;
  453. sparam.spectral_pri = param->ss_spectral_pri;
  454. sparam.fft_size = param->ss_fft_size;
  455. sparam.gc_enable = param->ss_gc_ena;
  456. sparam.restart_enable = param->ss_restart_ena;
  457. sparam.noise_floor_ref = param->ss_noise_floor_ref;
  458. sparam.init_delay = param->ss_init_delay;
  459. sparam.nb_tone_thr = param->ss_nb_tone_thr;
  460. sparam.str_bin_thr = param->ss_str_bin_thr;
  461. sparam.wb_rpt_mode = param->ss_wb_rpt_mode;
  462. sparam.rssi_rpt_mode = param->ss_rssi_rpt_mode;
  463. sparam.rssi_thr = param->ss_rssi_thr;
  464. sparam.pwr_format = param->ss_pwr_format;
  465. sparam.rpt_mode = param->ss_rpt_mode;
  466. sparam.bin_scale = param->ss_bin_scale;
  467. sparam.dbm_adj = param->ss_dbm_adj;
  468. sparam.chn_mask = param->ss_chn_mask;
  469. sparam.mode = smode;
  470. sparam.center_freq1 = param->ss_frequency.cfreq1;
  471. sparam.center_freq2 = param->ss_frequency.cfreq2;
  472. sparam.chan_width = param->ss_bandwidth;
  473. return psoc_spectral->wmi_ops.wmi_spectral_configure_cmd_send(
  474. GET_WMI_HDL_FROM_PDEV(pdev), &sparam);
  475. }
  476. /**
  477. * target_if_send_vdev_spectral_enable_cmd() - Send WMI command to
  478. * enable/disable Spectral
  479. * @spectral: Pointer to Spectral target_if internal private data
  480. * @smode: Spectral scan mode
  481. * @is_spectral_active_valid: Flag to indicate if spectral activate (trigger) is
  482. * valid
  483. * @is_spectral_active: Value of spectral activate
  484. * @is_spectral_enabled_valid: Flag to indicate if spectral enable is valid
  485. * @is_spectral_enabled: Value of spectral enable
  486. *
  487. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  488. */
  489. static int
  490. target_if_send_vdev_spectral_enable_cmd(struct target_if_spectral *spectral,
  491. enum spectral_scan_mode smode,
  492. uint8_t is_spectral_active_valid,
  493. uint8_t is_spectral_active,
  494. uint8_t is_spectral_enabled_valid,
  495. uint8_t is_spectral_enabled)
  496. {
  497. struct vdev_spectral_enable_params param;
  498. struct wlan_objmgr_psoc *psoc;
  499. struct wlan_objmgr_pdev *pdev = NULL;
  500. struct wlan_objmgr_vdev *vdev = NULL;
  501. struct target_if_psoc_spectral *psoc_spectral;
  502. if (!spectral) {
  503. spectral_err("spectral is null");
  504. return qdf_status_to_os_return(QDF_STATUS_E_NULL_VALUE);
  505. }
  506. pdev = spectral->pdev_obj;
  507. if (!pdev) {
  508. spectral_err("pdev is null");
  509. return qdf_status_to_os_return(QDF_STATUS_E_NULL_VALUE);
  510. }
  511. psoc = wlan_pdev_get_psoc(pdev);
  512. if (!psoc) {
  513. spectral_err("psoc is null");
  514. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  515. }
  516. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  517. if (!psoc_spectral) {
  518. spectral_err("psoc spectral object is null");
  519. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  520. }
  521. vdev = target_if_spectral_get_vdev(spectral, smode);
  522. if (!vdev)
  523. return QDF_STATUS_E_NOENT;
  524. qdf_mem_zero(&param, sizeof(param));
  525. param.vdev_id = wlan_vdev_get_id(vdev);
  526. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  527. param.active_valid = is_spectral_active_valid;
  528. param.enabled_valid = is_spectral_enabled_valid;
  529. param.active = is_spectral_active;
  530. param.enabled = is_spectral_enabled;
  531. param.mode = smode;
  532. return psoc_spectral->wmi_ops.wmi_spectral_enable_cmd_send(
  533. GET_WMI_HDL_FROM_PDEV(pdev), &param);
  534. }
  535. /**
  536. * is_spectral_arch_beryllium() - Check whether the given target Spectral
  537. * architecture is Beryllium
  538. * @target_tpe: Target type
  539. *
  540. * Return: true if the spectral architecture is Beryllium, else false
  541. */
  542. static inline bool is_spectral_arch_beryllium(uint32_t target_tpe)
  543. {
  544. if ((target_tpe == TARGET_TYPE_QCN9224) ||
  545. (target_tpe == TARGET_TYPE_QCA5332) ||
  546. (target_tpe == TARGET_TYPE_QCN6432))
  547. return true;
  548. return false;
  549. }
  550. /*
  551. * List of supported sscan BWs. Make sure to maintain the array elements in the
  552. * same order of BWs as that of struct spectral_supported_bws bitmap.
  553. */
  554. static const enum phy_ch_width supported_sscan_bw_list[] = {
  555. CH_WIDTH_5MHZ,
  556. CH_WIDTH_10MHZ,
  557. CH_WIDTH_20MHZ,
  558. CH_WIDTH_40MHZ,
  559. CH_WIDTH_80MHZ,
  560. CH_WIDTH_160MHZ,
  561. CH_WIDTH_80P80MHZ,
  562. #ifdef WLAN_FEATURE_11BE
  563. CH_WIDTH_320MHZ,
  564. #endif
  565. };
  566. #define INVALID_SSCAN_BW_POS (-1)
  567. int get_supported_sscan_bw_pos(enum phy_ch_width sscan_bw)
  568. {
  569. int max_pos, pos;
  570. max_pos = QDF_ARRAY_SIZE(supported_sscan_bw_list);
  571. for (pos = 0; pos < max_pos; pos++) {
  572. if (supported_sscan_bw_list[pos] == sscan_bw)
  573. return pos;
  574. }
  575. return INVALID_SSCAN_BW_POS;
  576. }
  577. /**
  578. * target_if_is_sscan_bw_supported() - Check whether the given sscan_bw is
  579. * supported
  580. * @spectral: Spectral LMAC object
  581. * @smode: Spectral scan mode
  582. * @sscan_bw: Spectral scan bandwidth
  583. * @op_bw: operating bandwidth
  584. * @is_bw_supported: Pointer to the caller variable where this function
  585. * populates whether @sscan_bw is supported
  586. * @is_80_80_agile: Indicates an 80+80 agile Scan request
  587. *
  588. * Return: QDF_STATUS of operation
  589. */
  590. static QDF_STATUS
  591. target_if_is_sscan_bw_supported(struct target_if_spectral *spectral,
  592. enum spectral_scan_mode smode,
  593. enum phy_ch_width sscan_bw,
  594. enum phy_ch_width op_bw,
  595. bool *is_bw_supported,
  596. bool is_80_80_agile)
  597. {
  598. struct spectral_supported_bws *supported_bws;
  599. *is_bw_supported = false;
  600. if (op_bw >= CH_WIDTH_INVALID) {
  601. spectral_err("Invalid channel width %d", op_bw);
  602. return QDF_STATUS_E_INVAL;
  603. }
  604. if ((is_80_80_agile && sscan_bw != CH_WIDTH_80P80MHZ) ||
  605. (!is_80_80_agile && sscan_bw == CH_WIDTH_80P80MHZ)) {
  606. *is_bw_supported = false;
  607. return QDF_STATUS_SUCCESS;
  608. }
  609. /* Get the supported sscan bandwidths for this operating bandwidth */
  610. supported_bws = &spectral->supported_bws[smode][op_bw];
  611. *is_bw_supported = supported_bws->bandwidths &
  612. (1 << get_supported_sscan_bw_pos(sscan_bw));
  613. return QDF_STATUS_SUCCESS;
  614. }
  615. /**
  616. * get_max_sscan_bw() - Get the maximum sscan bandwidth for a given operating
  617. * bandwidth
  618. * @spectral: Spectral LMAC object
  619. * @smode: Spectral scan mode
  620. * @op_bw: operating bandwidth
  621. *
  622. * Return: Maximum sscan bandwidth for @op_bw on success, else CH_WIDTH_INVALID
  623. */
  624. static enum phy_ch_width
  625. get_max_sscan_bw(struct target_if_spectral *spectral,
  626. enum spectral_scan_mode smode,
  627. enum phy_ch_width op_bw)
  628. {
  629. int op_bw_pos, pos;
  630. struct spectral_supported_bws *supported_bws;
  631. supported_bws = &spectral->supported_bws[smode][op_bw];
  632. op_bw_pos = get_supported_sscan_bw_pos(op_bw);
  633. /**
  634. * Start with operating bandwidth, and keep reducing the bandwidth until
  635. * a supported sscan BW is found.
  636. */
  637. for (pos = op_bw_pos; pos >= 0; pos--) {
  638. if (supported_bws->bandwidths & (1 << pos))
  639. return supported_sscan_bw_list[pos];
  640. }
  641. return CH_WIDTH_INVALID;
  642. }
  643. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  644. * corresponding translation for Agile channel width.
  645. * @spectral: pointer to Spectral object
  646. * @op_width: operating channel width
  647. * @is_80_80_agile: Indicates an 80+80 agile Scan request
  648. *
  649. * Return: The translated channel width enum.
  650. */
  651. static enum phy_ch_width
  652. target_if_spectral_find_agile_width(struct target_if_spectral *spectral,
  653. enum phy_ch_width op_bw,
  654. bool is_80_80_agile)
  655. {
  656. enum phy_ch_width agile_width;
  657. struct wlan_objmgr_pdev *pdev;
  658. struct wlan_objmgr_psoc *psoc;
  659. if (!spectral) {
  660. spectral_err("Spectral object is null");
  661. return CH_WIDTH_INVALID;
  662. }
  663. pdev = spectral->pdev_obj;
  664. if (!pdev) {
  665. spectral_err("pdev is null");
  666. return CH_WIDTH_INVALID;
  667. }
  668. psoc = wlan_pdev_get_psoc(pdev);
  669. if (!psoc) {
  670. spectral_err("psoc is null");
  671. return CH_WIDTH_INVALID;
  672. }
  673. agile_width = get_max_sscan_bw(spectral, SPECTRAL_SCAN_MODE_AGILE,
  674. op_bw);
  675. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  676. WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  677. switch (op_bw) {
  678. case CH_WIDTH_80P80MHZ:
  679. if (!is_80_80_agile)
  680. agile_width = CH_WIDTH_160MHZ;
  681. else
  682. agile_width = CH_WIDTH_80P80MHZ;
  683. break;
  684. case CH_WIDTH_160MHZ:
  685. if (is_80_80_agile)
  686. agile_width = CH_WIDTH_80P80MHZ;
  687. else
  688. agile_width = CH_WIDTH_160MHZ;
  689. break;
  690. default:
  691. break;
  692. }
  693. }
  694. return agile_width;
  695. }
  696. /**
  697. * get_default_sscan_bw() - Get the default sscan bandwidth for a given
  698. * operating bandwidth
  699. * @spectral: Spectral LMAC object
  700. * @smode: Spectral scan mode
  701. * @is_80_80_agile: Indicates an 80+80 agile Scan request
  702. *
  703. * Return: Default sscan bandwidth for @op_bw on success, else CH_WIDTH_INVALID
  704. */
  705. static enum phy_ch_width
  706. get_default_sscan_bw(struct target_if_spectral *spectral,
  707. enum spectral_scan_mode smode,
  708. bool is_80_80_agile)
  709. {
  710. struct wlan_objmgr_vdev *vdev;
  711. enum phy_ch_width vdev_ch_width, sscan_width;
  712. vdev = target_if_spectral_get_vdev(spectral, smode);
  713. if (!vdev) {
  714. spectral_err("vdev is null");
  715. return CH_WIDTH_INVALID;
  716. }
  717. vdev_ch_width = target_if_vdev_get_ch_width(vdev);
  718. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  719. if (vdev_ch_width >= CH_WIDTH_INVALID) {
  720. spectral_err("Invalid vdev channel width %d", vdev_ch_width);
  721. return CH_WIDTH_INVALID;
  722. }
  723. switch (smode) {
  724. case SPECTRAL_SCAN_MODE_NORMAL:
  725. sscan_width = get_max_sscan_bw(spectral, smode, vdev_ch_width);
  726. break;
  727. case SPECTRAL_SCAN_MODE_AGILE:
  728. sscan_width = target_if_spectral_find_agile_width(
  729. spectral, vdev_ch_width, is_80_80_agile);
  730. break;
  731. default:
  732. sscan_width = CH_WIDTH_INVALID;
  733. break;
  734. }
  735. return sscan_width;
  736. }
  737. /**
  738. * target_if_spectral_info_init_defaults() - Helper function to load defaults
  739. * for Spectral information (parameters and state) into cache.
  740. * @spectral: Pointer to Spectral target_if internal private data
  741. * @smode: Spectral scan mode
  742. *
  743. * It is assumed that the caller has obtained the requisite lock if applicable.
  744. * Note that this is currently treated as a temporary function. Ideally, we
  745. * would like to get defaults from the firmware.
  746. *
  747. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  748. */
  749. static QDF_STATUS
  750. target_if_spectral_info_init_defaults(struct target_if_spectral *spectral,
  751. enum spectral_scan_mode smode)
  752. {
  753. struct target_if_spectral_param_state_info *info;
  754. struct wlan_objmgr_vdev *vdev = NULL;
  755. enum phy_ch_width sscan_bw;
  756. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  757. spectral_err("Invalid Spectral mode %u", smode);
  758. return QDF_STATUS_E_FAILURE;
  759. }
  760. info = &spectral->param_info[smode];
  761. /* State */
  762. info->osps_cache.osc_spectral_active = SPECTRAL_SCAN_ACTIVE_DEFAULT;
  763. info->osps_cache.osc_spectral_enabled = SPECTRAL_SCAN_ENABLE_DEFAULT;
  764. /* Parameters */
  765. info->osps_cache.osc_params.ss_count = SPECTRAL_SCAN_COUNT_DEFAULT;
  766. if (spectral->spectral_gen == SPECTRAL_GEN3)
  767. info->osps_cache.osc_params.ss_period =
  768. SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT;
  769. else
  770. info->osps_cache.osc_params.ss_period =
  771. SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT;
  772. info->osps_cache.osc_params.ss_recapture =
  773. SPECTRAL_FFT_RECAPTURE_DEFAULT;
  774. info->osps_cache.osc_params.ss_spectral_pri =
  775. SPECTRAL_SCAN_PRIORITY_DEFAULT;
  776. info->osps_cache.osc_params.ss_fft_size =
  777. SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  778. info->osps_cache.osc_params.ss_gc_ena = SPECTRAL_SCAN_GC_ENA_DEFAULT;
  779. info->osps_cache.osc_params.ss_restart_ena =
  780. SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  781. info->osps_cache.osc_params.ss_noise_floor_ref =
  782. SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  783. info->osps_cache.osc_params.ss_init_delay =
  784. SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  785. info->osps_cache.osc_params.ss_nb_tone_thr =
  786. SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  787. info->osps_cache.osc_params.ss_str_bin_thr =
  788. SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  789. info->osps_cache.osc_params.ss_wb_rpt_mode =
  790. SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  791. info->osps_cache.osc_params.ss_rssi_rpt_mode =
  792. SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  793. info->osps_cache.osc_params.ss_rssi_thr =
  794. SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  795. info->osps_cache.osc_params.ss_pwr_format =
  796. SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  797. info->osps_cache.osc_params.ss_rpt_mode =
  798. SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  799. info->osps_cache.osc_params.ss_bin_scale =
  800. SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  801. info->osps_cache.osc_params.ss_dbm_adj = SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  802. vdev = target_if_spectral_get_vdev(spectral, smode);
  803. if (!vdev)
  804. return QDF_STATUS_E_NOENT;
  805. info->osps_cache.osc_params.ss_chn_mask =
  806. wlan_vdev_mlme_get_rxchainmask(vdev);
  807. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  808. info->osps_cache.osc_params.ss_short_report =
  809. SPECTRAL_SCAN_SHORT_REPORT_DEFAULT;
  810. info->osps_cache.osc_params.ss_fft_period =
  811. SPECTRAL_SCAN_FFT_PERIOD_DEFAULT;
  812. info->osps_cache.osc_params.ss_frequency.cfreq1 =
  813. SPECTRAL_SCAN_FREQUENCY_DEFAULT;
  814. info->osps_cache.osc_params.ss_frequency.cfreq2 =
  815. SPECTRAL_SCAN_FREQUENCY_DEFAULT;
  816. sscan_bw = get_default_sscan_bw(spectral, smode, false);
  817. if (sscan_bw >= CH_WIDTH_INVALID) {
  818. spectral_err("Invalid sscan BW %u", sscan_bw);
  819. return QDF_STATUS_E_FAILURE;
  820. }
  821. info->osps_cache.osc_params.ss_bandwidth = sscan_bw;
  822. /* The cache is now valid */
  823. info->osps_cache.osc_is_valid = 1;
  824. return QDF_STATUS_SUCCESS;
  825. }
  826. /**
  827. * target_if_log_read_spectral_active() - Helper function to log whether
  828. * spectral is active after reading cache
  829. * @function_name: Function name
  830. * @output: whether spectral is active or not
  831. *
  832. * Helper function to log whether spectral is active after reading cache
  833. *
  834. * Return: none
  835. */
  836. static void
  837. target_if_log_read_spectral_active(
  838. const char *function_name,
  839. unsigned char output)
  840. {
  841. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE. Returning val=%u",
  842. function_name, output);
  843. }
  844. /**
  845. * target_if_log_read_spectral_enabled() - Helper function to log whether
  846. * spectral is enabled after reading cache
  847. * @function_name: Function name
  848. * @output: whether spectral is enabled or not
  849. *
  850. * Helper function to log whether spectral is enabled after reading cache
  851. *
  852. * Return: none
  853. */
  854. static void
  855. target_if_log_read_spectral_enabled(
  856. const char *function_name,
  857. unsigned char output)
  858. {
  859. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED. Returning val=%u",
  860. function_name, output);
  861. }
  862. /**
  863. * target_if_log_read_spectral_params() - log spectral parameters
  864. * @function_name: Function name
  865. * @pparam: Spectral parameters
  866. *
  867. * Helper function to log spectral parameters after reading cache
  868. *
  869. * Return: none
  870. */
  871. static void
  872. target_if_log_read_spectral_params(
  873. const char *function_name,
  874. struct spectral_config *pparam)
  875. {
  876. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_PARAMS. Returning following params:\nss_count = %u\nss_period = %u\nss_recapture = %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",
  877. function_name,
  878. pparam->ss_count,
  879. pparam->ss_period,
  880. pparam->ss_recapture,
  881. pparam->ss_spectral_pri,
  882. pparam->ss_fft_size,
  883. pparam->ss_gc_ena,
  884. pparam->ss_restart_ena,
  885. (int8_t)pparam->ss_noise_floor_ref,
  886. pparam->ss_init_delay,
  887. pparam->ss_nb_tone_thr,
  888. pparam->ss_str_bin_thr,
  889. pparam->ss_wb_rpt_mode,
  890. pparam->ss_rssi_rpt_mode,
  891. (int8_t)pparam->ss_rssi_thr,
  892. pparam->ss_pwr_format,
  893. pparam->ss_rpt_mode,
  894. pparam->ss_bin_scale,
  895. pparam->ss_dbm_adj,
  896. pparam->ss_chn_mask,
  897. pparam->ss_frequency.cfreq1,
  898. pparam->ss_frequency.cfreq2);
  899. }
  900. /**
  901. * target_if_log_read_spectral_active_catch_validate() - Helper function to
  902. * log whether spectral is active after initializing the cache
  903. * @function_name: Function name
  904. * @output: whether spectral is active or not
  905. *
  906. * Helper function to log whether spectral is active after initializing cache
  907. *
  908. * Return: none
  909. */
  910. static void
  911. target_if_log_read_spectral_active_catch_validate(
  912. const char *function_name,
  913. unsigned char output)
  914. {
  915. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE on initial cache validation\nReturning val=%u",
  916. function_name, output);
  917. }
  918. /**
  919. * target_if_log_read_spectral_enabled_catch_validate() - Helper function to
  920. * log whether spectral is enabled after initializing the cache
  921. * @function_name: Function name
  922. * @output: whether spectral is enabled or not
  923. *
  924. * Helper function to log whether spectral is enabled after initializing cache
  925. *
  926. * Return: none
  927. */
  928. static void
  929. target_if_log_read_spectral_enabled_catch_validate(
  930. const char *function_name,
  931. unsigned char output)
  932. {
  933. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED on initial cache validation\nReturning val=%u\n",
  934. function_name, output);
  935. }
  936. /**
  937. * target_if_log_read_spectral_params_catch_validate() - Helper function to
  938. * log spectral parameters after initializing the cache
  939. * @function_name: Function name
  940. * @pparam: Spectral parameters
  941. *
  942. * Helper function to log spectral parameters after initializing the cache
  943. *
  944. * Return: none
  945. */
  946. static void
  947. target_if_log_read_spectral_params_catch_validate(
  948. const char *function_name,
  949. struct spectral_config *pparam)
  950. {
  951. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_PARAMS on initial cache validation\nReturning following params:\nss_count = %u\nss_period = %u\nss_recapture = %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",
  952. function_name,
  953. pparam->ss_count,
  954. pparam->ss_period,
  955. pparam->ss_recapture,
  956. pparam->ss_spectral_pri,
  957. pparam->ss_fft_size,
  958. pparam->ss_gc_ena,
  959. pparam->ss_restart_ena,
  960. (int8_t)pparam->ss_noise_floor_ref,
  961. pparam->ss_init_delay,
  962. pparam->ss_nb_tone_thr,
  963. pparam->ss_str_bin_thr,
  964. pparam->ss_wb_rpt_mode,
  965. pparam->ss_rssi_rpt_mode,
  966. (int8_t)pparam->ss_rssi_thr,
  967. pparam->ss_pwr_format,
  968. pparam->ss_rpt_mode,
  969. pparam->ss_bin_scale,
  970. pparam->ss_dbm_adj, pparam->ss_chn_mask);
  971. }
  972. /**
  973. * target_if_spectral_info_read() - Read spectral information from the cache.
  974. * @spectral: Pointer to Spectral target_if internal private data
  975. * @smode: Spectral scan mode
  976. * @specifier: target_if_spectral_info enumeration specifying which
  977. * information is required
  978. * @output: Void output pointer into which the information will be read
  979. * @output_len: size of object pointed to by output pointer
  980. *
  981. * Read spectral parameters or the desired state information from the cache.
  982. *
  983. * Return: 0 on success, negative error code on failure
  984. */
  985. static int
  986. target_if_spectral_info_read(
  987. struct target_if_spectral *spectral,
  988. enum spectral_scan_mode smode,
  989. enum target_if_spectral_info specifier,
  990. void *output, int output_len)
  991. {
  992. /*
  993. * Note: This function is designed to be able to accommodate
  994. * WMI reads for defaults, non-cacheable information, etc
  995. * if required.
  996. */
  997. struct target_if_spectral_param_state_info *info;
  998. int is_cacheable = 0;
  999. int init_def_retval = 0;
  1000. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1001. spectral_err("Invalid Spectral mode %u", smode);
  1002. return -EINVAL;
  1003. }
  1004. info = &spectral->param_info[smode];
  1005. if (!output)
  1006. return -EINVAL;
  1007. switch (specifier) {
  1008. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  1009. if (output_len != sizeof(info->osps_cache.osc_spectral_active))
  1010. return -EINVAL;
  1011. is_cacheable = 1;
  1012. break;
  1013. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  1014. if (output_len != sizeof(info->osps_cache.osc_spectral_enabled))
  1015. return -EINVAL;
  1016. is_cacheable = 1;
  1017. break;
  1018. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  1019. if (output_len != sizeof(info->osps_cache.osc_params))
  1020. return -EINVAL;
  1021. is_cacheable = 1;
  1022. break;
  1023. default:
  1024. spectral_err("Unknown target_if_spectral_info specifier");
  1025. return -EINVAL;
  1026. }
  1027. qdf_spin_lock_bh(&info->osps_lock);
  1028. if (is_cacheable) {
  1029. if (info->osps_cache.osc_is_valid) {
  1030. switch (specifier) {
  1031. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  1032. qdf_mem_copy(
  1033. output,
  1034. &info->osps_cache.osc_spectral_active,
  1035. sizeof(info->osps_cache.osc_spectral_active));
  1036. target_if_log_read_spectral_active(
  1037. __func__,
  1038. *((unsigned char *)output));
  1039. break;
  1040. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  1041. qdf_mem_copy(
  1042. output,
  1043. &info->osps_cache.osc_spectral_enabled,
  1044. sizeof(
  1045. info->osps_cache.osc_spectral_enabled));
  1046. target_if_log_read_spectral_enabled(
  1047. __func__,
  1048. *((unsigned char *)output));
  1049. break;
  1050. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  1051. qdf_mem_copy(
  1052. output,
  1053. &info->osps_cache.osc_params,
  1054. sizeof(info->osps_cache.osc_params));
  1055. target_if_log_read_spectral_params(
  1056. __func__,
  1057. (struct spectral_config *)output);
  1058. break;
  1059. default:
  1060. /* We can't reach this point */
  1061. break;
  1062. }
  1063. qdf_spin_unlock_bh(&info->osps_lock);
  1064. return 0;
  1065. }
  1066. }
  1067. /* Cache is invalid */
  1068. /*
  1069. * If WMI Reads are implemented to fetch defaults/non-cacheable info,
  1070. * then the below implementation will change
  1071. */
  1072. init_def_retval =
  1073. target_if_spectral_info_init_defaults(spectral, smode);
  1074. if (init_def_retval != QDF_STATUS_SUCCESS) {
  1075. qdf_spin_unlock_bh(&info->osps_lock);
  1076. if (init_def_retval == QDF_STATUS_E_NOENT)
  1077. return -ENOENT;
  1078. else
  1079. return -EINVAL;
  1080. }
  1081. /* target_if_spectral_info_init_defaults() has set cache to valid */
  1082. switch (specifier) {
  1083. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  1084. qdf_mem_copy(output,
  1085. &info->osps_cache.osc_spectral_active,
  1086. sizeof(info->osps_cache.osc_spectral_active));
  1087. target_if_log_read_spectral_active_catch_validate(
  1088. __func__,
  1089. *((unsigned char *)output));
  1090. break;
  1091. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  1092. qdf_mem_copy(output,
  1093. &info->osps_cache.osc_spectral_enabled,
  1094. sizeof(info->osps_cache.osc_spectral_enabled));
  1095. target_if_log_read_spectral_enabled_catch_validate(
  1096. __func__,
  1097. *((unsigned char *)output));
  1098. break;
  1099. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  1100. qdf_mem_copy(output,
  1101. &info->osps_cache.osc_params,
  1102. sizeof(info->osps_cache.osc_params));
  1103. target_if_log_read_spectral_params_catch_validate(
  1104. __func__,
  1105. (struct spectral_config *)output);
  1106. break;
  1107. default:
  1108. /* We can't reach this point */
  1109. break;
  1110. }
  1111. qdf_spin_unlock_bh(&info->osps_lock);
  1112. return 0;
  1113. }
  1114. /**
  1115. * target_if_log_write_spectral_active() - Helper function to log inputs and
  1116. * return value of call to configure the Spectral 'active' configuration,
  1117. * TARGET_IF_SPECTRAL_INFO_ACTIVE into firmware
  1118. * @function_name: Function name in which this is called
  1119. * @pval: whether spectral is active or not
  1120. * @ret: return value of the firmware write function
  1121. *
  1122. * Return: none
  1123. */
  1124. static void
  1125. target_if_log_write_spectral_active(
  1126. const char *function_name,
  1127. uint8_t pval,
  1128. int ret)
  1129. {
  1130. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE with val=%u status=%d",
  1131. function_name, pval, ret);
  1132. }
  1133. /**
  1134. * target_if_log_write_spectral_enabled() - Helper function to log inputs and
  1135. * return value of call to configure the Spectral 'enabled' configuration,
  1136. * TARGET_IF_SPECTRAL_INFO_ENABLED into firmware
  1137. * @function_name: Function name in which this is called
  1138. * @pval: whether spectral is enabled or not
  1139. * @ret: return value of the firmware write function
  1140. *
  1141. * Return: none
  1142. */
  1143. static void
  1144. target_if_log_write_spectral_enabled(
  1145. const char *function_name,
  1146. uint8_t pval,
  1147. int ret)
  1148. {
  1149. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED with val=%u status=%d",
  1150. function_name, pval, ret);
  1151. }
  1152. /**
  1153. * target_if_log_write_spectral_params() - Helper function to log inputs and
  1154. * return value of call to configure Spectral parameters,
  1155. * TARGET_IF_SPECTRAL_INFO_PARAMS into firmware
  1156. * @param: Spectral parameters
  1157. * @function_name: Function name in which this is called
  1158. * @ret: return value of the firmware write function
  1159. *
  1160. * Return: none
  1161. */
  1162. static void
  1163. target_if_log_write_spectral_params(
  1164. struct spectral_config *param,
  1165. const char *function_name,
  1166. int ret)
  1167. {
  1168. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_PARAMS. Params:\nss_count = %u\nss_period = %u\nss_recapture = %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",
  1169. function_name,
  1170. param->ss_count,
  1171. param->ss_period,
  1172. param->ss_recapture,
  1173. param->ss_spectral_pri,
  1174. param->ss_fft_size,
  1175. param->ss_gc_ena,
  1176. param->ss_restart_ena,
  1177. (int8_t)param->ss_noise_floor_ref,
  1178. param->ss_init_delay,
  1179. param->ss_nb_tone_thr,
  1180. param->ss_str_bin_thr,
  1181. param->ss_wb_rpt_mode,
  1182. param->ss_rssi_rpt_mode,
  1183. (int8_t)param->ss_rssi_thr,
  1184. param->ss_pwr_format,
  1185. param->ss_rpt_mode,
  1186. param->ss_bin_scale,
  1187. param->ss_dbm_adj,
  1188. param->ss_chn_mask,
  1189. param->ss_frequency.cfreq1,
  1190. param->ss_frequency.cfreq2,
  1191. ret);
  1192. }
  1193. /**
  1194. * target_if_spectral_info_write() - Write Spectral information to the
  1195. * firmware, and update cache
  1196. * @spectral: Pointer to Spectral target_if internal private data
  1197. * @smode: Spectral scan mode
  1198. * @specifier: target_if_spectral_info enumeration specifying which
  1199. * information is involved
  1200. * @input: void input pointer containing the information to be written
  1201. * @input_len: size of object pointed to by input pointer
  1202. *
  1203. * Write Spectral parameters or the desired state information to
  1204. * the firmware, and update cache
  1205. *
  1206. * Return: 0 on success, negative error code on failure
  1207. */
  1208. static int
  1209. target_if_spectral_info_write(
  1210. struct target_if_spectral *spectral,
  1211. enum spectral_scan_mode smode,
  1212. enum target_if_spectral_info specifier,
  1213. void *input, int input_len)
  1214. {
  1215. struct target_if_spectral_param_state_info *info;
  1216. int ret;
  1217. uint8_t *pval = NULL;
  1218. struct spectral_config *param = NULL;
  1219. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1220. spectral_err("Invalid Spectral mode %u", smode);
  1221. return -EINVAL;
  1222. }
  1223. info = &spectral->param_info[smode];
  1224. if (!input)
  1225. return -EINVAL;
  1226. switch (specifier) {
  1227. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  1228. if (input_len != sizeof(info->osps_cache.osc_spectral_active))
  1229. return -EINVAL;
  1230. pval = (uint8_t *)input;
  1231. qdf_spin_lock_bh(&info->osps_lock);
  1232. ret = target_if_send_vdev_spectral_enable_cmd(spectral, smode,
  1233. 1, *pval, 0, 0);
  1234. target_if_log_write_spectral_active(
  1235. __func__,
  1236. *pval,
  1237. ret);
  1238. if (ret < 0) {
  1239. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  1240. ret);
  1241. qdf_spin_unlock_bh(&info->osps_lock);
  1242. return ret;
  1243. }
  1244. info->osps_cache.osc_spectral_active = *pval;
  1245. /* The cache is now valid */
  1246. info->osps_cache.osc_is_valid = 1;
  1247. qdf_spin_unlock_bh(&info->osps_lock);
  1248. break;
  1249. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  1250. if (input_len != sizeof(info->osps_cache.osc_spectral_enabled))
  1251. return -EINVAL;
  1252. pval = (uint8_t *)input;
  1253. qdf_spin_lock_bh(&info->osps_lock);
  1254. ret = target_if_send_vdev_spectral_enable_cmd(spectral, smode,
  1255. 0, 0, 1, *pval);
  1256. target_if_log_write_spectral_enabled(
  1257. __func__,
  1258. *pval,
  1259. ret);
  1260. if (ret < 0) {
  1261. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  1262. ret);
  1263. qdf_spin_unlock_bh(&info->osps_lock);
  1264. return ret;
  1265. }
  1266. info->osps_cache.osc_spectral_enabled = *pval;
  1267. /* The cache is now valid */
  1268. info->osps_cache.osc_is_valid = 1;
  1269. qdf_spin_unlock_bh(&info->osps_lock);
  1270. break;
  1271. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  1272. if (input_len != sizeof(info->osps_cache.osc_params))
  1273. return -EINVAL;
  1274. param = (struct spectral_config *)input;
  1275. qdf_spin_lock_bh(&info->osps_lock);
  1276. ret = target_if_send_vdev_spectral_configure_cmd(spectral,
  1277. smode, param);
  1278. target_if_log_write_spectral_params(
  1279. param,
  1280. __func__,
  1281. ret);
  1282. if (ret < 0) {
  1283. spectral_err("target_if_send_vdev_spectral_configure_cmd failed with error=%d",
  1284. ret);
  1285. qdf_spin_unlock_bh(&info->osps_lock);
  1286. return ret;
  1287. }
  1288. qdf_mem_copy(&info->osps_cache.osc_params,
  1289. param, sizeof(info->osps_cache.osc_params));
  1290. /* The cache is now valid */
  1291. info->osps_cache.osc_is_valid = 1;
  1292. qdf_spin_unlock_bh(&info->osps_lock);
  1293. break;
  1294. default:
  1295. spectral_err("Unknown target_if_spectral_info specifier");
  1296. return -EINVAL;
  1297. }
  1298. return 0;
  1299. }
  1300. /**
  1301. * target_if_spectral_get_tsf64() - Function to get the TSF value
  1302. * @arg: Pointer to handle for Spectral target_if internal private data
  1303. *
  1304. * Get the last TSF received in WMI buffer
  1305. *
  1306. * Return: TSF value
  1307. */
  1308. static uint64_t
  1309. target_if_spectral_get_tsf64(void *arg)
  1310. {
  1311. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1312. return spectral->tsf64;
  1313. }
  1314. /**
  1315. * target_if_spectral_get_capability() - Function to get whether a
  1316. * given Spectral hardware capability is available
  1317. * @arg: Pointer to handle for Spectral target_if internal private data
  1318. * @type: Spectral hardware capability type
  1319. *
  1320. * Get whether a given Spectral hardware capability is available
  1321. *
  1322. * Return: True if the capability is available, false if the capability is not
  1323. * available
  1324. */
  1325. uint32_t
  1326. target_if_spectral_get_capability(void *arg, enum spectral_capability_type type)
  1327. {
  1328. int status = STATUS_FAIL;
  1329. switch (type) {
  1330. case SPECTRAL_CAP_PHYDIAG:
  1331. case SPECTRAL_CAP_RADAR:
  1332. case SPECTRAL_CAP_SPECTRAL_SCAN:
  1333. case SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN:
  1334. status = STATUS_PASS;
  1335. break;
  1336. default:
  1337. status = STATUS_FAIL;
  1338. }
  1339. return status;
  1340. }
  1341. /**
  1342. * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
  1343. * @arg: Pointer to handle for Spectral target_if internal private data
  1344. * @rxfilter: Rx filter to be used
  1345. *
  1346. * Note: This is only a placeholder function. It is not currently required since
  1347. * FW should be taking care of setting the required filters.
  1348. *
  1349. * Return: 0
  1350. */
  1351. uint32_t
  1352. target_if_spectral_set_rxfilter(void *arg, int rxfilter)
  1353. {
  1354. /*
  1355. * Will not be required since enabling of spectral in firmware
  1356. * will take care of this
  1357. */
  1358. return 0;
  1359. }
  1360. /**
  1361. * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
  1362. * @arg: Pointer to handle for Spectral target_if internal private data
  1363. *
  1364. * Note: This is only a placeholder function. It is not currently required since
  1365. * FW should be taking care of setting the required filters.
  1366. *
  1367. * Return: 0
  1368. */
  1369. uint32_t
  1370. target_if_spectral_get_rxfilter(void *arg)
  1371. {
  1372. /*
  1373. * Will not be required since enabling of spectral in firmware
  1374. * will take care of this
  1375. */
  1376. return 0;
  1377. }
  1378. /**
  1379. * target_if_sops_is_spectral_active() - Get whether Spectral is active
  1380. * @arg: Pointer to handle for Spectral target_if internal private data
  1381. * @smode: Spectral scan mode
  1382. *
  1383. * Function to check whether Spectral is active
  1384. *
  1385. * Return: True if Spectral is active, false if Spectral is not active
  1386. */
  1387. uint32_t
  1388. target_if_sops_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  1389. {
  1390. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1391. uint8_t val = 0;
  1392. int ret;
  1393. ret = target_if_spectral_info_read(
  1394. spectral,
  1395. smode,
  1396. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  1397. &val, sizeof(val));
  1398. if (ret != 0) {
  1399. /*
  1400. * Could not determine if Spectral is active.
  1401. * Return false as a safe value.
  1402. * XXX: Consider changing the function prototype
  1403. * to be able to indicate failure to fetch value.
  1404. */
  1405. return 0;
  1406. }
  1407. return val;
  1408. }
  1409. /**
  1410. * target_if_sops_is_spectral_enabled() - Get whether Spectral is enabled
  1411. * @arg: Pointer to handle for Spectral target_if internal private data
  1412. * @smode: Spectral scan mode
  1413. *
  1414. * Function to check whether Spectral is enabled
  1415. *
  1416. * Return: True if Spectral is enabled, false if Spectral is not enabled
  1417. */
  1418. uint32_t
  1419. target_if_sops_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  1420. {
  1421. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1422. uint8_t val = 0;
  1423. int ret;
  1424. ret = target_if_spectral_info_read(
  1425. spectral,
  1426. smode,
  1427. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1428. &val, sizeof(val));
  1429. if (ret != 0) {
  1430. /*
  1431. * Could not determine if Spectral is enabled.
  1432. * Return false as a safe value.
  1433. * XXX: Consider changing the function prototype
  1434. * to be able to indicate failure to fetch value.
  1435. */
  1436. return 0;
  1437. }
  1438. return val;
  1439. }
  1440. /**
  1441. * target_if_sops_start_spectral_scan() - Start Spectral scan
  1442. * @arg: Pointer to handle for Spectral target_if internal private data
  1443. * @smode: Spectral scan mode
  1444. * @err: Spectral error code
  1445. *
  1446. * Function to start spectral scan
  1447. *
  1448. * Return: 0 on success else failure
  1449. */
  1450. uint32_t
  1451. target_if_sops_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  1452. enum spectral_cp_error_code *err)
  1453. {
  1454. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1455. uint8_t val = 1;
  1456. uint8_t enabled = 0;
  1457. int ret;
  1458. ret = target_if_spectral_info_read(
  1459. spectral,
  1460. smode,
  1461. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1462. &enabled, sizeof(enabled));
  1463. if (ret != 0) {
  1464. /*
  1465. * Could not determine if Spectral is enabled. Assume we need
  1466. * to enable it
  1467. */
  1468. enabled = 0;
  1469. }
  1470. if (!enabled) {
  1471. ret = target_if_spectral_info_write(
  1472. spectral,
  1473. smode,
  1474. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1475. &val, sizeof(val));
  1476. if (ret != 0)
  1477. return ret;
  1478. }
  1479. ret = target_if_spectral_info_write(
  1480. spectral,
  1481. smode,
  1482. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  1483. &val, sizeof(val));
  1484. if (ret != 0)
  1485. return ret;
  1486. return 0;
  1487. }
  1488. /**
  1489. * target_if_sops_stop_spectral_scan() - Stop Spectral scan
  1490. * @arg: Pointer to handle for Spectral target_if internal private data
  1491. * @smode: Spectral scan mode
  1492. *
  1493. * Function to stop spectral scan
  1494. *
  1495. * Return: 0 on success else failure
  1496. */
  1497. uint32_t
  1498. target_if_sops_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  1499. {
  1500. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1501. uint8_t val = 0;
  1502. int tempret, ret = 0;
  1503. uint8_t enabled = 0;
  1504. tempret = target_if_spectral_info_read(
  1505. spectral,
  1506. smode,
  1507. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1508. &enabled, sizeof(enabled));
  1509. if (tempret)
  1510. /*
  1511. * Could not determine if Spectral is enabled. Assume scan is
  1512. * not in progress
  1513. */
  1514. enabled = 0;
  1515. /* if scan is not enabled, no need to send stop to FW */
  1516. if (!enabled)
  1517. return -EPERM;
  1518. tempret = target_if_spectral_info_write(
  1519. spectral,
  1520. smode,
  1521. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  1522. &val, sizeof(val));
  1523. if (tempret != 0)
  1524. ret = tempret;
  1525. tempret = target_if_spectral_info_write(
  1526. spectral,
  1527. smode,
  1528. TARGET_IF_SPECTRAL_INFO_ENABLED,
  1529. &val, sizeof(val));
  1530. if (tempret != 0)
  1531. ret = tempret;
  1532. if (ret == 0 && smode == SPECTRAL_SCAN_MODE_AGILE) {
  1533. struct target_if_spectral_ops *p_sops;
  1534. struct spectral_config *sparams;
  1535. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1536. sparams = &spectral->params[smode];
  1537. sparams->ss_frequency.cfreq1 = 0;
  1538. sparams->ss_frequency.cfreq2 = 0;
  1539. p_sops->configure_spectral(spectral, sparams, smode);
  1540. }
  1541. return ret;
  1542. }
  1543. /**
  1544. * target_if_spectral_get_extension_channel() - Get the Extension channel
  1545. * @arg: Pointer to handle for Spectral target_if internal private data
  1546. * @smode: Spectral scan mode
  1547. *
  1548. * Function to get the current Extension channel (in MHz)
  1549. *
  1550. * Return: Current Extension channel (in MHz) on success, 0 on failure or if
  1551. * extension channel is not present.
  1552. */
  1553. uint32_t
  1554. target_if_spectral_get_extension_channel(void *arg,
  1555. enum spectral_scan_mode smode)
  1556. {
  1557. /*
  1558. * XXX: Once we expand to use cases where Spectral could be activated
  1559. * without a channel being set to VDEV, we need to consider returning a
  1560. * negative value in case of failure and having all callers handle this.
  1561. */
  1562. struct target_if_spectral *spectral = NULL;
  1563. struct wlan_objmgr_vdev *vdev = NULL;
  1564. uint16_t sec20chan_freq = 0;
  1565. if (!arg) {
  1566. spectral_err("Null argument.");
  1567. return 0;
  1568. }
  1569. spectral = (struct target_if_spectral *)arg;
  1570. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1571. spectral_err("Invalid Spectral mode %u", smode);
  1572. return 0;
  1573. }
  1574. vdev = target_if_spectral_get_vdev(spectral, smode);
  1575. if (!vdev)
  1576. return 0;
  1577. if (target_if_vdev_get_sec20chan_freq_mhz(vdev, &sec20chan_freq) < 0) {
  1578. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1579. return 0;
  1580. }
  1581. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1582. return sec20chan_freq;
  1583. }
  1584. /**
  1585. * target_if_spectral_get_current_channel() - Get the current channel
  1586. * @arg: Pointer to handle for Spectral target_if internal private data
  1587. * @smode: Spectral scan mode
  1588. *
  1589. * Function to get the current channel (in MHz)
  1590. *
  1591. * Return: Current channel (in MHz) on success, 0 on failure
  1592. */
  1593. uint32_t
  1594. target_if_spectral_get_current_channel(void *arg, enum spectral_scan_mode smode)
  1595. {
  1596. /*
  1597. * XXX: Once we expand to use cases where Spectral could be activated
  1598. * without a channel being set to VDEV, we need to consider returning a
  1599. * negative value in case of failure and having all callers handle this.
  1600. */
  1601. struct target_if_spectral *spectral = NULL;
  1602. int16_t chan_freq = 0;
  1603. struct wlan_objmgr_vdev *vdev = NULL;
  1604. if (!arg) {
  1605. spectral_err("Null argument.");
  1606. return 0;
  1607. }
  1608. spectral = (struct target_if_spectral *)arg;
  1609. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1610. spectral_err("Invalid Spectral mode %u", smode);
  1611. return 0;
  1612. }
  1613. vdev = target_if_spectral_get_vdev(spectral, smode);
  1614. if (!vdev)
  1615. return 0;
  1616. chan_freq = target_if_vdev_get_chan_freq(vdev);
  1617. if (chan_freq < 0) {
  1618. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1619. return 0;
  1620. }
  1621. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1622. return chan_freq;
  1623. }
  1624. /**
  1625. * target_if_spectral_reset_hw() - Reset the hardware
  1626. * @arg: Pointer to handle for Spectral target_if internal private data
  1627. *
  1628. * This is only a placeholder since it is not currently required in the offload
  1629. * case.
  1630. *
  1631. * Return: 0
  1632. */
  1633. uint32_t
  1634. target_if_spectral_reset_hw(void *arg)
  1635. {
  1636. not_yet_implemented();
  1637. return 0;
  1638. }
  1639. /**
  1640. * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
  1641. * Noisefloor history buffer
  1642. * @arg: Pointer to handle for Spectral target_if internal private data
  1643. * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
  1644. *
  1645. * This is only a placeholder since it is not currently required in the offload
  1646. * case.
  1647. *
  1648. * Return: 0
  1649. */
  1650. uint32_t
  1651. target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1652. {
  1653. not_yet_implemented();
  1654. return 0;
  1655. }
  1656. /**
  1657. * target_if_spectral_get_ext_noisefloor() - Get the extension channel
  1658. * noisefloor
  1659. * @arg: Pointer to handle for Spectral target_if internal private data
  1660. *
  1661. * This is only a placeholder since it is not currently required in the offload
  1662. * case.
  1663. *
  1664. * Return: 0
  1665. */
  1666. int8_t
  1667. target_if_spectral_get_ext_noisefloor(void *arg)
  1668. {
  1669. not_yet_implemented();
  1670. return 0;
  1671. }
  1672. /**
  1673. * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
  1674. * @arg: Pointer to handle for Spectral target_if internal private data
  1675. *
  1676. * This is only a placeholder since it is not currently required in the offload
  1677. * case.
  1678. *
  1679. * Return: 0
  1680. */
  1681. int8_t
  1682. target_if_spectral_get_ctl_noisefloor(void *arg)
  1683. {
  1684. not_yet_implemented();
  1685. return 0;
  1686. }
  1687. /**
  1688. * target_if_spectral_sops_configure_params() - Configure user supplied Spectral
  1689. * parameters
  1690. * @arg: Pointer to handle for Spectral target_if internal private data
  1691. * @params: Spectral parameters
  1692. * @smode: Spectral scan mode
  1693. *
  1694. * Function to configure spectral parameters
  1695. *
  1696. * Return: 0 on success else failure
  1697. */
  1698. uint32_t
  1699. target_if_spectral_sops_configure_params(
  1700. void *arg, struct spectral_config *params,
  1701. enum spectral_scan_mode smode)
  1702. {
  1703. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1704. return target_if_spectral_info_write(
  1705. spectral,
  1706. smode,
  1707. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1708. params, sizeof(*params));
  1709. }
  1710. /**
  1711. * target_if_spectral_sops_get_params() - Get user configured Spectral
  1712. * parameters
  1713. * @arg: Pointer to handle for Spectral target_if internal private data
  1714. * @params: Pointer to buffer into which Spectral parameters should be copied
  1715. * @smode: Spectral scan mode
  1716. *
  1717. * Function to get the configured spectral parameters
  1718. *
  1719. * Return: 0 on success else failure
  1720. */
  1721. uint32_t
  1722. target_if_spectral_sops_get_params(void *arg, struct spectral_config *params,
  1723. enum spectral_scan_mode smode)
  1724. {
  1725. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1726. return target_if_spectral_info_read(
  1727. spectral,
  1728. smode,
  1729. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1730. params, sizeof(*params));
  1731. }
  1732. /**
  1733. * target_if_spectral_get_ent_mask() - Get enterprise mask
  1734. * @arg: Pointer to handle for Spectral target_if internal private data
  1735. *
  1736. * This is only a placeholder since it is not currently required in the offload
  1737. * case.
  1738. *
  1739. * Return: 0
  1740. */
  1741. static uint32_t
  1742. target_if_spectral_get_ent_mask(void *arg)
  1743. {
  1744. not_yet_implemented();
  1745. return 0;
  1746. }
  1747. /**
  1748. * target_if_spectral_get_macaddr() - Get radio MAC address
  1749. * @arg: Pointer to handle for Spectral target_if internal private data
  1750. * @addr: Pointer to buffer into which MAC address should be copied
  1751. *
  1752. * Function to get the MAC address of the pdev
  1753. *
  1754. * Return: 0 on success, -1 on failure
  1755. */
  1756. static uint32_t
  1757. target_if_spectral_get_macaddr(void *arg, char *addr)
  1758. {
  1759. uint8_t *myaddr = NULL;
  1760. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1761. struct wlan_objmgr_pdev *pdev = NULL;
  1762. pdev = spectral->pdev_obj;
  1763. wlan_pdev_obj_lock(pdev);
  1764. myaddr = wlan_pdev_get_hw_macaddr(pdev);
  1765. wlan_pdev_obj_unlock(pdev);
  1766. qdf_mem_copy(addr, myaddr, QDF_MAC_ADDR_SIZE);
  1767. return 0;
  1768. }
  1769. /**
  1770. * target_if_init_spectral_param_min_max_be() - Initialize Spectral parameter
  1771. * min and max values for beryllium chipsets
  1772. *
  1773. * @spectral: Spectral LMAC object
  1774. *
  1775. * Return: QDF_STATUS of operation
  1776. */
  1777. static QDF_STATUS
  1778. target_if_init_spectral_param_min_max_be(struct target_if_spectral *spectral)
  1779. {
  1780. struct spectral_param_min_max *param_min_max;
  1781. enum phy_ch_width op_bw;
  1782. QDF_STATUS status;
  1783. param_min_max = &spectral->param_min_max;
  1784. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3_BE;
  1785. param_min_max->scan_count_max = SPECTRAL_PARAM_SCAN_COUNT_MAX_GEN3_BE;
  1786. for (op_bw = CH_WIDTH_20MHZ; op_bw < CH_WIDTH_MAX; op_bw++) {
  1787. bool is_supported;
  1788. status = wlan_reg_is_chwidth_supported(spectral->pdev_obj,
  1789. op_bw, &is_supported);
  1790. if (QDF_IS_STATUS_ERROR(status)) {
  1791. spectral_err("Unable to check if ch_width(%d) is supported",
  1792. op_bw);
  1793. return QDF_STATUS_E_FAILURE;
  1794. }
  1795. if (!is_supported) {
  1796. param_min_max->fft_size_max[op_bw] = INVALID_FFT_SIZE;
  1797. continue;
  1798. }
  1799. switch (op_bw) {
  1800. case CH_WIDTH_20MHZ:
  1801. param_min_max->fft_size_max[op_bw] =
  1802. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_BE_20MHZ;
  1803. break;
  1804. case CH_WIDTH_40MHZ:
  1805. param_min_max->fft_size_max[op_bw] =
  1806. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_BE_40MHZ;
  1807. break;
  1808. default:
  1809. param_min_max->fft_size_max[op_bw] =
  1810. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_BE;
  1811. }
  1812. }
  1813. return QDF_STATUS_SUCCESS;
  1814. }
  1815. /**
  1816. * target_if_init_spectral_param_min_max() - Initialize Spectral parameter
  1817. * min and max values
  1818. *
  1819. * @spectral: Spectral LMAC object
  1820. * @gen: Spectral HW generation
  1821. * @target_type: Target type
  1822. *
  1823. * Initialize Spectral parameter min and max values
  1824. *
  1825. * Return: QDF_STATUS
  1826. */
  1827. static QDF_STATUS
  1828. target_if_init_spectral_param_min_max(
  1829. struct target_if_spectral *spectral,
  1830. enum spectral_gen gen, uint32_t target_type)
  1831. {
  1832. struct spectral_param_min_max *param_min_max;
  1833. if (!spectral) {
  1834. spectral_err("Spectral LMAC object is null");
  1835. return QDF_STATUS_E_NULL_VALUE;
  1836. }
  1837. if (is_spectral_arch_beryllium(target_type))
  1838. return target_if_init_spectral_param_min_max_be(spectral);
  1839. param_min_max = &spectral->param_min_max;
  1840. switch (gen) {
  1841. case SPECTRAL_GEN3:
  1842. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3;
  1843. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1844. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1845. param_min_max->scan_count_max =
  1846. SPECTRAL_PARAM_SCAN_COUNT_MAX_GEN3;
  1847. if (target_type == TARGET_TYPE_QCN9000 ||
  1848. target_type == TARGET_TYPE_QCN6122 ||
  1849. target_type == TARGET_TYPE_QCN9160 ||
  1850. target_type == TARGET_TYPE_QCA5018 ||
  1851. target_type == TARGET_TYPE_QCA6490 ||
  1852. target_type == TARGET_TYPE_KIWI ||
  1853. target_type == TARGET_TYPE_MANGO ||
  1854. target_type == TARGET_TYPE_PEACH) {
  1855. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1856. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1857. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1858. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1859. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1860. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1861. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1862. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1863. } else {
  1864. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1865. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1866. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1867. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1868. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1869. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1870. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1871. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1872. }
  1873. break;
  1874. case SPECTRAL_GEN2:
  1875. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1876. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1877. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1878. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1879. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1880. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1881. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1882. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1883. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1884. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1885. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1886. break;
  1887. default:
  1888. spectral_err("Invalid spectral generation %d", gen);
  1889. return QDF_STATUS_E_INVAL;
  1890. }
  1891. return QDF_STATUS_SUCCESS;
  1892. }
  1893. /**
  1894. * target_if_init_spectral_param_properties() - Initialize Spectral parameter
  1895. * properties
  1896. * @spectral: Pointer to Spectral target_if internal private data
  1897. *
  1898. * Initialize Spectral parameter properties
  1899. *
  1900. * Return: QDF_STATUS
  1901. */
  1902. static QDF_STATUS
  1903. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1904. {
  1905. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1906. int param;
  1907. /* Initialize default values for properties.
  1908. * Default values are supported for all the parameters for all modes
  1909. * and allows different values for each mode for all the parameters .
  1910. */
  1911. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1912. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1913. spectral->properties[smode][param].supported = true;
  1914. spectral->properties[smode][param].common_all_modes =
  1915. false;
  1916. }
  1917. }
  1918. /* Once FW advertisement is in place remove this hard coding */
  1919. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1920. spectral->properties[SPECTRAL_SCAN_MODE_NORMAL]
  1921. [SPECTRAL_PARAM_FREQUENCY].supported = false;
  1922. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1923. spectral->properties[smode]
  1924. [SPECTRAL_PARAM_SPECT_PRI].common_all_modes = true;
  1925. spectral->properties[smode]
  1926. [SPECTRAL_PARAM_SCAN_PERIOD].common_all_modes = true;
  1927. spectral->properties[smode]
  1928. [SPECTRAL_PARAM_INIT_DELAY].common_all_modes = true;
  1929. }
  1930. return QDF_STATUS_SUCCESS;
  1931. }
  1932. /* Bandwidth to half bandwidth mapping */
  1933. static const enum phy_ch_width half_bw_map[] = {
  1934. #ifdef WLAN_FEATURE_11BE
  1935. [CH_WIDTH_320MHZ] = CH_WIDTH_160MHZ,
  1936. #endif
  1937. [CH_WIDTH_80P80MHZ] = CH_WIDTH_80MHZ,
  1938. [CH_WIDTH_160MHZ] = CH_WIDTH_80MHZ,
  1939. [CH_WIDTH_80MHZ] = CH_WIDTH_40MHZ,
  1940. [CH_WIDTH_40MHZ] = CH_WIDTH_20MHZ,
  1941. [CH_WIDTH_20MHZ] = CH_WIDTH_10MHZ,
  1942. [CH_WIDTH_10MHZ] = CH_WIDTH_5MHZ,
  1943. [CH_WIDTH_5MHZ] = CH_WIDTH_INVALID
  1944. };
  1945. /**
  1946. * target_if_get_half_bandwidth() - Get half bandwidth for a given bandwidth
  1947. * @bw: bandwidth
  1948. *
  1949. * Return: Half bandwidth of @bw
  1950. */
  1951. static enum phy_ch_width target_if_get_half_bandwidth(enum phy_ch_width bw)
  1952. {
  1953. if (bw >= CH_WIDTH_INVALID)
  1954. return CH_WIDTH_INVALID;
  1955. return half_bw_map[bw];
  1956. }
  1957. /**
  1958. * target_if_populate_supported_sscan_bws_be() - Populate supported spectral
  1959. * scan bandwidths for beryllium chipsets
  1960. * @spectral: Spectral LMAC object
  1961. *
  1962. * Return: QDF_STATUS of operation
  1963. */
  1964. static QDF_STATUS
  1965. target_if_populate_supported_sscan_bws_be(struct target_if_spectral *spectral)
  1966. {
  1967. enum phy_ch_width op_bw;
  1968. struct spectral_supported_bws *supported_bws;
  1969. QDF_STATUS status;
  1970. if (!spectral) {
  1971. spectral_err("spectral variable is null");
  1972. return QDF_STATUS_E_NULL_VALUE;
  1973. }
  1974. /* 20MHz */
  1975. op_bw = CH_WIDTH_20MHZ;
  1976. supported_bws = &spectral->supported_bws
  1977. [SPECTRAL_SCAN_MODE_NORMAL][op_bw];
  1978. supported_bws->bandwidths |= 1 << get_supported_sscan_bw_pos(op_bw);
  1979. spectral->supported_sscan_bw_list
  1980. [SPECTRAL_SCAN_MODE_NORMAL][op_bw] = true;
  1981. supported_bws = &spectral->supported_bws
  1982. [SPECTRAL_SCAN_MODE_AGILE][op_bw];
  1983. supported_bws->bandwidths |= 1 << get_supported_sscan_bw_pos(op_bw);
  1984. spectral->supported_sscan_bw_list
  1985. [SPECTRAL_SCAN_MODE_AGILE][op_bw] = true;
  1986. for (op_bw = CH_WIDTH_40MHZ; op_bw < CH_WIDTH_MAX; op_bw++) {
  1987. bool is_supported;
  1988. enum phy_ch_width half_op_bw;
  1989. status = wlan_reg_is_chwidth_supported(spectral->pdev_obj,
  1990. op_bw, &is_supported);
  1991. if (QDF_IS_STATUS_ERROR(status)) {
  1992. spectral_err("Unable to check if ch_width(%d) is supported",
  1993. op_bw);
  1994. return QDF_STATUS_E_FAILURE;
  1995. }
  1996. if (!is_supported)
  1997. continue;
  1998. spectral_debug("Updating supported bw for op_bw: %d", op_bw);
  1999. /* Normal mode */
  2000. supported_bws = &spectral->supported_bws
  2001. [SPECTRAL_SCAN_MODE_NORMAL][op_bw];
  2002. supported_bws->bandwidths |=
  2003. 1 << get_supported_sscan_bw_pos(op_bw);
  2004. spectral->supported_sscan_bw_list
  2005. [SPECTRAL_SCAN_MODE_NORMAL][op_bw] = true;
  2006. /* Agile mode */
  2007. supported_bws = &spectral->supported_bws
  2008. [SPECTRAL_SCAN_MODE_AGILE][op_bw];
  2009. supported_bws->bandwidths |=
  2010. 1 << get_supported_sscan_bw_pos(op_bw);
  2011. spectral->supported_sscan_bw_list
  2012. [SPECTRAL_SCAN_MODE_AGILE][op_bw] = true;
  2013. half_op_bw = target_if_get_half_bandwidth(op_bw);
  2014. if (half_op_bw != CH_WIDTH_INVALID) {
  2015. supported_bws->bandwidths |=
  2016. 1 << get_supported_sscan_bw_pos(half_op_bw);
  2017. spectral->supported_sscan_bw_list
  2018. [SPECTRAL_SCAN_MODE_AGILE][half_op_bw] = true;
  2019. }
  2020. }
  2021. return QDF_STATUS_SUCCESS;
  2022. }
  2023. /**
  2024. * target_if_populate_supported_sscan_bws() - Populate supported spectral
  2025. * scan bandwidths
  2026. * @spectral: Spectral LMAC object
  2027. * @target_type: Target type
  2028. *
  2029. * Return: QDF_STATUS of operation
  2030. */
  2031. static QDF_STATUS
  2032. target_if_populate_supported_sscan_bws(struct target_if_spectral *spectral,
  2033. uint32_t target_type)
  2034. {
  2035. enum spectral_scan_mode smode;
  2036. enum phy_ch_width op_bw;
  2037. struct spectral_supported_bws *supported_bws;
  2038. struct wlan_objmgr_psoc *psoc;
  2039. QDF_STATUS status;
  2040. if (!spectral) {
  2041. spectral_err("spectral is null");
  2042. return QDF_STATUS_E_NULL_VALUE;
  2043. }
  2044. if (is_spectral_arch_beryllium(target_type))
  2045. return target_if_populate_supported_sscan_bws_be(spectral);
  2046. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  2047. if (!psoc) {
  2048. spectral_err("psoc is null");
  2049. return QDF_STATUS_E_NULL_VALUE;
  2050. }
  2051. for (op_bw = CH_WIDTH_20MHZ; op_bw < CH_WIDTH_MAX; op_bw++) {
  2052. bool is_supported;
  2053. status = wlan_reg_is_chwidth_supported(spectral->pdev_obj,
  2054. op_bw, &is_supported);
  2055. if (QDF_IS_STATUS_ERROR(status)) {
  2056. spectral_err("Unable to check if ch_width(%d) is supported",
  2057. op_bw);
  2058. return QDF_STATUS_E_FAILURE;
  2059. }
  2060. if (!is_supported)
  2061. continue;
  2062. spectral_debug("Updating supported bw for op_bw: %d", op_bw);
  2063. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2064. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2065. supported_bws = &spectral->supported_bws[smode][op_bw];
  2066. if (is_ch_width_160_or_80p80(op_bw) &&
  2067. smode == SPECTRAL_SCAN_MODE_AGILE) {
  2068. /**
  2069. * If fragmentation is supported, then only 80Hz
  2070. * agile width is supported
  2071. */
  2072. if (spectral->rparams.
  2073. fragmentation_160[smode]) {
  2074. supported_bws->bandwidths |=
  2075. 1 << get_supported_sscan_bw_pos(
  2076. CH_WIDTH_80MHZ);
  2077. spectral->supported_sscan_bw_list
  2078. [smode][CH_WIDTH_80MHZ] = true;
  2079. }
  2080. /**
  2081. * If restricted 80p80 is supported, then both
  2082. * 160 and 80p80 agile widths are supported for
  2083. * 160MHz, and only 160MHz agile width is
  2084. * supported for 80p80
  2085. */
  2086. if (wlan_psoc_nif_fw_ext_cap_get(
  2087. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  2088. supported_bws->bandwidths |=
  2089. 1 << get_supported_sscan_bw_pos(
  2090. CH_WIDTH_160MHZ);
  2091. spectral->supported_sscan_bw_list
  2092. [smode][CH_WIDTH_160MHZ] = true;
  2093. if (op_bw == CH_WIDTH_160MHZ) {
  2094. supported_bws->bandwidths |=
  2095. 1 << get_supported_sscan_bw_pos(
  2096. CH_WIDTH_80P80MHZ);
  2097. spectral->supported_sscan_bw_list
  2098. [smode][CH_WIDTH_80P80MHZ] = true;
  2099. }
  2100. }
  2101. } else {
  2102. supported_bws->bandwidths |=
  2103. 1 << get_supported_sscan_bw_pos(
  2104. op_bw);
  2105. spectral->supported_sscan_bw_list
  2106. [smode][op_bw] = true;
  2107. }
  2108. }
  2109. }
  2110. return QDF_STATUS_SUCCESS;
  2111. }
  2112. QDF_STATUS
  2113. target_if_init_spectral_capability(struct target_if_spectral *spectral,
  2114. uint32_t target_type)
  2115. {
  2116. struct wlan_objmgr_psoc *psoc;
  2117. struct wlan_objmgr_pdev *pdev;
  2118. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  2119. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  2120. struct target_psoc_info *tgt_psoc_info;
  2121. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  2122. struct spectral_caps *pcap = &spectral->capability;
  2123. QDF_STATUS status;
  2124. pdev = spectral->pdev_obj;
  2125. psoc = wlan_pdev_get_psoc(pdev);
  2126. if (!psoc) {
  2127. spectral_err("psoc is null");
  2128. return QDF_STATUS_E_FAILURE;
  2129. }
  2130. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  2131. if (!tgt_psoc_info) {
  2132. spectral_err("target_psoc_info is null");
  2133. return QDF_STATUS_E_FAILURE;
  2134. }
  2135. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  2136. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  2137. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  2138. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  2139. /* XXX : Workaround: Set Spectral capability */
  2140. pcap = &spectral->capability;
  2141. pcap->phydiag_cap = 1;
  2142. pcap->radar_cap = 1;
  2143. pcap->spectral_cap = wlan_pdev_nif_feat_ext_cap_get(
  2144. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  2145. pcap->advncd_spectral_cap = pcap->spectral_cap;
  2146. pcap->hw_gen = spectral->spectral_gen;
  2147. pcap->agile_spectral_cap = !wlan_pdev_nif_feat_ext_cap_get(
  2148. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  2149. pcap->agile_spectral_cap_160 = !wlan_pdev_nif_feat_ext_cap_get(
  2150. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  2151. pcap->agile_spectral_cap_80p80 = !wlan_pdev_nif_feat_ext_cap_get(
  2152. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  2153. pcap->agile_spectral_cap_320 = !wlan_pdev_nif_feat_ext_cap_get(
  2154. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  2155. if (scaling_params) {
  2156. for (param_idx = 0; param_idx < num_bin_scaling_params;
  2157. param_idx++) {
  2158. if (scaling_params[param_idx].pdev_id == pdev_id) {
  2159. pcap->is_scaling_params_populated = true;
  2160. pcap->formula_id =
  2161. scaling_params[param_idx].formula_id;
  2162. pcap->low_level_offset =
  2163. scaling_params[param_idx].low_level_offset;
  2164. pcap->high_level_offset =
  2165. scaling_params[param_idx].high_level_offset;
  2166. pcap->rssi_thr =
  2167. scaling_params[param_idx].rssi_thr;
  2168. pcap->default_agc_max_gain =
  2169. scaling_params[param_idx].default_agc_max_gain;
  2170. break;
  2171. }
  2172. }
  2173. }
  2174. pcap->num_detectors_20mhz = 1;
  2175. pcap->num_detectors_40mhz = 1;
  2176. pcap->num_detectors_80mhz = 1;
  2177. if (target_type == TARGET_TYPE_QCN9000 ||
  2178. target_type == TARGET_TYPE_QCN6122 ||
  2179. target_type == TARGET_TYPE_QCN9160 ||
  2180. target_type == TARGET_TYPE_QCA6490 ||
  2181. target_type == TARGET_TYPE_KIWI ||
  2182. target_type == TARGET_TYPE_MANGO ||
  2183. target_type == TARGET_TYPE_PEACH) {
  2184. pcap->num_detectors_160mhz = 1;
  2185. pcap->num_detectors_80p80mhz = 1;
  2186. pcap->num_detectors_320mhz = 0;
  2187. } else if (is_spectral_arch_beryllium(target_type)) {
  2188. pcap->num_detectors_160mhz = 1;
  2189. pcap->num_detectors_80p80mhz = 0;
  2190. pcap->num_detectors_320mhz = 1;
  2191. } else {
  2192. pcap->num_detectors_160mhz = 2;
  2193. pcap->num_detectors_80p80mhz = 2;
  2194. pcap->num_detectors_320mhz = 0;
  2195. }
  2196. status = target_if_populate_supported_sscan_bws(spectral, target_type);
  2197. if (QDF_IS_STATUS_ERROR(status)) {
  2198. spectral_err("Unable to populate supported sscan BWs");
  2199. return QDF_STATUS_E_FAILURE;
  2200. }
  2201. return QDF_STATUS_SUCCESS;
  2202. }
  2203. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2204. /**
  2205. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  2206. * internal operations with functions related to spectral simulation
  2207. * @p_sops: spectral low level ops table
  2208. *
  2209. * Initialize spectral target_if internal operations with functions
  2210. * related to spectral simulation
  2211. *
  2212. * Return: None
  2213. */
  2214. static void
  2215. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  2216. {
  2217. /*
  2218. * Spectral simulation is currently intended for platform transitions
  2219. * where underlying HW support may not be available for some time.
  2220. * Hence, we do not currently provide a runtime switch to turn the
  2221. * simulation on or off.
  2222. * In case of future requirements where runtime switches are required,
  2223. * this can be added. But it is suggested to use application layer
  2224. * simulation as far as possible in such cases, since the main
  2225. * use of record and replay of samples would concern higher
  2226. * level sample processing rather than lower level delivery.
  2227. */
  2228. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  2229. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  2230. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  2231. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  2232. p_sops->configure_spectral =
  2233. target_if_spectral_sops_sim_configure_params;
  2234. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  2235. }
  2236. #else
  2237. /**
  2238. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  2239. * internal operations
  2240. * @p_sops: spectral low level ops table
  2241. *
  2242. * Return: None
  2243. */
  2244. static void
  2245. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  2246. {
  2247. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  2248. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  2249. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  2250. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  2251. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  2252. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  2253. }
  2254. #endif
  2255. /**
  2256. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  2257. * operations common to all Spectral chipset generations
  2258. *
  2259. * Initializes target_if_spectral_ops common to all chipset generations
  2260. *
  2261. * Return: None
  2262. */
  2263. static void
  2264. target_if_init_spectral_ops_common(void)
  2265. {
  2266. struct target_if_spectral_ops *p_sops = &spectral_ops;
  2267. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  2268. p_sops->get_capability = target_if_spectral_get_capability;
  2269. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  2270. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  2271. target_if_init_spectral_simulation_ops(p_sops);
  2272. p_sops->get_extension_channel =
  2273. target_if_spectral_get_extension_channel;
  2274. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  2275. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  2276. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  2277. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  2278. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  2279. p_sops->reset_hw = target_if_spectral_reset_hw;
  2280. p_sops->get_chain_noise_floor =
  2281. target_if_spectral_get_chain_noise_floor;
  2282. }
  2283. /**
  2284. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  2285. * operations specific to Spectral chipset generation 2.
  2286. *
  2287. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  2288. *
  2289. * Return: None
  2290. */
  2291. static void
  2292. target_if_init_spectral_ops_gen2(void)
  2293. {
  2294. struct target_if_spectral_ops *p_sops = &spectral_ops;
  2295. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  2296. }
  2297. #ifdef BIG_ENDIAN_HOST
  2298. /**
  2299. * spectral_is_host_byte_swap_required() - Check if byte swap has to be done
  2300. * on the Host
  2301. * @pdev: pdev pointer
  2302. * @is_swap_required: Pointer to caller variable
  2303. *
  2304. * Return: QDF_STATUS of operation
  2305. */
  2306. static QDF_STATUS
  2307. spectral_is_host_byte_swap_required(struct wlan_objmgr_pdev *pdev,
  2308. bool *is_swap_required)
  2309. {
  2310. struct wlan_objmgr_psoc *psoc;
  2311. struct wmi_unified *wmi_handle;
  2312. if (!pdev) {
  2313. spectral_err("pdev is null");
  2314. return QDF_STATUS_E_INVAL;
  2315. }
  2316. psoc = wlan_pdev_get_psoc(pdev);
  2317. if (!psoc) {
  2318. spectral_err("psoc is null");
  2319. return QDF_STATUS_E_INVAL;
  2320. }
  2321. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  2322. if (!wmi_handle) {
  2323. spectral_err("wmi handle is null");
  2324. return QDF_STATUS_E_INVAL;
  2325. }
  2326. /**
  2327. * If a chipset supports byte-swap inside the target itself, then no
  2328. * need to apply byte swap on the Host.
  2329. */
  2330. *is_swap_required = !target_if_spectral_wmi_service_enabled(
  2331. psoc, wmi_handle,
  2332. wmi_service_phy_dma_byte_swap_support);
  2333. return QDF_STATUS_SUCCESS;
  2334. }
  2335. /**
  2336. * target_if_spectral_init_byte_swap_funcs_gen3() - Initialize byte-swap
  2337. * operations for Spectral chipset generation 3.
  2338. * @spectral: Spectral LMAC object
  2339. * @p_sops: Spectral function pointer table
  2340. *
  2341. * Return: None
  2342. */
  2343. static void
  2344. target_if_spectral_init_byte_swap_funcs_gen3(
  2345. struct target_if_spectral *spectral,
  2346. struct target_if_spectral_ops *p_sops)
  2347. {
  2348. bool is_swap_required;
  2349. QDF_STATUS status;
  2350. if (!spectral) {
  2351. spectral_err("spectral variable is null");
  2352. return;
  2353. }
  2354. if (!p_sops) {
  2355. spectral_err("spectral ops variable is null");
  2356. return;
  2357. }
  2358. status = spectral_is_host_byte_swap_required(spectral->pdev_obj,
  2359. &is_swap_required);
  2360. if (QDF_IS_STATUS_ERROR(status)) {
  2361. spectral_err("Failed to check whether byte swap is required");
  2362. return;
  2363. }
  2364. if (is_swap_required) {
  2365. p_sops->byte_swap_headers =
  2366. target_if_byte_swap_spectral_headers_gen3;
  2367. p_sops->byte_swap_fft_bins =
  2368. target_if_byte_swap_spectral_fft_bins_gen3;
  2369. } else {
  2370. p_sops->byte_swap_headers = NULL;
  2371. p_sops->byte_swap_fft_bins = NULL;
  2372. }
  2373. }
  2374. #else
  2375. static void
  2376. target_if_spectral_init_byte_swap_funcs_gen3(
  2377. struct target_if_spectral *spectral,
  2378. struct target_if_spectral_ops *p_sops)
  2379. {
  2380. if (!p_sops) {
  2381. spectral_err("spectral ops variable is null");
  2382. return;
  2383. }
  2384. /* Byte-swap is not required for little-endian Hosts */
  2385. p_sops->byte_swap_headers = NULL;
  2386. p_sops->byte_swap_fft_bins = NULL;
  2387. }
  2388. #endif /* BIG_ENDIAN_HOST */
  2389. /**
  2390. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  2391. * operations specific to Spectral chipset generation 3.
  2392. * @spectral: Spectral LMAC object
  2393. *
  2394. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  2395. *
  2396. * Return: None
  2397. */
  2398. static void
  2399. target_if_init_spectral_ops_gen3(struct target_if_spectral *spectral)
  2400. {
  2401. struct target_if_spectral_ops *p_sops = &spectral_ops;
  2402. p_sops->process_spectral_report =
  2403. target_if_spectral_process_report_gen3;
  2404. target_if_spectral_init_byte_swap_funcs_gen3(spectral, p_sops);
  2405. }
  2406. /**
  2407. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  2408. * operations.
  2409. * @spectral: Pointer to Spectral target_if internal private data
  2410. *
  2411. * Initializes all function pointers in target_if_spectral_ops for
  2412. * all generations
  2413. *
  2414. * Return: None
  2415. */
  2416. static void
  2417. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  2418. {
  2419. target_if_init_spectral_ops_common();
  2420. if (spectral->spectral_gen == SPECTRAL_GEN2)
  2421. target_if_init_spectral_ops_gen2();
  2422. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  2423. target_if_init_spectral_ops_gen3(spectral);
  2424. else
  2425. spectral_err("Invalid Spectral generation");
  2426. }
  2427. /*
  2428. * Dummy Functions:
  2429. * These functions are initially registered to avoid any crashes due to
  2430. * invocation of spectral functions before they are registered.
  2431. */
  2432. static uint64_t
  2433. null_get_tsf64(void *arg)
  2434. {
  2435. spectral_ops_not_registered("get_tsf64");
  2436. return 0;
  2437. }
  2438. static uint32_t
  2439. null_get_capability(void *arg, enum spectral_capability_type type)
  2440. {
  2441. /*
  2442. * TODO : We should have conditional compilation to get the capability
  2443. * : We have not yet attahced ATH layer here, so there is no
  2444. * : way to check the HAL capbalities
  2445. */
  2446. spectral_ops_not_registered("get_capability");
  2447. /* TODO : For the time being, we are returning TRUE */
  2448. return true;
  2449. }
  2450. static uint32_t
  2451. null_set_rxfilter(void *arg, int rxfilter)
  2452. {
  2453. spectral_ops_not_registered("set_rxfilter");
  2454. return 1;
  2455. }
  2456. static uint32_t
  2457. null_get_rxfilter(void *arg)
  2458. {
  2459. spectral_ops_not_registered("get_rxfilter");
  2460. return 0;
  2461. }
  2462. static uint32_t
  2463. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  2464. {
  2465. spectral_ops_not_registered("is_spectral_active");
  2466. return 1;
  2467. }
  2468. static uint32_t
  2469. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  2470. {
  2471. spectral_ops_not_registered("is_spectral_enabled");
  2472. return 1;
  2473. }
  2474. static uint32_t
  2475. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  2476. enum spectral_cp_error_code *err)
  2477. {
  2478. spectral_ops_not_registered("start_spectral_scan");
  2479. return 1;
  2480. }
  2481. static uint32_t
  2482. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  2483. {
  2484. spectral_ops_not_registered("stop_spectral_scan");
  2485. return 1;
  2486. }
  2487. static uint32_t
  2488. null_get_extension_channel(void *arg, enum spectral_scan_mode smode)
  2489. {
  2490. spectral_ops_not_registered("get_extension_channel");
  2491. return 1;
  2492. }
  2493. static int8_t
  2494. null_get_ctl_noisefloor(void *arg)
  2495. {
  2496. spectral_ops_not_registered("get_ctl_noisefloor");
  2497. return 1;
  2498. }
  2499. static int8_t
  2500. null_get_ext_noisefloor(void *arg)
  2501. {
  2502. spectral_ops_not_registered("get_ext_noisefloor");
  2503. return 0;
  2504. }
  2505. static uint32_t
  2506. null_configure_spectral(void *arg, struct spectral_config *params,
  2507. enum spectral_scan_mode smode)
  2508. {
  2509. spectral_ops_not_registered("configure_spectral");
  2510. return 0;
  2511. }
  2512. static uint32_t
  2513. null_get_spectral_config(void *arg, struct spectral_config *params,
  2514. enum spectral_scan_mode smode)
  2515. {
  2516. spectral_ops_not_registered("get_spectral_config");
  2517. return 0;
  2518. }
  2519. static uint32_t
  2520. null_get_ent_spectral_mask(void *arg)
  2521. {
  2522. spectral_ops_not_registered("get_ent_spectral_mask");
  2523. return 0;
  2524. }
  2525. static uint32_t
  2526. null_get_mac_address(void *arg, char *addr)
  2527. {
  2528. spectral_ops_not_registered("get_mac_address");
  2529. return 0;
  2530. }
  2531. static uint32_t
  2532. null_get_current_channel(void *arg, enum spectral_scan_mode smode)
  2533. {
  2534. spectral_ops_not_registered("get_current_channel");
  2535. return 0;
  2536. }
  2537. static uint32_t
  2538. null_reset_hw(void *arg)
  2539. {
  2540. spectral_ops_not_registered("get_current_channel");
  2541. return 0;
  2542. }
  2543. static uint32_t
  2544. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  2545. {
  2546. spectral_ops_not_registered("get_chain_noise_floor");
  2547. return 0;
  2548. }
  2549. static int
  2550. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  2551. uint8_t *data,
  2552. uint32_t datalen,
  2553. struct target_if_spectral_rfqual_info *p_rfqual,
  2554. struct target_if_spectral_chan_info *p_chaninfo,
  2555. uint64_t tsf64,
  2556. struct target_if_spectral_acs_stats *acs_stats)
  2557. {
  2558. spectral_ops_not_registered("spectral_process_phyerr");
  2559. return 0;
  2560. }
  2561. static int
  2562. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  2563. void *payload)
  2564. {
  2565. spectral_ops_not_registered("process_spectral_report");
  2566. return 0;
  2567. }
  2568. /**
  2569. * target_if_spectral_init_dummy_function_table() -
  2570. * Initialize target_if internal
  2571. * Spectral operations to dummy functions
  2572. * @ps: Pointer to Spectral target_if internal private data
  2573. *
  2574. * Initialize all the function pointers in target_if_spectral_ops with
  2575. * dummy functions.
  2576. *
  2577. * Return: None
  2578. */
  2579. static void
  2580. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  2581. {
  2582. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  2583. p_sops->get_tsf64 = null_get_tsf64;
  2584. p_sops->get_capability = null_get_capability;
  2585. p_sops->set_rxfilter = null_set_rxfilter;
  2586. p_sops->get_rxfilter = null_get_rxfilter;
  2587. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  2588. p_sops->is_spectral_active = null_is_spectral_active;
  2589. p_sops->start_spectral_scan = null_start_spectral_scan;
  2590. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  2591. p_sops->get_extension_channel = null_get_extension_channel;
  2592. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  2593. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  2594. p_sops->configure_spectral = null_configure_spectral;
  2595. p_sops->get_spectral_config = null_get_spectral_config;
  2596. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  2597. p_sops->get_mac_address = null_get_mac_address;
  2598. p_sops->get_current_channel = null_get_current_channel;
  2599. p_sops->reset_hw = null_reset_hw;
  2600. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  2601. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  2602. p_sops->process_spectral_report = null_process_spectral_report;
  2603. }
  2604. /**
  2605. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  2606. * operations
  2607. * @spectral: Pointer to Spectral target_if internal private data
  2608. * @p: Pointer to Spectral function table
  2609. *
  2610. * Return: None
  2611. */
  2612. static void
  2613. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  2614. struct target_if_spectral_ops *p)
  2615. {
  2616. struct target_if_spectral_ops *p_sops =
  2617. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2618. *p_sops = *p;
  2619. }
  2620. /**
  2621. * target_if_spectral_clear_stats() - Clear Spectral stats
  2622. * @spectral: Pointer to Spectral target_if internal private data
  2623. *
  2624. * Function to clear spectral stats
  2625. *
  2626. * Return: None
  2627. */
  2628. static void
  2629. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  2630. {
  2631. struct target_if_spectral_ops *p_sops =
  2632. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2633. qdf_mem_zero(&spectral->spectral_stats,
  2634. sizeof(struct target_if_spectral_stats));
  2635. spectral->spectral_stats.last_reset_tstamp =
  2636. p_sops->get_tsf64(spectral);
  2637. }
  2638. /**
  2639. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  2640. * @spectral: Pointer to Spectral target_if internal private data
  2641. *
  2642. * Function to check whether hardware supports spectral
  2643. *
  2644. * Return: True if HW supports Spectral, false if HW does not support Spectral
  2645. */
  2646. static int
  2647. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  2648. {
  2649. struct target_if_spectral_ops *p_sops = NULL;
  2650. struct spectral_caps *pcap = NULL;
  2651. int is_spectral_supported = true;
  2652. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2653. pcap = &spectral->capability;
  2654. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  2655. is_spectral_supported = false;
  2656. spectral_info("SPECTRAL : No PHYDIAG support");
  2657. return is_spectral_supported;
  2658. }
  2659. pcap->phydiag_cap = 1;
  2660. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  2661. is_spectral_supported = false;
  2662. spectral_info("SPECTRAL : No RADAR support");
  2663. return is_spectral_supported;
  2664. }
  2665. pcap->radar_cap = 1;
  2666. if (p_sops->get_capability(spectral,
  2667. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  2668. is_spectral_supported = false;
  2669. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  2670. return is_spectral_supported;
  2671. }
  2672. pcap->spectral_cap = 1;
  2673. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  2674. == false) {
  2675. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  2676. } else {
  2677. pcap->advncd_spectral_cap = 1;
  2678. }
  2679. return is_spectral_supported;
  2680. }
  2681. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2682. /**
  2683. * target_if_spectral_detach_simulation() - De-initialize Spectral
  2684. * Simulation functionality
  2685. * @spectral: Pointer to Spectral target_if internal private data
  2686. *
  2687. * Function to de-initialize Spectral Simulation functionality
  2688. *
  2689. * Return: None
  2690. */
  2691. static void
  2692. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  2693. {
  2694. target_if_spectral_sim_detach(spectral);
  2695. }
  2696. #else
  2697. static void
  2698. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  2699. {
  2700. }
  2701. #endif
  2702. /**
  2703. * target_if_spectral_detach() - De-initialize target_if Spectral
  2704. * @spectral: Pointer to Spectral target_if internal private data
  2705. *
  2706. * Function to detach target_if spectral
  2707. *
  2708. * Return: None
  2709. */
  2710. static void
  2711. target_if_spectral_detach(struct target_if_spectral *spectral)
  2712. {
  2713. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  2714. spectral_info("spectral detach");
  2715. if (spectral) {
  2716. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2717. qdf_spinlock_destroy
  2718. (&spectral->param_info[smode].osps_lock);
  2719. target_if_spectral_detach_simulation(spectral);
  2720. qdf_spinlock_destroy(&spectral->spectral_lock);
  2721. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  2722. qdf_spinlock_destroy(&spectral->detector_list_lock);
  2723. qdf_spinlock_destroy(&spectral->session_report_info_lock);
  2724. qdf_spinlock_destroy(&spectral->session_det_map_lock);
  2725. qdf_mem_free(spectral);
  2726. spectral = NULL;
  2727. }
  2728. }
  2729. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2730. /**
  2731. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  2732. * functionality
  2733. * @spectral: Pointer to Spectral target_if internal private data
  2734. *
  2735. * Function to initialize spectral simulation functionality
  2736. *
  2737. * Return: 0 on success, negative error code on failure
  2738. */
  2739. static int
  2740. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  2741. {
  2742. if (target_if_spectral_sim_attach(spectral)) {
  2743. qdf_mem_free(spectral);
  2744. return -EPERM;
  2745. }
  2746. return 0;
  2747. }
  2748. #else
  2749. static int
  2750. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  2751. {
  2752. return 0;
  2753. }
  2754. #endif
  2755. /**
  2756. * target_if_spectral_len_adj_swar_init() - Initialize FFT bin length adjustment
  2757. * related info
  2758. * @swar: Pointer to Spectral FFT bin length adjustment SWAR params
  2759. * @rparams: Pointer to Spectral report parameter object
  2760. * @target_type: Target type
  2761. *
  2762. * Function to Initialize parameters related to Spectral FFT bin
  2763. * length adjustment SWARs.
  2764. *
  2765. * Return: void
  2766. */
  2767. static void
  2768. target_if_spectral_len_adj_swar_init(struct spectral_fft_bin_len_adj_swar *swar,
  2769. struct spectral_report_params *rparams,
  2770. uint32_t target_type)
  2771. {
  2772. if (target_type == TARGET_TYPE_QCA8074V2 ||
  2773. target_type == TARGET_TYPE_QCA9574 ||
  2774. target_type == TARGET_TYPE_QCN9000 ||
  2775. target_type == TARGET_TYPE_QCN6122 ||
  2776. target_type == TARGET_TYPE_QCN9160 ||
  2777. target_type == TARGET_TYPE_QCA5018 ||
  2778. target_type == TARGET_TYPE_QCA6750 ||
  2779. target_type == TARGET_TYPE_QCA6490 ||
  2780. target_type == TARGET_TYPE_KIWI ||
  2781. target_type == TARGET_TYPE_MANGO ||
  2782. target_type == TARGET_TYPE_PEACH) {
  2783. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  2784. rparams->hw_fft_bin_width = 2;
  2785. } else if (target_type == TARGET_TYPE_QCA8074 ||
  2786. target_type == TARGET_TYPE_QCA6018 ||
  2787. target_type == TARGET_TYPE_QCA6390) {
  2788. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  2789. rparams->hw_fft_bin_width = 4;
  2790. } else {
  2791. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  2792. rparams->hw_fft_bin_width = 1;
  2793. }
  2794. if (target_type == TARGET_TYPE_QCA8074 ||
  2795. target_type == TARGET_TYPE_QCA8074V2 ||
  2796. target_type == TARGET_TYPE_QCA9574 ||
  2797. target_type == TARGET_TYPE_QCA6018 ||
  2798. target_type == TARGET_TYPE_QCN6122 ||
  2799. target_type == TARGET_TYPE_QCN9160 ||
  2800. target_type == TARGET_TYPE_QCN6432 ||
  2801. target_type == TARGET_TYPE_QCA5332 ||
  2802. target_type == TARGET_TYPE_QCA5018 ||
  2803. target_type == TARGET_TYPE_QCN9000 ||
  2804. target_type == TARGET_TYPE_QCA6490 ||
  2805. target_type == TARGET_TYPE_QCN9224 ||
  2806. target_type == TARGET_TYPE_KIWI ||
  2807. target_type == TARGET_TYPE_MANGO ||
  2808. target_type == TARGET_TYPE_PEACH) {
  2809. swar->inband_fftbin_size_adj = 1;
  2810. swar->null_fftbin_adj = 1;
  2811. } else {
  2812. swar->inband_fftbin_size_adj = 0;
  2813. swar->null_fftbin_adj = 0;
  2814. }
  2815. if (target_type == TARGET_TYPE_QCA8074V2)
  2816. swar->packmode_fftbin_size_adj = 1;
  2817. else
  2818. swar->packmode_fftbin_size_adj = 0;
  2819. }
  2820. /**
  2821. * target_if_spectral_report_params_init() - Initialize parameters which
  2822. * describes the structure of Spectral reports
  2823. *
  2824. * @rparams: Pointer to Spectral report parameter object
  2825. * @target_type: target type
  2826. *
  2827. * Function to Initialize parameters related to the structure of Spectral
  2828. * reports.
  2829. *
  2830. * Return: void
  2831. */
  2832. static void
  2833. target_if_spectral_report_params_init(
  2834. struct spectral_report_params *rparams,
  2835. uint32_t target_type)
  2836. {
  2837. enum spectral_scan_mode smode;
  2838. /* This entries are currently used by gen3 chipsets only. Hence
  2839. * initialization is done for gen3 alone. In future if other generations
  2840. * needs to use them they have to add proper initial values.
  2841. */
  2842. if (target_type == TARGET_TYPE_QCN9000 ||
  2843. target_type == TARGET_TYPE_QCN6122 ||
  2844. target_type == TARGET_TYPE_QCN9160 ||
  2845. target_type == TARGET_TYPE_QCN6432 ||
  2846. target_type == TARGET_TYPE_QCA5018 ||
  2847. target_type == TARGET_TYPE_QCA6750 ||
  2848. target_type == TARGET_TYPE_QCA6490 ||
  2849. target_type == TARGET_TYPE_QCA5332 ||
  2850. target_type == TARGET_TYPE_QCN9224 ||
  2851. target_type == TARGET_TYPE_KIWI ||
  2852. target_type == TARGET_TYPE_MANGO ||
  2853. target_type == TARGET_TYPE_PEACH) {
  2854. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_2;
  2855. rparams->num_spectral_detectors =
  2856. NUM_SPECTRAL_DETECTORS_GEN3_V2;
  2857. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2858. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2859. rparams->fragmentation_160[smode] = false;
  2860. } else {
  2861. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_1;
  2862. rparams->num_spectral_detectors =
  2863. NUM_SPECTRAL_DETECTORS_GEN3_V1;
  2864. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2865. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2866. rparams->fragmentation_160[smode] = true;
  2867. }
  2868. switch (rparams->version) {
  2869. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  2870. rparams->ssummary_padding_bytes =
  2871. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1;
  2872. rparams->fft_report_hdr_len =
  2873. FFT_REPORT_HEADER_LENGTH_GEN3_V1;
  2874. break;
  2875. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  2876. rparams->ssummary_padding_bytes =
  2877. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2;
  2878. rparams->fft_report_hdr_len =
  2879. FFT_REPORT_HEADER_LENGTH_GEN3_V2;
  2880. break;
  2881. }
  2882. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_0] =
  2883. SPECTRAL_SCAN_MODE_NORMAL;
  2884. if (target_type == TARGET_TYPE_QCN9000 ||
  2885. target_type == TARGET_TYPE_QCN6122 ||
  2886. target_type == TARGET_TYPE_QCN9224 ||
  2887. target_type == TARGET_TYPE_QCN6432 ||
  2888. target_type == TARGET_TYPE_QCN9160 ||
  2889. target_type == TARGET_TYPE_QCA6490 ||
  2890. target_type == TARGET_TYPE_KIWI ||
  2891. target_type == TARGET_TYPE_MANGO ||
  2892. target_type == TARGET_TYPE_PEACH) {
  2893. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2894. SPECTRAL_SCAN_MODE_AGILE;
  2895. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2896. SPECTRAL_SCAN_MODE_INVALID;
  2897. } else if (target_type == TARGET_TYPE_QCA5332) {
  2898. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2899. SPECTRAL_SCAN_MODE_INVALID;
  2900. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2901. SPECTRAL_SCAN_MODE_INVALID;
  2902. } else {
  2903. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2904. SPECTRAL_SCAN_MODE_NORMAL;
  2905. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2906. SPECTRAL_SCAN_MODE_AGILE;
  2907. }
  2908. }
  2909. /**
  2910. * target_if_spectral_timestamp_war_init() - Initialize Spectral timestamp WAR
  2911. * related info
  2912. * @twar: Pointer to Spectral timstamp WAR related info
  2913. *
  2914. * Function to Initialize parameters related to Spectral timestamp WAR
  2915. *
  2916. * Return: void
  2917. */
  2918. static void
  2919. target_if_spectral_timestamp_war_init(struct spectral_timestamp_war *twar)
  2920. {
  2921. enum spectral_scan_mode smode;
  2922. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2923. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2924. twar->last_fft_timestamp[smode] = 0;
  2925. twar->timestamp_war_offset[smode] = 0;
  2926. }
  2927. twar->target_reset_count = 0;
  2928. }
  2929. #ifdef OPTIMIZED_SAMP_MESSAGE
  2930. /**
  2931. * target_if_spectral_is_hw_mode_sbs() - Check if the given pdev is in SBS mode
  2932. * @pdev: pdev pointer
  2933. * @is_hw_mode_sbs: Pointer to the variable where this function should write
  2934. * whether the given pdev is in SBS mode
  2935. *
  2936. * Return: QDF_STATUS of operation
  2937. */
  2938. static QDF_STATUS
  2939. target_if_spectral_is_hw_mode_sbs(struct wlan_objmgr_pdev *pdev,
  2940. bool *is_hw_mode_sbs)
  2941. {
  2942. struct wlan_objmgr_psoc *psoc;
  2943. struct target_psoc_info *tgt_hdl;
  2944. enum wmi_host_hw_mode_config_type mode;
  2945. if (!is_hw_mode_sbs) {
  2946. spectral_err("is_hw_mode_sbs pointer is null.");
  2947. return QDF_STATUS_E_NULL_VALUE;
  2948. }
  2949. psoc = wlan_pdev_get_psoc(pdev);
  2950. if (!psoc) {
  2951. spectral_err("psoc is null");
  2952. return QDF_STATUS_E_NULL_VALUE;
  2953. }
  2954. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  2955. if (!tgt_hdl) {
  2956. spectral_err("target_psoc_info is null");
  2957. return QDF_STATUS_E_NULL_VALUE;
  2958. }
  2959. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  2960. switch (mode) {
  2961. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  2962. case WMI_HOST_HW_MODE_SBS:
  2963. case WMI_HOST_HW_MODE_DBS_SBS:
  2964. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  2965. *is_hw_mode_sbs = true;
  2966. break;
  2967. default:
  2968. *is_hw_mode_sbs = false;
  2969. break;
  2970. }
  2971. return QDF_STATUS_SUCCESS;
  2972. }
  2973. /**
  2974. * target_if_get_pdev_mac_phy_caps() - Get the MAC_PHY capabilities of a pdev
  2975. * @pdev: pdev pointer
  2976. *
  2977. * Return: On success, pointer to MAC_PHY capabilities of @pdev.
  2978. * On failure, NULL
  2979. */
  2980. static struct wlan_psoc_host_mac_phy_caps *
  2981. target_if_get_pdev_mac_phy_caps(struct wlan_objmgr_pdev *pdev)
  2982. {
  2983. struct wlan_objmgr_psoc *psoc;
  2984. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr;
  2985. struct target_psoc_info *tgt_psoc_info;
  2986. uint8_t pdev_id;
  2987. if (!pdev) {
  2988. spectral_err("pdev is NULL");
  2989. return NULL;
  2990. }
  2991. psoc = wlan_pdev_get_psoc(pdev);
  2992. if (!psoc) {
  2993. spectral_err("psoc is null");
  2994. return NULL;
  2995. }
  2996. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  2997. if (!tgt_psoc_info) {
  2998. spectral_err("target_psoc_info is null");
  2999. return NULL;
  3000. }
  3001. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  3002. if (!mac_phy_cap_arr) {
  3003. spectral_err("mac phy cap array is null");
  3004. return NULL;
  3005. }
  3006. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  3007. return &mac_phy_cap_arr[pdev_id];
  3008. }
  3009. /**
  3010. * struct target_if_sscan_pdev_phy_info - PHY information of the pdev on
  3011. * which sscan is done. A pointer to an instance of this structure is passed
  3012. * as an argument to the iterator function target_if_find_sscan_pdev_phya1()
  3013. * @phy_id: PHY ID of this pdev
  3014. * @is_using_phya1: Pointer to the variable where the iterator function should
  3015. * populate whether the given pdev is using PHYA1
  3016. */
  3017. struct target_if_sscan_pdev_phy_info {
  3018. uint8_t phy_id;
  3019. bool *is_using_phya1;
  3020. };
  3021. /**
  3022. * target_if_find_sscan_pdev_phya1() - This is an iterator function to
  3023. * wlan_objmgr_iterate_obj_list(). It checks whether a given sscan_pdev (pdev on
  3024. * which sscan is currently issued) is using PHYA1 by comparing against the pdev
  3025. * argument given by the wlan_objmgr_iterate_obj_list()
  3026. * @psoc: Pointer to psoc
  3027. * @object: Pointer to pdev
  3028. * @arg: Pointer to target_if_sscan_pdev_phy_info of the sscan_pdev for which
  3029. * we want to check if it uses PHYA1
  3030. *
  3031. * Return: None
  3032. */
  3033. static void
  3034. target_if_find_sscan_pdev_phya1(struct wlan_objmgr_psoc *psoc,
  3035. void *object, void *arg)
  3036. {
  3037. struct target_if_sscan_pdev_phy_info *sscan_pdev_phy_info = arg;
  3038. struct wlan_objmgr_pdev *cur_pdev = object;
  3039. struct wlan_psoc_host_mac_phy_caps *cur_mac_phy_caps;
  3040. cur_mac_phy_caps = target_if_get_pdev_mac_phy_caps(cur_pdev);
  3041. if (!cur_mac_phy_caps) {
  3042. spectral_err("Failed to get MAC PHY Capabilities of"
  3043. "pdev %pK", cur_pdev);
  3044. return;
  3045. }
  3046. spectral_debug("supported_bands: %0x phy_id: %d",
  3047. cur_mac_phy_caps->supported_bands,
  3048. cur_mac_phy_caps->phy_id);
  3049. /* No need to do anything if the current pdev is same as sscan_pdev */
  3050. if (sscan_pdev_phy_info->phy_id == cur_mac_phy_caps->phy_id)
  3051. return;
  3052. /**
  3053. * Compare the phy_id of both the SBS pdevs to figure out if
  3054. * the sscan_pdev using PHYA1
  3055. */
  3056. if (sscan_pdev_phy_info->phy_id > cur_mac_phy_caps->phy_id)
  3057. *sscan_pdev_phy_info->is_using_phya1 = true;
  3058. else
  3059. *sscan_pdev_phy_info->is_using_phya1 = false;
  3060. }
  3061. /**
  3062. * target_if_spectral_detector_list_init() - Initialize Spectral detector list
  3063. * based on target type
  3064. * @spectral: Pointer to Spectral target_if
  3065. *
  3066. * Function to initialize Spectral detector list for possible combinations of
  3067. * Spectral scan mode and channel width, based on target type.
  3068. *
  3069. * Return: Success/Failure
  3070. */
  3071. static QDF_STATUS
  3072. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  3073. {
  3074. struct sscan_detector_list *det_list;
  3075. enum spectral_scan_mode smode;
  3076. enum phy_ch_width ch_width;
  3077. QDF_STATUS ret;
  3078. bool is_hw_mode_sbs = false, is_using_phya1 = false;
  3079. if (!spectral) {
  3080. spectral_err_rl("Spectral LMAC object is null");
  3081. return QDF_STATUS_E_NULL_VALUE;
  3082. }
  3083. /**
  3084. * Special handling is required for SBS mode where the detector
  3085. * list should be the following.
  3086. * For the pdev that use PHYA0:
  3087. * detector 0 for normal mode
  3088. * detector 2 for agile mode
  3089. * For the pdev that use PHYA1:
  3090. * detector 1 for normal mode
  3091. * detector 2 for agile mode
  3092. *
  3093. * There is no direct way of knowing which pdevs are using PHYA0 or
  3094. * PHYA1. We need to look at the phy_id of a given pdev and compare
  3095. * against other pdevs on the same psoc to figure out whether the given
  3096. * pdev is operating using PHYA1.
  3097. */
  3098. /* First check whether this pdev is in SBS mode */
  3099. ret = target_if_spectral_is_hw_mode_sbs(spectral->pdev_obj,
  3100. &is_hw_mode_sbs);
  3101. if (QDF_IS_STATUS_ERROR(ret)) {
  3102. spectral_err("Failed to check whether hw mode is SBS");
  3103. return ret;
  3104. }
  3105. if (is_hw_mode_sbs) {
  3106. struct wlan_psoc_host_mac_phy_caps *mac_phy_caps;
  3107. struct target_if_sscan_pdev_phy_info pdev_phy_info;
  3108. mac_phy_caps =
  3109. target_if_get_pdev_mac_phy_caps(spectral->pdev_obj);
  3110. if (!mac_phy_caps) {
  3111. spectral_err("Failed to get MAC PHY Capabilities of"
  3112. "pdev %pK", spectral->pdev_obj);
  3113. return QDF_STATUS_E_FAILURE;
  3114. }
  3115. spectral_debug("bands: %0x phy_id: %d",
  3116. mac_phy_caps->supported_bands,
  3117. mac_phy_caps->phy_id);
  3118. pdev_phy_info.phy_id = mac_phy_caps->phy_id;
  3119. pdev_phy_info.is_using_phya1 = &is_using_phya1;
  3120. /* Iterate over all pdevs on this psoc */
  3121. wlan_objmgr_iterate_obj_list
  3122. (wlan_pdev_get_psoc(spectral->pdev_obj),
  3123. WLAN_PDEV_OP,
  3124. target_if_find_sscan_pdev_phya1,
  3125. &pdev_phy_info, 0,
  3126. WLAN_SPECTRAL_ID);
  3127. }
  3128. /**
  3129. * We assume there are 2 detectors. The Detector ID coming first will
  3130. * always be pri80 detector, and second detector for sec80.
  3131. */
  3132. ch_width = CH_WIDTH_20MHZ;
  3133. for (; ch_width < CH_WIDTH_MAX; ch_width++) {
  3134. /* Normal spectral scan */
  3135. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3136. spectral_debug("is_hw_mode_sbs: %d is_using_phya1:%d",
  3137. is_hw_mode_sbs, is_using_phya1);
  3138. qdf_spin_lock_bh(&spectral->detector_list_lock);
  3139. if (!spectral->supported_sscan_bw_list[smode][ch_width])
  3140. goto agile_handling;
  3141. det_list = &spectral->detector_list[smode][ch_width];
  3142. det_list->num_detectors = 1;
  3143. if (is_hw_mode_sbs && is_using_phya1)
  3144. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_1;
  3145. else
  3146. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_0;
  3147. if (is_ch_width_160_or_80p80(ch_width) &&
  3148. spectral->rparams.fragmentation_160[smode]) {
  3149. det_list->num_detectors += 1;
  3150. det_list->detectors[1] = SPECTRAL_DETECTOR_ID_1;
  3151. }
  3152. agile_handling:
  3153. /* Agile spectral scan */
  3154. smode = SPECTRAL_SCAN_MODE_AGILE;
  3155. if (!spectral->supported_sscan_bw_list[smode][ch_width]) {
  3156. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  3157. continue;
  3158. }
  3159. det_list = &spectral->detector_list[smode][ch_width];
  3160. det_list->num_detectors = 1;
  3161. if (spectral->rparams.fragmentation_160[smode])
  3162. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_2;
  3163. else
  3164. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_1;
  3165. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  3166. }
  3167. return QDF_STATUS_SUCCESS;
  3168. }
  3169. #else
  3170. static QDF_STATUS
  3171. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  3172. {
  3173. return QDF_STATUS_SUCCESS;
  3174. }
  3175. #endif /* OPTIMIZED_SAMP_MESSAGE */
  3176. /**
  3177. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  3178. * functionality for the given pdev
  3179. * @pdev: Pointer to pdev object
  3180. *
  3181. * Function to initialize pointer to spectral target_if internal private data
  3182. *
  3183. * Return: On success, pointer to Spectral target_if internal private data, on
  3184. * failure, NULL
  3185. */
  3186. void *
  3187. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  3188. {
  3189. struct target_if_spectral_ops *p_sops = NULL;
  3190. struct target_if_spectral *spectral = NULL;
  3191. uint32_t target_type;
  3192. uint32_t target_revision;
  3193. struct wlan_objmgr_psoc *psoc;
  3194. struct wlan_lmac_if_target_tx_ops *tgt_tx_ops;
  3195. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  3196. QDF_STATUS status;
  3197. struct wlan_lmac_if_tx_ops *tx_ops;
  3198. if (!pdev) {
  3199. spectral_err("SPECTRAL: pdev is NULL!");
  3200. return NULL;
  3201. }
  3202. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  3203. sizeof(struct target_if_spectral));
  3204. if (!spectral)
  3205. return spectral;
  3206. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  3207. /* Store pdev in Spectral */
  3208. spectral->pdev_obj = pdev;
  3209. spectral->vdev_id[SPECTRAL_SCAN_MODE_NORMAL] = WLAN_INVALID_VDEV_ID;
  3210. spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE] = WLAN_INVALID_VDEV_ID;
  3211. psoc = wlan_pdev_get_psoc(pdev);
  3212. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  3213. if (!tx_ops) {
  3214. spectral_err("tx_ops is NULL");
  3215. qdf_mem_free(spectral);
  3216. return NULL;
  3217. }
  3218. tgt_tx_ops = &tx_ops->target_tx_ops;
  3219. if (tgt_tx_ops->tgt_get_tgt_type) {
  3220. target_type = tgt_tx_ops->tgt_get_tgt_type(psoc);
  3221. } else {
  3222. qdf_mem_free(spectral);
  3223. return NULL;
  3224. }
  3225. if (tgt_tx_ops->tgt_get_tgt_revision) {
  3226. target_revision = tgt_tx_ops->tgt_get_tgt_revision(psoc);
  3227. } else {
  3228. qdf_mem_free(spectral);
  3229. return NULL;
  3230. }
  3231. /* init the function ptr table */
  3232. target_if_spectral_init_dummy_function_table(spectral);
  3233. /* get spectral function table */
  3234. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3235. /* TODO : Should this be called here of after ath_attach ? */
  3236. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  3237. spectral_info("HAL_CAP_PHYDIAG : Capable");
  3238. /* TODO: Need to fix the capability check for RADAR */
  3239. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  3240. spectral_info("HAL_CAP_RADAR : Capable");
  3241. /* TODO : Need to fix the capability check for SPECTRAL */
  3242. /* TODO : Should this be called here of after ath_attach ? */
  3243. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  3244. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  3245. qdf_spinlock_create(&spectral->spectral_lock);
  3246. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  3247. target_if_spectral_clear_stats(spectral);
  3248. if (target_type == TARGET_TYPE_QCA8074 ||
  3249. target_type == TARGET_TYPE_QCA8074V2 ||
  3250. target_type == TARGET_TYPE_QCA9574 ||
  3251. target_type == TARGET_TYPE_QCA5332 ||
  3252. target_type == TARGET_TYPE_QCA6018 ||
  3253. target_type == TARGET_TYPE_QCA5018 ||
  3254. target_type == TARGET_TYPE_QCA6390 ||
  3255. target_type == TARGET_TYPE_QCN6122 ||
  3256. target_type == TARGET_TYPE_QCN9160 ||
  3257. target_type == TARGET_TYPE_QCN6432 ||
  3258. target_type == TARGET_TYPE_QCA6490 ||
  3259. target_type == TARGET_TYPE_QCN9000 ||
  3260. target_type == TARGET_TYPE_QCA6750 ||
  3261. target_type == TARGET_TYPE_QCN9224 ||
  3262. target_type == TARGET_TYPE_KIWI ||
  3263. target_type == TARGET_TYPE_MANGO ||
  3264. target_type == TARGET_TYPE_PEACH)
  3265. spectral->direct_dma_support = true;
  3266. target_if_spectral_report_params_init(&spectral->rparams,
  3267. target_type);
  3268. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  3269. &spectral->rparams,
  3270. target_type);
  3271. if ((target_type == TARGET_TYPE_QCA8074) ||
  3272. (target_type == TARGET_TYPE_QCA8074V2) ||
  3273. (target_type == TARGET_TYPE_QCA9574) ||
  3274. (target_type == TARGET_TYPE_QCA6018) ||
  3275. (target_type == TARGET_TYPE_QCA5018) ||
  3276. (target_type == TARGET_TYPE_QCA5332) ||
  3277. (target_type == TARGET_TYPE_QCN6122) ||
  3278. (target_type == TARGET_TYPE_QCN9160) ||
  3279. (target_type == TARGET_TYPE_QCN6432) ||
  3280. (target_type == TARGET_TYPE_QCN9000) ||
  3281. (target_type == TARGET_TYPE_QCA6290) ||
  3282. (target_type == TARGET_TYPE_QCA6390) ||
  3283. (target_type == TARGET_TYPE_QCA6490) ||
  3284. (target_type == TARGET_TYPE_QCN9224) ||
  3285. (target_type == TARGET_TYPE_QCA6750) ||
  3286. (target_type == TARGET_TYPE_KIWI) ||
  3287. (target_type == TARGET_TYPE_MANGO) ||
  3288. (target_type == TARGET_TYPE_PEACH)) {
  3289. spectral->spectral_gen = SPECTRAL_GEN3;
  3290. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  3291. spectral->tag_sscan_summary_exp =
  3292. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  3293. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  3294. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  3295. } else {
  3296. spectral->spectral_gen = SPECTRAL_GEN2;
  3297. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  3298. spectral->tag_sscan_summary_exp =
  3299. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  3300. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  3301. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  3302. }
  3303. status = target_if_init_spectral_param_min_max(
  3304. spectral,
  3305. spectral->spectral_gen, target_type);
  3306. if (QDF_IS_STATUS_ERROR(status)) {
  3307. spectral_err("Failed to initialize parameter min max values");
  3308. goto fail;
  3309. }
  3310. target_if_init_spectral_param_properties(spectral);
  3311. /* Init spectral capability */
  3312. if (target_if_init_spectral_capability(spectral, target_type) !=
  3313. QDF_STATUS_SUCCESS) {
  3314. qdf_mem_free(spectral);
  3315. return NULL;
  3316. }
  3317. if (target_if_spectral_attach_simulation(spectral) < 0)
  3318. return NULL;
  3319. target_if_init_spectral_ops(spectral);
  3320. target_if_spectral_timestamp_war_init(&spectral->timestamp_war);
  3321. /* Spectral mode specific init */
  3322. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  3323. spectral->params_valid[smode] = false;
  3324. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  3325. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  3326. }
  3327. target_if_spectral_register_funcs(spectral, &spectral_ops);
  3328. if (target_if_spectral_check_hw_capability(spectral) == false) {
  3329. goto fail;
  3330. } else {
  3331. /*
  3332. * TODO: Once the driver architecture transitions to chipset
  3333. * versioning based checks, reflect this here.
  3334. */
  3335. spectral->is_160_format = false;
  3336. spectral->is_lb_edge_extrabins_format = false;
  3337. spectral->is_rb_edge_extrabins_format = false;
  3338. if (target_type == TARGET_TYPE_QCA9984 ||
  3339. target_type == TARGET_TYPE_QCA9888) {
  3340. spectral->is_160_format = true;
  3341. spectral->is_lb_edge_extrabins_format = true;
  3342. spectral->is_rb_edge_extrabins_format = true;
  3343. } else if ((target_type == TARGET_TYPE_AR900B) &&
  3344. (target_revision == AR900B_REV_2)) {
  3345. spectral->is_rb_edge_extrabins_format = true;
  3346. }
  3347. if (target_type == TARGET_TYPE_QCA9984 ||
  3348. target_type == TARGET_TYPE_QCA9888)
  3349. spectral->is_sec80_rssi_war_required = true;
  3350. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  3351. if (spectral->spectral_gen == SPECTRAL_GEN3)
  3352. init_160mhz_delivery_state_machine(spectral);
  3353. }
  3354. qdf_spinlock_create(&spectral->detector_list_lock);
  3355. qdf_spinlock_create(&spectral->session_report_info_lock);
  3356. qdf_spinlock_create(&spectral->session_det_map_lock);
  3357. return spectral;
  3358. fail:
  3359. target_if_spectral_detach(spectral);
  3360. return NULL;
  3361. }
  3362. /**
  3363. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  3364. * functionality for the given pdev
  3365. * @pdev: Pointer to pdev object
  3366. *
  3367. * Function to de-initialize pointer to spectral target_if internal private data
  3368. *
  3369. * Return: None
  3370. */
  3371. void
  3372. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  3373. {
  3374. struct target_if_spectral *spectral = NULL;
  3375. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3376. if (!spectral) {
  3377. spectral_err("SPECTRAL : Module doesn't exist");
  3378. return;
  3379. }
  3380. target_if_spectral_detach(spectral);
  3381. return;
  3382. }
  3383. /**
  3384. * target_if_psoc_spectral_deinit() - De-initialize target_if Spectral
  3385. * functionality for the given psoc
  3386. * @psoc: Pointer to psoc object
  3387. *
  3388. * Function to de-initialize pointer to psoc spectral target_if internal
  3389. * private data
  3390. *
  3391. * Return: None
  3392. */
  3393. static void
  3394. target_if_psoc_spectral_deinit(struct wlan_objmgr_psoc *psoc)
  3395. {
  3396. struct target_if_psoc_spectral *psoc_spectral;
  3397. if (!psoc) {
  3398. spectral_err("psoc is null");
  3399. return;
  3400. }
  3401. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  3402. if (!psoc_spectral) {
  3403. spectral_err("Spectral target_if psoc object is null");
  3404. return;
  3405. }
  3406. qdf_mem_free(psoc_spectral);
  3407. }
  3408. /**
  3409. * target_if_psoc_spectral_init() - Initialize target_if Spectral
  3410. * functionality for the given psoc
  3411. * @psoc: Pointer to psoc object
  3412. *
  3413. * Function to initialize pointer to psoc spectral target_if internal
  3414. * private data
  3415. *
  3416. * Return: On success, pointer to Spectral psoc target_if internal
  3417. * private data, on failure, NULL
  3418. */
  3419. static void *
  3420. target_if_psoc_spectral_init(struct wlan_objmgr_psoc *psoc)
  3421. {
  3422. struct target_if_psoc_spectral *psoc_spectral = NULL;
  3423. if (!psoc) {
  3424. spectral_err("psoc is null");
  3425. goto fail;
  3426. }
  3427. psoc_spectral = (struct target_if_psoc_spectral *)qdf_mem_malloc(
  3428. sizeof(struct target_if_psoc_spectral));
  3429. if (!psoc_spectral) {
  3430. spectral_err("Spectral lmac psoc object allocation failed");
  3431. goto fail;
  3432. }
  3433. psoc_spectral->psoc_obj = psoc;
  3434. return psoc_spectral;
  3435. fail:
  3436. if (psoc_spectral)
  3437. target_if_psoc_spectral_deinit(psoc);
  3438. return psoc_spectral;
  3439. }
  3440. /**
  3441. * target_if_is_center_freq_of_any_chan() - Check for center frequency
  3442. * @pdev: Pointer to pdev object
  3443. * @chan_freq: Center frequency of a WLAN channel
  3444. * @is_valid: Indicates whether given frequency is valid
  3445. *
  3446. * Helper routine to check whether given frequency is center frequency
  3447. * of a WLAN channel
  3448. *
  3449. * Return: QDF_STATUS
  3450. */
  3451. static QDF_STATUS
  3452. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  3453. uint32_t chan_freq,
  3454. bool *is_valid)
  3455. {
  3456. struct regulatory_channel *cur_chan_list;
  3457. int i;
  3458. if (!pdev) {
  3459. spectral_err("pdev object is null");
  3460. return QDF_STATUS_E_FAILURE;
  3461. }
  3462. if (!is_valid) {
  3463. spectral_err("is valid argument is null");
  3464. return QDF_STATUS_E_FAILURE;
  3465. }
  3466. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  3467. if (!cur_chan_list)
  3468. return QDF_STATUS_E_FAILURE;
  3469. if (wlan_reg_get_current_chan_list(
  3470. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  3471. spectral_err("Failed to get cur_chan list");
  3472. qdf_mem_free(cur_chan_list);
  3473. return QDF_STATUS_E_FAILURE;
  3474. }
  3475. *is_valid = false;
  3476. for (i = 0; i < NUM_CHANNELS; i++) {
  3477. uint32_t flags;
  3478. uint32_t center_freq;
  3479. flags = cur_chan_list[i].chan_flags;
  3480. center_freq = cur_chan_list[i].center_freq;
  3481. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  3482. (center_freq == chan_freq)) {
  3483. *is_valid = true;
  3484. break;
  3485. }
  3486. }
  3487. qdf_mem_free(cur_chan_list);
  3488. return QDF_STATUS_SUCCESS;
  3489. }
  3490. /**
  3491. * target_if_calculate_center_freq() - find center frequency of agile span
  3492. * @spectral: Pointer to Spectral object
  3493. * @ch_width: Channel width array
  3494. * @chan_freq: Center frequency of a WLAN channel
  3495. * @center_freq: Pointer to center frequency
  3496. *
  3497. * Helper routine to find the center frequency of the agile span from
  3498. * a WLAN channel center frequency
  3499. *
  3500. * Return: QDF_STATUS
  3501. */
  3502. static QDF_STATUS
  3503. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  3504. enum phy_ch_width *ch_width,
  3505. uint16_t chan_freq,
  3506. uint16_t *center_freq)
  3507. {
  3508. enum phy_ch_width agile_ch_width;
  3509. if (!spectral) {
  3510. spectral_err("spectral target if object is null");
  3511. return QDF_STATUS_E_FAILURE;
  3512. }
  3513. if (!ch_width) {
  3514. spectral_err("Channel width array is null");
  3515. return QDF_STATUS_E_INVAL;
  3516. }
  3517. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3518. if (!center_freq) {
  3519. spectral_err("center_freq argument is null");
  3520. return QDF_STATUS_E_FAILURE;
  3521. }
  3522. if (agile_ch_width == CH_WIDTH_20MHZ) {
  3523. *center_freq = chan_freq;
  3524. } else {
  3525. uint16_t start_freq;
  3526. uint16_t end_freq;
  3527. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3528. enum channel_state state;
  3529. state = wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3530. (spectral->pdev_obj, chan_freq, agile_ch_width,
  3531. &bonded_chan_ptr, REG_CURRENT_PWR_MODE,
  3532. NO_SCHANS_PUNC);
  3533. if (state == CHANNEL_STATE_DISABLE ||
  3534. state == CHANNEL_STATE_INVALID) {
  3535. spectral_err("Channel state is disable or invalid");
  3536. return QDF_STATUS_E_FAILURE;
  3537. }
  3538. if (!bonded_chan_ptr) {
  3539. spectral_err("Bonded channel is not found");
  3540. return QDF_STATUS_E_FAILURE;
  3541. }
  3542. start_freq = bonded_chan_ptr->start_freq;
  3543. end_freq = bonded_chan_ptr->end_freq;
  3544. *center_freq = (start_freq + end_freq) >> 1;
  3545. }
  3546. return QDF_STATUS_SUCCESS;
  3547. }
  3548. /**
  3549. * target_if_validate_center_freq() - validate agile center frequency
  3550. * @spectral: Pointer to Spectral object
  3551. * @ch_width: Channel width array
  3552. * @center_freq: User provided agile span center frequency
  3553. * @is_valid: Indicates whether agile span center frequency is valid
  3554. *
  3555. * Helper routine to validate user provided agile center frequency
  3556. *
  3557. * Return: QDF_STATUS
  3558. */
  3559. static QDF_STATUS
  3560. target_if_validate_center_freq(struct target_if_spectral *spectral,
  3561. enum phy_ch_width *ch_width,
  3562. uint16_t center_freq,
  3563. bool *is_valid)
  3564. {
  3565. enum phy_ch_width agile_ch_width;
  3566. struct wlan_objmgr_pdev *pdev;
  3567. QDF_STATUS status;
  3568. if (!spectral) {
  3569. spectral_err("spectral target if object is null");
  3570. return QDF_STATUS_E_FAILURE;
  3571. }
  3572. if (!ch_width) {
  3573. spectral_err("channel width array is null");
  3574. return QDF_STATUS_E_INVAL;
  3575. }
  3576. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3577. if (!is_valid) {
  3578. spectral_err("is_valid argument is null");
  3579. return QDF_STATUS_E_FAILURE;
  3580. }
  3581. pdev = spectral->pdev_obj;
  3582. if (agile_ch_width == CH_WIDTH_20MHZ) {
  3583. status = target_if_is_center_freq_of_any_chan
  3584. (pdev, center_freq, is_valid);
  3585. if (QDF_IS_STATUS_ERROR(status))
  3586. return QDF_STATUS_E_FAILURE;
  3587. } else {
  3588. uint16_t start_freq;
  3589. uint16_t end_freq;
  3590. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3591. bool is_chan;
  3592. status = target_if_is_center_freq_of_any_chan
  3593. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  3594. &is_chan);
  3595. if (QDF_IS_STATUS_ERROR(status))
  3596. return QDF_STATUS_E_FAILURE;
  3597. if (is_chan) {
  3598. uint32_t calulated_center_freq;
  3599. enum channel_state st;
  3600. st =
  3601. wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3602. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  3603. agile_ch_width,
  3604. &bonded_chan_ptr,
  3605. REG_CURRENT_PWR_MODE,
  3606. NO_SCHANS_PUNC);
  3607. if (st == CHANNEL_STATE_DISABLE ||
  3608. st == CHANNEL_STATE_INVALID) {
  3609. spectral_err("Channel state disable/invalid");
  3610. return QDF_STATUS_E_FAILURE;
  3611. }
  3612. if (!bonded_chan_ptr) {
  3613. spectral_err("Bonded channel is not found");
  3614. return QDF_STATUS_E_FAILURE;
  3615. }
  3616. start_freq = bonded_chan_ptr->start_freq;
  3617. end_freq = bonded_chan_ptr->end_freq;
  3618. calulated_center_freq = (start_freq + end_freq) >> 1;
  3619. *is_valid = (center_freq == calulated_center_freq);
  3620. } else {
  3621. *is_valid = false;
  3622. }
  3623. }
  3624. return QDF_STATUS_SUCCESS;
  3625. }
  3626. /**
  3627. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  3628. * check whether agile span overlaps with current operating band.
  3629. *
  3630. * @spectral: Pointer to Spectral object
  3631. * @ch_width: Channel width array
  3632. * @center_freq: Agile span center frequency
  3633. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  3634. *
  3635. * Helper routine to check whether agile span overlaps with current
  3636. * operating band.
  3637. *
  3638. * Return: QDF_STATUS
  3639. */
  3640. static QDF_STATUS
  3641. target_if_is_agile_span_overlap_with_operating_span
  3642. (struct target_if_spectral *spectral,
  3643. enum phy_ch_width *ch_width,
  3644. struct spectral_config_frequency *center_freq,
  3645. bool *is_overlapping)
  3646. {
  3647. enum phy_ch_width op_ch_width;
  3648. enum phy_ch_width agile_ch_width;
  3649. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3650. struct wlan_objmgr_vdev *vdev;
  3651. struct wlan_objmgr_pdev *pdev;
  3652. int16_t chan_freq;
  3653. uint32_t op_start_freq;
  3654. uint32_t op_end_freq;
  3655. uint32_t agile_start_freq;
  3656. uint32_t agile_end_freq;
  3657. uint32_t cfreq2;
  3658. if (!spectral) {
  3659. spectral_err("spectral object is NULL");
  3660. return QDF_STATUS_E_FAILURE;
  3661. }
  3662. pdev = spectral->pdev_obj;
  3663. if (!pdev) {
  3664. spectral_err("pdev object is NULL");
  3665. return QDF_STATUS_E_FAILURE;
  3666. }
  3667. if (!ch_width) {
  3668. spectral_err("channel width array is null");
  3669. return QDF_STATUS_E_FAILURE;
  3670. }
  3671. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  3672. if (op_ch_width == CH_WIDTH_INVALID) {
  3673. spectral_err("Invalid channel width");
  3674. return QDF_STATUS_E_INVAL;
  3675. }
  3676. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3677. if (agile_ch_width == CH_WIDTH_INVALID) {
  3678. spectral_err("Invalid channel width");
  3679. return QDF_STATUS_E_INVAL;
  3680. }
  3681. if (!is_overlapping) {
  3682. spectral_err("Argument(is_overlapping) is NULL");
  3683. return QDF_STATUS_E_FAILURE;
  3684. }
  3685. *is_overlapping = false;
  3686. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  3687. if (!vdev) {
  3688. spectral_err("vdev is NULL");
  3689. return QDF_STATUS_E_FAILURE;
  3690. }
  3691. chan_freq = target_if_vdev_get_chan_freq(vdev);
  3692. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  3693. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3694. if (cfreq2 < 0) {
  3695. spectral_err("cfreq2 is invalid");
  3696. return QDF_STATUS_E_FAILURE;
  3697. }
  3698. if (op_ch_width == CH_WIDTH_20MHZ) {
  3699. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  3700. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  3701. } else {
  3702. enum channel_state state;
  3703. state = wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3704. (pdev, chan_freq, op_ch_width, &bonded_chan_ptr,
  3705. REG_CURRENT_PWR_MODE, NO_SCHANS_PUNC);
  3706. if (state == CHANNEL_STATE_DISABLE ||
  3707. state == CHANNEL_STATE_INVALID) {
  3708. spectral_err("Channel state is disable or invalid");
  3709. return QDF_STATUS_E_FAILURE;
  3710. }
  3711. if (!bonded_chan_ptr) {
  3712. spectral_err("Bonded channel is not found");
  3713. return QDF_STATUS_E_FAILURE;
  3714. }
  3715. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  3716. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  3717. }
  3718. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3719. agile_start_freq = center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3720. agile_end_freq = center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3721. if (agile_end_freq > op_start_freq &&
  3722. op_end_freq > agile_start_freq)
  3723. *is_overlapping = true;
  3724. agile_start_freq = center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3725. agile_end_freq = center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3726. if (agile_end_freq > op_start_freq &&
  3727. op_end_freq > agile_start_freq)
  3728. *is_overlapping = true;
  3729. } else {
  3730. agile_start_freq = center_freq->cfreq1 -
  3731. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3732. agile_end_freq = center_freq->cfreq1 +
  3733. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3734. if (agile_end_freq > op_start_freq &&
  3735. op_end_freq > agile_start_freq)
  3736. *is_overlapping = true;
  3737. }
  3738. if (op_ch_width == CH_WIDTH_80P80MHZ) {
  3739. uint32_t sec80_start_feq;
  3740. uint32_t sec80_end_freq;
  3741. sec80_start_feq = cfreq2 - FREQ_OFFSET_40MHZ;
  3742. sec80_end_freq = cfreq2 + FREQ_OFFSET_40MHZ;
  3743. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3744. agile_start_freq =
  3745. center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3746. agile_end_freq =
  3747. center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3748. if (agile_end_freq > sec80_start_feq &&
  3749. sec80_end_freq > agile_start_freq)
  3750. *is_overlapping = true;
  3751. agile_start_freq =
  3752. center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3753. agile_end_freq =
  3754. center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3755. if (agile_end_freq > sec80_start_feq &&
  3756. sec80_end_freq > agile_start_freq)
  3757. *is_overlapping = true;
  3758. } else {
  3759. agile_start_freq = center_freq->cfreq1 -
  3760. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3761. agile_end_freq = center_freq->cfreq1 +
  3762. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3763. if (agile_end_freq > sec80_start_feq &&
  3764. sec80_end_freq > agile_start_freq)
  3765. *is_overlapping = true;
  3766. }
  3767. }
  3768. return QDF_STATUS_SUCCESS;
  3769. }
  3770. /**
  3771. * target_if_spectral_populate_chwidth() - Helper routine to
  3772. * populate channel width for different Spectral modes
  3773. *
  3774. * @spectral: Pointer to Spectral object
  3775. * @ch_width: Channel width array
  3776. * @is_80_80_agile: Indicates whether 80+80 agile scan is requested
  3777. *
  3778. * Helper routine to populate channel width for different Spectral modes
  3779. *
  3780. * Return: QDF_STATUS
  3781. */
  3782. static QDF_STATUS
  3783. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral,
  3784. enum phy_ch_width *ch_width,
  3785. bool is_80_80_agile)
  3786. {
  3787. enum spectral_scan_mode smode;
  3788. if (!spectral) {
  3789. spectral_err("Spectral variable is null");
  3790. return QDF_STATUS_E_NULL_VALUE;
  3791. }
  3792. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3793. for (; smode < SPECTRAL_SCAN_MODE_MAX; ++smode) {
  3794. /* If user has configured sscan bandwidth, use it */
  3795. if (spectral->sscan_width_configured[smode]) {
  3796. ch_width[smode] = spectral->params[smode].ss_bandwidth;
  3797. } else {
  3798. /* Otherwise, derive the default sscan bandwidth */
  3799. ch_width[smode] = get_default_sscan_bw(spectral, smode,
  3800. is_80_80_agile);
  3801. if (ch_width[smode] >= CH_WIDTH_INVALID) {
  3802. spectral_err("Invalid sscan BW %u",
  3803. ch_width[smode]);
  3804. return QDF_STATUS_E_FAILURE;
  3805. }
  3806. spectral->params[smode].ss_bandwidth = ch_width[smode];
  3807. }
  3808. }
  3809. return QDF_STATUS_SUCCESS;
  3810. }
  3811. /**
  3812. * target_if_spectral_is_valid_80p80_freq() - API to check whether given
  3813. * (cfreq1, cfreq2) pair forms a valid 80+80 combination
  3814. * @pdev: pointer to pdev
  3815. * @cfreq1: center frequency 1
  3816. * @cfreq2: center frequency 2
  3817. * @is_valid: Indicates weather the frequency is valid
  3818. *
  3819. * API to check whether given (cfreq1, cfreq2) pair forms a valid 80+80
  3820. * combination
  3821. *
  3822. * Return: QDF_Status
  3823. */
  3824. static QDF_STATUS
  3825. target_if_spectral_is_valid_80p80_freq(struct wlan_objmgr_pdev *pdev,
  3826. uint32_t cfreq1, uint32_t cfreq2,
  3827. bool *is_valid)
  3828. {
  3829. struct ch_params ch_params = {0};
  3830. enum channel_state chan_state1;
  3831. enum channel_state chan_state2;
  3832. struct wlan_objmgr_psoc *psoc;
  3833. struct ch_params temp_params = {0};
  3834. if (!is_valid) {
  3835. spectral_err("Argument(is_valid) is null");
  3836. return QDF_STATUS_E_NULL_VALUE;
  3837. }
  3838. if (!pdev) {
  3839. spectral_err("pdev is null.");
  3840. return QDF_STATUS_E_NULL_VALUE;
  3841. }
  3842. psoc = wlan_pdev_get_psoc(pdev);
  3843. if (!psoc) {
  3844. spectral_err("psoc is null.");
  3845. return QDF_STATUS_E_NULL_VALUE;
  3846. }
  3847. /* In restricted 80P80 MHz enabled, only one 80+80 MHz
  3848. * channel is supported with cfreq=5690 and cfreq=5775.
  3849. */
  3850. if (wlan_psoc_nif_fw_ext_cap_get(
  3851. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  3852. *is_valid = CHAN_WITHIN_RESTRICTED_80P80(cfreq1, cfreq2);
  3853. return QDF_STATUS_SUCCESS;
  3854. }
  3855. ch_params.center_freq_seg1 = wlan_reg_freq_to_chan(pdev, cfreq2);
  3856. ch_params.mhz_freq_seg1 = cfreq2;
  3857. ch_params.ch_width = CH_WIDTH_80P80MHZ;
  3858. wlan_reg_set_channel_params_for_pwrmode(
  3859. pdev,
  3860. cfreq1 - FREQ_OFFSET_10MHZ,
  3861. 0,
  3862. &ch_params,
  3863. REG_CURRENT_PWR_MODE);
  3864. if (ch_params.ch_width != CH_WIDTH_80P80MHZ) {
  3865. *is_valid = false;
  3866. return QDF_STATUS_SUCCESS;
  3867. }
  3868. if (ch_params.mhz_freq_seg0 != cfreq1 ||
  3869. ch_params.mhz_freq_seg1 != cfreq2) {
  3870. *is_valid = false;
  3871. return QDF_STATUS_SUCCESS;
  3872. }
  3873. temp_params.ch_width = CH_WIDTH_80MHZ;
  3874. chan_state1 = wlan_reg_get_5g_bonded_channel_state_for_pwrmode(
  3875. pdev,
  3876. ch_params.mhz_freq_seg0 - FREQ_OFFSET_10MHZ,
  3877. &temp_params,
  3878. REG_CURRENT_PWR_MODE);
  3879. if ((chan_state1 == CHANNEL_STATE_DISABLE) ||
  3880. (chan_state1 == CHANNEL_STATE_INVALID)) {
  3881. *is_valid = false;
  3882. return QDF_STATUS_SUCCESS;
  3883. }
  3884. temp_params.ch_width = CH_WIDTH_80MHZ;
  3885. chan_state2 = wlan_reg_get_5g_bonded_channel_state_for_pwrmode(
  3886. pdev,
  3887. ch_params.mhz_freq_seg1 - FREQ_OFFSET_10MHZ,
  3888. &temp_params,
  3889. REG_CURRENT_PWR_MODE);
  3890. if ((chan_state2 == CHANNEL_STATE_DISABLE) ||
  3891. (chan_state2 == CHANNEL_STATE_INVALID)) {
  3892. *is_valid = false;
  3893. return QDF_STATUS_SUCCESS;
  3894. }
  3895. if (abs(ch_params.mhz_freq_seg0 - ch_params.mhz_freq_seg1) <=
  3896. FREQ_OFFSET_80MHZ) {
  3897. *is_valid = false;
  3898. return QDF_STATUS_SUCCESS;
  3899. }
  3900. *is_valid = true;
  3901. return QDF_STATUS_SUCCESS;
  3902. }
  3903. /**
  3904. * _target_if_set_spectral_config() - Set spectral config
  3905. * @spectral: Pointer to spectral object
  3906. * @param: Spectral parameter id and value
  3907. * @smode: Spectral scan mode
  3908. * @err: Spectral error code
  3909. *
  3910. * API to set spectral configurations
  3911. *
  3912. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3913. */
  3914. static QDF_STATUS
  3915. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  3916. const struct spectral_cp_param *param,
  3917. const enum spectral_scan_mode smode,
  3918. enum spectral_cp_error_code *err)
  3919. {
  3920. struct spectral_config params;
  3921. struct target_if_spectral_ops *p_sops;
  3922. struct spectral_config *sparams;
  3923. QDF_STATUS status;
  3924. bool is_overlapping;
  3925. uint16_t agile_cfreq;
  3926. bool is_valid_chan;
  3927. struct spectral_param_min_max *param_min_max;
  3928. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  3929. enum spectral_scan_mode m;
  3930. struct spectral_config_frequency center_freq = {0};
  3931. bool is_bw_supported;
  3932. struct wlan_objmgr_vdev *vdev;
  3933. enum phy_ch_width op_bw;
  3934. if (!err) {
  3935. spectral_err("Error code argument is null");
  3936. return QDF_STATUS_E_NULL_VALUE;
  3937. }
  3938. *err = SPECTRAL_SCAN_ERR_INVALID;
  3939. if (!param) {
  3940. spectral_err("Parameter object is null");
  3941. return QDF_STATUS_E_FAILURE;
  3942. }
  3943. if (!spectral) {
  3944. spectral_err("spectral object is NULL");
  3945. return QDF_STATUS_E_FAILURE;
  3946. }
  3947. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3948. param_min_max = &spectral->param_min_max;
  3949. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3950. spectral_err("Invalid Spectral mode %u", smode);
  3951. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3952. return QDF_STATUS_E_FAILURE;
  3953. }
  3954. sparams = &spectral->params[smode];
  3955. m = SPECTRAL_SCAN_MODE_NORMAL;
  3956. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  3957. ch_width[m] = CH_WIDTH_INVALID;
  3958. if (!spectral->params_valid[smode]) {
  3959. target_if_spectral_info_read(spectral,
  3960. smode,
  3961. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3962. &spectral->params[smode],
  3963. sizeof(spectral->params[smode]));
  3964. spectral->params_valid[smode] = true;
  3965. }
  3966. switch (param->id) {
  3967. case SPECTRAL_PARAM_FFT_PERIOD:
  3968. sparams->ss_fft_period = param->value;
  3969. break;
  3970. case SPECTRAL_PARAM_SCAN_PERIOD:
  3971. sparams->ss_period = param->value;
  3972. if (sparams->ss_recapture && ((sparams->ss_period <
  3973. SPECTRAL_RECAPTURE_SCAN_PERIOD_THRESHOLD) ||
  3974. (smode == SPECTRAL_SCAN_MODE_AGILE))) {
  3975. sparams->ss_recapture = false;
  3976. spectral_err("FFT recapture cannot be enabled due to scan period: %d us or spectral scan mode: %d",
  3977. sparams->ss_period, smode);
  3978. }
  3979. break;
  3980. case SPECTRAL_PARAM_FFT_RECAPTURE:
  3981. if (param->value) {
  3982. if (sparams->ss_period >=
  3983. SPECTRAL_RECAPTURE_SCAN_PERIOD_THRESHOLD &&
  3984. smode == SPECTRAL_SCAN_MODE_NORMAL) {
  3985. sparams->ss_recapture = true;
  3986. } else {
  3987. spectral_err("FFT recapture cannot be enabled due to scan period: %d us or spectral scan mode: %d",
  3988. sparams->ss_period, smode);
  3989. sparams->ss_recapture = false;
  3990. }
  3991. } else {
  3992. sparams->ss_recapture = false;
  3993. }
  3994. break;
  3995. case SPECTRAL_PARAM_SCAN_COUNT:
  3996. if (param->value > param_min_max->scan_count_max) {
  3997. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3998. return QDF_STATUS_E_FAILURE;
  3999. }
  4000. sparams->ss_count = param->value;
  4001. break;
  4002. case SPECTRAL_PARAM_SHORT_REPORT:
  4003. sparams->ss_short_report = (!!param->value) ? true : false;
  4004. break;
  4005. case SPECTRAL_PARAM_SPECT_PRI:
  4006. sparams->ss_spectral_pri = (!!param->value) ? true : false;
  4007. break;
  4008. case SPECTRAL_PARAM_FFT_SIZE:
  4009. status = target_if_spectral_populate_chwidth
  4010. (spectral, ch_width, spectral->params
  4011. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  4012. if (QDF_IS_STATUS_ERROR(status))
  4013. return QDF_STATUS_E_FAILURE;
  4014. if ((param->value < param_min_max->fft_size_min) ||
  4015. (param->value > param_min_max->fft_size_max
  4016. [ch_width[smode]])) {
  4017. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4018. return QDF_STATUS_E_FAILURE;
  4019. }
  4020. sparams->ss_fft_size = param->value;
  4021. break;
  4022. case SPECTRAL_PARAM_GC_ENA:
  4023. sparams->ss_gc_ena = !!param->value;
  4024. break;
  4025. case SPECTRAL_PARAM_RESTART_ENA:
  4026. sparams->ss_restart_ena = !!param->value;
  4027. break;
  4028. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  4029. sparams->ss_noise_floor_ref = param->value;
  4030. break;
  4031. case SPECTRAL_PARAM_INIT_DELAY:
  4032. sparams->ss_init_delay = param->value;
  4033. break;
  4034. case SPECTRAL_PARAM_NB_TONE_THR:
  4035. sparams->ss_nb_tone_thr = param->value;
  4036. break;
  4037. case SPECTRAL_PARAM_STR_BIN_THR:
  4038. sparams->ss_str_bin_thr = param->value;
  4039. break;
  4040. case SPECTRAL_PARAM_WB_RPT_MODE:
  4041. sparams->ss_wb_rpt_mode = !!param->value;
  4042. break;
  4043. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  4044. sparams->ss_rssi_rpt_mode = !!param->value;
  4045. break;
  4046. case SPECTRAL_PARAM_RSSI_THR:
  4047. sparams->ss_rssi_thr = param->value;
  4048. break;
  4049. case SPECTRAL_PARAM_PWR_FORMAT:
  4050. sparams->ss_pwr_format = !!param->value;
  4051. break;
  4052. case SPECTRAL_PARAM_RPT_MODE:
  4053. if ((param->value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  4054. (param->value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  4055. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4056. return QDF_STATUS_E_FAILURE;
  4057. }
  4058. sparams->ss_rpt_mode = param->value;
  4059. break;
  4060. case SPECTRAL_PARAM_BIN_SCALE:
  4061. sparams->ss_bin_scale = param->value;
  4062. break;
  4063. case SPECTRAL_PARAM_DBM_ADJ:
  4064. sparams->ss_dbm_adj = !!param->value;
  4065. break;
  4066. case SPECTRAL_PARAM_CHN_MASK:
  4067. sparams->ss_chn_mask = param->value;
  4068. break;
  4069. case SPECTRAL_PARAM_FREQUENCY:
  4070. status = target_if_spectral_populate_chwidth(
  4071. spectral, ch_width, param->freq.cfreq2 > 0);
  4072. if (QDF_IS_STATUS_ERROR(status)) {
  4073. spectral_err("Failed to populate channel width");
  4074. return QDF_STATUS_E_FAILURE;
  4075. }
  4076. if (ch_width[smode] != CH_WIDTH_80P80MHZ &&
  4077. param->freq.cfreq2) {
  4078. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4079. spectral_err("Non zero cfreq2 expected for 80p80 only");
  4080. return QDF_STATUS_E_INVAL;
  4081. }
  4082. if (ch_width[smode] == CH_WIDTH_80P80MHZ &&
  4083. !param->freq.cfreq2) {
  4084. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4085. spectral_err("Non zero cfreq2 expected for 80p80");
  4086. return QDF_STATUS_E_INVAL;
  4087. }
  4088. status = target_if_is_center_freq_of_any_chan
  4089. (spectral->pdev_obj, param->freq.cfreq1,
  4090. &is_valid_chan);
  4091. if (QDF_IS_STATUS_ERROR(status))
  4092. return QDF_STATUS_E_FAILURE;
  4093. if (is_valid_chan) {
  4094. status = target_if_calculate_center_freq(
  4095. spectral, ch_width,
  4096. param->freq.cfreq1,
  4097. &agile_cfreq);
  4098. if (QDF_IS_STATUS_ERROR(status)) {
  4099. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4100. return QDF_STATUS_E_FAILURE;
  4101. }
  4102. } else {
  4103. bool is_valid_agile_cfreq;
  4104. status = target_if_validate_center_freq
  4105. (spectral, ch_width, param->freq.cfreq1,
  4106. &is_valid_agile_cfreq);
  4107. if (QDF_IS_STATUS_ERROR(status))
  4108. return QDF_STATUS_E_FAILURE;
  4109. if (!is_valid_agile_cfreq) {
  4110. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4111. spectral_err("Invalid agile center frequency");
  4112. return QDF_STATUS_E_FAILURE;
  4113. }
  4114. agile_cfreq = param->freq.cfreq1;
  4115. }
  4116. center_freq.cfreq1 = agile_cfreq;
  4117. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  4118. status = target_if_is_center_freq_of_any_chan
  4119. (spectral->pdev_obj, param->freq.cfreq2,
  4120. &is_valid_chan);
  4121. if (QDF_IS_STATUS_ERROR(status))
  4122. return QDF_STATUS_E_FAILURE;
  4123. if (is_valid_chan) {
  4124. status = target_if_calculate_center_freq(
  4125. spectral, ch_width,
  4126. param->freq.cfreq2,
  4127. &agile_cfreq);
  4128. if (QDF_IS_STATUS_ERROR(status)) {
  4129. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4130. return QDF_STATUS_E_FAILURE;
  4131. }
  4132. } else {
  4133. bool is_valid_agile_cfreq;
  4134. status = target_if_validate_center_freq
  4135. (spectral, ch_width, param->freq.cfreq2,
  4136. &is_valid_agile_cfreq);
  4137. if (QDF_IS_STATUS_ERROR(status))
  4138. return QDF_STATUS_E_FAILURE;
  4139. if (!is_valid_agile_cfreq) {
  4140. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4141. spectral_err("Invalid agile center frequency");
  4142. return QDF_STATUS_E_FAILURE;
  4143. }
  4144. agile_cfreq = param->freq.cfreq2;
  4145. }
  4146. center_freq.cfreq2 = agile_cfreq;
  4147. }
  4148. status = target_if_is_agile_span_overlap_with_operating_span
  4149. (spectral, ch_width,
  4150. &center_freq, &is_overlapping);
  4151. if (QDF_IS_STATUS_ERROR(status))
  4152. return QDF_STATUS_E_FAILURE;
  4153. if (is_overlapping) {
  4154. spectral_err("Agile freq %u, %u overlaps with operating span",
  4155. center_freq.cfreq1, center_freq.cfreq2);
  4156. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4157. return QDF_STATUS_E_FAILURE;
  4158. }
  4159. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  4160. bool is_valid_80p80;
  4161. status = target_if_spectral_is_valid_80p80_freq(
  4162. spectral->pdev_obj,
  4163. center_freq.cfreq1,
  4164. center_freq.cfreq2,
  4165. &is_valid_80p80);
  4166. if (QDF_IS_STATUS_ERROR(status))
  4167. return status;
  4168. if (!is_valid_80p80) {
  4169. spectral_err("Agile freq %u, %u is invalid 80+80 combination",
  4170. center_freq.cfreq1,
  4171. center_freq.cfreq2);
  4172. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4173. return QDF_STATUS_E_FAILURE;
  4174. }
  4175. }
  4176. sparams->ss_frequency.cfreq1 = center_freq.cfreq1;
  4177. sparams->ss_frequency.cfreq2 = center_freq.cfreq2;
  4178. break;
  4179. case SPECTRAL_PARAM_CHAN_WIDTH:
  4180. if (param->value >= CH_WIDTH_INVALID) {
  4181. spectral_err("invalid sscan width: %u", param->value);
  4182. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4183. return QDF_STATUS_E_FAILURE;
  4184. }
  4185. vdev = target_if_spectral_get_vdev(spectral, smode);
  4186. if (!vdev) {
  4187. spectral_err("vdev is null");
  4188. return QDF_STATUS_E_NULL_VALUE;
  4189. }
  4190. op_bw = target_if_vdev_get_ch_width(vdev);
  4191. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4192. /* Validate the bandwidth */
  4193. status = target_if_is_sscan_bw_supported(
  4194. spectral, smode,
  4195. param->value, op_bw, &is_bw_supported,
  4196. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  4197. ss_frequency.cfreq2 > 0);
  4198. if (QDF_IS_STATUS_ERROR(status)) {
  4199. spectral_err("Unable to check if given sscan_bw is supported");
  4200. return QDF_STATUS_E_FAILURE;
  4201. }
  4202. if (!is_bw_supported) {
  4203. spectral_err("sscan bw(%u) is not supported for the current operating width(%u) and sscan mode(%u)",
  4204. param->value, op_bw, smode);
  4205. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4206. return QDF_STATUS_E_FAILURE;
  4207. }
  4208. sparams->ss_bandwidth = param->value;
  4209. spectral->sscan_width_configured[smode] = true;
  4210. break;
  4211. }
  4212. p_sops->configure_spectral(spectral, sparams, smode);
  4213. /* only to validate the writes */
  4214. p_sops->get_spectral_config(spectral, &params, smode);
  4215. return QDF_STATUS_SUCCESS;
  4216. }
  4217. QDF_STATUS
  4218. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  4219. const struct spectral_cp_param *param,
  4220. const enum spectral_scan_mode smode,
  4221. enum spectral_cp_error_code *err)
  4222. {
  4223. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  4224. struct target_if_spectral *spectral;
  4225. QDF_STATUS status;
  4226. if (!err) {
  4227. spectral_err("Error code argument is null");
  4228. return QDF_STATUS_E_NULL_VALUE;
  4229. }
  4230. *err = SPECTRAL_SCAN_ERR_INVALID;
  4231. if (!pdev) {
  4232. spectral_err("pdev object is NULL");
  4233. return QDF_STATUS_E_FAILURE;
  4234. }
  4235. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4236. if (!spectral) {
  4237. spectral_err("spectral object is NULL");
  4238. return QDF_STATUS_E_FAILURE;
  4239. }
  4240. if (!param) {
  4241. spectral_err("parameter object is NULL");
  4242. return QDF_STATUS_E_FAILURE;
  4243. }
  4244. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4245. spectral_err("Invalid Spectral mode %u", smode);
  4246. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4247. return QDF_STATUS_E_FAILURE;
  4248. }
  4249. if (!spectral->properties[smode][param->id].supported) {
  4250. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  4251. param->id, smode);
  4252. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  4253. return QDF_STATUS_E_FAILURE;
  4254. }
  4255. if (spectral->properties[smode][param->id].common_all_modes) {
  4256. spectral_warn("Setting Spectral parameter %u for all modes",
  4257. param->id);
  4258. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  4259. status = _target_if_set_spectral_config
  4260. (spectral, param, mode, err);
  4261. if (QDF_IS_STATUS_ERROR(status))
  4262. return QDF_STATUS_E_FAILURE;
  4263. }
  4264. return QDF_STATUS_SUCCESS;
  4265. }
  4266. return _target_if_set_spectral_config(spectral, param, smode, err);
  4267. }
  4268. /**
  4269. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  4270. * @fft_len: FFT length
  4271. *
  4272. * API to get fft bin count for a given fft length
  4273. *
  4274. * Return: FFt bin count
  4275. */
  4276. static int
  4277. target_if_get_fft_bin_count(int fft_len)
  4278. {
  4279. int bin_count = 0;
  4280. switch (fft_len) {
  4281. case 5:
  4282. bin_count = 16;
  4283. break;
  4284. case 6:
  4285. bin_count = 32;
  4286. break;
  4287. case 7:
  4288. bin_count = 64;
  4289. break;
  4290. case 8:
  4291. bin_count = 128;
  4292. break;
  4293. case 9:
  4294. bin_count = 256;
  4295. break;
  4296. default:
  4297. break;
  4298. }
  4299. return bin_count;
  4300. }
  4301. /**
  4302. * target_if_init_upper_lower_flags() - Initializes control and extension
  4303. * segment flags
  4304. * @spectral: pointer to target if spectral object
  4305. * @smode: Spectral scan mode
  4306. *
  4307. * API to initialize the control and extension flags with the lower/upper
  4308. * segment based on the HT mode
  4309. *
  4310. * Return: FFt bin count
  4311. */
  4312. static void
  4313. target_if_init_upper_lower_flags(struct target_if_spectral *spectral,
  4314. enum spectral_scan_mode smode)
  4315. {
  4316. int current_channel = 0;
  4317. int ext_channel = 0;
  4318. struct target_if_spectral_ops *p_sops =
  4319. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4320. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4321. spectral_err("Invalid Spectral mode %u", smode);
  4322. return;
  4323. }
  4324. current_channel = p_sops->get_current_channel(spectral, smode);
  4325. ext_channel = p_sops->get_extension_channel(spectral, smode);
  4326. if ((current_channel == 0) || (ext_channel == 0))
  4327. return;
  4328. if (spectral->sc_spectral_20_40_mode) {
  4329. /* HT40 mode */
  4330. if (ext_channel < current_channel) {
  4331. spectral->lower_is_extension = 1;
  4332. spectral->upper_is_control = 1;
  4333. spectral->lower_is_control = 0;
  4334. spectral->upper_is_extension = 0;
  4335. } else {
  4336. spectral->lower_is_extension = 0;
  4337. spectral->upper_is_control = 0;
  4338. spectral->lower_is_control = 1;
  4339. spectral->upper_is_extension = 1;
  4340. }
  4341. } else {
  4342. /* HT20 mode, lower is always control */
  4343. spectral->lower_is_extension = 0;
  4344. spectral->upper_is_control = 0;
  4345. spectral->lower_is_control = 1;
  4346. spectral->upper_is_extension = 0;
  4347. }
  4348. }
  4349. /**
  4350. * target_if_get_spectral_config() - Get spectral configuration
  4351. * @pdev: Pointer to pdev object
  4352. * @param: Pointer to spectral_config structure in which the configuration
  4353. * should be returned
  4354. * @smode: Spectral scan mode
  4355. *
  4356. * API to get the current spectral configuration
  4357. *
  4358. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4359. */
  4360. QDF_STATUS
  4361. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  4362. struct spectral_config *param,
  4363. enum spectral_scan_mode smode)
  4364. {
  4365. struct target_if_spectral_ops *p_sops = NULL;
  4366. struct target_if_spectral *spectral = NULL;
  4367. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4368. if (!spectral) {
  4369. spectral_err("SPECTRAL : Module doesn't exist");
  4370. return QDF_STATUS_E_FAILURE;
  4371. }
  4372. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4373. if (!p_sops) {
  4374. spectral_err("p_sops is null");
  4375. return QDF_STATUS_E_FAILURE;
  4376. }
  4377. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4378. spectral_err("Invalid Spectral mode %u", smode);
  4379. return QDF_STATUS_E_FAILURE;
  4380. }
  4381. qdf_mem_zero(param, sizeof(struct spectral_config));
  4382. p_sops->get_spectral_config(spectral, param, smode);
  4383. return QDF_STATUS_SUCCESS;
  4384. }
  4385. #ifdef WLAN_FEATURE_11BE
  4386. /**
  4387. * target_if_spectral_get_num_detectors_for_higher_bws() - Get number of
  4388. * Spectral detectors for higher bandwidths
  4389. * @spectral: Pointer to target if Spectral object
  4390. * @ch_width: channel width
  4391. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  4392. *
  4393. * API to get number of Spectral detectors used for scan in the given channel
  4394. * width.
  4395. *
  4396. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  4397. */
  4398. static QDF_STATUS
  4399. target_if_spectral_get_num_detectors_for_higher_bws(
  4400. struct target_if_spectral *spectral,
  4401. enum phy_ch_width ch_width,
  4402. uint32_t *num_detectors)
  4403. {
  4404. switch (ch_width) {
  4405. case CH_WIDTH_320MHZ:
  4406. *num_detectors = spectral->capability.num_detectors_320mhz;
  4407. break;
  4408. default:
  4409. spectral_err("Unsupported channel width %d", ch_width);
  4410. return QDF_STATUS_E_INVAL;
  4411. }
  4412. return QDF_STATUS_SUCCESS;
  4413. }
  4414. #else
  4415. static QDF_STATUS
  4416. target_if_spectral_get_num_detectors_for_higher_bws(
  4417. struct target_if_spectral *spectral,
  4418. enum phy_ch_width ch_width,
  4419. uint32_t *num_detectors)
  4420. {
  4421. spectral_err("Unsupported channel width %d", ch_width);
  4422. return QDF_STATUS_E_INVAL;
  4423. }
  4424. #endif
  4425. /**
  4426. * target_if_spectral_get_num_detectors() - Get number of Spectral detectors
  4427. * @spectral: Pointer to target if Spectral object
  4428. * @ch_width: channel width
  4429. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  4430. *
  4431. * API to get number of Spectral detectors used for scan in the given channel
  4432. * width.
  4433. *
  4434. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  4435. */
  4436. static QDF_STATUS
  4437. target_if_spectral_get_num_detectors(struct target_if_spectral *spectral,
  4438. enum phy_ch_width ch_width,
  4439. uint32_t *num_detectors)
  4440. {
  4441. if (!spectral) {
  4442. spectral_err("target if spectral object is null");
  4443. return QDF_STATUS_E_INVAL;
  4444. }
  4445. if (ch_width >= CH_WIDTH_INVALID) {
  4446. spectral_err("Invalid channel width %d", ch_width);
  4447. return QDF_STATUS_E_INVAL;
  4448. }
  4449. if (!num_detectors) {
  4450. spectral_err("Invalid argument, number of detectors");
  4451. return QDF_STATUS_E_INVAL;
  4452. }
  4453. switch (ch_width) {
  4454. case CH_WIDTH_20MHZ:
  4455. *num_detectors = spectral->capability.num_detectors_20mhz;
  4456. break;
  4457. case CH_WIDTH_40MHZ:
  4458. *num_detectors = spectral->capability.num_detectors_40mhz;
  4459. break;
  4460. case CH_WIDTH_80MHZ:
  4461. *num_detectors = spectral->capability.num_detectors_80mhz;
  4462. break;
  4463. case CH_WIDTH_160MHZ:
  4464. *num_detectors = spectral->capability.num_detectors_160mhz;
  4465. break;
  4466. case CH_WIDTH_80P80MHZ:
  4467. *num_detectors = spectral->capability.num_detectors_80p80mhz;
  4468. break;
  4469. default:
  4470. return target_if_spectral_get_num_detectors_for_higher_bws(
  4471. spectral, ch_width, num_detectors);
  4472. }
  4473. return QDF_STATUS_SUCCESS;
  4474. }
  4475. /**
  4476. * target_if_spectral_finite_scan_init() - Initializations required for finite
  4477. * Spectral scan
  4478. * @spectral: Pointer to target of Spctral object
  4479. * @smode: Spectral scan mode
  4480. *
  4481. * This routine initializes the finite Spectral scan. Finite Spectral scan is
  4482. * triggered by configuring a non zero scan count.
  4483. *
  4484. * Return: QDF_STATUS_SUCCESS on success
  4485. */
  4486. static QDF_STATUS
  4487. target_if_spectral_finite_scan_init(struct target_if_spectral *spectral,
  4488. enum spectral_scan_mode smode)
  4489. {
  4490. struct target_if_finite_spectral_scan_params *finite_scan;
  4491. enum phy_ch_width ch_width;
  4492. uint32_t num_detectors;
  4493. QDF_STATUS status;
  4494. uint16_t sscan_count;
  4495. if (!spectral) {
  4496. spectral_err("target if spectral object is null");
  4497. return QDF_STATUS_E_INVAL;
  4498. }
  4499. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4500. spectral_err("Invalid Spectral mode");
  4501. return QDF_STATUS_E_INVAL;
  4502. }
  4503. ch_width = spectral->ch_width[smode];
  4504. status = target_if_spectral_get_num_detectors(spectral, ch_width,
  4505. &num_detectors);
  4506. if (QDF_IS_STATUS_ERROR(status)) {
  4507. spectral_err("Failed to get number of detectors");
  4508. return QDF_STATUS_E_FAILURE;
  4509. }
  4510. finite_scan = &spectral->finite_scan[smode];
  4511. sscan_count = spectral->params[smode].ss_count;
  4512. finite_scan->finite_spectral_scan = true;
  4513. finite_scan->num_reports_expected = num_detectors * sscan_count;
  4514. return QDF_STATUS_SUCCESS;
  4515. }
  4516. /**
  4517. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  4518. * parameters
  4519. * @spectral: Pointer to Spectral target_if internal private data
  4520. * @spectral_params: Pointer to Spectral parameters
  4521. * @smode: Spectral scan mode
  4522. * @err: Spectral error code
  4523. *
  4524. * Enable use of desired Spectral parameters by configuring them into HW, and
  4525. * starting Spectral scan
  4526. *
  4527. * Return: 0 on success, 1 on failure
  4528. */
  4529. int
  4530. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  4531. struct spectral_config *spectral_params,
  4532. enum spectral_scan_mode smode,
  4533. enum spectral_cp_error_code *err)
  4534. {
  4535. int extension_channel = 0;
  4536. int current_channel = 0;
  4537. struct target_if_spectral_ops *p_sops = NULL;
  4538. QDF_STATUS status;
  4539. struct wlan_objmgr_pdev *pdev;
  4540. struct wlan_objmgr_psoc *psoc;
  4541. if (!spectral) {
  4542. spectral_err("Spectral LMAC object is NULL");
  4543. return 1;
  4544. }
  4545. pdev = spectral->pdev_obj;
  4546. if (!pdev) {
  4547. spectral_err("pdev is null");
  4548. return QDF_STATUS_E_INVAL;
  4549. }
  4550. psoc = wlan_pdev_get_psoc(pdev);
  4551. if (!psoc) {
  4552. spectral_err("psoc is null");
  4553. return QDF_STATUS_E_INVAL;
  4554. }
  4555. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4556. spectral_err("Invalid Spectral mode %u", smode);
  4557. return 1;
  4558. }
  4559. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4560. if (!p_sops) {
  4561. spectral_err("p_sops is NULL");
  4562. return 1;
  4563. }
  4564. spectral->sc_spectral_noise_pwr_cal =
  4565. spectral_params->ss_spectral_pri ? 1 : 0;
  4566. /* check if extension channel is present */
  4567. extension_channel = p_sops->get_extension_channel(spectral, smode);
  4568. current_channel = p_sops->get_current_channel(spectral, smode);
  4569. if (spectral->capability.advncd_spectral_cap) {
  4570. spectral->lb_edge_extrabins = 0;
  4571. spectral->rb_edge_extrabins = 0;
  4572. if (spectral->is_lb_edge_extrabins_format &&
  4573. spectral->params[smode].ss_rpt_mode == 2) {
  4574. spectral->lb_edge_extrabins = 4;
  4575. }
  4576. if (spectral->is_rb_edge_extrabins_format &&
  4577. spectral->params[smode].ss_rpt_mode == 2) {
  4578. spectral->rb_edge_extrabins = 4;
  4579. }
  4580. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  4581. spectral->sc_spectral_20_40_mode = 0;
  4582. spectral->spectral_numbins =
  4583. target_if_get_fft_bin_count(
  4584. spectral->params[smode].ss_fft_size);
  4585. spectral->spectral_fft_len =
  4586. target_if_get_fft_bin_count(
  4587. spectral->params[smode].ss_fft_size);
  4588. spectral->spectral_data_len =
  4589. target_if_get_fft_bin_count(
  4590. spectral->params[smode].ss_fft_size);
  4591. /*
  4592. * Initialize classifier params to be sent to user
  4593. * space classifier
  4594. */
  4595. spectral->classifier_params.lower_chan_in_mhz =
  4596. current_channel;
  4597. spectral->classifier_params.upper_chan_in_mhz = 0;
  4598. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  4599. /* TODO : Remove this variable */
  4600. spectral->sc_spectral_20_40_mode = 1;
  4601. spectral->spectral_numbins =
  4602. target_if_get_fft_bin_count(
  4603. spectral->params[smode].ss_fft_size);
  4604. spectral->spectral_fft_len =
  4605. target_if_get_fft_bin_count(
  4606. spectral->params[smode].ss_fft_size);
  4607. spectral->spectral_data_len =
  4608. target_if_get_fft_bin_count(
  4609. spectral->params[smode].ss_fft_size);
  4610. /*
  4611. * Initialize classifier params to be sent to user
  4612. * space classifier
  4613. */
  4614. if (extension_channel < current_channel) {
  4615. spectral->classifier_params.lower_chan_in_mhz =
  4616. extension_channel;
  4617. spectral->classifier_params.upper_chan_in_mhz =
  4618. current_channel;
  4619. } else {
  4620. spectral->classifier_params.lower_chan_in_mhz =
  4621. current_channel;
  4622. spectral->classifier_params.upper_chan_in_mhz =
  4623. extension_channel;
  4624. }
  4625. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  4626. /* Set the FFT Size */
  4627. /* TODO : Remove this variable */
  4628. spectral->sc_spectral_20_40_mode = 0;
  4629. spectral->spectral_numbins =
  4630. target_if_get_fft_bin_count(
  4631. spectral->params[smode].ss_fft_size);
  4632. spectral->spectral_fft_len =
  4633. target_if_get_fft_bin_count(
  4634. spectral->params[smode].ss_fft_size);
  4635. spectral->spectral_data_len =
  4636. target_if_get_fft_bin_count(
  4637. spectral->params[smode].ss_fft_size);
  4638. /*
  4639. * Initialize classifier params to be sent to user
  4640. * space classifier
  4641. */
  4642. spectral->classifier_params.lower_chan_in_mhz =
  4643. current_channel;
  4644. spectral->classifier_params.upper_chan_in_mhz = 0;
  4645. /*
  4646. * Initialize classifier params to be sent to user
  4647. * space classifier
  4648. */
  4649. if (extension_channel < current_channel) {
  4650. spectral->classifier_params.lower_chan_in_mhz =
  4651. extension_channel;
  4652. spectral->classifier_params.upper_chan_in_mhz =
  4653. current_channel;
  4654. } else {
  4655. spectral->classifier_params.lower_chan_in_mhz =
  4656. current_channel;
  4657. spectral->classifier_params.upper_chan_in_mhz =
  4658. extension_channel;
  4659. }
  4660. } else if (is_ch_width_160_or_80p80(
  4661. spectral->ch_width[smode])) {
  4662. /* Set the FFT Size */
  4663. /* The below applies to both 160 and 80+80 cases */
  4664. /* TODO : Remove this variable */
  4665. spectral->sc_spectral_20_40_mode = 0;
  4666. spectral->spectral_numbins =
  4667. target_if_get_fft_bin_count(
  4668. spectral->params[smode].ss_fft_size);
  4669. spectral->spectral_fft_len =
  4670. target_if_get_fft_bin_count(
  4671. spectral->params[smode].ss_fft_size);
  4672. spectral->spectral_data_len =
  4673. target_if_get_fft_bin_count(
  4674. spectral->params[smode].ss_fft_size);
  4675. /*
  4676. * Initialize classifier params to be sent to user
  4677. * space classifier
  4678. */
  4679. spectral->classifier_params.lower_chan_in_mhz =
  4680. current_channel;
  4681. spectral->classifier_params.upper_chan_in_mhz = 0;
  4682. /*
  4683. * Initialize classifier params to be sent to user
  4684. * space classifier
  4685. */
  4686. if (extension_channel < current_channel) {
  4687. spectral->classifier_params.lower_chan_in_mhz =
  4688. extension_channel;
  4689. spectral->classifier_params.upper_chan_in_mhz =
  4690. current_channel;
  4691. } else {
  4692. spectral->classifier_params.lower_chan_in_mhz =
  4693. current_channel;
  4694. spectral->classifier_params.upper_chan_in_mhz =
  4695. extension_channel;
  4696. }
  4697. }
  4698. if (spectral->spectral_numbins) {
  4699. spectral->spectral_numbins +=
  4700. spectral->lb_edge_extrabins;
  4701. spectral->spectral_numbins +=
  4702. spectral->rb_edge_extrabins;
  4703. }
  4704. if (spectral->spectral_fft_len) {
  4705. spectral->spectral_fft_len +=
  4706. spectral->lb_edge_extrabins;
  4707. spectral->spectral_fft_len +=
  4708. spectral->rb_edge_extrabins;
  4709. }
  4710. if (spectral->spectral_data_len) {
  4711. spectral->spectral_data_len +=
  4712. spectral->lb_edge_extrabins;
  4713. spectral->spectral_data_len +=
  4714. spectral->rb_edge_extrabins;
  4715. }
  4716. } else {
  4717. /*
  4718. * The decision to find 20/40 mode is found based on the
  4719. * presence of extension channel
  4720. * instead of channel width, as the channel width can
  4721. * dynamically change
  4722. */
  4723. if (extension_channel == 0) {
  4724. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  4725. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  4726. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  4727. spectral->spectral_data_len =
  4728. SPECTRAL_HT20_TOTAL_DATA_LEN;
  4729. /* only valid in 20-40 mode */
  4730. spectral->spectral_lower_max_index_offset = -1;
  4731. /* only valid in 20-40 mode */
  4732. spectral->spectral_upper_max_index_offset = -1;
  4733. spectral->spectral_max_index_offset =
  4734. spectral->spectral_fft_len + 2;
  4735. spectral->sc_spectral_20_40_mode = 0;
  4736. /*
  4737. * Initialize classifier params to be sent to user
  4738. * space classifier
  4739. */
  4740. spectral->classifier_params.lower_chan_in_mhz =
  4741. current_channel;
  4742. spectral->classifier_params.upper_chan_in_mhz = 0;
  4743. } else {
  4744. spectral->spectral_numbins =
  4745. SPECTRAL_HT40_TOTAL_NUM_BINS;
  4746. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  4747. spectral->spectral_data_len =
  4748. SPECTRAL_HT40_TOTAL_DATA_LEN;
  4749. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  4750. /* only valid in 20 mode */
  4751. spectral->spectral_max_index_offset = -1;
  4752. spectral->spectral_lower_max_index_offset =
  4753. spectral->spectral_fft_len + 2;
  4754. spectral->spectral_upper_max_index_offset =
  4755. spectral->spectral_fft_len + 5;
  4756. spectral->sc_spectral_20_40_mode = 1;
  4757. /*
  4758. * Initialize classifier params to be sent to user
  4759. * space classifier
  4760. */
  4761. if (extension_channel < current_channel) {
  4762. spectral->classifier_params.lower_chan_in_mhz =
  4763. extension_channel;
  4764. spectral->classifier_params.upper_chan_in_mhz =
  4765. current_channel;
  4766. } else {
  4767. spectral->classifier_params.lower_chan_in_mhz =
  4768. current_channel;
  4769. spectral->classifier_params.upper_chan_in_mhz =
  4770. extension_channel;
  4771. }
  4772. }
  4773. }
  4774. spectral->send_single_packet = 0;
  4775. spectral->classifier_params.spectral_20_40_mode =
  4776. spectral->sc_spectral_20_40_mode;
  4777. spectral->classifier_params.spectral_dc_index =
  4778. spectral->spectral_dc_index;
  4779. spectral->spectral_sent_msg = 0;
  4780. spectral->classify_scan = 0;
  4781. spectral->num_spectral_data = 0;
  4782. if (!p_sops->is_spectral_active(spectral, smode)) {
  4783. p_sops->configure_spectral(spectral, spectral_params, smode);
  4784. spectral->rparams.marker[smode].is_valid = false;
  4785. if (spectral->params[smode].ss_count) {
  4786. status = target_if_spectral_finite_scan_init(spectral,
  4787. smode);
  4788. if (QDF_IS_STATUS_ERROR(status)) {
  4789. spectral_err("Failed to init finite scan");
  4790. return 1;
  4791. }
  4792. }
  4793. p_sops->start_spectral_scan(spectral, smode, err);
  4794. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  4795. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  4796. }
  4797. /* get current spectral configuration */
  4798. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  4799. target_if_init_upper_lower_flags(spectral, smode);
  4800. return 0;
  4801. }
  4802. /**
  4803. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  4804. * Agile DFS
  4805. * @psoc: Pointer to psoc
  4806. * @object: Pointer to pdev
  4807. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  4808. *
  4809. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  4810. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  4811. *
  4812. * Return: void
  4813. */
  4814. static void
  4815. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  4816. void *object, void *arg)
  4817. {
  4818. bool *is_aspectral_prohibited = arg;
  4819. struct wlan_objmgr_pdev *cur_pdev = object;
  4820. bool is_agile_precac_enabled_cur_pdev = false;
  4821. bool is_agile_rcac_enabled_cur_pdev = false;
  4822. QDF_STATUS status;
  4823. if (!is_aspectral_prohibited) {
  4824. spectral_err("Arg(Indication flag for agile spectral prohibition) is null.");
  4825. return;
  4826. }
  4827. if (*is_aspectral_prohibited)
  4828. return;
  4829. if (!psoc) {
  4830. spectral_err("psoc is null.");
  4831. *is_aspectral_prohibited = true;
  4832. return;
  4833. }
  4834. if (!cur_pdev) {
  4835. spectral_err("Current pdev is null.");
  4836. *is_aspectral_prohibited = true;
  4837. return;
  4838. }
  4839. status = ucfg_dfs_get_agile_precac_enable
  4840. (cur_pdev,
  4841. &is_agile_precac_enabled_cur_pdev);
  4842. if (QDF_IS_STATUS_ERROR(status)) {
  4843. spectral_err("Get agile precac failed, prohibiting aSpectral");
  4844. *is_aspectral_prohibited = true;
  4845. return;
  4846. }
  4847. status = ucfg_dfs_get_rcac_enable(cur_pdev,
  4848. &is_agile_rcac_enabled_cur_pdev);
  4849. if (QDF_IS_STATUS_ERROR(status)) {
  4850. spectral_err("Get agile RCAC failed, prohibiting aSpectral");
  4851. *is_aspectral_prohibited = true;
  4852. return;
  4853. }
  4854. if (is_agile_precac_enabled_cur_pdev) {
  4855. spectral_err("aDFS preCAC is in progress on one of the pdevs");
  4856. *is_aspectral_prohibited = true;
  4857. } else if (is_agile_rcac_enabled_cur_pdev) {
  4858. spectral_err("aDFS RCAC is in progress on one of the pdevs");
  4859. *is_aspectral_prohibited = true;
  4860. }
  4861. }
  4862. /**
  4863. * target_if_get_curr_band() - Get current operating band of pdev
  4864. * @pdev: pointer to pdev object
  4865. * @vdev_id: id of vdev
  4866. *
  4867. * API to get current operating band of a given pdev.
  4868. *
  4869. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  4870. */
  4871. static enum reg_wifi_band
  4872. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id)
  4873. {
  4874. struct wlan_objmgr_vdev *vdev;
  4875. int16_t chan_freq;
  4876. enum reg_wifi_band cur_band;
  4877. if (!pdev) {
  4878. spectral_err("pdev is NULL");
  4879. return REG_BAND_UNKNOWN;
  4880. }
  4881. if (vdev_id == WLAN_INVALID_VDEV_ID)
  4882. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  4883. else
  4884. vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, vdev_id,
  4885. WLAN_SPECTRAL_ID);
  4886. if (!vdev) {
  4887. spectral_debug("vdev is NULL");
  4888. return REG_BAND_UNKNOWN;
  4889. }
  4890. chan_freq = target_if_vdev_get_chan_freq(vdev);
  4891. cur_band = wlan_reg_freq_to_band(chan_freq);
  4892. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4893. return cur_band;
  4894. }
  4895. /**
  4896. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  4897. * any of the 5G pdevs
  4898. * @psoc: Pointer to psoc
  4899. * @object: Pointer to pdev
  4900. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  4901. * progress in any 5G pdevs
  4902. *
  4903. * Return: void
  4904. */
  4905. static void
  4906. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  4907. void *object, void *arg)
  4908. {
  4909. enum reg_wifi_band band;
  4910. bool *is_agile_scan_inprog_5g_pdev = arg;
  4911. struct target_if_spectral *spectral;
  4912. struct wlan_objmgr_pdev *cur_pdev = object;
  4913. struct target_if_spectral_ops *p_sops;
  4914. if (*is_agile_scan_inprog_5g_pdev)
  4915. return;
  4916. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  4917. if (!spectral) {
  4918. spectral_err("target if spectral handle is NULL");
  4919. return;
  4920. }
  4921. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4922. band = target_if_get_curr_band(
  4923. cur_pdev, spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE]);
  4924. if (band == REG_BAND_UNKNOWN) {
  4925. spectral_debug("Failed to get current band");
  4926. return;
  4927. }
  4928. if (band == REG_BAND_5G &&
  4929. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  4930. *is_agile_scan_inprog_5g_pdev = true;
  4931. }
  4932. /**
  4933. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  4934. * for current vdev rx chainmask.
  4935. *
  4936. * @spectral: Pointer to Spectral object
  4937. * @is_supported: Pointer to is_supported
  4938. *
  4939. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4940. */
  4941. static QDF_STATUS
  4942. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  4943. bool *is_supported)
  4944. {
  4945. struct wlan_objmgr_vdev *vdev;
  4946. uint8_t vdev_rxchainmask;
  4947. struct wlan_objmgr_psoc *psoc;
  4948. struct wlan_objmgr_pdev *pdev;
  4949. struct target_psoc_info *tgt_psoc_info;
  4950. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  4951. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  4952. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  4953. struct wlan_psoc_host_chainmask_table *table;
  4954. int j;
  4955. uint32_t table_id;
  4956. enum phy_ch_width ch_width;
  4957. uint8_t pdev_id;
  4958. if (!spectral) {
  4959. spectral_err("spectral target if object is null");
  4960. return QDF_STATUS_E_FAILURE;
  4961. }
  4962. if (!is_supported) {
  4963. spectral_err("is supported argument is null");
  4964. return QDF_STATUS_E_FAILURE;
  4965. }
  4966. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  4967. spectral_err("HW Agile mode is not supported up to gen 2");
  4968. return QDF_STATUS_E_FAILURE;
  4969. }
  4970. pdev = spectral->pdev_obj;
  4971. if (!pdev) {
  4972. spectral_err("pdev is null");
  4973. return QDF_STATUS_E_FAILURE;
  4974. }
  4975. psoc = wlan_pdev_get_psoc(pdev);
  4976. if (!psoc) {
  4977. spectral_err("psoc is null");
  4978. return QDF_STATUS_E_FAILURE;
  4979. }
  4980. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  4981. if (!vdev) {
  4982. spectral_err("First vdev is NULL");
  4983. return QDF_STATUS_E_FAILURE;
  4984. }
  4985. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  4986. if (!vdev_rxchainmask) {
  4987. spectral_err("vdev rx chainmask is zero");
  4988. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4989. return QDF_STATUS_E_FAILURE;
  4990. }
  4991. ch_width = target_if_vdev_get_ch_width(vdev);
  4992. if (ch_width == CH_WIDTH_INVALID) {
  4993. spectral_err("Invalid channel width");
  4994. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4995. return QDF_STATUS_E_FAILURE;
  4996. }
  4997. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4998. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  4999. if (!tgt_psoc_info) {
  5000. spectral_err("target_psoc_info is null");
  5001. return QDF_STATUS_E_FAILURE;
  5002. }
  5003. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  5004. if (!ext_svc_param) {
  5005. spectral_err("Extended service ready param null");
  5006. return QDF_STATUS_E_FAILURE;
  5007. }
  5008. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  5009. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  5010. if (!mac_phy_cap_arr) {
  5011. spectral_err("mac phy cap array is null");
  5012. return QDF_STATUS_E_FAILURE;
  5013. }
  5014. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  5015. if (!mac_phy_cap) {
  5016. spectral_err("mac phy cap is null");
  5017. return QDF_STATUS_E_FAILURE;
  5018. }
  5019. table_id = mac_phy_cap->chainmask_table_id;
  5020. table = &ext_svc_param->chainmask_table[table_id];
  5021. if (!table) {
  5022. spectral_err("chainmask table not found");
  5023. return QDF_STATUS_E_FAILURE;
  5024. }
  5025. for (j = 0; j < table->num_valid_chainmasks; j++) {
  5026. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  5027. if (ch_width <= CH_WIDTH_80MHZ)
  5028. *is_supported =
  5029. table->cap_list[j].supports_aSpectral;
  5030. else
  5031. *is_supported =
  5032. table->cap_list[j].supports_aSpectral_160;
  5033. break;
  5034. }
  5035. }
  5036. if (j == table->num_valid_chainmasks) {
  5037. spectral_err("vdev rx chainmask %u not found in table id = %u",
  5038. vdev_rxchainmask, table_id);
  5039. return QDF_STATUS_E_FAILURE;
  5040. }
  5041. return QDF_STATUS_SUCCESS;
  5042. }
  5043. #define INVALID_SPAN_NUM (-1)
  5044. /**
  5045. * target_if_spectral_get_num_spans() - Get number of spans for a given sscan_bw
  5046. * @pdev: Pointer to pdev object
  5047. * @sscan_bw: Spectral scan bandwidth
  5048. *
  5049. * Return: Number of spans on success, INVALID_SPAN_NUM on failure
  5050. */
  5051. static int
  5052. target_if_spectral_get_num_spans(
  5053. struct wlan_objmgr_pdev *pdev,
  5054. enum phy_ch_width sscan_bw)
  5055. {
  5056. struct wlan_objmgr_psoc *psoc;
  5057. int num_spans;
  5058. if (!pdev) {
  5059. spectral_err_rl("pdev is null");
  5060. return INVALID_SPAN_NUM;
  5061. }
  5062. psoc = wlan_pdev_get_psoc(pdev);
  5063. if (!psoc) {
  5064. spectral_err_rl("psoc is null");
  5065. return INVALID_SPAN_NUM;
  5066. }
  5067. if (sscan_bw == CH_WIDTH_80P80MHZ) {
  5068. num_spans = 2;
  5069. if (wlan_psoc_nif_fw_ext_cap_get(
  5070. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  5071. /* 5 MHz frequency span in restricted 80p80 case */
  5072. num_spans += 1;
  5073. } else {
  5074. num_spans = 1;
  5075. }
  5076. return num_spans;
  5077. }
  5078. #ifdef OPTIMIZED_SAMP_MESSAGE
  5079. /**
  5080. * target_if_spectral_populate_session_report_info() - Populate per-session
  5081. * report level information.
  5082. *
  5083. * @spectral: Pointer to Spectral object
  5084. * @smode: Spectral scan mode
  5085. *
  5086. * Return: Success/Failure
  5087. */
  5088. static QDF_STATUS
  5089. target_if_spectral_populate_session_report_info(
  5090. struct target_if_spectral *spectral,
  5091. enum spectral_scan_mode smode)
  5092. {
  5093. struct per_session_report_info *rpt_info;
  5094. if (!spectral) {
  5095. spectral_err_rl("Spectral LMAC object is null");
  5096. return QDF_STATUS_E_NULL_VALUE;
  5097. }
  5098. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5099. spectral_err_rl("Invalid Spectral scan mode");
  5100. return QDF_STATUS_E_FAILURE;
  5101. }
  5102. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5103. /* Fill per-session report information, based on the spectral mode */
  5104. rpt_info = &spectral->report_info[smode];
  5105. rpt_info->operating_bw = spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  5106. rpt_info->sscan_bw = spectral->ch_width[smode];
  5107. rpt_info->sscan_cfreq1 = spectral->params[smode].ss_frequency.cfreq1;
  5108. rpt_info->sscan_cfreq2 = spectral->params[smode].ss_frequency.cfreq2;
  5109. rpt_info->num_spans = target_if_spectral_get_num_spans(
  5110. spectral->pdev_obj,
  5111. rpt_info->sscan_bw);
  5112. if (rpt_info->num_spans == INVALID_SPAN_NUM) {
  5113. spectral_err_rl("Invalid number of spans: %u",
  5114. rpt_info->num_spans);
  5115. return QDF_STATUS_E_INVAL;
  5116. }
  5117. rpt_info->valid = true;
  5118. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5119. return QDF_STATUS_SUCCESS;
  5120. }
  5121. /**
  5122. * target_if_spectral_populate_session_det_host_info() - Populate per-session
  5123. * detector level information that is known to the Host
  5124. *
  5125. * @spectral: Pointer to Spectral object
  5126. * @smode: Spectral scan mode
  5127. *
  5128. * Return: Success/Failure
  5129. */
  5130. static QDF_STATUS
  5131. target_if_spectral_populate_session_det_host_info(
  5132. struct target_if_spectral *spectral,
  5133. enum spectral_scan_mode smode)
  5134. {
  5135. struct per_session_report_info *rpt_info;
  5136. struct sscan_detector_list *detector_list;
  5137. struct wlan_objmgr_psoc *psoc;
  5138. uint16_t dest_det_idx = 0;
  5139. uint16_t dest_span_idx = 0;
  5140. bool is_sec80 = false;
  5141. uint8_t det, dest_det;
  5142. if (!spectral) {
  5143. spectral_err_rl("Spectral LMAC object is null");
  5144. return QDF_STATUS_E_NULL_VALUE;
  5145. }
  5146. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5147. spectral_err_rl("Invalid Spectral scan mode");
  5148. return QDF_STATUS_E_FAILURE;
  5149. }
  5150. if (!spectral->pdev_obj) {
  5151. spectral_err_rl("Spectral PDEV is null");
  5152. return QDF_STATUS_E_NULL_VALUE;
  5153. }
  5154. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  5155. if (!psoc) {
  5156. spectral_err_rl("psoc is null");
  5157. return QDF_STATUS_E_NULL_VALUE;
  5158. }
  5159. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5160. rpt_info = &spectral->report_info[smode];
  5161. qdf_spin_lock_bh(&spectral->detector_list_lock);
  5162. /* Fill per-sesion detector-level information */
  5163. detector_list = &spectral->detector_list[smode][rpt_info->sscan_bw];
  5164. for (det = 0; det < detector_list->num_detectors; det++) {
  5165. struct per_session_det_map *det_map;
  5166. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  5167. det_map = &spectral->det_map[detector_list->detectors[det]];
  5168. if (detector_list->num_detectors > 1) {
  5169. if (det == 0) {
  5170. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  5171. det_map->send_to_upper_layers = false;
  5172. } else if (det == detector_list->num_detectors - 1) {
  5173. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  5174. det_map->send_to_upper_layers = true;
  5175. } else {
  5176. /* middle fragments */
  5177. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  5178. det_map->send_to_upper_layers = false;
  5179. }
  5180. } else {
  5181. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  5182. det_map->send_to_upper_layers = true;
  5183. }
  5184. det_map->num_dest_det_info = 1;
  5185. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ &&
  5186. wlan_psoc_nif_fw_ext_cap_get(
  5187. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  5188. /**
  5189. * In 165MHz case, 1 Spectral HW detector maps to 3
  5190. * detectors in SAMP msg.
  5191. */
  5192. det_map->num_dest_det_info += 2;
  5193. }
  5194. for (dest_det = 0; dest_det < det_map->num_dest_det_info;
  5195. dest_det++) {
  5196. struct per_session_dest_det_info *map_det_info;
  5197. map_det_info = &det_map->dest_det_info[dest_det];
  5198. map_det_info->freq_span_id = dest_span_idx;
  5199. map_det_info->det_id = dest_det_idx;
  5200. map_det_info->is_sec80 = is_sec80;
  5201. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ) {
  5202. /* Increment span ID for non-contiguous modes */
  5203. dest_det_idx = 0;
  5204. dest_span_idx++;
  5205. } else {
  5206. /* Increment detector ID for contiguous modes */
  5207. dest_det_idx++;
  5208. }
  5209. is_sec80 = !is_sec80;
  5210. }
  5211. det_map->det_map_valid[smode] = true;
  5212. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  5213. }
  5214. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  5215. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5216. return QDF_STATUS_SUCCESS;
  5217. }
  5218. #else
  5219. static QDF_STATUS
  5220. target_if_spectral_populate_session_report_info(
  5221. struct target_if_spectral *spectral,
  5222. enum spectral_scan_mode smode)
  5223. {
  5224. return QDF_STATUS_SUCCESS;
  5225. }
  5226. static QDF_STATUS
  5227. target_if_spectral_populate_session_det_host_info(
  5228. struct target_if_spectral *spectral,
  5229. enum spectral_scan_mode smode)
  5230. {
  5231. return QDF_STATUS_SUCCESS;
  5232. }
  5233. #endif /* OPTIMIZED_SAMP_MESSAGE */
  5234. QDF_STATUS
  5235. spectral_is_session_info_expected_from_target(struct wlan_objmgr_pdev *pdev,
  5236. bool *is_session_info_expected)
  5237. {
  5238. struct wlan_objmgr_psoc *psoc;
  5239. struct wmi_unified *wmi_handle;
  5240. if (!pdev) {
  5241. spectral_err("pdev is null");
  5242. return QDF_STATUS_E_NULL_VALUE;
  5243. }
  5244. psoc = wlan_pdev_get_psoc(pdev);
  5245. if (!psoc) {
  5246. spectral_err("psoc is null");
  5247. return QDF_STATUS_E_NULL_VALUE;
  5248. }
  5249. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  5250. if (!wmi_handle) {
  5251. spectral_err("wmi handle is null");
  5252. return QDF_STATUS_E_NULL_VALUE;
  5253. }
  5254. *is_session_info_expected = target_if_spectral_wmi_service_enabled(
  5255. psoc, wmi_handle,
  5256. wmi_service_spectral_session_info_support);
  5257. return QDF_STATUS_SUCCESS;
  5258. }
  5259. QDF_STATUS
  5260. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  5261. uint8_t vdev_id,
  5262. const enum spectral_scan_mode smode,
  5263. enum spectral_cp_error_code *err)
  5264. {
  5265. struct target_if_spectral_ops *p_sops;
  5266. struct target_if_spectral *spectral;
  5267. struct wlan_objmgr_psoc *psoc;
  5268. enum reg_wifi_band band;
  5269. QDF_STATUS ret;
  5270. bool is_session_info_expected;
  5271. if (!err) {
  5272. spectral_err("Error code argument is null");
  5273. return QDF_STATUS_E_NULL_VALUE;
  5274. }
  5275. *err = SPECTRAL_SCAN_ERR_INVALID;
  5276. if (!pdev) {
  5277. spectral_err("pdev object is NUll");
  5278. return QDF_STATUS_E_FAILURE;
  5279. }
  5280. psoc = wlan_pdev_get_psoc(pdev);
  5281. if (!psoc) {
  5282. spectral_err("psoc is null");
  5283. return QDF_STATUS_E_FAILURE;
  5284. }
  5285. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5286. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5287. spectral_err("Invalid Spectral mode %u", smode);
  5288. return QDF_STATUS_E_FAILURE;
  5289. }
  5290. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5291. if (!spectral) {
  5292. spectral_err("Spectral LMAC object is NUll");
  5293. return QDF_STATUS_E_FAILURE;
  5294. }
  5295. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5296. if (!p_sops) {
  5297. spectral_err("p_sops is null");
  5298. return QDF_STATUS_E_FAILURE;
  5299. }
  5300. if (p_sops->is_spectral_active(spectral, smode)) {
  5301. spectral_err("spectral in progress in current pdev, mode %d",
  5302. smode);
  5303. return QDF_STATUS_E_FAILURE;
  5304. }
  5305. spectral->vdev_id[smode] = vdev_id;
  5306. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5307. QDF_STATUS status;
  5308. bool is_supported = false;
  5309. status = target_if_is_agile_supported_cur_chmask(spectral,
  5310. &is_supported);
  5311. if (QDF_IS_STATUS_ERROR(status)) {
  5312. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5313. return QDF_STATUS_E_FAILURE;
  5314. }
  5315. if (!is_supported) {
  5316. spectral_err("aSpectral unsupported for cur chainmask");
  5317. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5318. return QDF_STATUS_E_FAILURE;
  5319. }
  5320. }
  5321. band = target_if_get_curr_band(spectral->pdev_obj, vdev_id);
  5322. if (band == REG_BAND_UNKNOWN) {
  5323. spectral_err("Failed to get current band");
  5324. return QDF_STATUS_E_FAILURE;
  5325. }
  5326. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  5327. struct target_psoc_info *tgt_hdl;
  5328. enum wmi_host_hw_mode_config_type mode;
  5329. bool is_agile_scan_inprog_5g_pdev;
  5330. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  5331. if (!tgt_hdl) {
  5332. target_if_err("target_psoc_info is null");
  5333. return QDF_STATUS_E_FAILURE;
  5334. }
  5335. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  5336. switch (mode) {
  5337. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  5338. case WMI_HOST_HW_MODE_SBS:
  5339. case WMI_HOST_HW_MODE_DBS_SBS:
  5340. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  5341. is_agile_scan_inprog_5g_pdev = false;
  5342. wlan_objmgr_iterate_obj_list
  5343. (psoc, WLAN_PDEV_OP,
  5344. target_if_is_agile_scan_active_in_5g,
  5345. &is_agile_scan_inprog_5g_pdev, 0,
  5346. WLAN_SPECTRAL_ID);
  5347. break;
  5348. default:
  5349. is_agile_scan_inprog_5g_pdev = false;
  5350. break;
  5351. }
  5352. if (is_agile_scan_inprog_5g_pdev) {
  5353. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  5354. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5355. return QDF_STATUS_E_FAILURE;
  5356. }
  5357. }
  5358. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5359. bool is_aspectral_prohibited = false;
  5360. QDF_STATUS status;
  5361. status = wlan_objmgr_iterate_obj_list
  5362. (psoc, WLAN_PDEV_OP,
  5363. target_if_is_aspectral_prohibited_by_adfs,
  5364. &is_aspectral_prohibited, 0,
  5365. WLAN_SPECTRAL_ID);
  5366. if (QDF_IS_STATUS_ERROR(status)) {
  5367. spectral_err("Failed to iterate over pdevs");
  5368. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5369. return QDF_STATUS_E_FAILURE;
  5370. }
  5371. if (is_aspectral_prohibited) {
  5372. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5373. return QDF_STATUS_E_FAILURE;
  5374. }
  5375. }
  5376. if (!spectral->params_valid[smode]) {
  5377. target_if_spectral_info_read(spectral,
  5378. smode,
  5379. TARGET_IF_SPECTRAL_INFO_PARAMS,
  5380. &spectral->params[smode],
  5381. sizeof(spectral->params[smode]));
  5382. spectral->params_valid[smode] = true;
  5383. }
  5384. qdf_spin_lock_bh(&spectral->spectral_lock);
  5385. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5386. QDF_STATUS status;
  5387. bool is_overlapping;
  5388. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  5389. enum spectral_scan_mode m;
  5390. enum phy_ch_width agile_ch_width;
  5391. m = SPECTRAL_SCAN_MODE_NORMAL;
  5392. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  5393. ch_width[m] = CH_WIDTH_INVALID;
  5394. status = target_if_spectral_populate_chwidth
  5395. (spectral, ch_width, spectral->params
  5396. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  5397. if (QDF_IS_STATUS_ERROR(status)) {
  5398. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5399. spectral_err("Failed to populate channel width");
  5400. return QDF_STATUS_E_FAILURE;
  5401. }
  5402. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  5403. if (!spectral->params[smode].ss_frequency.cfreq1) {
  5404. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  5405. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5406. spectral_err("Agile Spectral cfreq1 is 0");
  5407. return QDF_STATUS_E_FAILURE;
  5408. } else if (agile_ch_width == CH_WIDTH_80P80MHZ &&
  5409. !spectral->params[smode].ss_frequency.cfreq2) {
  5410. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  5411. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5412. spectral_err("Agile Spectral cfreq2 is 0");
  5413. return QDF_STATUS_E_FAILURE;
  5414. }
  5415. status = target_if_is_agile_span_overlap_with_operating_span
  5416. (spectral, ch_width,
  5417. &spectral->params[smode].ss_frequency,
  5418. &is_overlapping);
  5419. if (QDF_IS_STATUS_ERROR(status)) {
  5420. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5421. return QDF_STATUS_E_FAILURE;
  5422. }
  5423. if (is_overlapping) {
  5424. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  5425. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5426. return QDF_STATUS_E_FAILURE;
  5427. }
  5428. }
  5429. /* Populate detectot list first */
  5430. ret = target_if_spectral_detector_list_init(spectral);
  5431. if (QDF_IS_STATUS_ERROR(ret)) {
  5432. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5433. spectral_err("Failed to initialize detector list");
  5434. return ret;
  5435. }
  5436. ret = target_if_spectral_populate_chwidth(
  5437. spectral, spectral->ch_width,
  5438. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  5439. ss_frequency.cfreq2 > 0);
  5440. if (QDF_IS_STATUS_ERROR(ret)) {
  5441. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5442. spectral_err("Failed to get channel widths");
  5443. return ret;
  5444. }
  5445. ret = spectral_is_session_info_expected_from_target(
  5446. spectral->pdev_obj,
  5447. &is_session_info_expected);
  5448. if (QDF_IS_STATUS_ERROR(ret)) {
  5449. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5450. spectral_err("Failed to check if session info is expected");
  5451. return ret;
  5452. }
  5453. /* If FW doesn't send session info, populate it */
  5454. if (!is_session_info_expected) {
  5455. ret = target_if_spectral_populate_session_report_info(spectral,
  5456. smode);
  5457. if (QDF_IS_STATUS_ERROR(ret)) {
  5458. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5459. spectral_err("Failed to populate per-session report info");
  5460. return QDF_STATUS_E_FAILURE;
  5461. }
  5462. ret = target_if_spectral_populate_session_det_host_info(
  5463. spectral, smode);
  5464. if (QDF_IS_STATUS_ERROR(ret)) {
  5465. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5466. spectral_err("Failed to populate per-session detector info");
  5467. return QDF_STATUS_E_FAILURE;
  5468. }
  5469. }
  5470. target_if_spectral_scan_enable_params(spectral,
  5471. &spectral->params[smode], smode,
  5472. err);
  5473. spectral->sscan_width_configured[smode] = false;
  5474. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5475. return QDF_STATUS_SUCCESS;
  5476. }
  5477. QDF_STATUS
  5478. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  5479. const enum spectral_scan_mode smode,
  5480. enum spectral_cp_error_code *err)
  5481. {
  5482. struct target_if_spectral_ops *p_sops;
  5483. struct target_if_spectral *spectral;
  5484. uint8_t det;
  5485. if (!pdev) {
  5486. spectral_err("pdev object is NULL");
  5487. return QDF_STATUS_E_INVAL;
  5488. }
  5489. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  5490. spectral_info("Spectral feature is disabled");
  5491. return QDF_STATUS_COMP_DISABLED;
  5492. }
  5493. if (!err) {
  5494. spectral_err("Error code argument is null");
  5495. return QDF_STATUS_E_NULL_VALUE;
  5496. }
  5497. *err = SPECTRAL_SCAN_ERR_INVALID;
  5498. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5499. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5500. spectral_err("Invalid Spectral mode %u", smode);
  5501. return QDF_STATUS_E_FAILURE;
  5502. }
  5503. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5504. if (!spectral) {
  5505. spectral_err("Spectral LMAC object is NUll ");
  5506. return QDF_STATUS_E_FAILURE;
  5507. }
  5508. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5509. qdf_spin_lock_bh(&spectral->spectral_lock);
  5510. p_sops->stop_spectral_scan(spectral, smode);
  5511. if (spectral->classify_scan) {
  5512. /* TODO : Check if this logic is necessary */
  5513. spectral->detects_control_channel = 0;
  5514. spectral->detects_extension_channel = 0;
  5515. spectral->detects_above_dc = 0;
  5516. spectral->detects_below_dc = 0;
  5517. spectral->classify_scan = 0;
  5518. }
  5519. spectral->send_single_packet = 0;
  5520. spectral->sc_spectral_scan = 0;
  5521. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  5522. for (det = 0; det < MAX_DETECTORS_PER_PDEV; det++)
  5523. spectral->det_map[det].det_map_valid[smode] = false;
  5524. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  5525. /* Mark report info as invalid */
  5526. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5527. spectral->report_info[smode].valid = false;
  5528. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5529. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5530. return QDF_STATUS_SUCCESS;
  5531. }
  5532. /**
  5533. * target_if_is_spectral_active() - Get whether Spectral is active
  5534. * @pdev: Pointer to pdev object
  5535. * @smode: Spectral scan mode
  5536. *
  5537. * API to get whether Spectral is active
  5538. *
  5539. * Return: True if Spectral is active, false if Spectral is not active
  5540. */
  5541. bool
  5542. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  5543. const enum spectral_scan_mode smode)
  5544. {
  5545. struct target_if_spectral *spectral = NULL;
  5546. struct target_if_spectral_ops *p_sops = NULL;
  5547. if (!pdev) {
  5548. spectral_err("pdev is null");
  5549. return false;
  5550. }
  5551. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  5552. spectral_info("Spectral feature is disabled");
  5553. return false;
  5554. }
  5555. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5556. if (!spectral) {
  5557. spectral_err("SPECTRAL : Module doesn't exist");
  5558. return false;
  5559. }
  5560. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5561. if (!p_sops) {
  5562. spectral_err("p_sops is null");
  5563. return false;
  5564. }
  5565. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5566. spectral_err("Invalid Spectral mode %u", smode);
  5567. return false;
  5568. }
  5569. return p_sops->is_spectral_active(spectral, smode);
  5570. }
  5571. /**
  5572. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  5573. * @pdev: Pointer to pdev object
  5574. * @smode: Spectral scan mode
  5575. *
  5576. * API to get whether Spectral is enabled
  5577. *
  5578. * Return: True if Spectral is enabled, false if Spectral is not enabled
  5579. */
  5580. bool
  5581. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  5582. enum spectral_scan_mode smode)
  5583. {
  5584. struct target_if_spectral *spectral = NULL;
  5585. struct target_if_spectral_ops *p_sops = NULL;
  5586. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5587. if (!spectral) {
  5588. spectral_err("SPECTRAL : Module doesn't exist");
  5589. return false;
  5590. }
  5591. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5592. if (!p_sops) {
  5593. spectral_err("p_sops is null");
  5594. return false;
  5595. }
  5596. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5597. spectral_err("Invalid Spectral mode %u", smode);
  5598. return false;
  5599. }
  5600. return p_sops->is_spectral_enabled(spectral, smode);
  5601. }
  5602. #ifdef DIRECT_BUF_RX_DEBUG
  5603. /**
  5604. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  5605. * @pdev: Pointer to pdev object
  5606. * @enable: Enable/Disable Spectral DMA ring debug
  5607. *
  5608. * Start/stop Spectral DMA ring debug based on @enable.
  5609. * Also save the state for future use.
  5610. *
  5611. * Return: QDF_STATUS of operation
  5612. */
  5613. static QDF_STATUS
  5614. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  5615. {
  5616. struct target_if_spectral *spectral;
  5617. struct wlan_lmac_if_tx_ops *tx_ops;
  5618. struct wlan_objmgr_psoc *psoc;
  5619. if (!pdev)
  5620. return QDF_STATUS_E_FAILURE;
  5621. psoc = wlan_pdev_get_psoc(pdev);
  5622. if (!psoc) {
  5623. spectral_err("psoc is null");
  5624. return QDF_STATUS_E_INVAL;
  5625. }
  5626. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5627. if (!tx_ops) {
  5628. spectral_err("tx_ops is NULL");
  5629. return QDF_STATUS_E_INVAL;
  5630. }
  5631. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5632. if (!spectral) {
  5633. spectral_err("Spectal LMAC object is NULL");
  5634. return QDF_STATUS_E_INVAL;
  5635. }
  5636. /* Save the state */
  5637. spectral->dbr_ring_debug = enable;
  5638. if (enable)
  5639. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  5640. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  5641. else
  5642. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  5643. pdev, 0);
  5644. return QDF_STATUS_SUCCESS;
  5645. }
  5646. /**
  5647. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  5648. * @pdev: Pointer to pdev object
  5649. * @enable: Enable/Disable Spectral DMA buffer debug
  5650. *
  5651. * Start/stop Spectral DMA buffer debug based on @enable.
  5652. * Also save the state for future use.
  5653. *
  5654. * Return: QDF_STATUS of operation
  5655. */
  5656. static QDF_STATUS
  5657. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  5658. {
  5659. struct target_if_spectral *spectral;
  5660. struct wlan_lmac_if_tx_ops *tx_ops;
  5661. struct wlan_objmgr_psoc *psoc;
  5662. if (!pdev)
  5663. return QDF_STATUS_E_FAILURE;
  5664. psoc = wlan_pdev_get_psoc(pdev);
  5665. if (!psoc) {
  5666. spectral_err("psoc is null");
  5667. return QDF_STATUS_E_INVAL;
  5668. }
  5669. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5670. if (!tx_ops) {
  5671. spectral_err("tx_ops is NULL");
  5672. return QDF_STATUS_E_INVAL;
  5673. }
  5674. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5675. if (!spectral) {
  5676. spectral_err("Spectal LMAC object is NULL");
  5677. return QDF_STATUS_E_INVAL;
  5678. }
  5679. /* Save the state */
  5680. spectral->dbr_buff_debug = enable;
  5681. if (enable)
  5682. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  5683. pdev, 0, MEM_POISON_SIGNATURE);
  5684. else
  5685. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  5686. pdev, 0);
  5687. }
  5688. /**
  5689. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  5690. * debug based on the previous state
  5691. * @pdev: Pointer to pdev object
  5692. *
  5693. * Return: QDF_STATUS of operation
  5694. */
  5695. static QDF_STATUS
  5696. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  5697. {
  5698. struct target_if_spectral *spectral;
  5699. if (!pdev) {
  5700. spectral_err("pdev is NULL!");
  5701. return QDF_STATUS_E_FAILURE;
  5702. }
  5703. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5704. if (!spectral) {
  5705. spectral_err("Spectal LMAC object is NULL");
  5706. return QDF_STATUS_E_INVAL;
  5707. }
  5708. if (spectral->dbr_buff_debug)
  5709. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  5710. else
  5711. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  5712. }
  5713. /**
  5714. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  5715. * debug based on the previous state
  5716. * @pdev: Pointer to pdev object
  5717. *
  5718. * Return: QDF_STATUS of operation
  5719. */
  5720. static QDF_STATUS
  5721. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  5722. {
  5723. struct target_if_spectral *spectral;
  5724. if (!pdev) {
  5725. spectral_err("pdev is NULL!");
  5726. return QDF_STATUS_E_FAILURE;
  5727. }
  5728. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5729. if (!spectral) {
  5730. spectral_err("Spectal LMAC object is NULL");
  5731. return QDF_STATUS_E_INVAL;
  5732. }
  5733. if (spectral->dbr_ring_debug)
  5734. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  5735. else
  5736. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  5737. }
  5738. /**
  5739. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  5740. * @pdev: Pointer to pdev object
  5741. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  5742. * @debug_value: Value to be set for @dma_debug_type
  5743. *
  5744. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  5745. * based on @debug_value
  5746. *
  5747. * Return: QDF_STATUS of operation
  5748. */
  5749. static QDF_STATUS
  5750. target_if_spectral_set_dma_debug(
  5751. struct wlan_objmgr_pdev *pdev,
  5752. enum spectral_dma_debug dma_debug_type,
  5753. bool debug_value)
  5754. {
  5755. struct target_if_spectral_ops *p_sops;
  5756. struct wlan_objmgr_psoc *psoc;
  5757. struct wlan_lmac_if_tx_ops *tx_ops;
  5758. struct target_if_spectral *spectral;
  5759. if (!pdev)
  5760. return QDF_STATUS_E_FAILURE;
  5761. psoc = wlan_pdev_get_psoc(pdev);
  5762. if (!psoc) {
  5763. spectral_err("psoc is null");
  5764. return QDF_STATUS_E_INVAL;
  5765. }
  5766. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5767. if (!tx_ops) {
  5768. spectral_err("tx_ops is NULL");
  5769. return QDF_STATUS_E_FAILURE;
  5770. }
  5771. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  5772. spectral_err("Unable to fetch target type");
  5773. return QDF_STATUS_E_FAILURE;
  5774. }
  5775. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5776. if (!spectral) {
  5777. spectral_err("Spectal LMAC object is NULL");
  5778. return QDF_STATUS_E_INVAL;
  5779. }
  5780. if (spectral->direct_dma_support) {
  5781. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5782. if (p_sops->is_spectral_active(spectral,
  5783. SPECTRAL_SCAN_MODE_NORMAL) ||
  5784. p_sops->is_spectral_active(spectral,
  5785. SPECTRAL_SCAN_MODE_AGILE)) {
  5786. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  5787. return QDF_STATUS_E_FAILURE;
  5788. }
  5789. switch (dma_debug_type) {
  5790. case SPECTRAL_DMA_RING_DEBUG:
  5791. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  5792. break;
  5793. case SPECTRAL_DMA_BUFFER_DEBUG:
  5794. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  5795. break;
  5796. default:
  5797. spectral_err("Unsupported DMA debug type : %d",
  5798. dma_debug_type);
  5799. return QDF_STATUS_E_FAILURE;
  5800. }
  5801. }
  5802. return QDF_STATUS_SUCCESS;
  5803. }
  5804. #endif /* DIRECT_BUF_RX_DEBUG */
  5805. /**
  5806. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  5807. * @pdev: Pointer to pdev object
  5808. *
  5809. * Return: Whether Direct-DMA is supported on this radio
  5810. */
  5811. static bool
  5812. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  5813. {
  5814. struct target_if_spectral *spectral;
  5815. if (!pdev) {
  5816. spectral_err("pdev is NULL!");
  5817. return false;
  5818. }
  5819. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5820. if (!spectral) {
  5821. spectral_err("Spectral LMAC object is NULL");
  5822. return false;
  5823. }
  5824. return spectral->direct_dma_support;
  5825. }
  5826. /**
  5827. * target_if_set_debug_level() - Set debug level for Spectral
  5828. * @pdev: Pointer to pdev object
  5829. * @debug_level: Debug level
  5830. *
  5831. * API to set the debug level for Spectral
  5832. *
  5833. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5834. */
  5835. QDF_STATUS
  5836. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  5837. {
  5838. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  5839. return QDF_STATUS_SUCCESS;
  5840. }
  5841. /**
  5842. * target_if_get_debug_level() - Get debug level for Spectral
  5843. * @pdev: Pointer to pdev object
  5844. *
  5845. * API to get the debug level for Spectral
  5846. *
  5847. * Return: Current debug level
  5848. */
  5849. uint32_t
  5850. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  5851. {
  5852. return spectral_debug_level;
  5853. }
  5854. /**
  5855. * target_if_get_spectral_capinfo() - Get Spectral capability information
  5856. * @pdev: Pointer to pdev object
  5857. * @scaps: Buffer into which data should be copied
  5858. *
  5859. * API to get the spectral capability information
  5860. *
  5861. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5862. */
  5863. QDF_STATUS
  5864. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  5865. struct spectral_caps *scaps)
  5866. {
  5867. struct target_if_spectral *spectral = NULL;
  5868. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5869. if (!spectral) {
  5870. spectral_err("SPECTRAL : Module doesn't exist");
  5871. return QDF_STATUS_E_FAILURE;
  5872. }
  5873. qdf_mem_copy(scaps, &spectral->capability,
  5874. sizeof(struct spectral_caps));
  5875. return QDF_STATUS_SUCCESS;
  5876. }
  5877. /**
  5878. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  5879. * @pdev: Pointer to pdev object
  5880. * @stats: Buffer into which data should be copied
  5881. *
  5882. * API to get the spectral diagnostic statistics
  5883. *
  5884. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5885. */
  5886. QDF_STATUS
  5887. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  5888. struct spectral_diag_stats *stats)
  5889. {
  5890. struct target_if_spectral *spectral = NULL;
  5891. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5892. if (!spectral) {
  5893. spectral_err("SPECTRAL : Module doesn't exist");
  5894. return QDF_STATUS_E_FAILURE;
  5895. }
  5896. qdf_mem_copy(stats, &spectral->diag_stats,
  5897. sizeof(struct spectral_diag_stats));
  5898. return QDF_STATUS_SUCCESS;
  5899. }
  5900. /**
  5901. * target_if_register_spectral_wmi_ops() - Register Spectral WMI operations
  5902. * @psoc: Pointer to psoc object
  5903. * @wmi_ops: Pointer to the structure having Spectral WMI operations
  5904. *
  5905. * API for registering Spectral WMI operations in
  5906. * spectral internal data structure
  5907. *
  5908. * Return: QDF_STATUS
  5909. */
  5910. static QDF_STATUS
  5911. target_if_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
  5912. struct spectral_wmi_ops *wmi_ops)
  5913. {
  5914. struct target_if_psoc_spectral *psoc_spectral;
  5915. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5916. if (!psoc_spectral) {
  5917. spectral_err("Spectral LMAC object is null");
  5918. return QDF_STATUS_E_INVAL;
  5919. }
  5920. psoc_spectral->wmi_ops = *wmi_ops;
  5921. return QDF_STATUS_SUCCESS;
  5922. }
  5923. /**
  5924. * target_if_register_spectral_tgt_ops() - Register Spectral target operations
  5925. * @psoc: Pointer to psoc object
  5926. * @tgt_ops: Pointer to the structure having Spectral target operations
  5927. *
  5928. * API for registering Spectral target operations in
  5929. * spectral internal data structure
  5930. *
  5931. * Return: QDF_STATUS
  5932. */
  5933. static QDF_STATUS
  5934. target_if_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
  5935. struct spectral_tgt_ops *tgt_ops)
  5936. {
  5937. if (!psoc) {
  5938. spectral_err("psoc is null");
  5939. return QDF_STATUS_E_INVAL;
  5940. }
  5941. ops_tgt = *tgt_ops;
  5942. return QDF_STATUS_SUCCESS;
  5943. }
  5944. /**
  5945. * target_if_register_netlink_cb() - Register Netlink callbacks
  5946. * @pdev: Pointer to pdev object
  5947. * @nl_cb: Netlink callbacks to register
  5948. *
  5949. * Return: void
  5950. */
  5951. static void
  5952. target_if_register_netlink_cb(
  5953. struct wlan_objmgr_pdev *pdev,
  5954. struct spectral_nl_cb *nl_cb)
  5955. {
  5956. struct target_if_spectral *spectral = NULL;
  5957. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5958. if (!spectral) {
  5959. spectral_err("SPECTRAL : Module doesn't exist");
  5960. return;
  5961. }
  5962. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  5963. if (spectral->use_nl_bcast)
  5964. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  5965. else
  5966. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  5967. }
  5968. /**
  5969. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  5970. * Netlink messages to the application layer
  5971. * @pdev: Pointer to pdev object
  5972. *
  5973. * Return: true for broadcast, false for unicast
  5974. */
  5975. static bool
  5976. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  5977. {
  5978. struct target_if_spectral *spectral = NULL;
  5979. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5980. if (!spectral) {
  5981. spectral_err("SPECTRAL : Module doesn't exist");
  5982. return false;
  5983. }
  5984. return spectral->use_nl_bcast;
  5985. }
  5986. /**
  5987. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  5988. * @pdev: Pointer to pdev object
  5989. *
  5990. * Return: void
  5991. */
  5992. static void
  5993. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  5994. {
  5995. struct target_if_spectral *spectral = NULL;
  5996. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5997. if (!spectral) {
  5998. spectral_err("SPECTRAL : Module doesn't exist");
  5999. return;
  6000. }
  6001. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  6002. }
  6003. static int
  6004. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  6005. void *payload)
  6006. {
  6007. struct target_if_spectral *spectral = NULL;
  6008. struct target_if_spectral_ops *p_sops = NULL;
  6009. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  6010. if (!spectral) {
  6011. spectral_err("SPECTRAL : Module doesn't exist");
  6012. return -EPERM;
  6013. }
  6014. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  6015. if (!p_sops) {
  6016. spectral_err("p_sops is null");
  6017. return -EPERM;
  6018. }
  6019. return p_sops->process_spectral_report(pdev, payload);
  6020. }
  6021. #ifdef DIRECT_BUF_RX_DEBUG
  6022. static inline void
  6023. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  6024. {
  6025. if (!tx_ops) {
  6026. spectral_err("tx_ops is NULL");
  6027. return;
  6028. }
  6029. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  6030. target_if_spectral_set_dma_debug;
  6031. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  6032. target_if_spectral_check_and_do_dbr_ring_debug;
  6033. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  6034. target_if_spectral_check_and_do_dbr_buff_debug;
  6035. }
  6036. #else
  6037. static inline void
  6038. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  6039. {
  6040. }
  6041. #endif
  6042. #if defined(WLAN_CONV_SPECTRAL_ENABLE) && defined(SPECTRAL_MODULIZED_ENABLE)
  6043. /**
  6044. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  6045. * register WMI event handler
  6046. * @psoc: Pointer to psoc object
  6047. * @event_id: Event id
  6048. * @handler_func: Handler function
  6049. * @rx_ctx: Context of WMI event processing
  6050. *
  6051. * Wrapper function to register WMI event handler
  6052. *
  6053. * Return: 0 for success else failure
  6054. */
  6055. static int
  6056. target_if_spectral_wmi_unified_register_event_handler(
  6057. struct wlan_objmgr_psoc *psoc,
  6058. wmi_conv_event_id event_id,
  6059. wmi_unified_event_handler handler_func,
  6060. uint8_t rx_ctx)
  6061. {
  6062. wmi_unified_t wmi_handle;
  6063. struct target_if_psoc_spectral *psoc_spectral;
  6064. QDF_STATUS ret;
  6065. if (!psoc) {
  6066. spectral_err("psoc is null");
  6067. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6068. }
  6069. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6070. if (!wmi_handle) {
  6071. spectral_err("WMI handle is null");
  6072. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6073. }
  6074. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6075. if (!psoc_spectral) {
  6076. spectral_err("spectral object is null");
  6077. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6078. }
  6079. ret = psoc_spectral->wmi_ops.wmi_unified_register_event_handler(
  6080. wmi_handle, event_id, handler_func, rx_ctx);
  6081. return qdf_status_to_os_return(ret);
  6082. }
  6083. /**
  6084. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  6085. * to unregister WMI event handler
  6086. * @psoc: Pointer to psoc object
  6087. * @event_id: Event id
  6088. *
  6089. * Wrapper function to unregister WMI event handler
  6090. *
  6091. * Return: 0 for success else failure
  6092. */
  6093. static int
  6094. target_if_spectral_wmi_unified_unregister_event_handler(
  6095. struct wlan_objmgr_psoc *psoc,
  6096. wmi_conv_event_id event_id)
  6097. {
  6098. wmi_unified_t wmi_handle;
  6099. struct target_if_psoc_spectral *psoc_spectral;
  6100. QDF_STATUS ret;
  6101. if (!psoc) {
  6102. spectral_err("psoc is null");
  6103. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6104. }
  6105. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6106. if (!wmi_handle) {
  6107. spectral_err("WMI handle is null");
  6108. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6109. }
  6110. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6111. if (!psoc_spectral) {
  6112. spectral_err("spectral object is null");
  6113. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6114. }
  6115. ret = psoc_spectral->wmi_ops.wmi_unified_unregister_event_handler(
  6116. wmi_handle, event_id);
  6117. return qdf_status_to_os_return(ret);
  6118. }
  6119. /**
  6120. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  6121. * function to extract fixed parameters from start scan response event
  6122. * @psoc: Pointer to psoc object
  6123. * @evt_buf: Event buffer
  6124. * @param: Start scan response parameters
  6125. *
  6126. * Wrapper function to extract fixed parameters from start scan response event
  6127. *
  6128. * Return: QDF_STATUS
  6129. */
  6130. static QDF_STATUS
  6131. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6132. struct wlan_objmgr_psoc *psoc,
  6133. uint8_t *evt_buf,
  6134. struct spectral_startscan_resp_params *param)
  6135. {
  6136. wmi_unified_t wmi_handle;
  6137. struct target_if_psoc_spectral *psoc_spectral;
  6138. if (!psoc) {
  6139. spectral_err("psoc is null");
  6140. return QDF_STATUS_E_INVAL;
  6141. }
  6142. if (!evt_buf) {
  6143. spectral_err("WMI event buffer is null");
  6144. return QDF_STATUS_E_INVAL;
  6145. }
  6146. if (!param) {
  6147. spectral_err("Spectral startscan response parameters is null");
  6148. return QDF_STATUS_E_INVAL;
  6149. }
  6150. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6151. if (!wmi_handle) {
  6152. spectral_err("WMI handle is null");
  6153. return QDF_STATUS_E_INVAL;
  6154. }
  6155. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6156. if (!psoc_spectral) {
  6157. spectral_err("spectral object is null");
  6158. return QDF_STATUS_E_FAILURE;
  6159. }
  6160. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6161. wmi_handle, evt_buf, param);
  6162. }
  6163. /**
  6164. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  6165. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  6166. * secondary 80 MHz FFT bins
  6167. * @psoc: Pointer to psoc object
  6168. * @evt_buf: Event buffer
  6169. * @param: FFT bin start and end indices
  6170. *
  6171. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  6172. * and secondary 80 MHz FFT bins
  6173. *
  6174. * Return: QDF_STATUS
  6175. */
  6176. static QDF_STATUS
  6177. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6178. struct wlan_objmgr_psoc *psoc,
  6179. uint8_t *evt_buf,
  6180. struct spectral_fft_bin_markers_160_165mhz *param)
  6181. {
  6182. wmi_unified_t wmi_handle;
  6183. struct target_if_psoc_spectral *psoc_spectral;
  6184. if (!psoc) {
  6185. spectral_err("psoc is null");
  6186. return QDF_STATUS_E_INVAL;
  6187. }
  6188. if (!evt_buf) {
  6189. spectral_err("WMI event buffer is null");
  6190. return QDF_STATUS_E_INVAL;
  6191. }
  6192. if (!param) {
  6193. spectral_err("Spectral FFT bin markers is null");
  6194. return QDF_STATUS_E_INVAL;
  6195. }
  6196. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6197. if (!wmi_handle) {
  6198. spectral_err("WMI handle is null");
  6199. return QDF_STATUS_E_INVAL;
  6200. }
  6201. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6202. if (!psoc_spectral) {
  6203. spectral_err("spectral object is null");
  6204. return QDF_STATUS_E_FAILURE;
  6205. }
  6206. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fft_bin_index(
  6207. wmi_handle, evt_buf, param);
  6208. }
  6209. /**
  6210. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  6211. * object from scn handle
  6212. * @scn: scn handle
  6213. *
  6214. * Wrapper function to get psoc object from scn handle
  6215. *
  6216. * Return: Pointer to psoc object
  6217. */
  6218. static struct wlan_objmgr_psoc *
  6219. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  6220. {
  6221. if (!scn) {
  6222. spectral_err("scn is null");
  6223. return NULL;
  6224. }
  6225. return ops_tgt.tgt_get_psoc_from_scn_hdl(scn);
  6226. }
  6227. /**
  6228. * target_if_extract_pdev_spectral_session_chan_info() - Wrapper
  6229. * function to extract channel information for a spectral scan session
  6230. * @psoc: Pointer to psoc object
  6231. * @evt_buf: Event buffer
  6232. * @chan_info: Spectral session channel information data structure to be filled
  6233. * by this API
  6234. *
  6235. * Return: QDF_STATUS of operation
  6236. */
  6237. static QDF_STATUS
  6238. target_if_extract_pdev_spectral_session_chan_info(
  6239. struct wlan_objmgr_psoc *psoc,
  6240. void *evt_buf,
  6241. struct spectral_session_chan_info *chan_info)
  6242. {
  6243. wmi_unified_t wmi_handle;
  6244. struct target_if_psoc_spectral *psoc_spectral;
  6245. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6246. if (!wmi_handle) {
  6247. spectral_err("WMI handle is null");
  6248. return QDF_STATUS_E_NULL_VALUE;
  6249. }
  6250. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6251. if (!psoc_spectral) {
  6252. spectral_err("spectral object is null");
  6253. return QDF_STATUS_E_NULL_VALUE;
  6254. }
  6255. return psoc_spectral->wmi_ops.extract_pdev_spectral_session_chan_info(
  6256. wmi_handle, evt_buf, chan_info);
  6257. }
  6258. /**
  6259. * target_if_extract_pdev_spectral_session_detector_info() - Wrapper
  6260. * function to extract detector information for a spectral scan session
  6261. * @psoc: Pointer to psoc object
  6262. * @evt_buf: Event buffer
  6263. * @det_info: Spectral session detector information data structure to be filled
  6264. * by this API
  6265. * @det_info_idx: index in the array of spectral scan detector info TLVs
  6266. *
  6267. * Return: QDF_STATUS of operation
  6268. */
  6269. static QDF_STATUS
  6270. target_if_extract_pdev_spectral_session_detector_info(
  6271. struct wlan_objmgr_psoc *psoc, void *evt_buf,
  6272. struct spectral_session_det_info *det_info,
  6273. uint8_t det_info_idx)
  6274. {
  6275. wmi_unified_t wmi_handle;
  6276. struct target_if_psoc_spectral *psoc_spectral;
  6277. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6278. if (!wmi_handle) {
  6279. spectral_err("WMI handle is null");
  6280. return QDF_STATUS_E_NULL_VALUE;
  6281. }
  6282. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6283. if (!psoc_spectral) {
  6284. spectral_err("spectral object is null");
  6285. return QDF_STATUS_E_NULL_VALUE;
  6286. }
  6287. return psoc_spectral->wmi_ops.
  6288. extract_pdev_spectral_session_detector_info(
  6289. wmi_handle, evt_buf, det_info, det_info_idx);
  6290. }
  6291. /**
  6292. * target_if_wmi_extract_spectral_caps_fixed_param() - Wrapper function to
  6293. * extract fixed params from Spectral capabilities WMI event
  6294. * @psoc: Pointer to psoc object
  6295. * @evt_buf: Event buffer
  6296. * @param: Spectral capabilities event parameters data structure to be filled
  6297. * by this API
  6298. *
  6299. * Return: QDF_STATUS of operation
  6300. */
  6301. QDF_STATUS
  6302. target_if_wmi_extract_spectral_caps_fixed_param(
  6303. struct wlan_objmgr_psoc *psoc,
  6304. uint8_t *evt_buf,
  6305. struct spectral_capabilities_event_params *param)
  6306. {
  6307. struct target_if_psoc_spectral *psoc_spectral;
  6308. wmi_unified_t wmi_handle;
  6309. if (!psoc) {
  6310. spectral_err("psoc is null");
  6311. return QDF_STATUS_E_NULL_VALUE;
  6312. }
  6313. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6314. if (!wmi_handle) {
  6315. spectral_err("WMI handle is null");
  6316. return QDF_STATUS_E_NULL_VALUE;
  6317. }
  6318. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6319. if (!psoc_spectral) {
  6320. spectral_err("spectral object is null");
  6321. return QDF_STATUS_E_FAILURE;
  6322. }
  6323. return psoc_spectral->wmi_ops.extract_spectral_caps_fixed_param(
  6324. wmi_handle, evt_buf, param);
  6325. }
  6326. /**
  6327. * target_if_wmi_extract_spectral_scan_bw_caps() - Wrapper function to
  6328. * extract bandwidth capabilities from Spectral capabilities WMI event
  6329. * @psoc: Pointer to psoc object
  6330. * @evt_buf: Event buffer
  6331. * @bw_caps: Data structure to be filled by this API after extraction
  6332. *
  6333. * Return: QDF_STATUS of operation
  6334. */
  6335. QDF_STATUS
  6336. target_if_wmi_extract_spectral_scan_bw_caps(
  6337. struct wlan_objmgr_psoc *psoc,
  6338. uint8_t *evt_buf,
  6339. struct spectral_scan_bw_capabilities *bw_caps)
  6340. {
  6341. struct target_if_psoc_spectral *psoc_spectral;
  6342. wmi_unified_t wmi_handle;
  6343. if (!psoc) {
  6344. spectral_err("psoc is null");
  6345. return QDF_STATUS_E_INVAL;
  6346. }
  6347. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6348. if (!wmi_handle) {
  6349. spectral_err("WMI handle is null");
  6350. return QDF_STATUS_E_INVAL;
  6351. }
  6352. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6353. if (!psoc_spectral) {
  6354. spectral_err("spectral object is null");
  6355. return QDF_STATUS_E_FAILURE;
  6356. }
  6357. return psoc_spectral->wmi_ops.extract_spectral_scan_bw_caps(
  6358. wmi_handle, evt_buf, bw_caps);
  6359. }
  6360. /**
  6361. * target_if_wmi_extract_spectral_fft_size_caps() - Wrapper function to
  6362. * extract fft size capabilities from Spectral capabilities WMI event
  6363. * @psoc: Pointer to psoc object
  6364. * @evt_buf: Event buffer
  6365. * @fft_size_caps: Data structure to be filled by this API after extraction
  6366. *
  6367. * Return: QDF_STATUS of operation
  6368. */
  6369. QDF_STATUS
  6370. target_if_wmi_extract_spectral_fft_size_caps(
  6371. struct wlan_objmgr_psoc *psoc,
  6372. uint8_t *evt_buf,
  6373. struct spectral_fft_size_capabilities *fft_size_caps)
  6374. {
  6375. struct target_if_psoc_spectral *psoc_spectral;
  6376. wmi_unified_t wmi_handle;
  6377. if (!psoc) {
  6378. spectral_err("psoc is null");
  6379. return QDF_STATUS_E_INVAL;
  6380. }
  6381. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6382. if (!wmi_handle) {
  6383. spectral_err("WMI handle is null");
  6384. return QDF_STATUS_E_INVAL;
  6385. }
  6386. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6387. if (!psoc_spectral) {
  6388. spectral_err("spectral object is null");
  6389. return QDF_STATUS_E_FAILURE;
  6390. }
  6391. return psoc_spectral->wmi_ops.extract_spectral_fft_size_caps(
  6392. wmi_handle, evt_buf, fft_size_caps);
  6393. }
  6394. #else
  6395. /**
  6396. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  6397. * register WMI event handler
  6398. * @psoc: Pointer to psoc object
  6399. * @event_id: Event id
  6400. * @handler_func: Handler function
  6401. * @rx_ctx: Context of WMI event processing
  6402. *
  6403. * Wrapper function to register WMI event handler
  6404. *
  6405. * Return: 0 for success else failure
  6406. */
  6407. static int
  6408. target_if_spectral_wmi_unified_register_event_handler(
  6409. struct wlan_objmgr_psoc *psoc,
  6410. wmi_conv_event_id event_id,
  6411. wmi_unified_event_handler handler_func,
  6412. uint8_t rx_ctx)
  6413. {
  6414. wmi_unified_t wmi_handle;
  6415. QDF_STATUS ret;
  6416. if (!psoc) {
  6417. spectral_err("psoc is null");
  6418. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6419. }
  6420. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6421. if (!wmi_handle) {
  6422. spectral_err("WMI handle is null");
  6423. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6424. }
  6425. ret = wmi_unified_register_event_handler(wmi_handle, event_id,
  6426. handler_func, rx_ctx);
  6427. return qdf_status_to_os_return(ret);
  6428. }
  6429. /**
  6430. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  6431. * to unregister WMI event handler
  6432. * @psoc: Pointer to psoc object
  6433. * @event_id: Event id
  6434. *
  6435. * Wrapper function to unregister WMI event handler
  6436. *
  6437. * Return: 0 for success else failure
  6438. */
  6439. static int
  6440. target_if_spectral_wmi_unified_unregister_event_handler(
  6441. struct wlan_objmgr_psoc *psoc,
  6442. wmi_conv_event_id event_id)
  6443. {
  6444. wmi_unified_t wmi_handle;
  6445. QDF_STATUS ret;
  6446. if (!psoc) {
  6447. spectral_err("psoc is null");
  6448. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6449. }
  6450. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6451. if (!wmi_handle) {
  6452. spectral_err("WMI handle is null");
  6453. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6454. }
  6455. ret = wmi_unified_unregister_event_handler(wmi_handle, event_id);
  6456. return qdf_status_to_os_return(ret);
  6457. }
  6458. /**
  6459. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  6460. * function to extract fixed parameters from start scan response event
  6461. * @psoc: Pointer to psoc object
  6462. * @evt_buf: Event buffer
  6463. * @param: Start scan response parameters
  6464. *
  6465. * Wrapper function to extract fixed parameters from start scan response event
  6466. *
  6467. * Return: QDF_STATUS
  6468. */
  6469. static QDF_STATUS
  6470. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6471. struct wlan_objmgr_psoc *psoc,
  6472. uint8_t *evt_buf,
  6473. struct spectral_startscan_resp_params *param)
  6474. {
  6475. wmi_unified_t wmi_handle;
  6476. if (!psoc) {
  6477. spectral_err("psoc is null");
  6478. return QDF_STATUS_E_INVAL;
  6479. }
  6480. if (!evt_buf) {
  6481. spectral_err("WMI event buffer is null");
  6482. return QDF_STATUS_E_INVAL;
  6483. }
  6484. if (!param) {
  6485. spectral_err("Spectral startscan response parameters is null");
  6486. return QDF_STATUS_E_INVAL;
  6487. }
  6488. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6489. if (!wmi_handle) {
  6490. spectral_err("WMI handle is null");
  6491. return QDF_STATUS_E_INVAL;
  6492. }
  6493. return wmi_extract_pdev_sscan_fw_cmd_fixed_param(wmi_handle, evt_buf,
  6494. param);
  6495. }
  6496. /**
  6497. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  6498. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  6499. * secondary 80 MHz FFT bins
  6500. * @psoc: Pointer to psoc object
  6501. * @evt_buf: Event buffer
  6502. * @param: FFT bin start and end indices
  6503. *
  6504. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  6505. * and secondary 80 MHz FFT bins
  6506. *
  6507. * Return: QDF_STATUS
  6508. */
  6509. static QDF_STATUS
  6510. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6511. struct wlan_objmgr_psoc *psoc,
  6512. uint8_t *evt_buf,
  6513. struct spectral_fft_bin_markers_160_165mhz *param)
  6514. {
  6515. wmi_unified_t wmi_handle;
  6516. if (!psoc) {
  6517. spectral_err("psoc is null");
  6518. return QDF_STATUS_E_INVAL;
  6519. }
  6520. if (!evt_buf) {
  6521. spectral_err("WMI event buffer is null");
  6522. return QDF_STATUS_E_INVAL;
  6523. }
  6524. if (!param) {
  6525. spectral_err("Spectral FFT bin markers is null");
  6526. return QDF_STATUS_E_INVAL;
  6527. }
  6528. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6529. if (!wmi_handle) {
  6530. spectral_err("WMI handle is null");
  6531. return QDF_STATUS_E_INVAL;
  6532. }
  6533. return wmi_extract_pdev_sscan_fft_bin_index(wmi_handle, evt_buf, param);
  6534. }
  6535. /**
  6536. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  6537. * object from scn handle
  6538. * @scn: scn handle
  6539. *
  6540. * Wrapper function to get psoc object from scn handle
  6541. *
  6542. * Return: Pointer to psoc object
  6543. */
  6544. static struct wlan_objmgr_psoc *
  6545. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  6546. {
  6547. if (!scn) {
  6548. spectral_err("scn is null");
  6549. return NULL;
  6550. }
  6551. return target_if_get_psoc_from_scn_hdl(scn);
  6552. }
  6553. /**
  6554. * target_if_extract_pdev_spectral_session_chan_info() - Wrapper
  6555. * function to extract channel information for a spectral scan session
  6556. * @psoc: Pointer to psoc object
  6557. * @evt_buf: Event buffer
  6558. * @chan_info: Spectral session channel information data structure to be filled
  6559. * by this API
  6560. *
  6561. * Return: QDF_STATUS of operation
  6562. */
  6563. static QDF_STATUS
  6564. target_if_extract_pdev_spectral_session_chan_info(
  6565. struct wlan_objmgr_psoc *psoc,
  6566. void *evt_buf,
  6567. struct spectral_session_chan_info *chan_info)
  6568. {
  6569. wmi_unified_t wmi_handle;
  6570. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6571. if (!wmi_handle) {
  6572. spectral_err("WMI handle is null");
  6573. return QDF_STATUS_E_NULL_VALUE;
  6574. }
  6575. return wmi_extract_pdev_spectral_session_chan_info(
  6576. wmi_handle, evt_buf, chan_info);
  6577. }
  6578. /**
  6579. * target_if_extract_pdev_spectral_session_detector_info() - Wrapper
  6580. * function to extract detector information for a spectral scan session
  6581. * @psoc: Pointer to psoc object
  6582. * @evt_buf: Event buffer
  6583. * @det_info: Spectral session detector information data structure to be filled
  6584. * by this API
  6585. * @det_info_idx: index in the array of spectral scan detector info TLVs
  6586. *
  6587. * Return: QDF_STATUS of operation
  6588. */
  6589. static QDF_STATUS
  6590. target_if_extract_pdev_spectral_session_detector_info(
  6591. struct wlan_objmgr_psoc *psoc, void *evt_buf,
  6592. struct spectral_session_det_info *det_info,
  6593. uint8_t det_info_idx)
  6594. {
  6595. wmi_unified_t wmi_handle;
  6596. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6597. if (!wmi_handle) {
  6598. spectral_err("WMI handle is null");
  6599. return QDF_STATUS_E_NULL_VALUE;
  6600. }
  6601. return wmi_extract_pdev_spectral_session_detector_info(
  6602. wmi_handle, evt_buf, det_info, det_info_idx);
  6603. }
  6604. QDF_STATUS
  6605. target_if_wmi_extract_spectral_caps_fixed_param(
  6606. struct wlan_objmgr_psoc *psoc,
  6607. uint8_t *evt_buf,
  6608. struct spectral_capabilities_event_params *param)
  6609. {
  6610. wmi_unified_t wmi_handle;
  6611. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6612. if (!wmi_handle) {
  6613. spectral_err("WMI handle is null");
  6614. return QDF_STATUS_E_INVAL;
  6615. }
  6616. return wmi_extract_spectral_caps_fixed_param(wmi_handle, evt_buf,
  6617. param);
  6618. }
  6619. QDF_STATUS
  6620. target_if_wmi_extract_spectral_scan_bw_caps(
  6621. struct wlan_objmgr_psoc *psoc,
  6622. uint8_t *evt_buf,
  6623. struct spectral_scan_bw_capabilities *bw_caps)
  6624. {
  6625. wmi_unified_t wmi_handle;
  6626. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6627. if (!wmi_handle) {
  6628. spectral_err("WMI handle is null");
  6629. return QDF_STATUS_E_INVAL;
  6630. }
  6631. return wmi_extract_spectral_scan_bw_caps(wmi_handle, evt_buf, bw_caps);
  6632. }
  6633. QDF_STATUS
  6634. target_if_wmi_extract_spectral_fft_size_caps(
  6635. struct wlan_objmgr_psoc *psoc,
  6636. uint8_t *evt_buf,
  6637. struct spectral_fft_size_capabilities *fft_size_caps)
  6638. {
  6639. wmi_unified_t wmi_handle;
  6640. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6641. if (!wmi_handle) {
  6642. spectral_err("WMI handle is null");
  6643. return QDF_STATUS_E_INVAL;
  6644. }
  6645. return wmi_extract_spectral_fft_size_caps(wmi_handle, evt_buf,
  6646. fft_size_caps);
  6647. }
  6648. #endif
  6649. /**
  6650. * target_if_update_det_info_in_spectral_session() - Update detector
  6651. * information in spectral scan session
  6652. * @spectral: Spectral LMAC object
  6653. * @det_info: Pointer to spectral session detector information
  6654. * @smode: Spectral scan mode
  6655. *
  6656. * Return: QDF_STATUS of operation
  6657. */
  6658. static QDF_STATUS
  6659. target_if_update_det_info_in_spectral_session(
  6660. struct target_if_spectral *spectral,
  6661. const struct spectral_session_det_info *det_info,
  6662. enum spectral_scan_mode smode)
  6663. {
  6664. struct per_session_det_map *det_map;
  6665. struct per_session_dest_det_info *dest_det_info;
  6666. if (!spectral) {
  6667. spectral_err_rl("Spectral LMAC object is null");
  6668. return QDF_STATUS_E_NULL_VALUE;
  6669. }
  6670. if (det_info->det_id >= MAX_DETECTORS_PER_PDEV) {
  6671. spectral_err_rl("Detector Id: %u exceeding Max detectors.",
  6672. det_info->det_id);
  6673. return QDF_STATUS_E_INVAL;
  6674. }
  6675. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  6676. det_map = &spectral->det_map[det_info->det_id];
  6677. dest_det_info = &det_map->dest_det_info[0];
  6678. dest_det_info->start_freq = det_info->start_freq;
  6679. dest_det_info->end_freq = det_info->end_freq;
  6680. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  6681. /* This detector will be used for this smode throughout this session */
  6682. spectral->rparams.detid_mode_table[det_info->det_id] = smode;
  6683. return QDF_STATUS_SUCCESS;
  6684. }
  6685. /**
  6686. * target_if_update_chan_info_in_spectral_session() - Update channel information
  6687. * in spectral scan session
  6688. * @spectral: Spectral LMAC object
  6689. * @chan_info: Pointer to spectral session channel information
  6690. * @smode: Spectral scan mode
  6691. *
  6692. * Return: QDF_STATUS of operation
  6693. */
  6694. static QDF_STATUS
  6695. target_if_update_chan_info_in_spectral_session(
  6696. struct target_if_spectral *spectral,
  6697. const struct spectral_session_chan_info *chan_info,
  6698. enum spectral_scan_mode smode)
  6699. {
  6700. struct per_session_report_info *rpt_info;
  6701. if (!spectral) {
  6702. spectral_err_rl("Spectral LMAC object is null");
  6703. return QDF_STATUS_E_NULL_VALUE;
  6704. }
  6705. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6706. spectral_err_rl("Invalid Spectral scan mode :%u", smode);
  6707. return QDF_STATUS_E_FAILURE;
  6708. }
  6709. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  6710. rpt_info = &spectral->report_info[smode];
  6711. /* Update per-session report info */
  6712. rpt_info->pri20_freq = chan_info->operating_pri20_freq;
  6713. rpt_info->cfreq1 = chan_info->operating_cfreq1;
  6714. rpt_info->cfreq2 = chan_info->operating_cfreq2;
  6715. rpt_info->operating_bw = chan_info->operating_bw;
  6716. rpt_info->sscan_cfreq1 = chan_info->sscan_cfreq1;
  6717. rpt_info->sscan_cfreq2 = chan_info->sscan_cfreq2;
  6718. rpt_info->sscan_bw = chan_info->sscan_bw;
  6719. /* num_spans depends on sscan_bw, update it */
  6720. rpt_info->num_spans = target_if_spectral_get_num_spans(
  6721. spectral->pdev_obj,
  6722. rpt_info->sscan_bw);
  6723. if (rpt_info->num_spans == INVALID_SPAN_NUM) {
  6724. spectral_err_rl("Invalid number of spans: %u",
  6725. rpt_info->num_spans);
  6726. return QDF_STATUS_E_INVAL;
  6727. }
  6728. rpt_info->valid = true;
  6729. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  6730. return QDF_STATUS_SUCCESS;
  6731. }
  6732. /**
  6733. * target_if_spectral_fw_param_event_handler() - WMI event handler to
  6734. * process start scan response event
  6735. * @scn: Pointer to scn object
  6736. * @data_buf: Pointer to event buffer
  6737. * @data_len: Length of event buffer
  6738. *
  6739. * Return: 0 for success, else failure
  6740. */
  6741. static int
  6742. target_if_spectral_fw_param_event_handler(ol_scn_t scn, uint8_t *data_buf,
  6743. uint32_t data_len)
  6744. {
  6745. QDF_STATUS status;
  6746. struct wlan_objmgr_psoc *psoc;
  6747. struct wlan_objmgr_pdev *pdev;
  6748. struct wmi_unified *wmi_handle;
  6749. struct spectral_startscan_resp_params event_params = {0};
  6750. struct target_if_psoc_spectral *psoc_spectral;
  6751. struct target_if_spectral *spectral;
  6752. bool is_session_info_expected;
  6753. if (!scn) {
  6754. spectral_err("scn handle is null");
  6755. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6756. }
  6757. if (!data_buf) {
  6758. spectral_err("WMI event buffer null");
  6759. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6760. }
  6761. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  6762. if (!psoc) {
  6763. spectral_err("psoc is null");
  6764. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6765. }
  6766. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6767. if (!psoc_spectral) {
  6768. spectral_err("spectral object is null");
  6769. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6770. }
  6771. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6772. if (!wmi_handle) {
  6773. spectral_err("WMI handle is null");
  6774. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6775. }
  6776. status = target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6777. psoc, data_buf, &event_params);
  6778. if (QDF_IS_STATUS_ERROR(status)) {
  6779. spectral_err("unable to extract sscan fw fixed params");
  6780. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6781. }
  6782. if (event_params.smode >= SPECTRAL_SCAN_MODE_MAX ||
  6783. event_params.smode < SPECTRAL_SCAN_MODE_NORMAL) {
  6784. spectral_err("Invalid smode %d", event_params.smode);
  6785. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6786. }
  6787. pdev = wlan_objmgr_get_pdev_by_id(psoc, event_params.pdev_id,
  6788. WLAN_SPECTRAL_ID);
  6789. if (!pdev) {
  6790. spectral_err("pdev is null");
  6791. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6792. }
  6793. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  6794. if (!spectral) {
  6795. spectral_err("spectral object is null");
  6796. status = QDF_STATUS_E_FAILURE;
  6797. goto release_pdev_ref;
  6798. }
  6799. if (event_params.num_fft_bin_index == 1) {
  6800. status =
  6801. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6802. psoc, data_buf,
  6803. &spectral->rparams.marker[event_params.smode]);
  6804. if (QDF_IS_STATUS_ERROR(status)) {
  6805. spectral_err("unable to extract sscan fw fixed params");
  6806. goto release_pdev_ref;
  6807. }
  6808. } else {
  6809. spectral->rparams.marker[event_params.smode].is_valid = false;
  6810. }
  6811. status = spectral_is_session_info_expected_from_target(
  6812. pdev, &is_session_info_expected);
  6813. if (QDF_IS_STATUS_ERROR(status)) {
  6814. spectral_err("Failed to check if session info is expected");
  6815. goto release_pdev_ref;
  6816. }
  6817. if (is_session_info_expected) {
  6818. struct spectral_session_chan_info chan_info;
  6819. uint8_t det_info_idx = 0;
  6820. status = target_if_extract_pdev_spectral_session_chan_info(
  6821. psoc, data_buf, &chan_info);
  6822. if (QDF_IS_STATUS_ERROR(status)) {
  6823. spectral_err("Unable to extract spectral session channel info");
  6824. goto release_pdev_ref;
  6825. }
  6826. status = target_if_update_chan_info_in_spectral_session(
  6827. spectral, &chan_info, event_params.smode);
  6828. if (QDF_IS_STATUS_ERROR(status)) {
  6829. spectral_err("Unable to update channel info");
  6830. goto release_pdev_ref;
  6831. }
  6832. /* FFT bins info depends upon sscan_bw, update it */
  6833. status = target_if_populate_fft_bins_info(spectral,
  6834. event_params.smode);
  6835. if (QDF_IS_STATUS_ERROR(status)) {
  6836. spectral_err("Failed to populate FFT bins info");
  6837. goto release_pdev_ref;
  6838. }
  6839. /**
  6840. * per-session det info that depends on sscan_bw needs to be
  6841. * updated here
  6842. */
  6843. status = target_if_spectral_populate_session_det_host_info(
  6844. spectral, event_params.smode);
  6845. if (QDF_IS_STATUS_ERROR(status)) {
  6846. spectral_err("Failed to populate per-session det info");
  6847. goto release_pdev_ref;
  6848. }
  6849. for (; det_info_idx < event_params.num_det_info;
  6850. ++det_info_idx) {
  6851. struct spectral_session_det_info det_info;
  6852. status =
  6853. target_if_extract_pdev_spectral_session_detector_info
  6854. (psoc, data_buf, &det_info, det_info_idx);
  6855. if (QDF_IS_STATUS_ERROR(status)) {
  6856. spectral_err("Unable to extract spectral session detector info for %u",
  6857. det_info_idx);
  6858. goto release_pdev_ref;
  6859. }
  6860. status = target_if_update_det_info_in_spectral_session(
  6861. spectral, &det_info,
  6862. event_params.smode);
  6863. if (QDF_IS_STATUS_ERROR(status)) {
  6864. spectral_err("Unable to update detector info");
  6865. goto release_pdev_ref;
  6866. }
  6867. }
  6868. }
  6869. status = QDF_STATUS_SUCCESS;
  6870. release_pdev_ref:
  6871. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  6872. return qdf_status_to_os_return(status);
  6873. }
  6874. /**
  6875. * target_if_spectral_capabilities_event_handler() - Handler for the Spectral
  6876. * Capabilities event
  6877. * @scn: Pointer to scn object
  6878. * @data_buf: Pointer to event buffer
  6879. * @data_len: Length of event buffer
  6880. *
  6881. * Return: 0 for success, else failure
  6882. */
  6883. static int
  6884. target_if_spectral_capabilities_event_handler(ol_scn_t scn, uint8_t *data_buf,
  6885. uint32_t data_len)
  6886. {
  6887. QDF_STATUS status;
  6888. struct wlan_objmgr_psoc *psoc;
  6889. struct wmi_unified *wmi_handle;
  6890. struct spectral_capabilities_event_params event_params = {0};
  6891. struct spectral_scan_bw_capabilities *bw_caps;
  6892. struct spectral_fft_size_capabilities *fft_size_caps;
  6893. if (!scn) {
  6894. spectral_err("scn handle is null");
  6895. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6896. }
  6897. if (!data_buf) {
  6898. spectral_err("WMI event buffer null");
  6899. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6900. }
  6901. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  6902. if (!psoc) {
  6903. spectral_err("psoc is null");
  6904. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6905. }
  6906. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6907. if (!wmi_handle) {
  6908. spectral_err("WMI handle is null");
  6909. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6910. }
  6911. status = target_if_wmi_extract_spectral_caps_fixed_param(
  6912. psoc, data_buf, &event_params);
  6913. if (QDF_IS_STATUS_ERROR(status)) {
  6914. spectral_err("Failed to extract fixed parameters");
  6915. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6916. }
  6917. /* There should be atleast one capability */
  6918. if (!event_params.num_sscan_bw_caps) {
  6919. spectral_err("Number of spectral_scan_bw_capabilities is less than one.");
  6920. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6921. }
  6922. if (!event_params.num_fft_size_caps) {
  6923. spectral_err("Number of spectral_scan_fft_size_capabilities is less than one.");
  6924. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6925. }
  6926. bw_caps = qdf_mem_malloc(
  6927. sizeof(*bw_caps) * event_params.num_sscan_bw_caps);
  6928. if (!bw_caps) {
  6929. spectral_err("memory allocation failed");
  6930. return qdf_status_to_os_return(QDF_STATUS_E_NOMEM);
  6931. }
  6932. status = target_if_wmi_extract_spectral_scan_bw_caps(psoc, data_buf,
  6933. bw_caps);
  6934. if (QDF_IS_STATUS_ERROR(status)) {
  6935. spectral_err("Failed to extract BW caps");
  6936. status = QDF_STATUS_E_FAILURE;
  6937. goto free_bw_caps;
  6938. }
  6939. fft_size_caps = qdf_mem_malloc(
  6940. sizeof(*fft_size_caps) * event_params.num_fft_size_caps);
  6941. if (!fft_size_caps) {
  6942. spectral_err("memory allocation failed");
  6943. status = QDF_STATUS_E_NOMEM;
  6944. goto free_bw_caps;
  6945. }
  6946. status = target_if_wmi_extract_spectral_fft_size_caps(psoc, data_buf,
  6947. fft_size_caps);
  6948. if (QDF_IS_STATUS_ERROR(status)) {
  6949. spectral_err("Failed to extract fft size caps");
  6950. status = QDF_STATUS_E_FAILURE;
  6951. goto free_fft_size_caps;
  6952. }
  6953. status = QDF_STATUS_SUCCESS;
  6954. free_fft_size_caps:
  6955. qdf_mem_free(fft_size_caps);
  6956. free_bw_caps:
  6957. qdf_mem_free(bw_caps);
  6958. return qdf_status_to_os_return(status);
  6959. }
  6960. static QDF_STATUS
  6961. target_if_spectral_register_events(struct wlan_objmgr_psoc *psoc)
  6962. {
  6963. int ret;
  6964. if (!psoc) {
  6965. spectral_err("psoc is null");
  6966. return QDF_STATUS_E_INVAL;
  6967. }
  6968. ret = target_if_spectral_wmi_unified_register_event_handler(
  6969. psoc,
  6970. wmi_pdev_sscan_fw_param_eventid,
  6971. target_if_spectral_fw_param_event_handler,
  6972. WMI_RX_UMAC_CTX);
  6973. if (ret)
  6974. spectral_debug("event handler not supported, ret=%d", ret);
  6975. ret = target_if_spectral_wmi_unified_register_event_handler(
  6976. psoc,
  6977. wmi_spectral_capabilities_eventid,
  6978. target_if_spectral_capabilities_event_handler,
  6979. WMI_RX_UMAC_CTX);
  6980. if (ret)
  6981. spectral_debug("event handler not supported, ret=%d", ret);
  6982. return QDF_STATUS_SUCCESS;
  6983. }
  6984. static QDF_STATUS
  6985. target_if_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
  6986. {
  6987. int ret;
  6988. if (!psoc) {
  6989. spectral_err("psoc is null");
  6990. return QDF_STATUS_E_INVAL;
  6991. }
  6992. target_if_spectral_wmi_unified_unregister_event_handler(
  6993. psoc, wmi_spectral_capabilities_eventid);
  6994. ret = target_if_spectral_wmi_unified_unregister_event_handler(
  6995. psoc, wmi_pdev_sscan_fw_param_eventid);
  6996. if (ret)
  6997. spectral_debug("Unregister WMI event handler failed, ret = %d",
  6998. ret);
  6999. return QDF_STATUS_SUCCESS;
  7000. }
  7001. void
  7002. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  7003. {
  7004. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  7005. target_if_pdev_spectral_init;
  7006. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  7007. target_if_pdev_spectral_deinit;
  7008. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init =
  7009. target_if_psoc_spectral_init;
  7010. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit =
  7011. target_if_psoc_spectral_deinit;
  7012. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  7013. target_if_set_spectral_config;
  7014. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  7015. target_if_get_spectral_config;
  7016. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  7017. target_if_start_spectral_scan;
  7018. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  7019. target_if_stop_spectral_scan;
  7020. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  7021. target_if_is_spectral_active;
  7022. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  7023. target_if_is_spectral_enabled;
  7024. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  7025. target_if_set_debug_level;
  7026. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  7027. target_if_get_debug_level;
  7028. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  7029. target_if_get_spectral_capinfo;
  7030. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  7031. target_if_get_spectral_diagstats;
  7032. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_wmi_ops =
  7033. target_if_register_spectral_wmi_ops;
  7034. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_tgt_ops =
  7035. target_if_register_spectral_tgt_ops;
  7036. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  7037. target_if_register_netlink_cb;
  7038. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  7039. target_if_use_nl_bcast;
  7040. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  7041. target_if_deregister_netlink_cb;
  7042. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  7043. target_if_process_spectral_report;
  7044. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  7045. target_if_spectral_direct_dma_support;
  7046. tx_ops->sptrl_tx_ops.sptrlto_register_events =
  7047. target_if_spectral_register_events;
  7048. tx_ops->sptrl_tx_ops.sptrlto_unregister_events =
  7049. target_if_spectral_unregister_events;
  7050. tx_ops->sptrl_tx_ops.sptrlto_init_pdev_feature_caps =
  7051. target_if_spectral_init_pdev_feature_caps;
  7052. target_if_sptrl_debug_register_tx_ops(tx_ops);
  7053. }
  7054. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  7055. void
  7056. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  7057. uint16_t cw_int, uint32_t dcs_enabled)
  7058. {
  7059. struct spectral_samp_msg *msg = NULL;
  7060. struct target_if_spectral_ops *p_sops = NULL;
  7061. struct target_if_spectral *spectral = NULL;
  7062. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  7063. if (!spectral) {
  7064. spectral_err("SPECTRAL : Module doesn't exist");
  7065. return;
  7066. }
  7067. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  7068. if (!p_sops) {
  7069. spectral_err("p_sops is null");
  7070. return;
  7071. }
  7072. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  7073. spectral->pdev_obj,
  7074. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  7075. SPECTRAL_MSG_BUF_NEW);
  7076. if (msg) {
  7077. msg->int_type = cw_int ?
  7078. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  7079. msg->dcs_enabled = dcs_enabled;
  7080. msg->signature = SPECTRAL_SIGNATURE;
  7081. p_sops->get_mac_address(spectral, msg->macaddr);
  7082. if (spectral->send_phy_data
  7083. (pdev,
  7084. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  7085. spectral->spectral_sent_msg++;
  7086. }
  7087. }
  7088. qdf_export_symbol(target_if_spectral_send_intf_found_msg);
  7089. QDF_STATUS
  7090. target_if_spectral_is_finite_scan(struct target_if_spectral *spectral,
  7091. enum spectral_scan_mode smode,
  7092. bool *finite_spectral_scan)
  7093. {
  7094. struct target_if_finite_spectral_scan_params *finite_scan;
  7095. if (!spectral) {
  7096. spectral_err_rl("target if spectral object is null");
  7097. return QDF_STATUS_E_INVAL;
  7098. }
  7099. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  7100. spectral_err_rl("invalid spectral mode %d", smode);
  7101. return QDF_STATUS_E_INVAL;
  7102. }
  7103. if (!finite_spectral_scan) {
  7104. spectral_err_rl("Invalid pointer");
  7105. return QDF_STATUS_E_INVAL;
  7106. }
  7107. finite_scan = &spectral->finite_scan[smode];
  7108. *finite_spectral_scan = finite_scan->finite_spectral_scan;
  7109. return QDF_STATUS_SUCCESS;
  7110. }
  7111. QDF_STATUS
  7112. target_if_spectral_finite_scan_update(struct target_if_spectral *spectral,
  7113. enum spectral_scan_mode smode)
  7114. {
  7115. struct target_if_finite_spectral_scan_params *finite_scan;
  7116. if (!spectral) {
  7117. spectral_err_rl("target if spectral object is null");
  7118. return QDF_STATUS_E_INVAL;
  7119. }
  7120. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  7121. spectral_err_rl("Invalid Spectral mode");
  7122. return QDF_STATUS_E_INVAL;
  7123. }
  7124. finite_scan = &spectral->finite_scan[smode];
  7125. if (!finite_scan->num_reports_expected) {
  7126. spectral_err_rl("Error, No reports expected");
  7127. return QDF_STATUS_E_FAILURE;
  7128. }
  7129. finite_scan->num_reports_expected--;
  7130. if (!finite_scan->num_reports_expected) {
  7131. QDF_STATUS status;
  7132. enum spectral_cp_error_code err;
  7133. /* received expected number of reports from target, stop scan */
  7134. status = target_if_stop_spectral_scan(spectral->pdev_obj, smode,
  7135. &err);
  7136. if (QDF_IS_STATUS_ERROR(status)) {
  7137. spectral_err_rl("Failed to stop finite Spectral scan");
  7138. return QDF_STATUS_E_FAILURE;
  7139. }
  7140. finite_scan->finite_spectral_scan = false;
  7141. }
  7142. return QDF_STATUS_SUCCESS;
  7143. }