target_if_spectral.c 220 KB

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