target_if_spectral.c 220 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083
  1. /*
  2. * Copyright (c) 2011,2017-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include <wlan_tgt_def_config.h>
  20. #include <hif.h>
  21. #include <target_type.h>
  22. #include <hif_hw_version.h>
  23. #include <wmi_unified_api.h>
  24. #include <target_if_spectral.h>
  25. #include <wlan_lmac_if_def.h>
  26. #include <wlan_osif_priv.h>
  27. #include <init_deinit_lmac.h>
  28. #include <reg_services_public_struct.h>
  29. #include <target_if_spectral_sim.h>
  30. #include <target_if.h>
  31. #include <qdf_module.h>
  32. #include <wlan_reg_services_api.h>
  33. #include <wlan_dfs_ucfg_api.h>
  34. /**
  35. * @spectral_ops - Spectral function table, holds the Spectral functions that
  36. * depend on whether the architecture is Direct Attach or Offload. This is used
  37. * to populate the actual Spectral function table present in the Spectral
  38. * module.
  39. */
  40. struct target_if_spectral_ops spectral_ops;
  41. int spectral_debug_level = DEBUG_SPECTRAL;
  42. struct spectral_tgt_ops ops_tgt;
  43. #ifdef SPECTRAL_MODULIZED_ENABLE
  44. /**
  45. * target_if_spectral_wmi_service_enabled() - API to check whether a
  46. * given WMI service is enabled
  47. * @psoc: Pointer to psoc
  48. * @wmi_handle: WMI handle
  49. * @service_id: service id
  50. *
  51. * Return: true or false
  52. */
  53. static
  54. bool target_if_spectral_wmi_service_enabled(struct wlan_objmgr_psoc *psoc,
  55. wmi_unified_t wmi_handle,
  56. uint32_t service_id)
  57. {
  58. struct target_if_psoc_spectral *psoc_spectral;
  59. if (!psoc) {
  60. spectral_err("psoc is null");
  61. return false;
  62. }
  63. if (!wmi_handle) {
  64. spectral_err("wmi handle is null");
  65. return false;
  66. }
  67. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  68. if (!psoc_spectral) {
  69. spectral_err("psoc spectral object is null");
  70. return false;
  71. }
  72. return psoc_spectral->wmi_ops.wmi_service_enabled(wmi_handle,
  73. service_id);
  74. }
  75. #else
  76. /**
  77. * target_if_spectral_wmi_service_enabled() - API to check whether a
  78. * given WMI service is enabled
  79. * @psoc: Pointer to psoc
  80. * @wmi_handle: WMI handle
  81. * @service_id: service id
  82. *
  83. * Return: true or false
  84. */
  85. static
  86. bool target_if_spectral_wmi_service_enabled(struct wlan_objmgr_psoc *psoc,
  87. wmi_unified_t wmi_handle,
  88. uint32_t service_id)
  89. {
  90. return wmi_service_enabled(wmi_handle, service_id);
  91. }
  92. #endif /* SPECTRAL_MODULIZED_ENABLE */
  93. struct target_if_spectral *get_target_if_spectral_handle_from_pdev(
  94. struct wlan_objmgr_pdev *pdev)
  95. {
  96. struct target_if_spectral *spectral;
  97. struct wlan_objmgr_psoc *psoc;
  98. struct wlan_lmac_if_rx_ops *rx_ops;
  99. if (!pdev) {
  100. spectral_err("pdev is null");
  101. return NULL;
  102. }
  103. psoc = wlan_pdev_get_psoc(pdev);
  104. if (!psoc) {
  105. spectral_err("psoc is null");
  106. return NULL;
  107. }
  108. rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
  109. if (!rx_ops) {
  110. spectral_err("rx_ops is null");
  111. return NULL;
  112. }
  113. spectral = (struct target_if_spectral *)
  114. rx_ops->sptrl_rx_ops.sptrlro_get_pdev_target_handle(pdev);
  115. return spectral;
  116. }
  117. qdf_export_symbol(get_target_if_spectral_handle_from_pdev);
  118. /**
  119. * target_if_spectral_get_normal_mode_cap() - API to get normal
  120. * Spectral scan capability of a given pdev
  121. * @pdev: pdev handle
  122. * @normal_mode_disable: Pointer to caller variable
  123. *
  124. * API to get normal Spectral scan mode capability a given pdev.
  125. * This information is derived from the WMI service
  126. * "WMI_SERVICE_SPECTRAL_SCAN_DISABLED".
  127. *
  128. * Return: QDF_STATUS on success
  129. */
  130. static QDF_STATUS
  131. target_if_spectral_get_normal_mode_cap(struct wlan_objmgr_pdev *pdev,
  132. bool *normal_mode_disable)
  133. {
  134. struct wlan_objmgr_psoc *psoc;
  135. struct wmi_unified *wmi_handle;
  136. struct target_if_psoc_spectral *psoc_spectral;
  137. if (!pdev) {
  138. spectral_err("pdev is null");
  139. return QDF_STATUS_E_INVAL;
  140. }
  141. psoc = wlan_pdev_get_psoc(pdev);
  142. if (!psoc) {
  143. spectral_err("psoc is null");
  144. return QDF_STATUS_E_INVAL;
  145. }
  146. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  147. if (!psoc_spectral) {
  148. spectral_err("psoc spectral object is null");
  149. return QDF_STATUS_E_INVAL;
  150. }
  151. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  152. if (!wmi_handle) {
  153. spectral_err("wmi handle is null");
  154. return QDF_STATUS_E_INVAL;
  155. }
  156. *normal_mode_disable = target_if_spectral_wmi_service_enabled(psoc,
  157. wmi_handle, wmi_service_spectral_scan_disabled);
  158. return QDF_STATUS_SUCCESS;
  159. }
  160. /**
  161. * target_if_spectral_get_agile_mode_cap() - API to check agile
  162. * Spectral scan mode capability of a given pdev.
  163. * @pdev: pdev handle
  164. * @agile_cap: Pointer to caller variable
  165. *
  166. * API to check agile Spectral scan mode is disabled for a given pdev.
  167. * This information is derived from the chain mask table entries.
  168. *
  169. * Return: QDF_STATUS on success
  170. */
  171. static QDF_STATUS
  172. target_if_spectral_get_agile_mode_cap(
  173. struct wlan_objmgr_pdev *pdev,
  174. struct target_if_spectral_agile_mode_cap *agile_cap)
  175. {
  176. struct wlan_objmgr_psoc *psoc;
  177. struct target_psoc_info *tgt_psoc_info;
  178. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr;
  179. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap;
  180. uint8_t pdev_id, i;
  181. uint32_t table_id;
  182. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  183. struct wlan_psoc_host_chainmask_table *table;
  184. struct wmi_unified *wmi_handle;
  185. if (!pdev) {
  186. spectral_err("pdev is null");
  187. return QDF_STATUS_E_INVAL;
  188. }
  189. psoc = wlan_pdev_get_psoc(pdev);
  190. if (!psoc) {
  191. spectral_err("psoc is null");
  192. return QDF_STATUS_E_FAILURE;
  193. }
  194. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  195. if (!wmi_handle) {
  196. spectral_err("wmi handle is null");
  197. return QDF_STATUS_E_INVAL;
  198. }
  199. /* Agile Spectral is disabled for legacy targets */
  200. if (!target_if_spectral_wmi_service_enabled(psoc, wmi_handle,
  201. wmi_service_ext_msg)) {
  202. agile_cap->agile_spectral_cap = false;
  203. agile_cap->agile_spectral_cap_160 = false;
  204. agile_cap->agile_spectral_cap_80p80 = false;
  205. agile_cap->agile_spectral_cap_320 = false;
  206. return QDF_STATUS_SUCCESS;
  207. }
  208. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  209. if (!tgt_psoc_info) {
  210. spectral_err("target_psoc_info is null");
  211. return QDF_STATUS_E_FAILURE;
  212. }
  213. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  214. if (!mac_phy_cap_arr) {
  215. spectral_err("mac phy cap array is null");
  216. return QDF_STATUS_E_FAILURE;
  217. }
  218. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  219. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  220. table_id = mac_phy_cap->chainmask_table_id;
  221. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  222. if (!ext_svc_param) {
  223. spectral_err("Extended service ready params null");
  224. return QDF_STATUS_E_FAILURE;
  225. }
  226. table = &ext_svc_param->chainmask_table[table_id];
  227. for (i = 0; i < table->num_valid_chainmasks; i++) {
  228. agile_cap->agile_spectral_cap |=
  229. table->cap_list[i].supports_aSpectral;
  230. agile_cap->agile_spectral_cap_160 |=
  231. table->cap_list[i].supports_aSpectral_160;
  232. agile_cap->agile_spectral_cap_320 |= 0;
  233. }
  234. agile_cap->agile_spectral_cap_80p80 = agile_cap->agile_spectral_cap_160;
  235. return QDF_STATUS_SUCCESS;
  236. }
  237. /**
  238. * target_if_spectral_init_pdev_feature_cap_per_mode() - API to initialize
  239. * Spectral scan pdev feature caps for a given Spectral mode
  240. * @pdev: pdev handle
  241. * @smode: Spectral scan mode
  242. *
  243. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE/
  244. * QDF_STATUS_E_INVAL on failure
  245. */
  246. static QDF_STATUS
  247. target_if_spectral_init_pdev_feature_cap_per_mode(struct wlan_objmgr_pdev *pdev,
  248. enum spectral_scan_mode smode)
  249. {
  250. struct wlan_objmgr_psoc *psoc;
  251. bool normal_mode_disable;
  252. struct target_if_spectral_agile_mode_cap agile_cap = { 0 };
  253. QDF_STATUS status;
  254. if (!pdev) {
  255. spectral_err("pdev is null");
  256. return QDF_STATUS_E_INVAL;
  257. }
  258. psoc = wlan_pdev_get_psoc(pdev);
  259. if (!psoc) {
  260. spectral_err("psoc is null");
  261. return QDF_STATUS_E_INVAL;
  262. }
  263. switch (smode) {
  264. case SPECTRAL_SCAN_MODE_NORMAL:
  265. if (target_if_spectral_is_feature_disabled_psoc(psoc)) {
  266. wlan_pdev_nif_feat_ext_cap_set(
  267. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  268. return QDF_STATUS_SUCCESS;
  269. }
  270. status = target_if_spectral_get_normal_mode_cap(
  271. pdev, &normal_mode_disable);
  272. if (QDF_IS_STATUS_ERROR(status)) {
  273. spectral_err("Failed to get normal spectral scan caps");
  274. return QDF_STATUS_E_FAILURE;
  275. }
  276. if (normal_mode_disable)
  277. wlan_pdev_nif_feat_ext_cap_set(
  278. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  279. else
  280. wlan_pdev_nif_feat_ext_cap_clear(
  281. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  282. break;
  283. case SPECTRAL_SCAN_MODE_AGILE:
  284. if (target_if_spectral_is_feature_disabled_psoc(psoc)) {
  285. wlan_pdev_nif_feat_ext_cap_set(
  286. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  287. wlan_pdev_nif_feat_ext_cap_set(
  288. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  289. wlan_pdev_nif_feat_ext_cap_set(
  290. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  291. wlan_pdev_nif_feat_ext_cap_set(
  292. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  293. return QDF_STATUS_SUCCESS;
  294. }
  295. status = target_if_spectral_get_agile_mode_cap(
  296. pdev, &agile_cap);
  297. if (QDF_IS_STATUS_ERROR(status)) {
  298. spectral_err("Failed to get agile Spectral capability");
  299. return QDF_STATUS_E_FAILURE;
  300. }
  301. if (!agile_cap.agile_spectral_cap)
  302. wlan_pdev_nif_feat_ext_cap_set(
  303. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  304. else
  305. wlan_pdev_nif_feat_ext_cap_clear(
  306. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  307. if (!agile_cap.agile_spectral_cap_160)
  308. wlan_pdev_nif_feat_ext_cap_set(
  309. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  310. else
  311. wlan_pdev_nif_feat_ext_cap_clear(
  312. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  313. if (!agile_cap.agile_spectral_cap_80p80)
  314. wlan_pdev_nif_feat_ext_cap_set(
  315. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  316. else
  317. wlan_pdev_nif_feat_ext_cap_clear(
  318. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  319. if (!agile_cap.agile_spectral_cap_320)
  320. wlan_pdev_nif_feat_ext_cap_set(
  321. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  322. else
  323. wlan_pdev_nif_feat_ext_cap_clear(
  324. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  325. break;
  326. default:
  327. spectral_err("Invalid Spectral scan mode %d", smode);
  328. return QDF_STATUS_E_INVAL;
  329. }
  330. return QDF_STATUS_SUCCESS;
  331. }
  332. /**
  333. * target_if_spectral_init_pdev_feature_caps() - API to initialize
  334. * Spectral scan pdev feature caps for a given pdev
  335. * @pdev: pdev handle
  336. *
  337. * API initialize normal and agile Spectral scan pdev
  338. * feature caps for a given pdev.
  339. *
  340. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  341. */
  342. static QDF_STATUS
  343. target_if_spectral_init_pdev_feature_caps(struct wlan_objmgr_pdev *pdev)
  344. {
  345. enum spectral_scan_mode smode;
  346. if (!pdev) {
  347. spectral_err("pdev is NULL!");
  348. return QDF_STATUS_E_INVAL;
  349. }
  350. smode = SPECTRAL_SCAN_MODE_NORMAL;
  351. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  352. QDF_STATUS status;
  353. status = target_if_spectral_init_pdev_feature_cap_per_mode(
  354. pdev, smode);
  355. if (QDF_IS_STATUS_ERROR(status))
  356. return QDF_STATUS_E_INVAL;
  357. }
  358. return QDF_STATUS_SUCCESS;
  359. }
  360. static void target_if_spectral_get_firstvdev_pdev(struct wlan_objmgr_pdev *pdev,
  361. void *obj, void *arg)
  362. {
  363. struct wlan_objmgr_vdev *vdev = obj;
  364. struct wlan_objmgr_vdev **first_vdev = arg;
  365. if (!(*first_vdev))
  366. *first_vdev = vdev;
  367. }
  368. struct wlan_objmgr_vdev *
  369. target_if_spectral_get_vdev(struct target_if_spectral *spectral,
  370. enum spectral_scan_mode smode)
  371. {
  372. struct wlan_objmgr_pdev *pdev = NULL;
  373. struct wlan_objmgr_vdev *first_vdev = NULL;
  374. 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. target_type == TARGET_TYPE_PEACH) {
  1832. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1833. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1834. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1835. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1836. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1837. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1838. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1839. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1840. } else {
  1841. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1842. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1843. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1844. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1845. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1846. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1847. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1848. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1849. }
  1850. break;
  1851. case SPECTRAL_GEN2:
  1852. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1853. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1854. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1855. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1856. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1857. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1858. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1859. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1860. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1861. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1862. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1863. break;
  1864. default:
  1865. spectral_err("Invalid spectral generation %d", gen);
  1866. return QDF_STATUS_E_INVAL;
  1867. }
  1868. return QDF_STATUS_SUCCESS;
  1869. }
  1870. /**
  1871. * target_if_init_spectral_param_properties() - Initialize Spectral parameter
  1872. * properties
  1873. * @spectral: Pointer to Spectral target_if internal private data
  1874. *
  1875. * Initialize Spectral parameter properties
  1876. *
  1877. * Return: QDF_STATUS
  1878. */
  1879. static QDF_STATUS
  1880. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1881. {
  1882. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1883. int param;
  1884. /* Initialize default values for properties.
  1885. * Default values are supported for all the parameters for all modes
  1886. * and allows different values for each mode for all the parameters .
  1887. */
  1888. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1889. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1890. spectral->properties[smode][param].supported = true;
  1891. spectral->properties[smode][param].common_all_modes =
  1892. false;
  1893. }
  1894. }
  1895. /* Once FW advertisement is in place remove this hard coding */
  1896. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1897. spectral->properties[SPECTRAL_SCAN_MODE_NORMAL]
  1898. [SPECTRAL_PARAM_FREQUENCY].supported = false;
  1899. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1900. spectral->properties[smode]
  1901. [SPECTRAL_PARAM_SPECT_PRI].common_all_modes = true;
  1902. spectral->properties[smode]
  1903. [SPECTRAL_PARAM_SCAN_PERIOD].common_all_modes = true;
  1904. spectral->properties[smode]
  1905. [SPECTRAL_PARAM_INIT_DELAY].common_all_modes = true;
  1906. }
  1907. return QDF_STATUS_SUCCESS;
  1908. }
  1909. /* Bandwidth to half bandwidth mapping */
  1910. static const enum phy_ch_width half_bw_map[] = {
  1911. #ifdef WLAN_FEATURE_11BE
  1912. [CH_WIDTH_320MHZ] = CH_WIDTH_160MHZ,
  1913. #endif
  1914. [CH_WIDTH_80P80MHZ] = CH_WIDTH_80MHZ,
  1915. [CH_WIDTH_160MHZ] = CH_WIDTH_80MHZ,
  1916. [CH_WIDTH_80MHZ] = CH_WIDTH_40MHZ,
  1917. [CH_WIDTH_40MHZ] = CH_WIDTH_20MHZ,
  1918. [CH_WIDTH_20MHZ] = CH_WIDTH_10MHZ,
  1919. [CH_WIDTH_10MHZ] = CH_WIDTH_5MHZ,
  1920. [CH_WIDTH_5MHZ] = CH_WIDTH_INVALID
  1921. };
  1922. /**
  1923. * target_if_get_half_bandwidth() - Get half bandwidth for a given bandwidth
  1924. * @bw: bandwidth
  1925. *
  1926. * Return: Half bandwidth of @bw
  1927. */
  1928. static enum phy_ch_width target_if_get_half_bandwidth(enum phy_ch_width bw)
  1929. {
  1930. if (bw >= CH_WIDTH_INVALID)
  1931. return CH_WIDTH_INVALID;
  1932. return half_bw_map[bw];
  1933. }
  1934. /**
  1935. * target_if_populate_supported_sscan_bws_be() - Populate supported spectral
  1936. * scan bandwidths for beryllium chipsets
  1937. * @spectral: Spectral LMAC object
  1938. *
  1939. * Return: QDF_STATUS of operation
  1940. */
  1941. static QDF_STATUS
  1942. target_if_populate_supported_sscan_bws_be(struct target_if_spectral *spectral)
  1943. {
  1944. enum phy_ch_width op_bw;
  1945. struct spectral_supported_bws *supported_bws;
  1946. QDF_STATUS status;
  1947. qdf_assert_always(spectral);
  1948. /* 20MHz */
  1949. op_bw = CH_WIDTH_20MHZ;
  1950. supported_bws = &spectral->supported_bws
  1951. [SPECTRAL_SCAN_MODE_NORMAL][op_bw];
  1952. supported_bws->bandwidths |= 1 << get_supported_sscan_bw_pos(op_bw);
  1953. spectral->supported_sscan_bw_list
  1954. [SPECTRAL_SCAN_MODE_NORMAL][op_bw] = true;
  1955. supported_bws = &spectral->supported_bws
  1956. [SPECTRAL_SCAN_MODE_AGILE][op_bw];
  1957. supported_bws->bandwidths |= 1 << get_supported_sscan_bw_pos(op_bw);
  1958. spectral->supported_sscan_bw_list
  1959. [SPECTRAL_SCAN_MODE_AGILE][op_bw] = true;
  1960. for (op_bw = CH_WIDTH_40MHZ; op_bw < CH_WIDTH_MAX; op_bw++) {
  1961. bool is_supported;
  1962. enum phy_ch_width half_op_bw;
  1963. status = wlan_reg_is_chwidth_supported(spectral->pdev_obj,
  1964. op_bw, &is_supported);
  1965. if (QDF_IS_STATUS_ERROR(status)) {
  1966. spectral_err("Unable to check if ch_width(%d) is supported",
  1967. op_bw);
  1968. return QDF_STATUS_E_FAILURE;
  1969. }
  1970. if (!is_supported)
  1971. continue;
  1972. spectral_debug("Updating supported bw for op_bw: %d", op_bw);
  1973. /* Normal mode */
  1974. supported_bws = &spectral->supported_bws
  1975. [SPECTRAL_SCAN_MODE_NORMAL][op_bw];
  1976. supported_bws->bandwidths |=
  1977. 1 << get_supported_sscan_bw_pos(op_bw);
  1978. spectral->supported_sscan_bw_list
  1979. [SPECTRAL_SCAN_MODE_NORMAL][op_bw] = true;
  1980. /* Agile mode */
  1981. supported_bws = &spectral->supported_bws
  1982. [SPECTRAL_SCAN_MODE_AGILE][op_bw];
  1983. supported_bws->bandwidths |=
  1984. 1 << get_supported_sscan_bw_pos(op_bw);
  1985. spectral->supported_sscan_bw_list
  1986. [SPECTRAL_SCAN_MODE_AGILE][op_bw] = true;
  1987. half_op_bw = target_if_get_half_bandwidth(op_bw);
  1988. if (half_op_bw != CH_WIDTH_INVALID) {
  1989. supported_bws->bandwidths |=
  1990. 1 << get_supported_sscan_bw_pos(half_op_bw);
  1991. spectral->supported_sscan_bw_list
  1992. [SPECTRAL_SCAN_MODE_AGILE][half_op_bw] = true;
  1993. }
  1994. }
  1995. return QDF_STATUS_SUCCESS;
  1996. }
  1997. /**
  1998. * target_if_populate_supported_sscan_bws() - Populate supported spectral
  1999. * scan bandwidths
  2000. * @spectral: Spectral LMAC object
  2001. * @target_type: Target type
  2002. *
  2003. * Return: QDF_STATUS of operation
  2004. */
  2005. static QDF_STATUS
  2006. target_if_populate_supported_sscan_bws(struct target_if_spectral *spectral,
  2007. uint32_t target_type)
  2008. {
  2009. enum spectral_scan_mode smode;
  2010. enum phy_ch_width op_bw;
  2011. struct spectral_supported_bws *supported_bws;
  2012. struct wlan_objmgr_psoc *psoc;
  2013. QDF_STATUS status;
  2014. qdf_assert_always(spectral);
  2015. if (is_spectral_arch_beryllium(target_type))
  2016. return target_if_populate_supported_sscan_bws_be(spectral);
  2017. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  2018. if (!psoc) {
  2019. spectral_err("psoc is null");
  2020. return QDF_STATUS_E_NULL_VALUE;
  2021. }
  2022. for (op_bw = CH_WIDTH_20MHZ; op_bw < CH_WIDTH_MAX; op_bw++) {
  2023. bool is_supported;
  2024. status = wlan_reg_is_chwidth_supported(spectral->pdev_obj,
  2025. op_bw, &is_supported);
  2026. if (QDF_IS_STATUS_ERROR(status)) {
  2027. spectral_err("Unable to check if ch_width(%d) is supported",
  2028. op_bw);
  2029. return QDF_STATUS_E_FAILURE;
  2030. }
  2031. if (!is_supported)
  2032. continue;
  2033. spectral_debug("Updating supported bw for op_bw: %d", op_bw);
  2034. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2035. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2036. supported_bws = &spectral->supported_bws[smode][op_bw];
  2037. if (is_ch_width_160_or_80p80(op_bw) &&
  2038. smode == SPECTRAL_SCAN_MODE_AGILE) {
  2039. /**
  2040. * If fragmentation is supported, then only 80Hz
  2041. * agile width is supported
  2042. */
  2043. if (spectral->rparams.
  2044. fragmentation_160[smode]) {
  2045. supported_bws->bandwidths |=
  2046. 1 << get_supported_sscan_bw_pos(
  2047. CH_WIDTH_80MHZ);
  2048. spectral->supported_sscan_bw_list
  2049. [smode][CH_WIDTH_80MHZ] = true;
  2050. }
  2051. /**
  2052. * If restricted 80p80 is supported, then both
  2053. * 160 and 80p80 agile widths are supported for
  2054. * 160MHz, and only 160MHz agile width is
  2055. * supported for 80p80
  2056. */
  2057. if (wlan_psoc_nif_fw_ext_cap_get(
  2058. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  2059. supported_bws->bandwidths |=
  2060. 1 << get_supported_sscan_bw_pos(
  2061. CH_WIDTH_160MHZ);
  2062. spectral->supported_sscan_bw_list
  2063. [smode][CH_WIDTH_160MHZ] = true;
  2064. if (op_bw == CH_WIDTH_160MHZ) {
  2065. supported_bws->bandwidths |=
  2066. 1 << get_supported_sscan_bw_pos(
  2067. CH_WIDTH_80P80MHZ);
  2068. spectral->supported_sscan_bw_list
  2069. [smode][CH_WIDTH_80P80MHZ] = true;
  2070. }
  2071. }
  2072. } else {
  2073. supported_bws->bandwidths |=
  2074. 1 << get_supported_sscan_bw_pos(
  2075. op_bw);
  2076. spectral->supported_sscan_bw_list
  2077. [smode][op_bw] = true;
  2078. }
  2079. }
  2080. }
  2081. return QDF_STATUS_SUCCESS;
  2082. }
  2083. QDF_STATUS
  2084. target_if_init_spectral_capability(struct target_if_spectral *spectral,
  2085. uint32_t target_type)
  2086. {
  2087. struct wlan_objmgr_psoc *psoc;
  2088. struct wlan_objmgr_pdev *pdev;
  2089. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  2090. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  2091. struct target_psoc_info *tgt_psoc_info;
  2092. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  2093. struct spectral_caps *pcap = &spectral->capability;
  2094. QDF_STATUS status;
  2095. pdev = spectral->pdev_obj;
  2096. psoc = wlan_pdev_get_psoc(pdev);
  2097. if (!psoc) {
  2098. spectral_err("psoc is null");
  2099. return QDF_STATUS_E_FAILURE;
  2100. }
  2101. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  2102. if (!tgt_psoc_info) {
  2103. spectral_err("target_psoc_info is null");
  2104. return QDF_STATUS_E_FAILURE;
  2105. }
  2106. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  2107. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  2108. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  2109. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  2110. /* XXX : Workaround: Set Spectral capability */
  2111. pcap = &spectral->capability;
  2112. pcap->phydiag_cap = 1;
  2113. pcap->radar_cap = 1;
  2114. pcap->spectral_cap = wlan_pdev_nif_feat_ext_cap_get(
  2115. pdev, WLAN_PDEV_FEXT_NORMAL_SPECTRAL_SCAN_DIS);
  2116. pcap->advncd_spectral_cap = pcap->spectral_cap;
  2117. pcap->hw_gen = spectral->spectral_gen;
  2118. pcap->agile_spectral_cap = !wlan_pdev_nif_feat_ext_cap_get(
  2119. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_DIS);
  2120. pcap->agile_spectral_cap_160 = !wlan_pdev_nif_feat_ext_cap_get(
  2121. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_160_DIS);
  2122. pcap->agile_spectral_cap_80p80 = !wlan_pdev_nif_feat_ext_cap_get(
  2123. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_80P80_DIS);
  2124. pcap->agile_spectral_cap_320 = !wlan_pdev_nif_feat_ext_cap_get(
  2125. pdev, WLAN_PDEV_FEXT_AGILE_SPECTRAL_SCAN_320_DIS);
  2126. if (scaling_params) {
  2127. for (param_idx = 0; param_idx < num_bin_scaling_params;
  2128. param_idx++) {
  2129. if (scaling_params[param_idx].pdev_id == pdev_id) {
  2130. pcap->is_scaling_params_populated = true;
  2131. pcap->formula_id =
  2132. scaling_params[param_idx].formula_id;
  2133. pcap->low_level_offset =
  2134. scaling_params[param_idx].low_level_offset;
  2135. pcap->high_level_offset =
  2136. scaling_params[param_idx].high_level_offset;
  2137. pcap->rssi_thr =
  2138. scaling_params[param_idx].rssi_thr;
  2139. pcap->default_agc_max_gain =
  2140. scaling_params[param_idx].default_agc_max_gain;
  2141. break;
  2142. }
  2143. }
  2144. }
  2145. pcap->num_detectors_20mhz = 1;
  2146. pcap->num_detectors_40mhz = 1;
  2147. pcap->num_detectors_80mhz = 1;
  2148. if (target_type == TARGET_TYPE_QCN9000 ||
  2149. target_type == TARGET_TYPE_QCN6122 ||
  2150. target_type == TARGET_TYPE_QCN9160 ||
  2151. target_type == TARGET_TYPE_QCA6490 ||
  2152. target_type == TARGET_TYPE_KIWI ||
  2153. target_type == TARGET_TYPE_MANGO ||
  2154. target_type == TARGET_TYPE_PEACH) {
  2155. pcap->num_detectors_160mhz = 1;
  2156. pcap->num_detectors_80p80mhz = 1;
  2157. pcap->num_detectors_320mhz = 0;
  2158. } else if (is_spectral_arch_beryllium(target_type)) {
  2159. pcap->num_detectors_160mhz = 1;
  2160. pcap->num_detectors_80p80mhz = 0;
  2161. pcap->num_detectors_320mhz = 1;
  2162. } else {
  2163. pcap->num_detectors_160mhz = 2;
  2164. pcap->num_detectors_80p80mhz = 2;
  2165. pcap->num_detectors_320mhz = 0;
  2166. }
  2167. status = target_if_populate_supported_sscan_bws(spectral, target_type);
  2168. if (QDF_IS_STATUS_ERROR(status)) {
  2169. spectral_err("Unable to populate supported sscan BWs");
  2170. return QDF_STATUS_E_FAILURE;
  2171. }
  2172. return QDF_STATUS_SUCCESS;
  2173. }
  2174. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2175. /**
  2176. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  2177. * internal operations with functions related to spectral simulation
  2178. * @p_sops: spectral low level ops table
  2179. *
  2180. * Initialize spectral target_if internal operations with functions
  2181. * related to spectral simulation
  2182. *
  2183. * Return: None
  2184. */
  2185. static void
  2186. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  2187. {
  2188. /*
  2189. * Spectral simulation is currently intended for platform transitions
  2190. * where underlying HW support may not be available for some time.
  2191. * Hence, we do not currently provide a runtime switch to turn the
  2192. * simulation on or off.
  2193. * In case of future requirements where runtime switches are required,
  2194. * this can be added. But it is suggested to use application layer
  2195. * simulation as far as possible in such cases, since the main
  2196. * use of record and replay of samples would concern higher
  2197. * level sample processing rather than lower level delivery.
  2198. */
  2199. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  2200. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  2201. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  2202. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  2203. p_sops->configure_spectral =
  2204. target_if_spectral_sops_sim_configure_params;
  2205. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  2206. }
  2207. #else
  2208. /**
  2209. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  2210. * internal operations
  2211. * @p_sops: spectral low level ops table
  2212. *
  2213. * Return: None
  2214. */
  2215. static void
  2216. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  2217. {
  2218. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  2219. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  2220. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  2221. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  2222. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  2223. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  2224. }
  2225. #endif
  2226. /**
  2227. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  2228. * operations common to all Spectral chipset generations
  2229. *
  2230. * Initializes target_if_spectral_ops common to all chipset generations
  2231. *
  2232. * Return: None
  2233. */
  2234. static void
  2235. target_if_init_spectral_ops_common(void)
  2236. {
  2237. struct target_if_spectral_ops *p_sops = &spectral_ops;
  2238. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  2239. p_sops->get_capability = target_if_spectral_get_capability;
  2240. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  2241. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  2242. target_if_init_spectral_simulation_ops(p_sops);
  2243. p_sops->get_extension_channel =
  2244. target_if_spectral_get_extension_channel;
  2245. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  2246. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  2247. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  2248. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  2249. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  2250. p_sops->reset_hw = target_if_spectral_reset_hw;
  2251. p_sops->get_chain_noise_floor =
  2252. target_if_spectral_get_chain_noise_floor;
  2253. }
  2254. /**
  2255. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  2256. * operations specific to Spectral chipset generation 2.
  2257. *
  2258. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  2259. *
  2260. * Return: None
  2261. */
  2262. static void
  2263. target_if_init_spectral_ops_gen2(void)
  2264. {
  2265. struct target_if_spectral_ops *p_sops = &spectral_ops;
  2266. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  2267. }
  2268. #ifdef BIG_ENDIAN_HOST
  2269. /**
  2270. * spectral_is_host_byte_swap_required() - Check if byte swap has to be done
  2271. * on the Host
  2272. * @pdev: pdev pointer
  2273. * @is_swap_required: Pointer to caller variable
  2274. *
  2275. * Return: QDF_STATUS of operation
  2276. */
  2277. static QDF_STATUS
  2278. spectral_is_host_byte_swap_required(struct wlan_objmgr_pdev *pdev,
  2279. bool *is_swap_required)
  2280. {
  2281. struct wlan_objmgr_psoc *psoc;
  2282. struct wmi_unified *wmi_handle;
  2283. if (!pdev) {
  2284. spectral_err("pdev is null");
  2285. return QDF_STATUS_E_INVAL;
  2286. }
  2287. psoc = wlan_pdev_get_psoc(pdev);
  2288. if (!psoc) {
  2289. spectral_err("psoc is null");
  2290. return QDF_STATUS_E_INVAL;
  2291. }
  2292. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  2293. if (!wmi_handle) {
  2294. spectral_err("wmi handle is null");
  2295. return QDF_STATUS_E_INVAL;
  2296. }
  2297. /**
  2298. * If a chipset supports byte-swap inside the target itself, then no
  2299. * need to apply byte swap on the Host.
  2300. */
  2301. *is_swap_required = !target_if_spectral_wmi_service_enabled(
  2302. psoc, wmi_handle,
  2303. wmi_service_phy_dma_byte_swap_support);
  2304. return QDF_STATUS_SUCCESS;
  2305. }
  2306. /**
  2307. * target_if_spectral_init_byte_swap_funcs_gen3() - Initialize byte-swap
  2308. * operations for Spectral chipset generation 3.
  2309. * @spectral: Spectral LMAC object
  2310. * @p_sops: Spectral function pointer table
  2311. *
  2312. * Return: None
  2313. */
  2314. static void
  2315. target_if_spectral_init_byte_swap_funcs_gen3(
  2316. struct target_if_spectral *spectral,
  2317. struct target_if_spectral_ops *p_sops)
  2318. {
  2319. bool is_swap_required;
  2320. QDF_STATUS status;
  2321. qdf_assert_always(spectral);
  2322. qdf_assert_always(p_sops);
  2323. status = spectral_is_host_byte_swap_required(spectral->pdev_obj,
  2324. &is_swap_required);
  2325. if (QDF_IS_STATUS_ERROR(status)) {
  2326. spectral_err("Failed to check whether byte swap is required");
  2327. return;
  2328. }
  2329. if (is_swap_required) {
  2330. p_sops->byte_swap_headers =
  2331. target_if_byte_swap_spectral_headers_gen3;
  2332. p_sops->byte_swap_fft_bins =
  2333. target_if_byte_swap_spectral_fft_bins_gen3;
  2334. } else {
  2335. p_sops->byte_swap_headers = NULL;
  2336. p_sops->byte_swap_fft_bins = NULL;
  2337. }
  2338. }
  2339. #else
  2340. static void
  2341. target_if_spectral_init_byte_swap_funcs_gen3(
  2342. struct target_if_spectral *spectral,
  2343. struct target_if_spectral_ops *p_sops)
  2344. {
  2345. qdf_assert_always(p_sops);
  2346. /* Byte-swap is not required for little-endian Hosts */
  2347. p_sops->byte_swap_headers = NULL;
  2348. p_sops->byte_swap_fft_bins = NULL;
  2349. }
  2350. #endif /* BIG_ENDIAN_HOST */
  2351. /**
  2352. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  2353. * operations specific to Spectral chipset generation 3.
  2354. * @spectral: Spectral LMAC object
  2355. *
  2356. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  2357. *
  2358. * Return: None
  2359. */
  2360. static void
  2361. target_if_init_spectral_ops_gen3(struct target_if_spectral *spectral)
  2362. {
  2363. struct target_if_spectral_ops *p_sops = &spectral_ops;
  2364. p_sops->process_spectral_report =
  2365. target_if_spectral_process_report_gen3;
  2366. target_if_spectral_init_byte_swap_funcs_gen3(spectral, p_sops);
  2367. }
  2368. /**
  2369. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  2370. * operations.
  2371. * @spectral: Pointer to Spectral target_if internal private data
  2372. *
  2373. * Initializes all function pointers in target_if_spectral_ops for
  2374. * all generations
  2375. *
  2376. * Return: None
  2377. */
  2378. static void
  2379. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  2380. {
  2381. target_if_init_spectral_ops_common();
  2382. if (spectral->spectral_gen == SPECTRAL_GEN2)
  2383. target_if_init_spectral_ops_gen2();
  2384. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  2385. target_if_init_spectral_ops_gen3(spectral);
  2386. else
  2387. spectral_err("Invalid Spectral generation");
  2388. }
  2389. /*
  2390. * Dummy Functions:
  2391. * These functions are initially registered to avoid any crashes due to
  2392. * invocation of spectral functions before they are registered.
  2393. */
  2394. static uint64_t
  2395. null_get_tsf64(void *arg)
  2396. {
  2397. spectral_ops_not_registered("get_tsf64");
  2398. return 0;
  2399. }
  2400. static uint32_t
  2401. null_get_capability(void *arg, enum spectral_capability_type type)
  2402. {
  2403. /*
  2404. * TODO : We should have conditional compilation to get the capability
  2405. * : We have not yet attahced ATH layer here, so there is no
  2406. * : way to check the HAL capbalities
  2407. */
  2408. spectral_ops_not_registered("get_capability");
  2409. /* TODO : For the time being, we are returning TRUE */
  2410. return true;
  2411. }
  2412. static uint32_t
  2413. null_set_rxfilter(void *arg, int rxfilter)
  2414. {
  2415. spectral_ops_not_registered("set_rxfilter");
  2416. return 1;
  2417. }
  2418. static uint32_t
  2419. null_get_rxfilter(void *arg)
  2420. {
  2421. spectral_ops_not_registered("get_rxfilter");
  2422. return 0;
  2423. }
  2424. static uint32_t
  2425. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  2426. {
  2427. spectral_ops_not_registered("is_spectral_active");
  2428. return 1;
  2429. }
  2430. static uint32_t
  2431. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  2432. {
  2433. spectral_ops_not_registered("is_spectral_enabled");
  2434. return 1;
  2435. }
  2436. static uint32_t
  2437. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  2438. enum spectral_cp_error_code *err)
  2439. {
  2440. spectral_ops_not_registered("start_spectral_scan");
  2441. return 1;
  2442. }
  2443. static uint32_t
  2444. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  2445. {
  2446. spectral_ops_not_registered("stop_spectral_scan");
  2447. return 1;
  2448. }
  2449. static uint32_t
  2450. null_get_extension_channel(void *arg, enum spectral_scan_mode smode)
  2451. {
  2452. spectral_ops_not_registered("get_extension_channel");
  2453. return 1;
  2454. }
  2455. static int8_t
  2456. null_get_ctl_noisefloor(void *arg)
  2457. {
  2458. spectral_ops_not_registered("get_ctl_noisefloor");
  2459. return 1;
  2460. }
  2461. static int8_t
  2462. null_get_ext_noisefloor(void *arg)
  2463. {
  2464. spectral_ops_not_registered("get_ext_noisefloor");
  2465. return 0;
  2466. }
  2467. static uint32_t
  2468. null_configure_spectral(void *arg, struct spectral_config *params,
  2469. enum spectral_scan_mode smode)
  2470. {
  2471. spectral_ops_not_registered("configure_spectral");
  2472. return 0;
  2473. }
  2474. static uint32_t
  2475. null_get_spectral_config(void *arg, struct spectral_config *params,
  2476. enum spectral_scan_mode smode)
  2477. {
  2478. spectral_ops_not_registered("get_spectral_config");
  2479. return 0;
  2480. }
  2481. static uint32_t
  2482. null_get_ent_spectral_mask(void *arg)
  2483. {
  2484. spectral_ops_not_registered("get_ent_spectral_mask");
  2485. return 0;
  2486. }
  2487. static uint32_t
  2488. null_get_mac_address(void *arg, char *addr)
  2489. {
  2490. spectral_ops_not_registered("get_mac_address");
  2491. return 0;
  2492. }
  2493. static uint32_t
  2494. null_get_current_channel(void *arg, enum spectral_scan_mode smode)
  2495. {
  2496. spectral_ops_not_registered("get_current_channel");
  2497. return 0;
  2498. }
  2499. static uint32_t
  2500. null_reset_hw(void *arg)
  2501. {
  2502. spectral_ops_not_registered("get_current_channel");
  2503. return 0;
  2504. }
  2505. static uint32_t
  2506. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  2507. {
  2508. spectral_ops_not_registered("get_chain_noise_floor");
  2509. return 0;
  2510. }
  2511. static int
  2512. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  2513. uint8_t *data,
  2514. uint32_t datalen,
  2515. struct target_if_spectral_rfqual_info *p_rfqual,
  2516. struct target_if_spectral_chan_info *p_chaninfo,
  2517. uint64_t tsf64,
  2518. struct target_if_spectral_acs_stats *acs_stats)
  2519. {
  2520. spectral_ops_not_registered("spectral_process_phyerr");
  2521. return 0;
  2522. }
  2523. static int
  2524. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  2525. void *payload)
  2526. {
  2527. spectral_ops_not_registered("process_spectral_report");
  2528. return 0;
  2529. }
  2530. /**
  2531. * target_if_spectral_init_dummy_function_table() -
  2532. * Initialize target_if internal
  2533. * Spectral operations to dummy functions
  2534. * @ps: Pointer to Spectral target_if internal private data
  2535. *
  2536. * Initialize all the function pointers in target_if_spectral_ops with
  2537. * dummy functions.
  2538. *
  2539. * Return: None
  2540. */
  2541. static void
  2542. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  2543. {
  2544. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  2545. p_sops->get_tsf64 = null_get_tsf64;
  2546. p_sops->get_capability = null_get_capability;
  2547. p_sops->set_rxfilter = null_set_rxfilter;
  2548. p_sops->get_rxfilter = null_get_rxfilter;
  2549. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  2550. p_sops->is_spectral_active = null_is_spectral_active;
  2551. p_sops->start_spectral_scan = null_start_spectral_scan;
  2552. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  2553. p_sops->get_extension_channel = null_get_extension_channel;
  2554. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  2555. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  2556. p_sops->configure_spectral = null_configure_spectral;
  2557. p_sops->get_spectral_config = null_get_spectral_config;
  2558. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  2559. p_sops->get_mac_address = null_get_mac_address;
  2560. p_sops->get_current_channel = null_get_current_channel;
  2561. p_sops->reset_hw = null_reset_hw;
  2562. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  2563. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  2564. p_sops->process_spectral_report = null_process_spectral_report;
  2565. }
  2566. /**
  2567. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  2568. * operations
  2569. * @spectral: Pointer to Spectral target_if internal private data
  2570. * @p: Pointer to Spectral function table
  2571. *
  2572. * Return: None
  2573. */
  2574. static void
  2575. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  2576. struct target_if_spectral_ops *p)
  2577. {
  2578. struct target_if_spectral_ops *p_sops =
  2579. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2580. *p_sops = *p;
  2581. }
  2582. /**
  2583. * target_if_spectral_clear_stats() - Clear Spectral stats
  2584. * @spectral: Pointer to Spectral target_if internal private data
  2585. *
  2586. * Function to clear spectral stats
  2587. *
  2588. * Return: None
  2589. */
  2590. static void
  2591. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  2592. {
  2593. struct target_if_spectral_ops *p_sops =
  2594. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2595. qdf_mem_zero(&spectral->spectral_stats,
  2596. sizeof(struct target_if_spectral_stats));
  2597. spectral->spectral_stats.last_reset_tstamp =
  2598. p_sops->get_tsf64(spectral);
  2599. }
  2600. /**
  2601. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  2602. * @spectral: Pointer to Spectral target_if internal private data
  2603. *
  2604. * Function to check whether hardware supports spectral
  2605. *
  2606. * Return: True if HW supports Spectral, false if HW does not support Spectral
  2607. */
  2608. static int
  2609. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  2610. {
  2611. struct target_if_spectral_ops *p_sops = NULL;
  2612. struct spectral_caps *pcap = NULL;
  2613. int is_spectral_supported = true;
  2614. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2615. pcap = &spectral->capability;
  2616. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  2617. is_spectral_supported = false;
  2618. spectral_info("SPECTRAL : No PHYDIAG support");
  2619. return is_spectral_supported;
  2620. }
  2621. pcap->phydiag_cap = 1;
  2622. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  2623. is_spectral_supported = false;
  2624. spectral_info("SPECTRAL : No RADAR support");
  2625. return is_spectral_supported;
  2626. }
  2627. pcap->radar_cap = 1;
  2628. if (p_sops->get_capability(spectral,
  2629. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  2630. is_spectral_supported = false;
  2631. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  2632. return is_spectral_supported;
  2633. }
  2634. pcap->spectral_cap = 1;
  2635. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  2636. == false) {
  2637. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  2638. } else {
  2639. pcap->advncd_spectral_cap = 1;
  2640. }
  2641. return is_spectral_supported;
  2642. }
  2643. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2644. /**
  2645. * target_if_spectral_detach_simulation() - De-initialize Spectral
  2646. * Simulation functionality
  2647. * @spectral: Pointer to Spectral target_if internal private data
  2648. *
  2649. * Function to de-initialize Spectral Simulation functionality
  2650. *
  2651. * Return: None
  2652. */
  2653. static void
  2654. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  2655. {
  2656. target_if_spectral_sim_detach(spectral);
  2657. }
  2658. #else
  2659. static void
  2660. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  2661. {
  2662. }
  2663. #endif
  2664. /**
  2665. * target_if_spectral_detach() - De-initialize target_if Spectral
  2666. * @pdev: Pointer to pdev object
  2667. *
  2668. * Function to detach target_if spectral
  2669. *
  2670. * Return: None
  2671. */
  2672. static void
  2673. target_if_spectral_detach(struct target_if_spectral *spectral)
  2674. {
  2675. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  2676. spectral_info("spectral detach");
  2677. if (spectral) {
  2678. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2679. qdf_spinlock_destroy
  2680. (&spectral->param_info[smode].osps_lock);
  2681. target_if_spectral_detach_simulation(spectral);
  2682. qdf_spinlock_destroy(&spectral->spectral_lock);
  2683. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  2684. qdf_spinlock_destroy(&spectral->detector_list_lock);
  2685. qdf_spinlock_destroy(&spectral->session_report_info_lock);
  2686. qdf_spinlock_destroy(&spectral->session_det_map_lock);
  2687. qdf_mem_free(spectral);
  2688. spectral = NULL;
  2689. }
  2690. }
  2691. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  2692. /**
  2693. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  2694. * functionality
  2695. * @spectral: Pointer to Spectral target_if internal private data
  2696. *
  2697. * Function to initialize spectral simulation functionality
  2698. *
  2699. * Return: 0 on success, negative error code on failure
  2700. */
  2701. static int
  2702. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  2703. {
  2704. if (target_if_spectral_sim_attach(spectral)) {
  2705. qdf_mem_free(spectral);
  2706. return -EPERM;
  2707. }
  2708. return 0;
  2709. }
  2710. #else
  2711. static int
  2712. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  2713. {
  2714. return 0;
  2715. }
  2716. #endif
  2717. /**
  2718. * target_if_spectral_len_adj_swar_init() - Initialize FFT bin length adjustment
  2719. * related info
  2720. * @swar: Pointer to Spectral FFT bin length adjustment SWAR params
  2721. * @rparams: Pointer to Spectral report parameter object
  2722. * @target_type: Target type
  2723. *
  2724. * Function to Initialize parameters related to Spectral FFT bin
  2725. * length adjustment SWARs.
  2726. *
  2727. * Return: void
  2728. */
  2729. static void
  2730. target_if_spectral_len_adj_swar_init(struct spectral_fft_bin_len_adj_swar *swar,
  2731. struct spectral_report_params *rparams,
  2732. uint32_t target_type)
  2733. {
  2734. if (target_type == TARGET_TYPE_QCA8074V2 ||
  2735. target_type == TARGET_TYPE_QCA9574 ||
  2736. target_type == TARGET_TYPE_QCN9000 ||
  2737. target_type == TARGET_TYPE_QCN6122 ||
  2738. target_type == TARGET_TYPE_QCN9160 ||
  2739. target_type == TARGET_TYPE_QCA5018 ||
  2740. target_type == TARGET_TYPE_QCA6750 ||
  2741. target_type == TARGET_TYPE_QCA6490 ||
  2742. target_type == TARGET_TYPE_KIWI ||
  2743. target_type == TARGET_TYPE_MANGO ||
  2744. target_type == TARGET_TYPE_PEACH) {
  2745. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  2746. rparams->hw_fft_bin_width = 2;
  2747. } else if (target_type == TARGET_TYPE_QCA8074 ||
  2748. target_type == TARGET_TYPE_QCA6018 ||
  2749. target_type == TARGET_TYPE_QCA6390) {
  2750. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  2751. rparams->hw_fft_bin_width = 4;
  2752. } else {
  2753. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  2754. rparams->hw_fft_bin_width = 1;
  2755. }
  2756. if (target_type == TARGET_TYPE_QCA8074 ||
  2757. target_type == TARGET_TYPE_QCA8074V2 ||
  2758. target_type == TARGET_TYPE_QCA9574 ||
  2759. target_type == TARGET_TYPE_QCA6018 ||
  2760. target_type == TARGET_TYPE_QCN6122 ||
  2761. target_type == TARGET_TYPE_QCN9160 ||
  2762. target_type == TARGET_TYPE_QCA5332 ||
  2763. target_type == TARGET_TYPE_QCA5018 ||
  2764. target_type == TARGET_TYPE_QCN9000 ||
  2765. target_type == TARGET_TYPE_QCA6490 ||
  2766. target_type == TARGET_TYPE_QCN9224 ||
  2767. target_type == TARGET_TYPE_KIWI ||
  2768. target_type == TARGET_TYPE_MANGO ||
  2769. target_type == TARGET_TYPE_PEACH) {
  2770. swar->inband_fftbin_size_adj = 1;
  2771. swar->null_fftbin_adj = 1;
  2772. } else {
  2773. swar->inband_fftbin_size_adj = 0;
  2774. swar->null_fftbin_adj = 0;
  2775. }
  2776. if (target_type == TARGET_TYPE_QCA8074V2)
  2777. swar->packmode_fftbin_size_adj = 1;
  2778. else
  2779. swar->packmode_fftbin_size_adj = 0;
  2780. }
  2781. /**
  2782. * target_if_spectral_report_params_init() - Initialize parameters which
  2783. * describes the structure of Spectral reports
  2784. *
  2785. * @rparams: Pointer to Spectral report parameter object
  2786. * @target_type: target type
  2787. *
  2788. * Function to Initialize parameters related to the structure of Spectral
  2789. * reports.
  2790. *
  2791. * Return: void
  2792. */
  2793. static void
  2794. target_if_spectral_report_params_init(
  2795. struct spectral_report_params *rparams,
  2796. uint32_t target_type)
  2797. {
  2798. enum spectral_scan_mode smode;
  2799. /* This entries are currently used by gen3 chipsets only. Hence
  2800. * initialization is done for gen3 alone. In future if other generations
  2801. * needs to use them they have to add proper initial values.
  2802. */
  2803. if (target_type == TARGET_TYPE_QCN9000 ||
  2804. target_type == TARGET_TYPE_QCN6122 ||
  2805. target_type == TARGET_TYPE_QCN9160 ||
  2806. target_type == TARGET_TYPE_QCA5018 ||
  2807. target_type == TARGET_TYPE_QCA6750 ||
  2808. target_type == TARGET_TYPE_QCA6490 ||
  2809. target_type == TARGET_TYPE_QCA5332 ||
  2810. target_type == TARGET_TYPE_QCN9224 ||
  2811. target_type == TARGET_TYPE_KIWI ||
  2812. target_type == TARGET_TYPE_MANGO ||
  2813. target_type == TARGET_TYPE_PEACH) {
  2814. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_2;
  2815. rparams->num_spectral_detectors =
  2816. NUM_SPECTRAL_DETECTORS_GEN3_V2;
  2817. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2818. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2819. rparams->fragmentation_160[smode] = false;
  2820. } else {
  2821. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_1;
  2822. rparams->num_spectral_detectors =
  2823. NUM_SPECTRAL_DETECTORS_GEN3_V1;
  2824. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2825. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2826. rparams->fragmentation_160[smode] = true;
  2827. }
  2828. switch (rparams->version) {
  2829. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  2830. rparams->ssumaary_padding_bytes =
  2831. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1;
  2832. rparams->fft_report_hdr_len =
  2833. FFT_REPORT_HEADER_LENGTH_GEN3_V1;
  2834. break;
  2835. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  2836. rparams->ssumaary_padding_bytes =
  2837. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2;
  2838. rparams->fft_report_hdr_len =
  2839. FFT_REPORT_HEADER_LENGTH_GEN3_V2;
  2840. break;
  2841. default:
  2842. qdf_assert_always(0);
  2843. }
  2844. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_0] =
  2845. SPECTRAL_SCAN_MODE_NORMAL;
  2846. if (target_type == TARGET_TYPE_QCN9000 ||
  2847. target_type == TARGET_TYPE_QCN6122 ||
  2848. target_type == TARGET_TYPE_QCN9224 ||
  2849. target_type == TARGET_TYPE_QCN9160 ||
  2850. target_type == TARGET_TYPE_QCA6490 ||
  2851. target_type == TARGET_TYPE_KIWI ||
  2852. target_type == TARGET_TYPE_MANGO ||
  2853. target_type == TARGET_TYPE_PEACH) {
  2854. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2855. SPECTRAL_SCAN_MODE_AGILE;
  2856. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2857. SPECTRAL_SCAN_MODE_INVALID;
  2858. } else if (target_type == TARGET_TYPE_QCA5332) {
  2859. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2860. SPECTRAL_SCAN_MODE_INVALID;
  2861. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2862. SPECTRAL_SCAN_MODE_INVALID;
  2863. } else {
  2864. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  2865. SPECTRAL_SCAN_MODE_NORMAL;
  2866. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  2867. SPECTRAL_SCAN_MODE_AGILE;
  2868. }
  2869. }
  2870. /**
  2871. * target_if_spectral_timestamp_war_init() - Initialize Spectral timestamp WAR
  2872. * related info
  2873. * @twar: Pointer to Spectral timstamp WAR related info
  2874. *
  2875. * Function to Initialize parameters related to Spectral timestamp WAR
  2876. *
  2877. * Return: void
  2878. */
  2879. static void
  2880. target_if_spectral_timestamp_war_init(struct spectral_timestamp_war *twar)
  2881. {
  2882. enum spectral_scan_mode smode;
  2883. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2884. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2885. twar->last_fft_timestamp[smode] = 0;
  2886. twar->timestamp_war_offset[smode] = 0;
  2887. }
  2888. twar->target_reset_count = 0;
  2889. }
  2890. #ifdef OPTIMIZED_SAMP_MESSAGE
  2891. /**
  2892. * target_if_spectral_is_hw_mode_sbs() - Check if the given pdev is in SBS mode
  2893. * @pdev: pdev pointer
  2894. * @is_hw_mode_sbs: Pointer to the variable where this function should write
  2895. * whether the given pdev is in SBS mode
  2896. *
  2897. * Return: QDF_STATUS of operation
  2898. */
  2899. static QDF_STATUS
  2900. target_if_spectral_is_hw_mode_sbs(struct wlan_objmgr_pdev *pdev,
  2901. bool *is_hw_mode_sbs)
  2902. {
  2903. struct wlan_objmgr_psoc *psoc;
  2904. struct target_psoc_info *tgt_hdl;
  2905. enum wmi_host_hw_mode_config_type mode;
  2906. qdf_assert_always(is_hw_mode_sbs);
  2907. psoc = wlan_pdev_get_psoc(pdev);
  2908. if (!psoc) {
  2909. spectral_err("psoc is null");
  2910. return QDF_STATUS_E_NULL_VALUE;
  2911. }
  2912. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  2913. if (!tgt_hdl) {
  2914. spectral_err("target_psoc_info is null");
  2915. return QDF_STATUS_E_NULL_VALUE;
  2916. }
  2917. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  2918. switch (mode) {
  2919. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  2920. case WMI_HOST_HW_MODE_SBS:
  2921. case WMI_HOST_HW_MODE_DBS_SBS:
  2922. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  2923. *is_hw_mode_sbs = true;
  2924. break;
  2925. default:
  2926. *is_hw_mode_sbs = false;
  2927. break;
  2928. }
  2929. return QDF_STATUS_SUCCESS;
  2930. }
  2931. /**
  2932. * target_if_get_pdev_mac_phy_caps() - Get the MAC_PHY capabilities of a pdev
  2933. * @pdev: pdev pointer
  2934. *
  2935. * Return: On success, pointer to MAC_PHY capabilities of @pdev.
  2936. * On failure, NULL
  2937. */
  2938. static struct wlan_psoc_host_mac_phy_caps *
  2939. target_if_get_pdev_mac_phy_caps(struct wlan_objmgr_pdev *pdev)
  2940. {
  2941. struct wlan_objmgr_psoc *psoc;
  2942. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr;
  2943. struct target_psoc_info *tgt_psoc_info;
  2944. uint8_t pdev_id;
  2945. if (!pdev) {
  2946. spectral_err("pdev is NULL");
  2947. return NULL;
  2948. }
  2949. psoc = wlan_pdev_get_psoc(pdev);
  2950. if (!psoc) {
  2951. spectral_err("psoc is null");
  2952. return NULL;
  2953. }
  2954. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  2955. if (!tgt_psoc_info) {
  2956. spectral_err("target_psoc_info is null");
  2957. return NULL;
  2958. }
  2959. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  2960. if (!mac_phy_cap_arr) {
  2961. spectral_err("mac phy cap array is null");
  2962. return NULL;
  2963. }
  2964. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  2965. return &mac_phy_cap_arr[pdev_id];
  2966. }
  2967. /**
  2968. * struct target_if_sscan_pdev_phy_info - PHY information of the pdev on
  2969. * which sscan is done. A pointer to an instance of this structure is passed
  2970. * as an argument to the iterator function target_if_find_sscan_pdev_phya1()
  2971. * @phy_id: PHY ID of this pdev
  2972. * @is_using_phya1: Pointer to the variable where the iterator function should
  2973. * populate whether the given pdev is using PHYA1
  2974. */
  2975. struct target_if_sscan_pdev_phy_info {
  2976. uint8_t phy_id;
  2977. bool *is_using_phya1;
  2978. };
  2979. /**
  2980. * target_if_find_sscan_pdev_phya1() - This is an iterator function to
  2981. * wlan_objmgr_iterate_obj_list(). It checks whether a given sscan_pdev (pdev on
  2982. * which sscan is currently issued) is using PHYA1 by comparing against the pdev
  2983. * argument given by the wlan_objmgr_iterate_obj_list()
  2984. * @psoc: Pointer to psoc
  2985. * @object: Pointer to pdev
  2986. * @arg: Pointer to target_if_sscan_pdev_phy_info of the sscan_pdev for which
  2987. * we want to check if it uses PHYA1
  2988. *
  2989. * Return: None
  2990. */
  2991. static void
  2992. target_if_find_sscan_pdev_phya1(struct wlan_objmgr_psoc *psoc,
  2993. void *object, void *arg)
  2994. {
  2995. struct target_if_sscan_pdev_phy_info *sscan_pdev_phy_info = arg;
  2996. struct wlan_objmgr_pdev *cur_pdev = object;
  2997. struct wlan_psoc_host_mac_phy_caps *cur_mac_phy_caps;
  2998. cur_mac_phy_caps = target_if_get_pdev_mac_phy_caps(cur_pdev);
  2999. if (!cur_mac_phy_caps) {
  3000. spectral_err("Failed to get MAC PHY Capabilities of"
  3001. "pdev %pK", cur_pdev);
  3002. return;
  3003. }
  3004. spectral_debug("supported_bands: %0x phy_id: %d",
  3005. cur_mac_phy_caps->supported_bands,
  3006. cur_mac_phy_caps->phy_id);
  3007. /* No need to do anything if the current pdev is same as sscan_pdev */
  3008. if (sscan_pdev_phy_info->phy_id == cur_mac_phy_caps->phy_id)
  3009. return;
  3010. /**
  3011. * Compare the phy_id of both the SBS pdevs to figure out if
  3012. * the sscan_pdev using PHYA1
  3013. */
  3014. if (sscan_pdev_phy_info->phy_id > cur_mac_phy_caps->phy_id)
  3015. *sscan_pdev_phy_info->is_using_phya1 = true;
  3016. else
  3017. *sscan_pdev_phy_info->is_using_phya1 = false;
  3018. }
  3019. /**
  3020. * target_if_spectral_detector_list_init() - Initialize Spectral detector list
  3021. * based on target type
  3022. * @spectral: Pointer to Spectral target_if
  3023. *
  3024. * Function to initialize Spectral detector list for possible combinations of
  3025. * Spectral scan mode and channel width, based on target type.
  3026. *
  3027. * Return: Success/Failure
  3028. */
  3029. static QDF_STATUS
  3030. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  3031. {
  3032. struct sscan_detector_list *det_list;
  3033. enum spectral_scan_mode smode;
  3034. enum phy_ch_width ch_width;
  3035. QDF_STATUS ret;
  3036. bool is_hw_mode_sbs = false, is_using_phya1 = false;
  3037. if (!spectral) {
  3038. spectral_err_rl("Spectral LMAC object is null");
  3039. return QDF_STATUS_E_NULL_VALUE;
  3040. }
  3041. /**
  3042. * Special handling is required for SBS mode where the detector
  3043. * list should be the following.
  3044. * For the pdev that use PHYA0:
  3045. * detector 0 for normal mode
  3046. * detector 2 for agile mode
  3047. * For the pdev that use PHYA1:
  3048. * detector 1 for normal mode
  3049. * detector 2 for agile mode
  3050. *
  3051. * There is no direct way of knowing which pdevs are using PHYA0 or
  3052. * PHYA1. We need to look at the phy_id of a given pdev and compare
  3053. * against other pdevs on the same psoc to figure out whether the given
  3054. * pdev is operating using PHYA1.
  3055. */
  3056. /* First check whether this pdev is in SBS mode */
  3057. ret = target_if_spectral_is_hw_mode_sbs(spectral->pdev_obj,
  3058. &is_hw_mode_sbs);
  3059. if (QDF_IS_STATUS_ERROR(ret)) {
  3060. spectral_err("Failed to check whether hw mode is SBS");
  3061. return ret;
  3062. }
  3063. if (is_hw_mode_sbs) {
  3064. struct wlan_psoc_host_mac_phy_caps *mac_phy_caps;
  3065. struct target_if_sscan_pdev_phy_info pdev_phy_info;
  3066. mac_phy_caps =
  3067. target_if_get_pdev_mac_phy_caps(spectral->pdev_obj);
  3068. if (!mac_phy_caps) {
  3069. spectral_err("Failed to get MAC PHY Capabilities of"
  3070. "pdev %pK", spectral->pdev_obj);
  3071. return QDF_STATUS_E_FAILURE;
  3072. }
  3073. spectral_debug("bands: %0x phy_id: %d",
  3074. mac_phy_caps->supported_bands,
  3075. mac_phy_caps->phy_id);
  3076. pdev_phy_info.phy_id = mac_phy_caps->phy_id;
  3077. pdev_phy_info.is_using_phya1 = &is_using_phya1;
  3078. /* Iterate over all pdevs on this psoc */
  3079. wlan_objmgr_iterate_obj_list
  3080. (wlan_pdev_get_psoc(spectral->pdev_obj),
  3081. WLAN_PDEV_OP,
  3082. target_if_find_sscan_pdev_phya1,
  3083. &pdev_phy_info, 0,
  3084. WLAN_SPECTRAL_ID);
  3085. }
  3086. /**
  3087. * We assume there are 2 detectors. The Detector ID coming first will
  3088. * always be pri80 detector, and second detector for sec80.
  3089. */
  3090. ch_width = CH_WIDTH_20MHZ;
  3091. for (; ch_width < CH_WIDTH_MAX; ch_width++) {
  3092. /* Normal spectral scan */
  3093. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3094. spectral_debug("is_hw_mode_sbs: %d is_using_phya1:%d",
  3095. is_hw_mode_sbs, is_using_phya1);
  3096. qdf_spin_lock_bh(&spectral->detector_list_lock);
  3097. if (!spectral->supported_sscan_bw_list[smode][ch_width])
  3098. goto agile_handling;
  3099. det_list = &spectral->detector_list[smode][ch_width];
  3100. det_list->num_detectors = 1;
  3101. if (is_hw_mode_sbs && is_using_phya1)
  3102. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_1;
  3103. else
  3104. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_0;
  3105. if (is_ch_width_160_or_80p80(ch_width) &&
  3106. spectral->rparams.fragmentation_160[smode]) {
  3107. det_list->num_detectors += 1;
  3108. det_list->detectors[1] = SPECTRAL_DETECTOR_ID_1;
  3109. }
  3110. agile_handling:
  3111. /* Agile spectral scan */
  3112. smode = SPECTRAL_SCAN_MODE_AGILE;
  3113. if (!spectral->supported_sscan_bw_list[smode][ch_width]) {
  3114. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  3115. continue;
  3116. }
  3117. det_list = &spectral->detector_list[smode][ch_width];
  3118. det_list->num_detectors = 1;
  3119. if (spectral->rparams.fragmentation_160[smode])
  3120. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_2;
  3121. else
  3122. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_1;
  3123. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  3124. }
  3125. return QDF_STATUS_SUCCESS;
  3126. }
  3127. #else
  3128. static QDF_STATUS
  3129. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  3130. {
  3131. return QDF_STATUS_SUCCESS;
  3132. }
  3133. #endif /* OPTIMIZED_SAMP_MESSAGE */
  3134. /**
  3135. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  3136. * functionality for the given pdev
  3137. * @pdev: Pointer to pdev object
  3138. *
  3139. * Function to initialize pointer to spectral target_if internal private data
  3140. *
  3141. * Return: On success, pointer to Spectral target_if internal private data, on
  3142. * failure, NULL
  3143. */
  3144. void *
  3145. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  3146. {
  3147. struct target_if_spectral_ops *p_sops = NULL;
  3148. struct target_if_spectral *spectral = NULL;
  3149. uint32_t target_type;
  3150. uint32_t target_revision;
  3151. struct wlan_objmgr_psoc *psoc;
  3152. struct wlan_lmac_if_target_tx_ops *tgt_tx_ops;
  3153. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  3154. QDF_STATUS status;
  3155. struct wlan_lmac_if_tx_ops *tx_ops;
  3156. if (!pdev) {
  3157. spectral_err("SPECTRAL: pdev is NULL!");
  3158. return NULL;
  3159. }
  3160. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  3161. sizeof(struct target_if_spectral));
  3162. if (!spectral)
  3163. return spectral;
  3164. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  3165. /* Store pdev in Spectral */
  3166. spectral->pdev_obj = pdev;
  3167. spectral->vdev_id[SPECTRAL_SCAN_MODE_NORMAL] = WLAN_INVALID_VDEV_ID;
  3168. spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE] = WLAN_INVALID_VDEV_ID;
  3169. psoc = wlan_pdev_get_psoc(pdev);
  3170. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  3171. if (!tx_ops) {
  3172. spectral_err("tx_ops is NULL");
  3173. qdf_mem_free(spectral);
  3174. return NULL;
  3175. }
  3176. tgt_tx_ops = &tx_ops->target_tx_ops;
  3177. if (tgt_tx_ops->tgt_get_tgt_type) {
  3178. target_type = tgt_tx_ops->tgt_get_tgt_type(psoc);
  3179. } else {
  3180. qdf_mem_free(spectral);
  3181. return NULL;
  3182. }
  3183. if (tgt_tx_ops->tgt_get_tgt_revision) {
  3184. target_revision = tgt_tx_ops->tgt_get_tgt_revision(psoc);
  3185. } else {
  3186. qdf_mem_free(spectral);
  3187. return NULL;
  3188. }
  3189. /* init the function ptr table */
  3190. target_if_spectral_init_dummy_function_table(spectral);
  3191. /* get spectral function table */
  3192. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3193. /* TODO : Should this be called here of after ath_attach ? */
  3194. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  3195. spectral_info("HAL_CAP_PHYDIAG : Capable");
  3196. /* TODO: Need to fix the capability check for RADAR */
  3197. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  3198. spectral_info("HAL_CAP_RADAR : Capable");
  3199. /* TODO : Need to fix the capability check for SPECTRAL */
  3200. /* TODO : Should this be called here of after ath_attach ? */
  3201. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  3202. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  3203. qdf_spinlock_create(&spectral->spectral_lock);
  3204. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  3205. target_if_spectral_clear_stats(spectral);
  3206. if (target_type == TARGET_TYPE_QCA8074 ||
  3207. target_type == TARGET_TYPE_QCA8074V2 ||
  3208. target_type == TARGET_TYPE_QCA9574 ||
  3209. target_type == TARGET_TYPE_QCA5332 ||
  3210. target_type == TARGET_TYPE_QCA6018 ||
  3211. target_type == TARGET_TYPE_QCA5018 ||
  3212. target_type == TARGET_TYPE_QCA6390 ||
  3213. target_type == TARGET_TYPE_QCN6122 ||
  3214. target_type == TARGET_TYPE_QCN9160 ||
  3215. target_type == TARGET_TYPE_QCA6490 ||
  3216. target_type == TARGET_TYPE_QCN9000 ||
  3217. target_type == TARGET_TYPE_QCA6750 ||
  3218. target_type == TARGET_TYPE_QCN9224 ||
  3219. target_type == TARGET_TYPE_KIWI ||
  3220. target_type == TARGET_TYPE_MANGO ||
  3221. target_type == TARGET_TYPE_PEACH)
  3222. spectral->direct_dma_support = true;
  3223. target_if_spectral_report_params_init(&spectral->rparams,
  3224. target_type);
  3225. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  3226. &spectral->rparams,
  3227. target_type);
  3228. if ((target_type == TARGET_TYPE_QCA8074) ||
  3229. (target_type == TARGET_TYPE_QCA8074V2) ||
  3230. (target_type == TARGET_TYPE_QCA9574) ||
  3231. (target_type == TARGET_TYPE_QCA6018) ||
  3232. (target_type == TARGET_TYPE_QCA5018) ||
  3233. (target_type == TARGET_TYPE_QCA5332) ||
  3234. (target_type == TARGET_TYPE_QCN6122) ||
  3235. (target_type == TARGET_TYPE_QCN9160) ||
  3236. (target_type == TARGET_TYPE_QCN9000) ||
  3237. (target_type == TARGET_TYPE_QCA6290) ||
  3238. (target_type == TARGET_TYPE_QCA6390) ||
  3239. (target_type == TARGET_TYPE_QCA6490) ||
  3240. (target_type == TARGET_TYPE_QCN9224) ||
  3241. (target_type == TARGET_TYPE_QCA6750) ||
  3242. (target_type == TARGET_TYPE_KIWI) ||
  3243. (target_type == TARGET_TYPE_MANGO) ||
  3244. (target_type == TARGET_TYPE_PEACH)) {
  3245. spectral->spectral_gen = SPECTRAL_GEN3;
  3246. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  3247. spectral->tag_sscan_summary_exp =
  3248. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  3249. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  3250. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  3251. } else {
  3252. spectral->spectral_gen = SPECTRAL_GEN2;
  3253. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  3254. spectral->tag_sscan_summary_exp =
  3255. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  3256. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  3257. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  3258. }
  3259. status = target_if_init_spectral_param_min_max(
  3260. spectral,
  3261. spectral->spectral_gen, target_type);
  3262. if (QDF_IS_STATUS_ERROR(status)) {
  3263. spectral_err("Failed to initialize parameter min max values");
  3264. goto fail;
  3265. }
  3266. target_if_init_spectral_param_properties(spectral);
  3267. /* Init spectral capability */
  3268. if (target_if_init_spectral_capability(spectral, target_type) !=
  3269. QDF_STATUS_SUCCESS) {
  3270. qdf_mem_free(spectral);
  3271. return NULL;
  3272. }
  3273. if (target_if_spectral_attach_simulation(spectral) < 0)
  3274. return NULL;
  3275. target_if_init_spectral_ops(spectral);
  3276. target_if_spectral_timestamp_war_init(&spectral->timestamp_war);
  3277. /* Spectral mode specific init */
  3278. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  3279. spectral->params_valid[smode] = false;
  3280. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  3281. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  3282. }
  3283. target_if_spectral_register_funcs(spectral, &spectral_ops);
  3284. if (target_if_spectral_check_hw_capability(spectral) == false) {
  3285. goto fail;
  3286. } else {
  3287. /*
  3288. * TODO: Once the driver architecture transitions to chipset
  3289. * versioning based checks, reflect this here.
  3290. */
  3291. spectral->is_160_format = false;
  3292. spectral->is_lb_edge_extrabins_format = false;
  3293. spectral->is_rb_edge_extrabins_format = false;
  3294. if (target_type == TARGET_TYPE_QCA9984 ||
  3295. target_type == TARGET_TYPE_QCA9888) {
  3296. spectral->is_160_format = true;
  3297. spectral->is_lb_edge_extrabins_format = true;
  3298. spectral->is_rb_edge_extrabins_format = true;
  3299. } else if ((target_type == TARGET_TYPE_AR900B) &&
  3300. (target_revision == AR900B_REV_2)) {
  3301. spectral->is_rb_edge_extrabins_format = true;
  3302. }
  3303. if (target_type == TARGET_TYPE_QCA9984 ||
  3304. target_type == TARGET_TYPE_QCA9888)
  3305. spectral->is_sec80_rssi_war_required = true;
  3306. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  3307. if (spectral->spectral_gen == SPECTRAL_GEN3)
  3308. init_160mhz_delivery_state_machine(spectral);
  3309. }
  3310. qdf_spinlock_create(&spectral->detector_list_lock);
  3311. qdf_spinlock_create(&spectral->session_report_info_lock);
  3312. qdf_spinlock_create(&spectral->session_det_map_lock);
  3313. return spectral;
  3314. fail:
  3315. target_if_spectral_detach(spectral);
  3316. return NULL;
  3317. }
  3318. /**
  3319. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  3320. * functionality for the given pdev
  3321. * @pdev: Pointer to pdev object
  3322. *
  3323. * Function to de-initialize pointer to spectral target_if internal private data
  3324. *
  3325. * Return: None
  3326. */
  3327. void
  3328. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  3329. {
  3330. struct target_if_spectral *spectral = NULL;
  3331. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3332. if (!spectral) {
  3333. spectral_err("SPECTRAL : Module doesn't exist");
  3334. return;
  3335. }
  3336. target_if_spectral_detach(spectral);
  3337. return;
  3338. }
  3339. /**
  3340. * target_if_psoc_spectral_deinit() - De-initialize target_if Spectral
  3341. * functionality for the given psoc
  3342. * @psoc: Pointer to psoc object
  3343. *
  3344. * Function to de-initialize pointer to psoc spectral target_if internal
  3345. * private data
  3346. *
  3347. * Return: None
  3348. */
  3349. static void
  3350. target_if_psoc_spectral_deinit(struct wlan_objmgr_psoc *psoc)
  3351. {
  3352. struct target_if_psoc_spectral *psoc_spectral;
  3353. if (!psoc) {
  3354. spectral_err("psoc is null");
  3355. return;
  3356. }
  3357. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  3358. if (!psoc_spectral) {
  3359. spectral_err("Spectral target_if psoc object is null");
  3360. return;
  3361. }
  3362. qdf_mem_free(psoc_spectral);
  3363. }
  3364. /**
  3365. * target_if_psoc_spectral_init() - Initialize target_if Spectral
  3366. * functionality for the given psoc
  3367. * @psoc: Pointer to psoc object
  3368. *
  3369. * Function to initialize pointer to psoc spectral target_if internal
  3370. * private data
  3371. *
  3372. * Return: On success, pointer to Spectral psoc target_if internal
  3373. * private data, on failure, NULL
  3374. */
  3375. static void *
  3376. target_if_psoc_spectral_init(struct wlan_objmgr_psoc *psoc)
  3377. {
  3378. struct target_if_psoc_spectral *psoc_spectral = NULL;
  3379. if (!psoc) {
  3380. spectral_err("psoc is null");
  3381. goto fail;
  3382. }
  3383. psoc_spectral = (struct target_if_psoc_spectral *)qdf_mem_malloc(
  3384. sizeof(struct target_if_psoc_spectral));
  3385. if (!psoc_spectral) {
  3386. spectral_err("Spectral lmac psoc object allocation failed");
  3387. goto fail;
  3388. }
  3389. psoc_spectral->psoc_obj = psoc;
  3390. return psoc_spectral;
  3391. fail:
  3392. if (psoc_spectral)
  3393. target_if_psoc_spectral_deinit(psoc);
  3394. return psoc_spectral;
  3395. }
  3396. /**
  3397. * target_if_calculate_center_freq() - Helper routine to
  3398. * check whether given frequency is center frequency of a
  3399. * WLAN channel
  3400. *
  3401. * @spectral: Pointer to Spectral object
  3402. * @chan_freq: Center frequency of a WLAN channel
  3403. * @is_valid: Indicates whether given frequency is valid
  3404. *
  3405. * Return: QDF_STATUS
  3406. */
  3407. static QDF_STATUS
  3408. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  3409. uint32_t chan_freq,
  3410. bool *is_valid)
  3411. {
  3412. struct regulatory_channel *cur_chan_list;
  3413. int i;
  3414. if (!pdev) {
  3415. spectral_err("pdev object is null");
  3416. return QDF_STATUS_E_FAILURE;
  3417. }
  3418. if (!is_valid) {
  3419. spectral_err("is valid argument is null");
  3420. return QDF_STATUS_E_FAILURE;
  3421. }
  3422. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  3423. if (!cur_chan_list)
  3424. return QDF_STATUS_E_FAILURE;
  3425. if (wlan_reg_get_current_chan_list(
  3426. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  3427. spectral_err("Failed to get cur_chan list");
  3428. qdf_mem_free(cur_chan_list);
  3429. return QDF_STATUS_E_FAILURE;
  3430. }
  3431. *is_valid = false;
  3432. for (i = 0; i < NUM_CHANNELS; i++) {
  3433. uint32_t flags;
  3434. uint32_t center_freq;
  3435. flags = cur_chan_list[i].chan_flags;
  3436. center_freq = cur_chan_list[i].center_freq;
  3437. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  3438. (center_freq == chan_freq)) {
  3439. *is_valid = true;
  3440. break;
  3441. }
  3442. }
  3443. qdf_mem_free(cur_chan_list);
  3444. return QDF_STATUS_SUCCESS;
  3445. }
  3446. /**
  3447. * target_if_calculate_center_freq() - Helper routine to
  3448. * find the center frequency of the agile span from a
  3449. * WLAN channel center frequency
  3450. *
  3451. * @spectral: Pointer to Spectral object
  3452. * @ch_width: Channel width array
  3453. * @chan_freq: Center frequency of a WLAN channel
  3454. * @center_freq: Pointer to center frequency
  3455. *
  3456. * Return: QDF_STATUS
  3457. */
  3458. static QDF_STATUS
  3459. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  3460. enum phy_ch_width *ch_width,
  3461. uint16_t chan_freq,
  3462. uint16_t *center_freq)
  3463. {
  3464. enum phy_ch_width agile_ch_width;
  3465. if (!spectral) {
  3466. spectral_err("spectral target if object is null");
  3467. return QDF_STATUS_E_FAILURE;
  3468. }
  3469. if (!ch_width) {
  3470. spectral_err("Channel width array is null");
  3471. return QDF_STATUS_E_INVAL;
  3472. }
  3473. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3474. if (!center_freq) {
  3475. spectral_err("center_freq argument is null");
  3476. return QDF_STATUS_E_FAILURE;
  3477. }
  3478. if (agile_ch_width == CH_WIDTH_20MHZ) {
  3479. *center_freq = chan_freq;
  3480. } else {
  3481. uint16_t start_freq;
  3482. uint16_t end_freq;
  3483. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3484. enum channel_state state;
  3485. state = wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3486. (spectral->pdev_obj, chan_freq, agile_ch_width,
  3487. &bonded_chan_ptr, REG_CURRENT_PWR_MODE,
  3488. NO_SCHANS_PUNC);
  3489. if (state == CHANNEL_STATE_DISABLE ||
  3490. state == CHANNEL_STATE_INVALID) {
  3491. spectral_err("Channel state is disable or invalid");
  3492. return QDF_STATUS_E_FAILURE;
  3493. }
  3494. if (!bonded_chan_ptr) {
  3495. spectral_err("Bonded channel is not found");
  3496. return QDF_STATUS_E_FAILURE;
  3497. }
  3498. start_freq = bonded_chan_ptr->start_freq;
  3499. end_freq = bonded_chan_ptr->end_freq;
  3500. *center_freq = (start_freq + end_freq) >> 1;
  3501. }
  3502. return QDF_STATUS_SUCCESS;
  3503. }
  3504. /**
  3505. * target_if_validate_center_freq() - Helper routine to
  3506. * validate user provided agile center frequency
  3507. *
  3508. * @spectral: Pointer to Spectral object
  3509. * @ch_width: Channel width array
  3510. * @center_freq: User provided agile span center frequency
  3511. * @is_valid: Indicates whether agile span center frequency is valid
  3512. *
  3513. * Return: QDF_STATUS
  3514. */
  3515. static QDF_STATUS
  3516. target_if_validate_center_freq(struct target_if_spectral *spectral,
  3517. enum phy_ch_width *ch_width,
  3518. uint16_t center_freq,
  3519. bool *is_valid)
  3520. {
  3521. enum phy_ch_width agile_ch_width;
  3522. struct wlan_objmgr_pdev *pdev;
  3523. QDF_STATUS status;
  3524. if (!spectral) {
  3525. spectral_err("spectral target if object is null");
  3526. return QDF_STATUS_E_FAILURE;
  3527. }
  3528. if (!ch_width) {
  3529. spectral_err("channel width array is null");
  3530. return QDF_STATUS_E_INVAL;
  3531. }
  3532. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3533. if (!is_valid) {
  3534. spectral_err("is_valid argument is null");
  3535. return QDF_STATUS_E_FAILURE;
  3536. }
  3537. pdev = spectral->pdev_obj;
  3538. if (agile_ch_width == CH_WIDTH_20MHZ) {
  3539. status = target_if_is_center_freq_of_any_chan
  3540. (pdev, center_freq, is_valid);
  3541. if (QDF_IS_STATUS_ERROR(status))
  3542. return QDF_STATUS_E_FAILURE;
  3543. } else {
  3544. uint16_t start_freq;
  3545. uint16_t end_freq;
  3546. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3547. bool is_chan;
  3548. status = target_if_is_center_freq_of_any_chan
  3549. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  3550. &is_chan);
  3551. if (QDF_IS_STATUS_ERROR(status))
  3552. return QDF_STATUS_E_FAILURE;
  3553. if (is_chan) {
  3554. uint32_t calulated_center_freq;
  3555. enum channel_state st;
  3556. st =
  3557. wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3558. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  3559. agile_ch_width,
  3560. &bonded_chan_ptr,
  3561. REG_CURRENT_PWR_MODE,
  3562. NO_SCHANS_PUNC);
  3563. if (st == CHANNEL_STATE_DISABLE ||
  3564. st == CHANNEL_STATE_INVALID) {
  3565. spectral_err("Channel state disable/invalid");
  3566. return QDF_STATUS_E_FAILURE;
  3567. }
  3568. if (!bonded_chan_ptr) {
  3569. spectral_err("Bonded channel is not found");
  3570. return QDF_STATUS_E_FAILURE;
  3571. }
  3572. start_freq = bonded_chan_ptr->start_freq;
  3573. end_freq = bonded_chan_ptr->end_freq;
  3574. calulated_center_freq = (start_freq + end_freq) >> 1;
  3575. *is_valid = (center_freq == calulated_center_freq);
  3576. } else {
  3577. *is_valid = false;
  3578. }
  3579. }
  3580. return QDF_STATUS_SUCCESS;
  3581. }
  3582. /**
  3583. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  3584. * check whether agile span overlaps with current operating band.
  3585. *
  3586. * @spectral: Pointer to Spectral object
  3587. * @ch_width: Channel width array
  3588. * @center_freq: Agile span center frequency
  3589. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  3590. *
  3591. * Helper routine to check whether agile span overlaps with current
  3592. * operating band.
  3593. *
  3594. * Return: QDF_STATUS
  3595. */
  3596. static QDF_STATUS
  3597. target_if_is_agile_span_overlap_with_operating_span
  3598. (struct target_if_spectral *spectral,
  3599. enum phy_ch_width *ch_width,
  3600. struct spectral_config_frequency *center_freq,
  3601. bool *is_overlapping)
  3602. {
  3603. enum phy_ch_width op_ch_width;
  3604. enum phy_ch_width agile_ch_width;
  3605. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3606. struct wlan_objmgr_vdev *vdev;
  3607. struct wlan_objmgr_pdev *pdev;
  3608. int16_t chan_freq;
  3609. uint32_t op_start_freq;
  3610. uint32_t op_end_freq;
  3611. uint32_t agile_start_freq;
  3612. uint32_t agile_end_freq;
  3613. uint32_t cfreq2;
  3614. if (!spectral) {
  3615. spectral_err("Spectral object is NULL");
  3616. return QDF_STATUS_E_FAILURE;
  3617. }
  3618. pdev = spectral->pdev_obj;
  3619. if (!pdev) {
  3620. spectral_err("pdev object is NULL");
  3621. return QDF_STATUS_E_FAILURE;
  3622. }
  3623. if (!ch_width) {
  3624. spectral_err("channel width array is null");
  3625. return QDF_STATUS_E_FAILURE;
  3626. }
  3627. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  3628. if (op_ch_width == CH_WIDTH_INVALID) {
  3629. spectral_err("Invalid channel width");
  3630. return QDF_STATUS_E_INVAL;
  3631. }
  3632. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3633. if (agile_ch_width == CH_WIDTH_INVALID) {
  3634. spectral_err("Invalid channel width");
  3635. return QDF_STATUS_E_INVAL;
  3636. }
  3637. if (!is_overlapping) {
  3638. spectral_err("Argument(is_overlapping) is NULL");
  3639. return QDF_STATUS_E_FAILURE;
  3640. }
  3641. *is_overlapping = false;
  3642. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  3643. if (!vdev) {
  3644. spectral_err("vdev is NULL");
  3645. return QDF_STATUS_E_FAILURE;
  3646. }
  3647. chan_freq = target_if_vdev_get_chan_freq(vdev);
  3648. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  3649. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3650. if (cfreq2 < 0) {
  3651. spectral_err("cfreq2 is invalid");
  3652. return QDF_STATUS_E_FAILURE;
  3653. }
  3654. if (op_ch_width == CH_WIDTH_20MHZ) {
  3655. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  3656. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  3657. } else {
  3658. enum channel_state state;
  3659. state = wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3660. (pdev, chan_freq, op_ch_width, &bonded_chan_ptr,
  3661. REG_CURRENT_PWR_MODE, NO_SCHANS_PUNC);
  3662. if (state == CHANNEL_STATE_DISABLE ||
  3663. state == CHANNEL_STATE_INVALID) {
  3664. spectral_err("Channel state is disable or invalid");
  3665. return QDF_STATUS_E_FAILURE;
  3666. }
  3667. if (!bonded_chan_ptr) {
  3668. spectral_err("Bonded channel is not found");
  3669. return QDF_STATUS_E_FAILURE;
  3670. }
  3671. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  3672. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  3673. }
  3674. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3675. agile_start_freq = center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3676. agile_end_freq = center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3677. if (agile_end_freq > op_start_freq &&
  3678. op_end_freq > agile_start_freq)
  3679. *is_overlapping = true;
  3680. agile_start_freq = center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3681. agile_end_freq = center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3682. if (agile_end_freq > op_start_freq &&
  3683. op_end_freq > agile_start_freq)
  3684. *is_overlapping = true;
  3685. } else {
  3686. agile_start_freq = center_freq->cfreq1 -
  3687. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3688. agile_end_freq = center_freq->cfreq1 +
  3689. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3690. if (agile_end_freq > op_start_freq &&
  3691. op_end_freq > agile_start_freq)
  3692. *is_overlapping = true;
  3693. }
  3694. if (op_ch_width == CH_WIDTH_80P80MHZ) {
  3695. uint32_t sec80_start_feq;
  3696. uint32_t sec80_end_freq;
  3697. sec80_start_feq = cfreq2 - FREQ_OFFSET_40MHZ;
  3698. sec80_end_freq = cfreq2 + FREQ_OFFSET_40MHZ;
  3699. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3700. agile_start_freq =
  3701. center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3702. agile_end_freq =
  3703. center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3704. if (agile_end_freq > sec80_start_feq &&
  3705. sec80_end_freq > agile_start_freq)
  3706. *is_overlapping = true;
  3707. agile_start_freq =
  3708. center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3709. agile_end_freq =
  3710. center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3711. if (agile_end_freq > sec80_start_feq &&
  3712. sec80_end_freq > agile_start_freq)
  3713. *is_overlapping = true;
  3714. } else {
  3715. agile_start_freq = center_freq->cfreq1 -
  3716. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3717. agile_end_freq = center_freq->cfreq1 +
  3718. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3719. if (agile_end_freq > sec80_start_feq &&
  3720. sec80_end_freq > agile_start_freq)
  3721. *is_overlapping = true;
  3722. }
  3723. }
  3724. return QDF_STATUS_SUCCESS;
  3725. }
  3726. /**
  3727. * target_if_spectral_populate_chwidth() - Helper routine to
  3728. * populate channel width for different Spectral modes
  3729. *
  3730. * @spectral: Pointer to Spectral object
  3731. * @ch_width: Channel width array
  3732. * @is_80_80_agile: Indicates whether 80+80 agile scan is requested
  3733. *
  3734. * Helper routine to populate channel width for different Spectral modes
  3735. *
  3736. * Return: QDF_STATUS
  3737. */
  3738. static QDF_STATUS
  3739. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral,
  3740. enum phy_ch_width *ch_width,
  3741. bool is_80_80_agile)
  3742. {
  3743. enum spectral_scan_mode smode;
  3744. qdf_assert_always(spectral);
  3745. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3746. for (; smode < SPECTRAL_SCAN_MODE_MAX; ++smode) {
  3747. /* If user has configured sscan bandwidth, use it */
  3748. if (spectral->sscan_width_configured[smode]) {
  3749. ch_width[smode] = spectral->params[smode].ss_bandwidth;
  3750. } else {
  3751. /* Otherwise, derive the default sscan bandwidth */
  3752. ch_width[smode] = get_default_sscan_bw(spectral, smode,
  3753. is_80_80_agile);
  3754. if (ch_width[smode] >= CH_WIDTH_INVALID) {
  3755. spectral_err("Invalid sscan BW %u",
  3756. ch_width[smode]);
  3757. return QDF_STATUS_E_FAILURE;
  3758. }
  3759. spectral->params[smode].ss_bandwidth = ch_width[smode];
  3760. }
  3761. }
  3762. return QDF_STATUS_SUCCESS;
  3763. }
  3764. /**
  3765. * target_if_spectral_is_valid_80p80_freq() - API to check whether given
  3766. * (cfreq1, cfreq2) pair forms a valid 80+80 combination
  3767. * @pdev: pointer to pdev
  3768. * @cfreq1: center frequency 1
  3769. * @cfreq2: center frequency 2
  3770. *
  3771. * API to check whether given (cfreq1, cfreq2) pair forms a valid 80+80
  3772. * combination
  3773. *
  3774. * Return: true or false
  3775. */
  3776. static bool
  3777. target_if_spectral_is_valid_80p80_freq(struct wlan_objmgr_pdev *pdev,
  3778. uint32_t cfreq1, uint32_t cfreq2)
  3779. {
  3780. struct ch_params ch_params = {0};
  3781. enum channel_state chan_state1;
  3782. enum channel_state chan_state2;
  3783. struct wlan_objmgr_psoc *psoc;
  3784. struct ch_params temp_params = {0};
  3785. qdf_assert_always(pdev);
  3786. psoc = wlan_pdev_get_psoc(pdev);
  3787. qdf_assert_always(psoc);
  3788. /* In restricted 80P80 MHz enabled, only one 80+80 MHz
  3789. * channel is supported with cfreq=5690 and cfreq=5775.
  3790. */
  3791. if (wlan_psoc_nif_fw_ext_cap_get(
  3792. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  3793. return CHAN_WITHIN_RESTRICTED_80P80(cfreq1, cfreq2);
  3794. ch_params.center_freq_seg1 = wlan_reg_freq_to_chan(pdev, cfreq2);
  3795. ch_params.mhz_freq_seg1 = cfreq2;
  3796. ch_params.ch_width = CH_WIDTH_80P80MHZ;
  3797. wlan_reg_set_channel_params_for_pwrmode(
  3798. pdev,
  3799. cfreq1 - FREQ_OFFSET_10MHZ,
  3800. 0,
  3801. &ch_params,
  3802. REG_CURRENT_PWR_MODE);
  3803. if (ch_params.ch_width != CH_WIDTH_80P80MHZ)
  3804. return false;
  3805. if (ch_params.mhz_freq_seg0 != cfreq1 ||
  3806. ch_params.mhz_freq_seg1 != cfreq2)
  3807. return false;
  3808. temp_params.ch_width = CH_WIDTH_80MHZ;
  3809. chan_state1 = wlan_reg_get_5g_bonded_channel_state_for_pwrmode(
  3810. pdev,
  3811. ch_params.mhz_freq_seg0 - FREQ_OFFSET_10MHZ,
  3812. &temp_params,
  3813. REG_CURRENT_PWR_MODE);
  3814. if ((chan_state1 == CHANNEL_STATE_DISABLE) ||
  3815. (chan_state1 == CHANNEL_STATE_INVALID))
  3816. return false;
  3817. temp_params.ch_width = CH_WIDTH_80MHZ;
  3818. chan_state2 = wlan_reg_get_5g_bonded_channel_state_for_pwrmode(
  3819. pdev,
  3820. ch_params.mhz_freq_seg1 - FREQ_OFFSET_10MHZ,
  3821. &temp_params,
  3822. REG_CURRENT_PWR_MODE);
  3823. if ((chan_state2 == CHANNEL_STATE_DISABLE) ||
  3824. (chan_state2 == CHANNEL_STATE_INVALID))
  3825. return false;
  3826. if (abs(ch_params.mhz_freq_seg0 - ch_params.mhz_freq_seg1) <=
  3827. FREQ_OFFSET_80MHZ)
  3828. return false;
  3829. return true;
  3830. }
  3831. /**
  3832. * _target_if_set_spectral_config() - Set spectral config
  3833. * @spectral: Pointer to spectral object
  3834. * @param: Spectral parameter id and value
  3835. * @smode: Spectral scan mode
  3836. * @err: Spectral error code
  3837. *
  3838. * API to set spectral configurations
  3839. *
  3840. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3841. */
  3842. static QDF_STATUS
  3843. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  3844. const struct spectral_cp_param *param,
  3845. const enum spectral_scan_mode smode,
  3846. enum spectral_cp_error_code *err)
  3847. {
  3848. struct spectral_config params;
  3849. struct target_if_spectral_ops *p_sops;
  3850. struct spectral_config *sparams;
  3851. QDF_STATUS status;
  3852. bool is_overlapping;
  3853. uint16_t agile_cfreq;
  3854. bool is_valid_chan;
  3855. struct spectral_param_min_max *param_min_max;
  3856. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  3857. enum spectral_scan_mode m;
  3858. struct spectral_config_frequency center_freq = {0};
  3859. bool is_bw_supported;
  3860. struct wlan_objmgr_vdev *vdev;
  3861. enum phy_ch_width op_bw;
  3862. if (!err) {
  3863. spectral_err("Error code argument is null");
  3864. QDF_ASSERT(0);
  3865. return QDF_STATUS_E_FAILURE;
  3866. }
  3867. *err = SPECTRAL_SCAN_ERR_INVALID;
  3868. if (!param) {
  3869. spectral_err("Parameter object is null");
  3870. return QDF_STATUS_E_FAILURE;
  3871. }
  3872. if (!spectral) {
  3873. spectral_err("spectral object is NULL");
  3874. return QDF_STATUS_E_FAILURE;
  3875. }
  3876. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3877. param_min_max = &spectral->param_min_max;
  3878. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3879. spectral_err("Invalid Spectral mode %u", smode);
  3880. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3881. return QDF_STATUS_E_FAILURE;
  3882. }
  3883. sparams = &spectral->params[smode];
  3884. m = SPECTRAL_SCAN_MODE_NORMAL;
  3885. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  3886. ch_width[m] = CH_WIDTH_INVALID;
  3887. if (!spectral->params_valid[smode]) {
  3888. target_if_spectral_info_read(spectral,
  3889. smode,
  3890. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3891. &spectral->params[smode],
  3892. sizeof(spectral->params[smode]));
  3893. spectral->params_valid[smode] = true;
  3894. }
  3895. switch (param->id) {
  3896. case SPECTRAL_PARAM_FFT_PERIOD:
  3897. sparams->ss_fft_period = param->value;
  3898. break;
  3899. case SPECTRAL_PARAM_SCAN_PERIOD:
  3900. sparams->ss_period = param->value;
  3901. if (sparams->ss_recapture && ((sparams->ss_period <
  3902. SPECTRAL_RECAPTURE_SCAN_PERIOD_THRESHOLD) ||
  3903. (smode == SPECTRAL_SCAN_MODE_AGILE))) {
  3904. sparams->ss_recapture = false;
  3905. spectral_err("FFT recapture cannot be enabled due to scan period: %d us or spectral scan mode: %d",
  3906. sparams->ss_period, smode);
  3907. }
  3908. break;
  3909. case SPECTRAL_PARAM_FFT_RECAPTURE:
  3910. if (param->value) {
  3911. if (sparams->ss_period >=
  3912. SPECTRAL_RECAPTURE_SCAN_PERIOD_THRESHOLD &&
  3913. smode == SPECTRAL_SCAN_MODE_NORMAL) {
  3914. sparams->ss_recapture = true;
  3915. } else {
  3916. spectral_err("FFT recapture cannot be enabled due to scan period: %d us or spectral scan mode: %d",
  3917. sparams->ss_period, smode);
  3918. sparams->ss_recapture = false;
  3919. }
  3920. } else {
  3921. sparams->ss_recapture = false;
  3922. }
  3923. break;
  3924. case SPECTRAL_PARAM_SCAN_COUNT:
  3925. sparams->ss_count = param->value;
  3926. break;
  3927. case SPECTRAL_PARAM_SHORT_REPORT:
  3928. sparams->ss_short_report = (!!param->value) ? true : false;
  3929. break;
  3930. case SPECTRAL_PARAM_SPECT_PRI:
  3931. sparams->ss_spectral_pri = (!!param->value) ? true : false;
  3932. break;
  3933. case SPECTRAL_PARAM_FFT_SIZE:
  3934. status = target_if_spectral_populate_chwidth
  3935. (spectral, ch_width, spectral->params
  3936. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  3937. if (QDF_IS_STATUS_ERROR(status))
  3938. return QDF_STATUS_E_FAILURE;
  3939. if ((param->value < param_min_max->fft_size_min) ||
  3940. (param->value > param_min_max->fft_size_max
  3941. [ch_width[smode]])) {
  3942. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3943. return QDF_STATUS_E_FAILURE;
  3944. }
  3945. sparams->ss_fft_size = param->value;
  3946. break;
  3947. case SPECTRAL_PARAM_GC_ENA:
  3948. sparams->ss_gc_ena = !!param->value;
  3949. break;
  3950. case SPECTRAL_PARAM_RESTART_ENA:
  3951. sparams->ss_restart_ena = !!param->value;
  3952. break;
  3953. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  3954. sparams->ss_noise_floor_ref = param->value;
  3955. break;
  3956. case SPECTRAL_PARAM_INIT_DELAY:
  3957. sparams->ss_init_delay = param->value;
  3958. break;
  3959. case SPECTRAL_PARAM_NB_TONE_THR:
  3960. sparams->ss_nb_tone_thr = param->value;
  3961. break;
  3962. case SPECTRAL_PARAM_STR_BIN_THR:
  3963. sparams->ss_str_bin_thr = param->value;
  3964. break;
  3965. case SPECTRAL_PARAM_WB_RPT_MODE:
  3966. sparams->ss_wb_rpt_mode = !!param->value;
  3967. break;
  3968. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  3969. sparams->ss_rssi_rpt_mode = !!param->value;
  3970. break;
  3971. case SPECTRAL_PARAM_RSSI_THR:
  3972. sparams->ss_rssi_thr = param->value;
  3973. break;
  3974. case SPECTRAL_PARAM_PWR_FORMAT:
  3975. sparams->ss_pwr_format = !!param->value;
  3976. break;
  3977. case SPECTRAL_PARAM_RPT_MODE:
  3978. if ((param->value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  3979. (param->value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  3980. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3981. return QDF_STATUS_E_FAILURE;
  3982. }
  3983. sparams->ss_rpt_mode = param->value;
  3984. break;
  3985. case SPECTRAL_PARAM_BIN_SCALE:
  3986. sparams->ss_bin_scale = param->value;
  3987. break;
  3988. case SPECTRAL_PARAM_DBM_ADJ:
  3989. sparams->ss_dbm_adj = !!param->value;
  3990. break;
  3991. case SPECTRAL_PARAM_CHN_MASK:
  3992. sparams->ss_chn_mask = param->value;
  3993. break;
  3994. case SPECTRAL_PARAM_FREQUENCY:
  3995. status = target_if_spectral_populate_chwidth(
  3996. spectral, ch_width, param->freq.cfreq2 > 0);
  3997. if (QDF_IS_STATUS_ERROR(status)) {
  3998. spectral_err("Failed to populate channel width");
  3999. return QDF_STATUS_E_FAILURE;
  4000. }
  4001. if (ch_width[smode] != CH_WIDTH_80P80MHZ &&
  4002. param->freq.cfreq2) {
  4003. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4004. spectral_err("Non zero cfreq2 expected for 80p80 only");
  4005. return QDF_STATUS_E_INVAL;
  4006. }
  4007. if (ch_width[smode] == CH_WIDTH_80P80MHZ &&
  4008. !param->freq.cfreq2) {
  4009. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4010. spectral_err("Non zero cfreq2 expected for 80p80");
  4011. return QDF_STATUS_E_INVAL;
  4012. }
  4013. status = target_if_is_center_freq_of_any_chan
  4014. (spectral->pdev_obj, param->freq.cfreq1,
  4015. &is_valid_chan);
  4016. if (QDF_IS_STATUS_ERROR(status))
  4017. return QDF_STATUS_E_FAILURE;
  4018. if (is_valid_chan) {
  4019. status = target_if_calculate_center_freq(
  4020. spectral, ch_width,
  4021. param->freq.cfreq1,
  4022. &agile_cfreq);
  4023. if (QDF_IS_STATUS_ERROR(status)) {
  4024. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4025. return QDF_STATUS_E_FAILURE;
  4026. }
  4027. } else {
  4028. bool is_valid_agile_cfreq;
  4029. status = target_if_validate_center_freq
  4030. (spectral, ch_width, param->freq.cfreq1,
  4031. &is_valid_agile_cfreq);
  4032. if (QDF_IS_STATUS_ERROR(status))
  4033. return QDF_STATUS_E_FAILURE;
  4034. if (!is_valid_agile_cfreq) {
  4035. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4036. spectral_err("Invalid agile center frequency");
  4037. return QDF_STATUS_E_FAILURE;
  4038. }
  4039. agile_cfreq = param->freq.cfreq1;
  4040. }
  4041. center_freq.cfreq1 = agile_cfreq;
  4042. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  4043. status = target_if_is_center_freq_of_any_chan
  4044. (spectral->pdev_obj, param->freq.cfreq2,
  4045. &is_valid_chan);
  4046. if (QDF_IS_STATUS_ERROR(status))
  4047. return QDF_STATUS_E_FAILURE;
  4048. if (is_valid_chan) {
  4049. status = target_if_calculate_center_freq(
  4050. spectral, ch_width,
  4051. param->freq.cfreq2,
  4052. &agile_cfreq);
  4053. if (QDF_IS_STATUS_ERROR(status)) {
  4054. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4055. return QDF_STATUS_E_FAILURE;
  4056. }
  4057. } else {
  4058. bool is_valid_agile_cfreq;
  4059. status = target_if_validate_center_freq
  4060. (spectral, ch_width, param->freq.cfreq2,
  4061. &is_valid_agile_cfreq);
  4062. if (QDF_IS_STATUS_ERROR(status))
  4063. return QDF_STATUS_E_FAILURE;
  4064. if (!is_valid_agile_cfreq) {
  4065. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4066. spectral_err("Invalid agile center frequency");
  4067. return QDF_STATUS_E_FAILURE;
  4068. }
  4069. agile_cfreq = param->freq.cfreq2;
  4070. }
  4071. center_freq.cfreq2 = agile_cfreq;
  4072. }
  4073. status = target_if_is_agile_span_overlap_with_operating_span
  4074. (spectral, ch_width,
  4075. &center_freq, &is_overlapping);
  4076. if (QDF_IS_STATUS_ERROR(status))
  4077. return QDF_STATUS_E_FAILURE;
  4078. if (is_overlapping) {
  4079. spectral_err("Agile freq %u, %u overlaps with operating span",
  4080. center_freq.cfreq1, center_freq.cfreq2);
  4081. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4082. return QDF_STATUS_E_FAILURE;
  4083. }
  4084. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  4085. bool is_valid_80p80;
  4086. is_valid_80p80 = target_if_spectral_is_valid_80p80_freq(
  4087. spectral->pdev_obj,
  4088. center_freq.cfreq1,
  4089. center_freq.cfreq2);
  4090. if (!is_valid_80p80) {
  4091. spectral_err("Agile freq %u, %u is invalid 80+80 combination",
  4092. center_freq.cfreq1,
  4093. center_freq.cfreq2);
  4094. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4095. return QDF_STATUS_E_FAILURE;
  4096. }
  4097. }
  4098. sparams->ss_frequency.cfreq1 = center_freq.cfreq1;
  4099. sparams->ss_frequency.cfreq2 = center_freq.cfreq2;
  4100. break;
  4101. case SPECTRAL_PARAM_CHAN_WIDTH:
  4102. if (param->value >= CH_WIDTH_INVALID) {
  4103. spectral_err("invalid sscan width: %u", param->value);
  4104. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4105. return QDF_STATUS_E_FAILURE;
  4106. }
  4107. vdev = target_if_spectral_get_vdev(spectral, smode);
  4108. if (!vdev) {
  4109. spectral_err("vdev is null");
  4110. return QDF_STATUS_E_NULL_VALUE;
  4111. }
  4112. op_bw = target_if_vdev_get_ch_width(vdev);
  4113. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4114. /* Validate the bandwidth */
  4115. status = target_if_is_sscan_bw_supported(
  4116. spectral, smode,
  4117. param->value, op_bw, &is_bw_supported,
  4118. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  4119. ss_frequency.cfreq2 > 0);
  4120. if (QDF_IS_STATUS_ERROR(status)) {
  4121. spectral_err("Unable to check if given sscan_bw is supported");
  4122. return QDF_STATUS_E_FAILURE;
  4123. }
  4124. if (!is_bw_supported) {
  4125. spectral_err("sscan bw(%u) is not supported for the current operating width(%u) and sscan mode(%u)",
  4126. param->value, op_bw, smode);
  4127. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4128. return QDF_STATUS_E_FAILURE;
  4129. }
  4130. sparams->ss_bandwidth = param->value;
  4131. spectral->sscan_width_configured[smode] = true;
  4132. break;
  4133. }
  4134. p_sops->configure_spectral(spectral, sparams, smode);
  4135. /* only to validate the writes */
  4136. p_sops->get_spectral_config(spectral, &params, smode);
  4137. return QDF_STATUS_SUCCESS;
  4138. }
  4139. QDF_STATUS
  4140. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  4141. const struct spectral_cp_param *param,
  4142. const enum spectral_scan_mode smode,
  4143. enum spectral_cp_error_code *err)
  4144. {
  4145. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  4146. struct target_if_spectral *spectral;
  4147. QDF_STATUS status;
  4148. if (!err) {
  4149. spectral_err("Error code argument is null");
  4150. QDF_ASSERT(0);
  4151. return QDF_STATUS_E_FAILURE;
  4152. }
  4153. *err = SPECTRAL_SCAN_ERR_INVALID;
  4154. if (!pdev) {
  4155. spectral_err("pdev object is NULL");
  4156. return QDF_STATUS_E_FAILURE;
  4157. }
  4158. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4159. if (!spectral) {
  4160. spectral_err("spectral object is NULL");
  4161. return QDF_STATUS_E_FAILURE;
  4162. }
  4163. if (!param) {
  4164. spectral_err("parameter object is NULL");
  4165. return QDF_STATUS_E_FAILURE;
  4166. }
  4167. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4168. spectral_err("Invalid Spectral mode %u", smode);
  4169. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4170. return QDF_STATUS_E_FAILURE;
  4171. }
  4172. if (!spectral->properties[smode][param->id].supported) {
  4173. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  4174. param->id, smode);
  4175. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  4176. return QDF_STATUS_E_FAILURE;
  4177. }
  4178. if (spectral->properties[smode][param->id].common_all_modes) {
  4179. spectral_warn("Setting Spectral parameter %u for all modes",
  4180. param->id);
  4181. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  4182. status = _target_if_set_spectral_config
  4183. (spectral, param, mode, err);
  4184. if (QDF_IS_STATUS_ERROR(status))
  4185. return QDF_STATUS_E_FAILURE;
  4186. }
  4187. return QDF_STATUS_SUCCESS;
  4188. }
  4189. return _target_if_set_spectral_config(spectral, param, smode, err);
  4190. }
  4191. /**
  4192. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  4193. * @fft_len: FFT length
  4194. * @pdev: Pointer to pdev object
  4195. *
  4196. * API to get fft bin count for a given fft length
  4197. *
  4198. * Return: FFt bin count
  4199. */
  4200. static int
  4201. target_if_get_fft_bin_count(int fft_len)
  4202. {
  4203. int bin_count = 0;
  4204. switch (fft_len) {
  4205. case 5:
  4206. bin_count = 16;
  4207. break;
  4208. case 6:
  4209. bin_count = 32;
  4210. break;
  4211. case 7:
  4212. bin_count = 64;
  4213. break;
  4214. case 8:
  4215. bin_count = 128;
  4216. break;
  4217. case 9:
  4218. bin_count = 256;
  4219. break;
  4220. default:
  4221. break;
  4222. }
  4223. return bin_count;
  4224. }
  4225. /**
  4226. * target_if_init_upper_lower_flags() - Initializes control and extension
  4227. * segment flags
  4228. * @spectral: pointer to target if spectral object
  4229. * @smode: Spectral scan mode
  4230. *
  4231. * API to initialize the control and extension flags with the lower/upper
  4232. * segment based on the HT mode
  4233. *
  4234. * Return: FFt bin count
  4235. */
  4236. static void
  4237. target_if_init_upper_lower_flags(struct target_if_spectral *spectral,
  4238. enum spectral_scan_mode smode)
  4239. {
  4240. int current_channel = 0;
  4241. int ext_channel = 0;
  4242. struct target_if_spectral_ops *p_sops =
  4243. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4244. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4245. spectral_err("Invalid Spectral mode %u", smode);
  4246. return;
  4247. }
  4248. current_channel = p_sops->get_current_channel(spectral, smode);
  4249. ext_channel = p_sops->get_extension_channel(spectral, smode);
  4250. if ((current_channel == 0) || (ext_channel == 0))
  4251. return;
  4252. if (spectral->sc_spectral_20_40_mode) {
  4253. /* HT40 mode */
  4254. if (ext_channel < current_channel) {
  4255. spectral->lower_is_extension = 1;
  4256. spectral->upper_is_control = 1;
  4257. spectral->lower_is_control = 0;
  4258. spectral->upper_is_extension = 0;
  4259. } else {
  4260. spectral->lower_is_extension = 0;
  4261. spectral->upper_is_control = 0;
  4262. spectral->lower_is_control = 1;
  4263. spectral->upper_is_extension = 1;
  4264. }
  4265. } else {
  4266. /* HT20 mode, lower is always control */
  4267. spectral->lower_is_extension = 0;
  4268. spectral->upper_is_control = 0;
  4269. spectral->lower_is_control = 1;
  4270. spectral->upper_is_extension = 0;
  4271. }
  4272. }
  4273. /**
  4274. * target_if_get_spectral_config() - Get spectral configuration
  4275. * @pdev: Pointer to pdev object
  4276. * @param: Pointer to spectral_config structure in which the configuration
  4277. * should be returned
  4278. * @smode: Spectral scan mode
  4279. *
  4280. * API to get the current spectral configuration
  4281. *
  4282. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4283. */
  4284. QDF_STATUS
  4285. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  4286. struct spectral_config *param,
  4287. enum spectral_scan_mode smode)
  4288. {
  4289. struct target_if_spectral_ops *p_sops = NULL;
  4290. struct target_if_spectral *spectral = NULL;
  4291. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4292. if (!spectral) {
  4293. spectral_err("SPECTRAL : Module doesn't exist");
  4294. return QDF_STATUS_E_FAILURE;
  4295. }
  4296. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4297. if (!p_sops) {
  4298. spectral_err("p_sops is null");
  4299. return QDF_STATUS_E_FAILURE;
  4300. }
  4301. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4302. spectral_err("Invalid Spectral mode %u", smode);
  4303. return QDF_STATUS_E_FAILURE;
  4304. }
  4305. qdf_mem_zero(param, sizeof(struct spectral_config));
  4306. p_sops->get_spectral_config(spectral, param, smode);
  4307. return QDF_STATUS_SUCCESS;
  4308. }
  4309. #ifdef WLAN_FEATURE_11BE
  4310. /**
  4311. * target_if_spectral_get_num_detectors_for_higher_bws() - Get number of
  4312. * Spectral detectors for higher bandwidths
  4313. * @spectral: Pointer to target if Spectral object
  4314. * @ch_width: channel width
  4315. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  4316. *
  4317. * API to get number of Spectral detectors used for scan in the given channel
  4318. * width.
  4319. *
  4320. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  4321. */
  4322. static QDF_STATUS
  4323. target_if_spectral_get_num_detectors_for_higher_bws(
  4324. struct target_if_spectral *spectral,
  4325. enum phy_ch_width ch_width,
  4326. uint32_t *num_detectors)
  4327. {
  4328. switch (ch_width) {
  4329. case CH_WIDTH_320MHZ:
  4330. *num_detectors = spectral->capability.num_detectors_320mhz;
  4331. break;
  4332. default:
  4333. spectral_err("Unsupported channel width %d", ch_width);
  4334. return QDF_STATUS_E_INVAL;
  4335. }
  4336. return QDF_STATUS_SUCCESS;
  4337. }
  4338. #else
  4339. static QDF_STATUS
  4340. target_if_spectral_get_num_detectors_for_higher_bws(
  4341. struct target_if_spectral *spectral,
  4342. enum phy_ch_width ch_width,
  4343. uint32_t *num_detectors)
  4344. {
  4345. spectral_err("Unsupported channel width %d", ch_width);
  4346. return QDF_STATUS_E_INVAL;
  4347. }
  4348. #endif
  4349. /**
  4350. * target_if_spectral_get_num_detectors() - Get number of Spectral detectors
  4351. * @spectral: Pointer to target if Spectral object
  4352. * @ch_width: channel width
  4353. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  4354. *
  4355. * API to get number of Spectral detectors used for scan in the given channel
  4356. * width.
  4357. *
  4358. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  4359. */
  4360. static QDF_STATUS
  4361. target_if_spectral_get_num_detectors(struct target_if_spectral *spectral,
  4362. enum phy_ch_width ch_width,
  4363. uint32_t *num_detectors)
  4364. {
  4365. if (!spectral) {
  4366. spectral_err("target if spectral object is null");
  4367. return QDF_STATUS_E_INVAL;
  4368. }
  4369. if (ch_width >= CH_WIDTH_INVALID) {
  4370. spectral_err("Invalid channel width %d", ch_width);
  4371. return QDF_STATUS_E_INVAL;
  4372. }
  4373. if (!num_detectors) {
  4374. spectral_err("Invalid argument, number of detectors");
  4375. return QDF_STATUS_E_INVAL;
  4376. }
  4377. switch (ch_width) {
  4378. case CH_WIDTH_20MHZ:
  4379. *num_detectors = spectral->capability.num_detectors_20mhz;
  4380. break;
  4381. case CH_WIDTH_40MHZ:
  4382. *num_detectors = spectral->capability.num_detectors_40mhz;
  4383. break;
  4384. case CH_WIDTH_80MHZ:
  4385. *num_detectors = spectral->capability.num_detectors_80mhz;
  4386. break;
  4387. case CH_WIDTH_160MHZ:
  4388. *num_detectors = spectral->capability.num_detectors_160mhz;
  4389. break;
  4390. case CH_WIDTH_80P80MHZ:
  4391. *num_detectors = spectral->capability.num_detectors_80p80mhz;
  4392. break;
  4393. default:
  4394. return target_if_spectral_get_num_detectors_for_higher_bws(
  4395. spectral, ch_width, num_detectors);
  4396. }
  4397. return QDF_STATUS_SUCCESS;
  4398. }
  4399. /**
  4400. * target_if_spectral_finite_scan_init() - Initializations required for finite
  4401. * Spectral scan
  4402. * @spectral: Pointer to target of Spctral object
  4403. * @smode: Spectral scan mode
  4404. *
  4405. * This routine initializes the finite Spectral scan. Finite Spectral scan is
  4406. * triggered by configuring a non zero scan count.
  4407. *
  4408. * Return: QDF_STATUS_SUCCESS on success
  4409. */
  4410. static QDF_STATUS
  4411. target_if_spectral_finite_scan_init(struct target_if_spectral *spectral,
  4412. enum spectral_scan_mode smode)
  4413. {
  4414. struct target_if_finite_spectral_scan_params *finite_scan;
  4415. enum phy_ch_width ch_width;
  4416. uint32_t num_detectors;
  4417. QDF_STATUS status;
  4418. uint16_t sscan_count;
  4419. if (!spectral) {
  4420. spectral_err("target if spectral object is null");
  4421. return QDF_STATUS_E_INVAL;
  4422. }
  4423. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4424. spectral_err("Invalid Spectral mode");
  4425. return QDF_STATUS_E_INVAL;
  4426. }
  4427. ch_width = spectral->ch_width[smode];
  4428. status = target_if_spectral_get_num_detectors(spectral, ch_width,
  4429. &num_detectors);
  4430. if (QDF_IS_STATUS_ERROR(status)) {
  4431. spectral_err("Failed to get number of detectors");
  4432. return QDF_STATUS_E_FAILURE;
  4433. }
  4434. finite_scan = &spectral->finite_scan[smode];
  4435. sscan_count = spectral->params[smode].ss_count;
  4436. finite_scan->finite_spectral_scan = true;
  4437. finite_scan->num_reports_expected = num_detectors * sscan_count;
  4438. return QDF_STATUS_SUCCESS;
  4439. }
  4440. /**
  4441. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  4442. * parameters
  4443. * @spectral: Pointer to Spectral target_if internal private data
  4444. * @spectral_params: Pointer to Spectral parameters
  4445. * @smode: Spectral scan mode
  4446. * @err: Spectral error code
  4447. *
  4448. * Enable use of desired Spectral parameters by configuring them into HW, and
  4449. * starting Spectral scan
  4450. *
  4451. * Return: 0 on success, 1 on failure
  4452. */
  4453. int
  4454. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  4455. struct spectral_config *spectral_params,
  4456. enum spectral_scan_mode smode,
  4457. enum spectral_cp_error_code *err)
  4458. {
  4459. int extension_channel = 0;
  4460. int current_channel = 0;
  4461. struct target_if_spectral_ops *p_sops = NULL;
  4462. QDF_STATUS status;
  4463. struct wlan_objmgr_pdev *pdev;
  4464. struct wlan_objmgr_psoc *psoc;
  4465. if (!spectral) {
  4466. spectral_err("Spectral LMAC object is NULL");
  4467. return 1;
  4468. }
  4469. pdev = spectral->pdev_obj;
  4470. if (!pdev) {
  4471. spectral_err("pdev is null");
  4472. return QDF_STATUS_E_INVAL;
  4473. }
  4474. psoc = wlan_pdev_get_psoc(pdev);
  4475. if (!psoc) {
  4476. spectral_err("psoc is null");
  4477. return QDF_STATUS_E_INVAL;
  4478. }
  4479. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4480. spectral_err("Invalid Spectral mode %u", smode);
  4481. return 1;
  4482. }
  4483. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4484. if (!p_sops) {
  4485. spectral_err("p_sops is NULL");
  4486. return 1;
  4487. }
  4488. spectral->sc_spectral_noise_pwr_cal =
  4489. spectral_params->ss_spectral_pri ? 1 : 0;
  4490. /* check if extension channel is present */
  4491. extension_channel = p_sops->get_extension_channel(spectral, smode);
  4492. current_channel = p_sops->get_current_channel(spectral, smode);
  4493. if (spectral->capability.advncd_spectral_cap) {
  4494. spectral->lb_edge_extrabins = 0;
  4495. spectral->rb_edge_extrabins = 0;
  4496. if (spectral->is_lb_edge_extrabins_format &&
  4497. spectral->params[smode].ss_rpt_mode == 2) {
  4498. spectral->lb_edge_extrabins = 4;
  4499. }
  4500. if (spectral->is_rb_edge_extrabins_format &&
  4501. spectral->params[smode].ss_rpt_mode == 2) {
  4502. spectral->rb_edge_extrabins = 4;
  4503. }
  4504. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  4505. spectral->sc_spectral_20_40_mode = 0;
  4506. spectral->spectral_numbins =
  4507. target_if_get_fft_bin_count(
  4508. spectral->params[smode].ss_fft_size);
  4509. spectral->spectral_fft_len =
  4510. target_if_get_fft_bin_count(
  4511. spectral->params[smode].ss_fft_size);
  4512. spectral->spectral_data_len =
  4513. target_if_get_fft_bin_count(
  4514. spectral->params[smode].ss_fft_size);
  4515. /*
  4516. * Initialize classifier params to be sent to user
  4517. * space classifier
  4518. */
  4519. spectral->classifier_params.lower_chan_in_mhz =
  4520. current_channel;
  4521. spectral->classifier_params.upper_chan_in_mhz = 0;
  4522. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  4523. /* TODO : Remove this variable */
  4524. spectral->sc_spectral_20_40_mode = 1;
  4525. spectral->spectral_numbins =
  4526. target_if_get_fft_bin_count(
  4527. spectral->params[smode].ss_fft_size);
  4528. spectral->spectral_fft_len =
  4529. target_if_get_fft_bin_count(
  4530. spectral->params[smode].ss_fft_size);
  4531. spectral->spectral_data_len =
  4532. target_if_get_fft_bin_count(
  4533. spectral->params[smode].ss_fft_size);
  4534. /*
  4535. * Initialize classifier params to be sent to user
  4536. * space classifier
  4537. */
  4538. if (extension_channel < current_channel) {
  4539. spectral->classifier_params.lower_chan_in_mhz =
  4540. extension_channel;
  4541. spectral->classifier_params.upper_chan_in_mhz =
  4542. current_channel;
  4543. } else {
  4544. spectral->classifier_params.lower_chan_in_mhz =
  4545. current_channel;
  4546. spectral->classifier_params.upper_chan_in_mhz =
  4547. extension_channel;
  4548. }
  4549. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  4550. /* Set the FFT Size */
  4551. /* TODO : Remove this variable */
  4552. spectral->sc_spectral_20_40_mode = 0;
  4553. spectral->spectral_numbins =
  4554. target_if_get_fft_bin_count(
  4555. spectral->params[smode].ss_fft_size);
  4556. spectral->spectral_fft_len =
  4557. target_if_get_fft_bin_count(
  4558. spectral->params[smode].ss_fft_size);
  4559. spectral->spectral_data_len =
  4560. target_if_get_fft_bin_count(
  4561. spectral->params[smode].ss_fft_size);
  4562. /*
  4563. * Initialize classifier params to be sent to user
  4564. * space classifier
  4565. */
  4566. spectral->classifier_params.lower_chan_in_mhz =
  4567. current_channel;
  4568. spectral->classifier_params.upper_chan_in_mhz = 0;
  4569. /*
  4570. * Initialize classifier params to be sent to user
  4571. * space classifier
  4572. */
  4573. if (extension_channel < current_channel) {
  4574. spectral->classifier_params.lower_chan_in_mhz =
  4575. extension_channel;
  4576. spectral->classifier_params.upper_chan_in_mhz =
  4577. current_channel;
  4578. } else {
  4579. spectral->classifier_params.lower_chan_in_mhz =
  4580. current_channel;
  4581. spectral->classifier_params.upper_chan_in_mhz =
  4582. extension_channel;
  4583. }
  4584. } else if (is_ch_width_160_or_80p80(
  4585. spectral->ch_width[smode])) {
  4586. /* Set the FFT Size */
  4587. /* The below applies to both 160 and 80+80 cases */
  4588. /* TODO : Remove this variable */
  4589. spectral->sc_spectral_20_40_mode = 0;
  4590. spectral->spectral_numbins =
  4591. target_if_get_fft_bin_count(
  4592. spectral->params[smode].ss_fft_size);
  4593. spectral->spectral_fft_len =
  4594. target_if_get_fft_bin_count(
  4595. spectral->params[smode].ss_fft_size);
  4596. spectral->spectral_data_len =
  4597. target_if_get_fft_bin_count(
  4598. spectral->params[smode].ss_fft_size);
  4599. /*
  4600. * Initialize classifier params to be sent to user
  4601. * space classifier
  4602. */
  4603. spectral->classifier_params.lower_chan_in_mhz =
  4604. current_channel;
  4605. spectral->classifier_params.upper_chan_in_mhz = 0;
  4606. /*
  4607. * Initialize classifier params to be sent to user
  4608. * space classifier
  4609. */
  4610. if (extension_channel < current_channel) {
  4611. spectral->classifier_params.lower_chan_in_mhz =
  4612. extension_channel;
  4613. spectral->classifier_params.upper_chan_in_mhz =
  4614. current_channel;
  4615. } else {
  4616. spectral->classifier_params.lower_chan_in_mhz =
  4617. current_channel;
  4618. spectral->classifier_params.upper_chan_in_mhz =
  4619. extension_channel;
  4620. }
  4621. }
  4622. if (spectral->spectral_numbins) {
  4623. spectral->spectral_numbins +=
  4624. spectral->lb_edge_extrabins;
  4625. spectral->spectral_numbins +=
  4626. spectral->rb_edge_extrabins;
  4627. }
  4628. if (spectral->spectral_fft_len) {
  4629. spectral->spectral_fft_len +=
  4630. spectral->lb_edge_extrabins;
  4631. spectral->spectral_fft_len +=
  4632. spectral->rb_edge_extrabins;
  4633. }
  4634. if (spectral->spectral_data_len) {
  4635. spectral->spectral_data_len +=
  4636. spectral->lb_edge_extrabins;
  4637. spectral->spectral_data_len +=
  4638. spectral->rb_edge_extrabins;
  4639. }
  4640. } else {
  4641. /*
  4642. * The decision to find 20/40 mode is found based on the
  4643. * presence of extension channel
  4644. * instead of channel width, as the channel width can
  4645. * dynamically change
  4646. */
  4647. if (extension_channel == 0) {
  4648. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  4649. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  4650. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  4651. spectral->spectral_data_len =
  4652. SPECTRAL_HT20_TOTAL_DATA_LEN;
  4653. /* only valid in 20-40 mode */
  4654. spectral->spectral_lower_max_index_offset = -1;
  4655. /* only valid in 20-40 mode */
  4656. spectral->spectral_upper_max_index_offset = -1;
  4657. spectral->spectral_max_index_offset =
  4658. spectral->spectral_fft_len + 2;
  4659. spectral->sc_spectral_20_40_mode = 0;
  4660. /*
  4661. * Initialize classifier params to be sent to user
  4662. * space classifier
  4663. */
  4664. spectral->classifier_params.lower_chan_in_mhz =
  4665. current_channel;
  4666. spectral->classifier_params.upper_chan_in_mhz = 0;
  4667. } else {
  4668. spectral->spectral_numbins =
  4669. SPECTRAL_HT40_TOTAL_NUM_BINS;
  4670. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  4671. spectral->spectral_data_len =
  4672. SPECTRAL_HT40_TOTAL_DATA_LEN;
  4673. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  4674. /* only valid in 20 mode */
  4675. spectral->spectral_max_index_offset = -1;
  4676. spectral->spectral_lower_max_index_offset =
  4677. spectral->spectral_fft_len + 2;
  4678. spectral->spectral_upper_max_index_offset =
  4679. spectral->spectral_fft_len + 5;
  4680. spectral->sc_spectral_20_40_mode = 1;
  4681. /*
  4682. * Initialize classifier params to be sent to user
  4683. * space classifier
  4684. */
  4685. if (extension_channel < current_channel) {
  4686. spectral->classifier_params.lower_chan_in_mhz =
  4687. extension_channel;
  4688. spectral->classifier_params.upper_chan_in_mhz =
  4689. current_channel;
  4690. } else {
  4691. spectral->classifier_params.lower_chan_in_mhz =
  4692. current_channel;
  4693. spectral->classifier_params.upper_chan_in_mhz =
  4694. extension_channel;
  4695. }
  4696. }
  4697. }
  4698. spectral->send_single_packet = 0;
  4699. spectral->classifier_params.spectral_20_40_mode =
  4700. spectral->sc_spectral_20_40_mode;
  4701. spectral->classifier_params.spectral_dc_index =
  4702. spectral->spectral_dc_index;
  4703. spectral->spectral_sent_msg = 0;
  4704. spectral->classify_scan = 0;
  4705. spectral->num_spectral_data = 0;
  4706. if (!p_sops->is_spectral_active(spectral, smode)) {
  4707. p_sops->configure_spectral(spectral, spectral_params, smode);
  4708. spectral->rparams.marker[smode].is_valid = false;
  4709. if (spectral->params[smode].ss_count) {
  4710. status = target_if_spectral_finite_scan_init(spectral,
  4711. smode);
  4712. if (QDF_IS_STATUS_ERROR(status)) {
  4713. spectral_err("Failed to init finite scan");
  4714. return 1;
  4715. }
  4716. }
  4717. p_sops->start_spectral_scan(spectral, smode, err);
  4718. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  4719. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  4720. }
  4721. /* get current spectral configuration */
  4722. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  4723. target_if_init_upper_lower_flags(spectral, smode);
  4724. return 0;
  4725. }
  4726. /**
  4727. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  4728. * Agile DFS
  4729. * @psoc: Pointer to psoc
  4730. * @object: Pointer to pdev
  4731. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  4732. *
  4733. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  4734. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  4735. *
  4736. * Return: void
  4737. */
  4738. static void
  4739. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  4740. void *object, void *arg)
  4741. {
  4742. bool *is_aspectral_prohibited = arg;
  4743. struct wlan_objmgr_pdev *cur_pdev = object;
  4744. bool is_agile_precac_enabled_cur_pdev = false;
  4745. bool is_agile_rcac_enabled_cur_pdev = false;
  4746. QDF_STATUS status;
  4747. qdf_assert_always(is_aspectral_prohibited);
  4748. if (*is_aspectral_prohibited)
  4749. return;
  4750. qdf_assert_always(psoc);
  4751. qdf_assert_always(cur_pdev);
  4752. status = ucfg_dfs_get_agile_precac_enable
  4753. (cur_pdev,
  4754. &is_agile_precac_enabled_cur_pdev);
  4755. if (QDF_IS_STATUS_ERROR(status)) {
  4756. spectral_err("Get agile precac failed, prohibiting aSpectral");
  4757. *is_aspectral_prohibited = true;
  4758. return;
  4759. }
  4760. status = ucfg_dfs_get_rcac_enable(cur_pdev,
  4761. &is_agile_rcac_enabled_cur_pdev);
  4762. if (QDF_IS_STATUS_ERROR(status)) {
  4763. spectral_err("Get agile RCAC failed, prohibiting aSpectral");
  4764. *is_aspectral_prohibited = true;
  4765. return;
  4766. }
  4767. if (is_agile_precac_enabled_cur_pdev) {
  4768. spectral_err("aDFS preCAC is in progress on one of the pdevs");
  4769. *is_aspectral_prohibited = true;
  4770. } else if (is_agile_rcac_enabled_cur_pdev) {
  4771. spectral_err("aDFS RCAC is in progress on one of the pdevs");
  4772. *is_aspectral_prohibited = true;
  4773. }
  4774. }
  4775. /**
  4776. * target_if_get_curr_band() - Get current operating band of pdev
  4777. *
  4778. * @pdev: pointer to pdev object
  4779. *
  4780. * API to get current operating band of a given pdev.
  4781. *
  4782. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  4783. */
  4784. static enum reg_wifi_band
  4785. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id)
  4786. {
  4787. struct wlan_objmgr_vdev *vdev;
  4788. int16_t chan_freq;
  4789. enum reg_wifi_band cur_band;
  4790. if (!pdev) {
  4791. spectral_err("pdev is NULL");
  4792. return REG_BAND_UNKNOWN;
  4793. }
  4794. if (vdev_id == WLAN_INVALID_VDEV_ID)
  4795. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  4796. else
  4797. vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, vdev_id,
  4798. WLAN_SPECTRAL_ID);
  4799. if (!vdev) {
  4800. spectral_debug("vdev is NULL");
  4801. return REG_BAND_UNKNOWN;
  4802. }
  4803. chan_freq = target_if_vdev_get_chan_freq(vdev);
  4804. cur_band = wlan_reg_freq_to_band(chan_freq);
  4805. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4806. return cur_band;
  4807. }
  4808. /**
  4809. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  4810. * any of the 5G pdevs
  4811. * @psoc: Pointer to psoc
  4812. * @object: Pointer to pdev
  4813. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  4814. * progress in any 5G pdevs
  4815. *
  4816. * Return: void
  4817. */
  4818. static void
  4819. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  4820. void *object, void *arg)
  4821. {
  4822. enum reg_wifi_band band;
  4823. bool *is_agile_scan_inprog_5g_pdev = arg;
  4824. struct target_if_spectral *spectral;
  4825. struct wlan_objmgr_pdev *cur_pdev = object;
  4826. struct target_if_spectral_ops *p_sops;
  4827. if (*is_agile_scan_inprog_5g_pdev)
  4828. return;
  4829. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  4830. if (!spectral) {
  4831. spectral_err("target if spectral handle is NULL");
  4832. return;
  4833. }
  4834. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4835. band = target_if_get_curr_band(
  4836. cur_pdev, spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE]);
  4837. if (band == REG_BAND_UNKNOWN) {
  4838. spectral_debug("Failed to get current band");
  4839. return;
  4840. }
  4841. if (band == REG_BAND_5G &&
  4842. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  4843. *is_agile_scan_inprog_5g_pdev = true;
  4844. }
  4845. /**
  4846. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  4847. * for current vdev rx chainmask.
  4848. *
  4849. * @spectral: Pointer to Spectral object
  4850. * @is_supported: Pointer to is_supported
  4851. *
  4852. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4853. */
  4854. static QDF_STATUS
  4855. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  4856. bool *is_supported)
  4857. {
  4858. struct wlan_objmgr_vdev *vdev;
  4859. uint8_t vdev_rxchainmask;
  4860. struct wlan_objmgr_psoc *psoc;
  4861. struct wlan_objmgr_pdev *pdev;
  4862. struct target_psoc_info *tgt_psoc_info;
  4863. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  4864. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  4865. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  4866. struct wlan_psoc_host_chainmask_table *table;
  4867. int j;
  4868. uint32_t table_id;
  4869. enum phy_ch_width ch_width;
  4870. uint8_t pdev_id;
  4871. if (!spectral) {
  4872. spectral_err("spectral target if object is null");
  4873. return QDF_STATUS_E_FAILURE;
  4874. }
  4875. if (!is_supported) {
  4876. spectral_err("is supported argument is null");
  4877. return QDF_STATUS_E_FAILURE;
  4878. }
  4879. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  4880. spectral_err("HW Agile mode is not supported up to gen 2");
  4881. return QDF_STATUS_E_FAILURE;
  4882. }
  4883. pdev = spectral->pdev_obj;
  4884. if (!pdev) {
  4885. spectral_err("pdev is null");
  4886. return QDF_STATUS_E_FAILURE;
  4887. }
  4888. psoc = wlan_pdev_get_psoc(pdev);
  4889. if (!psoc) {
  4890. spectral_err("psoc is null");
  4891. return QDF_STATUS_E_FAILURE;
  4892. }
  4893. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  4894. if (!vdev) {
  4895. spectral_err("First vdev is NULL");
  4896. return QDF_STATUS_E_FAILURE;
  4897. }
  4898. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  4899. if (!vdev_rxchainmask) {
  4900. spectral_err("vdev rx chainmask is zero");
  4901. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4902. return QDF_STATUS_E_FAILURE;
  4903. }
  4904. ch_width = target_if_vdev_get_ch_width(vdev);
  4905. if (ch_width == CH_WIDTH_INVALID) {
  4906. spectral_err("Invalid channel width");
  4907. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4908. return QDF_STATUS_E_FAILURE;
  4909. }
  4910. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4911. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  4912. if (!tgt_psoc_info) {
  4913. spectral_err("target_psoc_info is null");
  4914. return QDF_STATUS_E_FAILURE;
  4915. }
  4916. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  4917. if (!ext_svc_param) {
  4918. spectral_err("Extended service ready param null");
  4919. return QDF_STATUS_E_FAILURE;
  4920. }
  4921. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  4922. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  4923. if (!mac_phy_cap_arr) {
  4924. spectral_err("mac phy cap array is null");
  4925. return QDF_STATUS_E_FAILURE;
  4926. }
  4927. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  4928. if (!mac_phy_cap) {
  4929. spectral_err("mac phy cap is null");
  4930. return QDF_STATUS_E_FAILURE;
  4931. }
  4932. table_id = mac_phy_cap->chainmask_table_id;
  4933. table = &ext_svc_param->chainmask_table[table_id];
  4934. if (!table) {
  4935. spectral_err("chainmask table not found");
  4936. return QDF_STATUS_E_FAILURE;
  4937. }
  4938. for (j = 0; j < table->num_valid_chainmasks; j++) {
  4939. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  4940. if (ch_width <= CH_WIDTH_80MHZ)
  4941. *is_supported =
  4942. table->cap_list[j].supports_aSpectral;
  4943. else
  4944. *is_supported =
  4945. table->cap_list[j].supports_aSpectral_160;
  4946. break;
  4947. }
  4948. }
  4949. if (j == table->num_valid_chainmasks) {
  4950. spectral_err("vdev rx chainmask %u not found in table id = %u",
  4951. vdev_rxchainmask, table_id);
  4952. return QDF_STATUS_E_FAILURE;
  4953. }
  4954. return QDF_STATUS_SUCCESS;
  4955. }
  4956. #define INVALID_SPAN_NUM (-1)
  4957. /**
  4958. * target_if_spectral_get_num_spans() - Get number of spans for a given sscan_bw
  4959. * @pdev: Pointer to pdev object
  4960. * @sscan_bw: Spectral scan bandwidth
  4961. *
  4962. * Return: Number of spans on success, INVALID_SPAN_NUM on failure
  4963. */
  4964. static int
  4965. target_if_spectral_get_num_spans(
  4966. struct wlan_objmgr_pdev *pdev,
  4967. enum phy_ch_width sscan_bw)
  4968. {
  4969. struct wlan_objmgr_psoc *psoc;
  4970. int num_spans;
  4971. if (!pdev) {
  4972. spectral_err_rl("pdev is null");
  4973. return INVALID_SPAN_NUM;
  4974. }
  4975. psoc = wlan_pdev_get_psoc(pdev);
  4976. if (!psoc) {
  4977. spectral_err_rl("psoc is null");
  4978. return INVALID_SPAN_NUM;
  4979. }
  4980. if (sscan_bw == CH_WIDTH_80P80MHZ) {
  4981. num_spans = 2;
  4982. if (wlan_psoc_nif_fw_ext_cap_get(
  4983. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  4984. /* 5 MHz frequency span in restricted 80p80 case */
  4985. num_spans += 1;
  4986. } else {
  4987. num_spans = 1;
  4988. }
  4989. return num_spans;
  4990. }
  4991. #ifdef OPTIMIZED_SAMP_MESSAGE
  4992. /**
  4993. * target_if_spectral_populate_session_report_info() - Populate per-session
  4994. * report level information.
  4995. *
  4996. * @spectral: Pointer to Spectral object
  4997. * @smode: Spectral scan mode
  4998. *
  4999. * Return: Success/Failure
  5000. */
  5001. static QDF_STATUS
  5002. target_if_spectral_populate_session_report_info(
  5003. struct target_if_spectral *spectral,
  5004. enum spectral_scan_mode smode)
  5005. {
  5006. struct per_session_report_info *rpt_info;
  5007. if (!spectral) {
  5008. spectral_err_rl("Spectral LMAC object is null");
  5009. return QDF_STATUS_E_NULL_VALUE;
  5010. }
  5011. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  5012. spectral_err_rl("Invalid Spectral scan mode");
  5013. return QDF_STATUS_E_FAILURE;
  5014. }
  5015. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5016. /* Fill per-session report information, based on the spectral mode */
  5017. rpt_info = &spectral->report_info[smode];
  5018. rpt_info->operating_bw = spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  5019. rpt_info->sscan_bw = spectral->ch_width[smode];
  5020. rpt_info->sscan_cfreq1 = spectral->params[smode].ss_frequency.cfreq1;
  5021. rpt_info->sscan_cfreq2 = spectral->params[smode].ss_frequency.cfreq2;
  5022. rpt_info->num_spans = target_if_spectral_get_num_spans(
  5023. spectral->pdev_obj,
  5024. rpt_info->sscan_bw);
  5025. qdf_assert_always(rpt_info->num_spans != INVALID_SPAN_NUM);
  5026. rpt_info->valid = true;
  5027. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5028. return QDF_STATUS_SUCCESS;
  5029. }
  5030. /**
  5031. * target_if_spectral_populate_session_det_host_info() - Populate per-session
  5032. * detector level information that is known to the Host
  5033. *
  5034. * @spectral: Pointer to Spectral object
  5035. * @smode: Spectral scan mode
  5036. *
  5037. * Return: Success/Failure
  5038. */
  5039. static QDF_STATUS
  5040. target_if_spectral_populate_session_det_host_info(
  5041. struct target_if_spectral *spectral,
  5042. enum spectral_scan_mode smode)
  5043. {
  5044. struct per_session_report_info *rpt_info;
  5045. struct sscan_detector_list *detector_list;
  5046. struct wlan_objmgr_psoc *psoc;
  5047. uint16_t dest_det_idx = 0;
  5048. uint16_t dest_span_idx = 0;
  5049. bool is_sec80 = false;
  5050. uint8_t det, dest_det;
  5051. if (!spectral) {
  5052. spectral_err_rl("Spectral LMAC object is null");
  5053. return QDF_STATUS_E_NULL_VALUE;
  5054. }
  5055. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  5056. spectral_err_rl("Invalid Spectral scan mode");
  5057. return QDF_STATUS_E_FAILURE;
  5058. }
  5059. if (!spectral->pdev_obj) {
  5060. spectral_err_rl("Spectral PDEV is null");
  5061. return QDF_STATUS_E_NULL_VALUE;
  5062. }
  5063. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  5064. if (!psoc) {
  5065. spectral_err_rl("psoc is null");
  5066. return QDF_STATUS_E_NULL_VALUE;
  5067. }
  5068. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5069. rpt_info = &spectral->report_info[smode];
  5070. qdf_spin_lock_bh(&spectral->detector_list_lock);
  5071. /* Fill per-sesion detector-level information */
  5072. detector_list = &spectral->detector_list[smode][rpt_info->sscan_bw];
  5073. for (det = 0; det < detector_list->num_detectors; det++) {
  5074. struct per_session_det_map *det_map;
  5075. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  5076. det_map = &spectral->det_map[detector_list->detectors[det]];
  5077. if (detector_list->num_detectors > 1) {
  5078. if (det == 0) {
  5079. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  5080. det_map->send_to_upper_layers = false;
  5081. } else if (det == detector_list->num_detectors - 1) {
  5082. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  5083. det_map->send_to_upper_layers = true;
  5084. } else {
  5085. /* middle fragments */
  5086. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  5087. det_map->send_to_upper_layers = false;
  5088. }
  5089. } else {
  5090. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  5091. det_map->send_to_upper_layers = true;
  5092. }
  5093. det_map->num_dest_det_info = 1;
  5094. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ &&
  5095. wlan_psoc_nif_fw_ext_cap_get(
  5096. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  5097. /**
  5098. * In 165MHz case, 1 Spectral HW detector maps to 3
  5099. * detectors in SAMP msg.
  5100. */
  5101. det_map->num_dest_det_info += 2;
  5102. }
  5103. for (dest_det = 0; dest_det < det_map->num_dest_det_info;
  5104. dest_det++) {
  5105. struct per_session_dest_det_info *map_det_info;
  5106. map_det_info = &det_map->dest_det_info[dest_det];
  5107. map_det_info->freq_span_id = dest_span_idx;
  5108. map_det_info->det_id = dest_det_idx;
  5109. map_det_info->is_sec80 = is_sec80;
  5110. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ) {
  5111. /* Increment span ID for non-contiguous modes */
  5112. dest_det_idx = 0;
  5113. dest_span_idx++;
  5114. } else {
  5115. /* Increment detector ID for contiguous modes */
  5116. dest_det_idx++;
  5117. }
  5118. is_sec80 = !is_sec80;
  5119. }
  5120. det_map->det_map_valid[smode] = true;
  5121. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  5122. }
  5123. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  5124. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5125. return QDF_STATUS_SUCCESS;
  5126. }
  5127. #else
  5128. static QDF_STATUS
  5129. target_if_spectral_populate_session_report_info(
  5130. struct target_if_spectral *spectral,
  5131. enum spectral_scan_mode smode)
  5132. {
  5133. return QDF_STATUS_SUCCESS;
  5134. }
  5135. static QDF_STATUS
  5136. target_if_spectral_populate_session_det_host_info(
  5137. struct target_if_spectral *spectral,
  5138. enum spectral_scan_mode smode)
  5139. {
  5140. return QDF_STATUS_SUCCESS;
  5141. }
  5142. #endif /* OPTIMIZED_SAMP_MESSAGE */
  5143. QDF_STATUS
  5144. spectral_is_session_info_expected_from_target(struct wlan_objmgr_pdev *pdev,
  5145. bool *is_session_info_expected)
  5146. {
  5147. struct wlan_objmgr_psoc *psoc;
  5148. struct wmi_unified *wmi_handle;
  5149. if (!pdev) {
  5150. spectral_err("pdev is null");
  5151. return QDF_STATUS_E_NULL_VALUE;
  5152. }
  5153. psoc = wlan_pdev_get_psoc(pdev);
  5154. if (!psoc) {
  5155. spectral_err("psoc is null");
  5156. return QDF_STATUS_E_NULL_VALUE;
  5157. }
  5158. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  5159. if (!wmi_handle) {
  5160. spectral_err("wmi handle is null");
  5161. return QDF_STATUS_E_NULL_VALUE;
  5162. }
  5163. *is_session_info_expected = target_if_spectral_wmi_service_enabled(
  5164. psoc, wmi_handle,
  5165. wmi_service_spectral_session_info_support);
  5166. return QDF_STATUS_SUCCESS;
  5167. }
  5168. QDF_STATUS
  5169. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  5170. uint8_t vdev_id,
  5171. const enum spectral_scan_mode smode,
  5172. enum spectral_cp_error_code *err)
  5173. {
  5174. struct target_if_spectral_ops *p_sops;
  5175. struct target_if_spectral *spectral;
  5176. struct wlan_objmgr_psoc *psoc;
  5177. enum reg_wifi_band band;
  5178. QDF_STATUS ret;
  5179. bool is_session_info_expected;
  5180. if (!err) {
  5181. spectral_err("Error code argument is null");
  5182. QDF_ASSERT(0);
  5183. return QDF_STATUS_E_FAILURE;
  5184. }
  5185. *err = SPECTRAL_SCAN_ERR_INVALID;
  5186. if (!pdev) {
  5187. spectral_err("pdev object is NUll");
  5188. return QDF_STATUS_E_FAILURE;
  5189. }
  5190. psoc = wlan_pdev_get_psoc(pdev);
  5191. if (!psoc) {
  5192. spectral_err("psoc is null");
  5193. return QDF_STATUS_E_FAILURE;
  5194. }
  5195. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5196. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5197. spectral_err("Invalid Spectral mode %u", smode);
  5198. return QDF_STATUS_E_FAILURE;
  5199. }
  5200. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5201. if (!spectral) {
  5202. spectral_err("Spectral LMAC object is NUll");
  5203. return QDF_STATUS_E_FAILURE;
  5204. }
  5205. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5206. if (!p_sops) {
  5207. spectral_err("p_sops is null");
  5208. return QDF_STATUS_E_FAILURE;
  5209. }
  5210. if (p_sops->is_spectral_active(spectral, smode)) {
  5211. spectral_err("spectral in progress in current pdev, mode %d",
  5212. smode);
  5213. return QDF_STATUS_E_FAILURE;
  5214. }
  5215. spectral->vdev_id[smode] = vdev_id;
  5216. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5217. QDF_STATUS status;
  5218. bool is_supported = false;
  5219. status = target_if_is_agile_supported_cur_chmask(spectral,
  5220. &is_supported);
  5221. if (QDF_IS_STATUS_ERROR(status)) {
  5222. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5223. return QDF_STATUS_E_FAILURE;
  5224. }
  5225. if (!is_supported) {
  5226. spectral_err("aSpectral unsupported for cur chainmask");
  5227. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5228. return QDF_STATUS_E_FAILURE;
  5229. }
  5230. }
  5231. band = target_if_get_curr_band(spectral->pdev_obj, vdev_id);
  5232. if (band == REG_BAND_UNKNOWN) {
  5233. spectral_err("Failed to get current band");
  5234. return QDF_STATUS_E_FAILURE;
  5235. }
  5236. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  5237. struct target_psoc_info *tgt_hdl;
  5238. enum wmi_host_hw_mode_config_type mode;
  5239. bool is_agile_scan_inprog_5g_pdev;
  5240. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  5241. if (!tgt_hdl) {
  5242. target_if_err("target_psoc_info is null");
  5243. return QDF_STATUS_E_FAILURE;
  5244. }
  5245. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  5246. switch (mode) {
  5247. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  5248. case WMI_HOST_HW_MODE_SBS:
  5249. case WMI_HOST_HW_MODE_DBS_SBS:
  5250. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  5251. is_agile_scan_inprog_5g_pdev = false;
  5252. wlan_objmgr_iterate_obj_list
  5253. (psoc, WLAN_PDEV_OP,
  5254. target_if_is_agile_scan_active_in_5g,
  5255. &is_agile_scan_inprog_5g_pdev, 0,
  5256. WLAN_SPECTRAL_ID);
  5257. break;
  5258. default:
  5259. is_agile_scan_inprog_5g_pdev = false;
  5260. break;
  5261. }
  5262. if (is_agile_scan_inprog_5g_pdev) {
  5263. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  5264. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5265. return QDF_STATUS_E_FAILURE;
  5266. }
  5267. }
  5268. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5269. bool is_aspectral_prohibited = false;
  5270. QDF_STATUS status;
  5271. status = wlan_objmgr_iterate_obj_list
  5272. (psoc, WLAN_PDEV_OP,
  5273. target_if_is_aspectral_prohibited_by_adfs,
  5274. &is_aspectral_prohibited, 0,
  5275. WLAN_SPECTRAL_ID);
  5276. if (QDF_IS_STATUS_ERROR(status)) {
  5277. spectral_err("Failed to iterate over pdevs");
  5278. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5279. return QDF_STATUS_E_FAILURE;
  5280. }
  5281. if (is_aspectral_prohibited) {
  5282. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5283. return QDF_STATUS_E_FAILURE;
  5284. }
  5285. }
  5286. if (!spectral->params_valid[smode]) {
  5287. target_if_spectral_info_read(spectral,
  5288. smode,
  5289. TARGET_IF_SPECTRAL_INFO_PARAMS,
  5290. &spectral->params[smode],
  5291. sizeof(spectral->params[smode]));
  5292. spectral->params_valid[smode] = true;
  5293. }
  5294. qdf_spin_lock_bh(&spectral->spectral_lock);
  5295. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5296. QDF_STATUS status;
  5297. bool is_overlapping;
  5298. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  5299. enum spectral_scan_mode m;
  5300. enum phy_ch_width agile_ch_width;
  5301. m = SPECTRAL_SCAN_MODE_NORMAL;
  5302. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  5303. ch_width[m] = CH_WIDTH_INVALID;
  5304. status = target_if_spectral_populate_chwidth
  5305. (spectral, ch_width, spectral->params
  5306. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  5307. if (QDF_IS_STATUS_ERROR(status)) {
  5308. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5309. spectral_err("Failed to populate channel width");
  5310. return QDF_STATUS_E_FAILURE;
  5311. }
  5312. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  5313. if (!spectral->params[smode].ss_frequency.cfreq1) {
  5314. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  5315. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5316. spectral_err("Agile Spectral cfreq1 is 0");
  5317. return QDF_STATUS_E_FAILURE;
  5318. } else if (agile_ch_width == CH_WIDTH_80P80MHZ &&
  5319. !spectral->params[smode].ss_frequency.cfreq2) {
  5320. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  5321. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5322. spectral_err("Agile Spectral cfreq2 is 0");
  5323. return QDF_STATUS_E_FAILURE;
  5324. }
  5325. status = target_if_is_agile_span_overlap_with_operating_span
  5326. (spectral, ch_width,
  5327. &spectral->params[smode].ss_frequency,
  5328. &is_overlapping);
  5329. if (QDF_IS_STATUS_ERROR(status)) {
  5330. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5331. return QDF_STATUS_E_FAILURE;
  5332. }
  5333. if (is_overlapping) {
  5334. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  5335. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5336. return QDF_STATUS_E_FAILURE;
  5337. }
  5338. }
  5339. /* Populate detectot list first */
  5340. ret = target_if_spectral_detector_list_init(spectral);
  5341. if (QDF_IS_STATUS_ERROR(ret)) {
  5342. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5343. spectral_err("Failed to initialize detector list");
  5344. return ret;
  5345. }
  5346. ret = target_if_spectral_populate_chwidth(
  5347. spectral, spectral->ch_width,
  5348. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  5349. ss_frequency.cfreq2 > 0);
  5350. if (QDF_IS_STATUS_ERROR(ret)) {
  5351. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5352. spectral_err("Failed to get channel widths");
  5353. return ret;
  5354. }
  5355. ret = spectral_is_session_info_expected_from_target(
  5356. spectral->pdev_obj,
  5357. &is_session_info_expected);
  5358. if (QDF_IS_STATUS_ERROR(ret)) {
  5359. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5360. spectral_err("Failed to check if session info is expected");
  5361. return ret;
  5362. }
  5363. /* If FW doesn't send session info, populate it */
  5364. if (!is_session_info_expected) {
  5365. ret = target_if_spectral_populate_session_report_info(spectral,
  5366. smode);
  5367. if (QDF_IS_STATUS_ERROR(ret)) {
  5368. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5369. spectral_err("Failed to populate per-session report info");
  5370. return QDF_STATUS_E_FAILURE;
  5371. }
  5372. ret = target_if_spectral_populate_session_det_host_info(
  5373. spectral, smode);
  5374. if (QDF_IS_STATUS_ERROR(ret)) {
  5375. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5376. spectral_err("Failed to populate per-session detector info");
  5377. return QDF_STATUS_E_FAILURE;
  5378. }
  5379. }
  5380. target_if_spectral_scan_enable_params(spectral,
  5381. &spectral->params[smode], smode,
  5382. err);
  5383. spectral->sscan_width_configured[smode] = false;
  5384. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5385. return QDF_STATUS_SUCCESS;
  5386. }
  5387. QDF_STATUS
  5388. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  5389. const enum spectral_scan_mode smode,
  5390. enum spectral_cp_error_code *err)
  5391. {
  5392. struct target_if_spectral_ops *p_sops;
  5393. struct target_if_spectral *spectral;
  5394. uint8_t det;
  5395. if (!pdev) {
  5396. spectral_err("pdev object is NULL");
  5397. return QDF_STATUS_E_INVAL;
  5398. }
  5399. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  5400. spectral_info("Spectral feature is disabled");
  5401. return QDF_STATUS_COMP_DISABLED;
  5402. }
  5403. if (!err) {
  5404. spectral_err("Error code argument is null");
  5405. QDF_ASSERT(0);
  5406. return QDF_STATUS_E_FAILURE;
  5407. }
  5408. *err = SPECTRAL_SCAN_ERR_INVALID;
  5409. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5410. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5411. spectral_err("Invalid Spectral mode %u", smode);
  5412. return QDF_STATUS_E_FAILURE;
  5413. }
  5414. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5415. if (!spectral) {
  5416. spectral_err("Spectral LMAC object is NUll ");
  5417. return QDF_STATUS_E_FAILURE;
  5418. }
  5419. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5420. qdf_spin_lock_bh(&spectral->spectral_lock);
  5421. p_sops->stop_spectral_scan(spectral, smode);
  5422. if (spectral->classify_scan) {
  5423. /* TODO : Check if this logic is necessary */
  5424. spectral->detects_control_channel = 0;
  5425. spectral->detects_extension_channel = 0;
  5426. spectral->detects_above_dc = 0;
  5427. spectral->detects_below_dc = 0;
  5428. spectral->classify_scan = 0;
  5429. }
  5430. spectral->send_single_packet = 0;
  5431. spectral->sc_spectral_scan = 0;
  5432. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  5433. for (det = 0; det < MAX_DETECTORS_PER_PDEV; det++)
  5434. spectral->det_map[det].det_map_valid[smode] = false;
  5435. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  5436. /* Mark report info as invalid */
  5437. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5438. spectral->report_info[smode].valid = false;
  5439. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5440. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5441. return QDF_STATUS_SUCCESS;
  5442. }
  5443. /**
  5444. * target_if_is_spectral_active() - Get whether Spectral is active
  5445. * @pdev: Pointer to pdev object
  5446. * @smode: Spectral scan mode
  5447. *
  5448. * API to get whether Spectral is active
  5449. *
  5450. * Return: True if Spectral is active, false if Spectral is not active
  5451. */
  5452. bool
  5453. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  5454. const enum spectral_scan_mode smode)
  5455. {
  5456. struct target_if_spectral *spectral = NULL;
  5457. struct target_if_spectral_ops *p_sops = NULL;
  5458. if (!pdev) {
  5459. spectral_err("pdev is null");
  5460. return false;
  5461. }
  5462. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  5463. spectral_info("Spectral feature is disabled");
  5464. return false;
  5465. }
  5466. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5467. if (!spectral) {
  5468. spectral_err("SPECTRAL : Module doesn't exist");
  5469. return false;
  5470. }
  5471. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5472. if (!p_sops) {
  5473. spectral_err("p_sops is null");
  5474. return false;
  5475. }
  5476. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5477. spectral_err("Invalid Spectral mode %u", smode);
  5478. return false;
  5479. }
  5480. return p_sops->is_spectral_active(spectral, smode);
  5481. }
  5482. /**
  5483. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  5484. * @pdev: Pointer to pdev object
  5485. * @smode: Spectral scan mode
  5486. *
  5487. * API to get whether Spectral is enabled
  5488. *
  5489. * Return: True if Spectral is enabled, false if Spectral is not enabled
  5490. */
  5491. bool
  5492. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  5493. enum spectral_scan_mode smode)
  5494. {
  5495. struct target_if_spectral *spectral = NULL;
  5496. struct target_if_spectral_ops *p_sops = NULL;
  5497. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5498. if (!spectral) {
  5499. spectral_err("SPECTRAL : Module doesn't exist");
  5500. return false;
  5501. }
  5502. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5503. if (!p_sops) {
  5504. spectral_err("p_sops is null");
  5505. return false;
  5506. }
  5507. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5508. spectral_err("Invalid Spectral mode %u", smode);
  5509. return false;
  5510. }
  5511. return p_sops->is_spectral_enabled(spectral, smode);
  5512. }
  5513. #ifdef DIRECT_BUF_RX_DEBUG
  5514. /**
  5515. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  5516. * @pdev: Pointer to pdev object
  5517. * @enable: Enable/Disable Spectral DMA ring debug
  5518. *
  5519. * Start/stop Spectral DMA ring debug based on @enable.
  5520. * Also save the state for future use.
  5521. *
  5522. * Return: QDF_STATUS of operation
  5523. */
  5524. static QDF_STATUS
  5525. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  5526. {
  5527. struct target_if_spectral *spectral;
  5528. struct wlan_lmac_if_tx_ops *tx_ops;
  5529. struct wlan_objmgr_psoc *psoc;
  5530. if (!pdev)
  5531. return QDF_STATUS_E_FAILURE;
  5532. psoc = wlan_pdev_get_psoc(pdev);
  5533. if (!psoc) {
  5534. spectral_err("psoc is null");
  5535. return QDF_STATUS_E_INVAL;
  5536. }
  5537. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5538. if (!tx_ops) {
  5539. spectral_err("tx_ops is NULL");
  5540. return QDF_STATUS_E_INVAL;
  5541. }
  5542. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5543. if (!spectral) {
  5544. spectral_err("Spectal LMAC object is NULL");
  5545. return QDF_STATUS_E_INVAL;
  5546. }
  5547. /* Save the state */
  5548. spectral->dbr_ring_debug = enable;
  5549. if (enable)
  5550. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  5551. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  5552. else
  5553. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  5554. pdev, 0);
  5555. return QDF_STATUS_SUCCESS;
  5556. }
  5557. /**
  5558. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  5559. * @pdev: Pointer to pdev object
  5560. * @enable: Enable/Disable Spectral DMA buffer debug
  5561. *
  5562. * Start/stop Spectral DMA buffer debug based on @enable.
  5563. * Also save the state for future use.
  5564. *
  5565. * Return: QDF_STATUS of operation
  5566. */
  5567. static QDF_STATUS
  5568. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  5569. {
  5570. struct target_if_spectral *spectral;
  5571. struct wlan_lmac_if_tx_ops *tx_ops;
  5572. struct wlan_objmgr_psoc *psoc;
  5573. if (!pdev)
  5574. return QDF_STATUS_E_FAILURE;
  5575. psoc = wlan_pdev_get_psoc(pdev);
  5576. if (!psoc) {
  5577. spectral_err("psoc is null");
  5578. return QDF_STATUS_E_INVAL;
  5579. }
  5580. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5581. if (!tx_ops) {
  5582. spectral_err("tx_ops is NULL");
  5583. return QDF_STATUS_E_INVAL;
  5584. }
  5585. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5586. if (!spectral) {
  5587. spectral_err("Spectal LMAC object is NULL");
  5588. return QDF_STATUS_E_INVAL;
  5589. }
  5590. /* Save the state */
  5591. spectral->dbr_buff_debug = enable;
  5592. if (enable)
  5593. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  5594. pdev, 0, MEM_POISON_SIGNATURE);
  5595. else
  5596. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  5597. pdev, 0);
  5598. }
  5599. /**
  5600. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  5601. * debug based on the previous state
  5602. * @pdev: Pointer to pdev object
  5603. *
  5604. * Return: QDF_STATUS of operation
  5605. */
  5606. static QDF_STATUS
  5607. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  5608. {
  5609. struct target_if_spectral *spectral;
  5610. if (!pdev) {
  5611. spectral_err("pdev is NULL!");
  5612. return QDF_STATUS_E_FAILURE;
  5613. }
  5614. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5615. if (!spectral) {
  5616. spectral_err("Spectal LMAC object is NULL");
  5617. return QDF_STATUS_E_INVAL;
  5618. }
  5619. if (spectral->dbr_buff_debug)
  5620. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  5621. else
  5622. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  5623. }
  5624. /**
  5625. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  5626. * debug based on the previous state
  5627. * @pdev: Pointer to pdev object
  5628. *
  5629. * Return: QDF_STATUS of operation
  5630. */
  5631. static QDF_STATUS
  5632. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  5633. {
  5634. struct target_if_spectral *spectral;
  5635. if (!pdev) {
  5636. spectral_err("pdev is NULL!");
  5637. return QDF_STATUS_E_FAILURE;
  5638. }
  5639. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5640. if (!spectral) {
  5641. spectral_err("Spectal LMAC object is NULL");
  5642. return QDF_STATUS_E_INVAL;
  5643. }
  5644. if (spectral->dbr_ring_debug)
  5645. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  5646. else
  5647. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  5648. }
  5649. /**
  5650. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  5651. * @pdev: Pointer to pdev object
  5652. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  5653. * @debug_value: Value to be set for @dma_debug_type
  5654. *
  5655. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  5656. * based on @debug_value
  5657. *
  5658. * Return: QDF_STATUS of operation
  5659. */
  5660. static QDF_STATUS
  5661. target_if_spectral_set_dma_debug(
  5662. struct wlan_objmgr_pdev *pdev,
  5663. enum spectral_dma_debug dma_debug_type,
  5664. bool debug_value)
  5665. {
  5666. struct target_if_spectral_ops *p_sops;
  5667. struct wlan_objmgr_psoc *psoc;
  5668. struct wlan_lmac_if_tx_ops *tx_ops;
  5669. struct target_if_spectral *spectral;
  5670. if (!pdev)
  5671. return QDF_STATUS_E_FAILURE;
  5672. psoc = wlan_pdev_get_psoc(pdev);
  5673. if (!psoc) {
  5674. spectral_err("psoc is null");
  5675. return QDF_STATUS_E_INVAL;
  5676. }
  5677. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5678. if (!tx_ops) {
  5679. spectral_err("tx_ops is NULL");
  5680. return QDF_STATUS_E_FAILURE;
  5681. }
  5682. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  5683. spectral_err("Unable to fetch target type");
  5684. return QDF_STATUS_E_FAILURE;
  5685. }
  5686. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5687. if (!spectral) {
  5688. spectral_err("Spectal LMAC object is NULL");
  5689. return QDF_STATUS_E_INVAL;
  5690. }
  5691. if (spectral->direct_dma_support) {
  5692. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5693. if (p_sops->is_spectral_active(spectral,
  5694. SPECTRAL_SCAN_MODE_NORMAL) ||
  5695. p_sops->is_spectral_active(spectral,
  5696. SPECTRAL_SCAN_MODE_AGILE)) {
  5697. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  5698. return QDF_STATUS_E_FAILURE;
  5699. }
  5700. switch (dma_debug_type) {
  5701. case SPECTRAL_DMA_RING_DEBUG:
  5702. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  5703. break;
  5704. case SPECTRAL_DMA_BUFFER_DEBUG:
  5705. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  5706. break;
  5707. default:
  5708. spectral_err("Unsupported DMA debug type : %d",
  5709. dma_debug_type);
  5710. return QDF_STATUS_E_FAILURE;
  5711. }
  5712. }
  5713. return QDF_STATUS_SUCCESS;
  5714. }
  5715. #endif /* DIRECT_BUF_RX_DEBUG */
  5716. /**
  5717. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  5718. * @pdev: Pointer to pdev object
  5719. *
  5720. * Return: Whether Direct-DMA is supported on this radio
  5721. */
  5722. static bool
  5723. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  5724. {
  5725. struct target_if_spectral *spectral;
  5726. if (!pdev) {
  5727. spectral_err("pdev is NULL!");
  5728. return false;
  5729. }
  5730. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5731. if (!spectral) {
  5732. spectral_err("Spectral LMAC object is NULL");
  5733. return false;
  5734. }
  5735. return spectral->direct_dma_support;
  5736. }
  5737. /**
  5738. * target_if_set_debug_level() - Set debug level for Spectral
  5739. * @pdev: Pointer to pdev object
  5740. * @debug_level: Debug level
  5741. *
  5742. * API to set the debug level for Spectral
  5743. *
  5744. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5745. */
  5746. QDF_STATUS
  5747. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  5748. {
  5749. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  5750. return QDF_STATUS_SUCCESS;
  5751. }
  5752. /**
  5753. * target_if_get_debug_level() - Get debug level for Spectral
  5754. * @pdev: Pointer to pdev object
  5755. *
  5756. * API to get the debug level for Spectral
  5757. *
  5758. * Return: Current debug level
  5759. */
  5760. uint32_t
  5761. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  5762. {
  5763. return spectral_debug_level;
  5764. }
  5765. /**
  5766. * target_if_get_spectral_capinfo() - Get Spectral capability information
  5767. * @pdev: Pointer to pdev object
  5768. * @scaps: Buffer into which data should be copied
  5769. *
  5770. * API to get the spectral capability information
  5771. *
  5772. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5773. */
  5774. QDF_STATUS
  5775. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  5776. struct spectral_caps *scaps)
  5777. {
  5778. struct target_if_spectral *spectral = NULL;
  5779. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5780. if (!spectral) {
  5781. spectral_err("SPECTRAL : Module doesn't exist");
  5782. return QDF_STATUS_E_FAILURE;
  5783. }
  5784. qdf_mem_copy(scaps, &spectral->capability,
  5785. sizeof(struct spectral_caps));
  5786. return QDF_STATUS_SUCCESS;
  5787. }
  5788. /**
  5789. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  5790. * @pdev: Pointer to pdev object
  5791. * @stats: Buffer into which data should be copied
  5792. *
  5793. * API to get the spectral diagnostic statistics
  5794. *
  5795. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5796. */
  5797. QDF_STATUS
  5798. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  5799. struct spectral_diag_stats *stats)
  5800. {
  5801. struct target_if_spectral *spectral = NULL;
  5802. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5803. if (!spectral) {
  5804. spectral_err("SPECTRAL : Module doesn't exist");
  5805. return QDF_STATUS_E_FAILURE;
  5806. }
  5807. qdf_mem_copy(stats, &spectral->diag_stats,
  5808. sizeof(struct spectral_diag_stats));
  5809. return QDF_STATUS_SUCCESS;
  5810. }
  5811. /**
  5812. * target_if_register_spectral_wmi_ops() - Register Spectral WMI operations
  5813. * @psoc: Pointer to psoc object
  5814. * @wmi_ops: Pointer to the structure having Spectral WMI operations
  5815. *
  5816. * API for registering Spectral WMI operations in
  5817. * spectral internal data structure
  5818. *
  5819. * Return: QDF_STATUS
  5820. */
  5821. static QDF_STATUS
  5822. target_if_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
  5823. struct spectral_wmi_ops *wmi_ops)
  5824. {
  5825. struct target_if_psoc_spectral *psoc_spectral;
  5826. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5827. if (!psoc_spectral) {
  5828. spectral_err("Spectral LMAC object is null");
  5829. return QDF_STATUS_E_INVAL;
  5830. }
  5831. psoc_spectral->wmi_ops = *wmi_ops;
  5832. return QDF_STATUS_SUCCESS;
  5833. }
  5834. /**
  5835. * target_if_register_spectral_tgt_ops() - Register Spectral target operations
  5836. * @psoc: Pointer to psoc object
  5837. * @tgt_ops: Pointer to the structure having Spectral target operations
  5838. *
  5839. * API for registering Spectral target operations in
  5840. * spectral internal data structure
  5841. *
  5842. * Return: QDF_STATUS
  5843. */
  5844. static QDF_STATUS
  5845. target_if_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
  5846. struct spectral_tgt_ops *tgt_ops)
  5847. {
  5848. if (!psoc) {
  5849. spectral_err("psoc is null");
  5850. return QDF_STATUS_E_INVAL;
  5851. }
  5852. ops_tgt = *tgt_ops;
  5853. return QDF_STATUS_SUCCESS;
  5854. }
  5855. /**
  5856. * target_if_register_netlink_cb() - Register Netlink callbacks
  5857. * @pdev: Pointer to pdev object
  5858. * @nl_cb: Netlink callbacks to register
  5859. *
  5860. * Return: void
  5861. */
  5862. static void
  5863. target_if_register_netlink_cb(
  5864. struct wlan_objmgr_pdev *pdev,
  5865. struct spectral_nl_cb *nl_cb)
  5866. {
  5867. struct target_if_spectral *spectral = NULL;
  5868. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5869. if (!spectral) {
  5870. spectral_err("SPECTRAL : Module doesn't exist");
  5871. return;
  5872. }
  5873. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  5874. if (spectral->use_nl_bcast)
  5875. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  5876. else
  5877. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  5878. }
  5879. /**
  5880. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  5881. * Netlink messages to the application layer
  5882. * @pdev: Pointer to pdev object
  5883. *
  5884. * Return: true for broadcast, false for unicast
  5885. */
  5886. static bool
  5887. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  5888. {
  5889. struct target_if_spectral *spectral = NULL;
  5890. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5891. if (!spectral) {
  5892. spectral_err("SPECTRAL : Module doesn't exist");
  5893. return false;
  5894. }
  5895. return spectral->use_nl_bcast;
  5896. }
  5897. /**
  5898. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  5899. * @pdev: Pointer to pdev object
  5900. *
  5901. * Return: void
  5902. */
  5903. static void
  5904. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  5905. {
  5906. struct target_if_spectral *spectral = NULL;
  5907. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5908. if (!spectral) {
  5909. spectral_err("SPECTRAL : Module doesn't exist");
  5910. return;
  5911. }
  5912. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  5913. }
  5914. static int
  5915. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  5916. void *payload)
  5917. {
  5918. struct target_if_spectral *spectral = NULL;
  5919. struct target_if_spectral_ops *p_sops = NULL;
  5920. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5921. if (!spectral) {
  5922. spectral_err("SPECTRAL : Module doesn't exist");
  5923. return -EPERM;
  5924. }
  5925. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5926. if (!p_sops) {
  5927. spectral_err("p_sops is null");
  5928. return -EPERM;
  5929. }
  5930. return p_sops->process_spectral_report(pdev, payload);
  5931. }
  5932. #ifdef DIRECT_BUF_RX_DEBUG
  5933. static inline void
  5934. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5935. {
  5936. if (!tx_ops) {
  5937. spectral_err("tx_ops is NULL");
  5938. return;
  5939. }
  5940. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  5941. target_if_spectral_set_dma_debug;
  5942. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  5943. target_if_spectral_check_and_do_dbr_ring_debug;
  5944. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  5945. target_if_spectral_check_and_do_dbr_buff_debug;
  5946. }
  5947. #else
  5948. static inline void
  5949. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5950. {
  5951. }
  5952. #endif
  5953. #if defined(WLAN_CONV_SPECTRAL_ENABLE) && defined(SPECTRAL_MODULIZED_ENABLE)
  5954. /**
  5955. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  5956. * register WMI event handler
  5957. * @psoc: Pointer to psoc object
  5958. * @event_id: Event id
  5959. * @handler_func: Handler function
  5960. * @rx_ctx: Context of WMI event processing
  5961. *
  5962. * Wrapper function to register WMI event handler
  5963. *
  5964. * Return: 0 for success else failure
  5965. */
  5966. static int
  5967. target_if_spectral_wmi_unified_register_event_handler(
  5968. struct wlan_objmgr_psoc *psoc,
  5969. wmi_conv_event_id event_id,
  5970. wmi_unified_event_handler handler_func,
  5971. uint8_t rx_ctx)
  5972. {
  5973. wmi_unified_t wmi_handle;
  5974. struct target_if_psoc_spectral *psoc_spectral;
  5975. QDF_STATUS ret;
  5976. if (!psoc) {
  5977. spectral_err("psoc is null");
  5978. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5979. }
  5980. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5981. if (!wmi_handle) {
  5982. spectral_err("WMI handle is null");
  5983. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5984. }
  5985. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5986. if (!psoc_spectral) {
  5987. spectral_err("spectral object is null");
  5988. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5989. }
  5990. ret = psoc_spectral->wmi_ops.wmi_unified_register_event_handler(
  5991. wmi_handle, event_id, handler_func, rx_ctx);
  5992. return qdf_status_to_os_return(ret);
  5993. }
  5994. /**
  5995. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  5996. * to unregister WMI event handler
  5997. * @psoc: Pointer to psoc object
  5998. * @event_id: Event id
  5999. *
  6000. * Wrapper function to unregister WMI event handler
  6001. *
  6002. * Return: 0 for success else failure
  6003. */
  6004. static int
  6005. target_if_spectral_wmi_unified_unregister_event_handler(
  6006. struct wlan_objmgr_psoc *psoc,
  6007. wmi_conv_event_id event_id)
  6008. {
  6009. wmi_unified_t wmi_handle;
  6010. struct target_if_psoc_spectral *psoc_spectral;
  6011. QDF_STATUS ret;
  6012. if (!psoc) {
  6013. spectral_err("psoc is null");
  6014. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6015. }
  6016. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6017. if (!wmi_handle) {
  6018. spectral_err("WMI handle is null");
  6019. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6020. }
  6021. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6022. if (!psoc_spectral) {
  6023. spectral_err("spectral object is null");
  6024. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6025. }
  6026. ret = psoc_spectral->wmi_ops.wmi_unified_unregister_event_handler(
  6027. wmi_handle, event_id);
  6028. return qdf_status_to_os_return(ret);
  6029. }
  6030. /**
  6031. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  6032. * function to extract fixed parameters from start scan response event
  6033. * @psoc: Pointer to psoc object
  6034. * @evt_buf: Event buffer
  6035. * @param: Start scan response parameters
  6036. *
  6037. * Wrapper function to extract fixed parameters from start scan response event
  6038. *
  6039. * Return: QDF_STATUS
  6040. */
  6041. static QDF_STATUS
  6042. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6043. struct wlan_objmgr_psoc *psoc,
  6044. uint8_t *evt_buf,
  6045. struct spectral_startscan_resp_params *param)
  6046. {
  6047. wmi_unified_t wmi_handle;
  6048. struct target_if_psoc_spectral *psoc_spectral;
  6049. if (!psoc) {
  6050. spectral_err("psoc is null");
  6051. return QDF_STATUS_E_INVAL;
  6052. }
  6053. if (!evt_buf) {
  6054. spectral_err("WMI event buffer is null");
  6055. return QDF_STATUS_E_INVAL;
  6056. }
  6057. if (!param) {
  6058. spectral_err("Spectral startscan response parameters is null");
  6059. return QDF_STATUS_E_INVAL;
  6060. }
  6061. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6062. if (!wmi_handle) {
  6063. spectral_err("WMI handle is null");
  6064. return QDF_STATUS_E_INVAL;
  6065. }
  6066. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6067. if (!psoc_spectral) {
  6068. spectral_err("spectral object is null");
  6069. return QDF_STATUS_E_FAILURE;
  6070. }
  6071. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6072. wmi_handle, evt_buf, param);
  6073. }
  6074. /**
  6075. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  6076. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  6077. * secondary 80 MHz FFT bins
  6078. * @psoc: Pointer to psoc object
  6079. * @evt_buf: Event buffer
  6080. * @param: FFT bin start and end indices
  6081. *
  6082. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  6083. * and secondary 80 MHz FFT bins
  6084. *
  6085. * Return: QDF_STATUS
  6086. */
  6087. static QDF_STATUS
  6088. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6089. struct wlan_objmgr_psoc *psoc,
  6090. uint8_t *evt_buf,
  6091. struct spectral_fft_bin_markers_160_165mhz *param)
  6092. {
  6093. wmi_unified_t wmi_handle;
  6094. struct target_if_psoc_spectral *psoc_spectral;
  6095. if (!psoc) {
  6096. spectral_err("psoc is null");
  6097. return QDF_STATUS_E_INVAL;
  6098. }
  6099. if (!evt_buf) {
  6100. spectral_err("WMI event buffer is null");
  6101. return QDF_STATUS_E_INVAL;
  6102. }
  6103. if (!param) {
  6104. spectral_err("Spectral FFT bin markers is null");
  6105. return QDF_STATUS_E_INVAL;
  6106. }
  6107. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6108. if (!wmi_handle) {
  6109. spectral_err("WMI handle is null");
  6110. return QDF_STATUS_E_INVAL;
  6111. }
  6112. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6113. if (!psoc_spectral) {
  6114. spectral_err("spectral object is null");
  6115. return QDF_STATUS_E_FAILURE;
  6116. }
  6117. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fft_bin_index(
  6118. wmi_handle, evt_buf, param);
  6119. }
  6120. /**
  6121. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  6122. * object from scn handle
  6123. * @scn: scn handle
  6124. *
  6125. * Wrapper function to get psoc object from scn handle
  6126. *
  6127. * Return: Pointer to psoc object
  6128. */
  6129. static struct wlan_objmgr_psoc *
  6130. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  6131. {
  6132. if (!scn) {
  6133. spectral_err("scn is null");
  6134. return NULL;
  6135. }
  6136. return ops_tgt.tgt_get_psoc_from_scn_hdl(scn);
  6137. }
  6138. /**
  6139. * target_if_extract_pdev_spectral_session_chan_info() - Wrapper
  6140. * function to extract channel information for a spectral scan session
  6141. * @psoc: Pointer to psoc object
  6142. * @evt_buf: Event buffer
  6143. * @chan_info: Spectral session channel information data structure to be filled
  6144. * by this API
  6145. *
  6146. * Return: QDF_STATUS of operation
  6147. */
  6148. static QDF_STATUS
  6149. target_if_extract_pdev_spectral_session_chan_info(
  6150. struct wlan_objmgr_psoc *psoc,
  6151. void *evt_buf,
  6152. struct spectral_session_chan_info *chan_info)
  6153. {
  6154. wmi_unified_t wmi_handle;
  6155. struct target_if_psoc_spectral *psoc_spectral;
  6156. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6157. if (!wmi_handle) {
  6158. spectral_err("WMI handle is null");
  6159. return QDF_STATUS_E_NULL_VALUE;
  6160. }
  6161. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6162. if (!psoc_spectral) {
  6163. spectral_err("spectral object is null");
  6164. return QDF_STATUS_E_NULL_VALUE;
  6165. }
  6166. return psoc_spectral->wmi_ops.extract_pdev_spectral_session_chan_info(
  6167. wmi_handle, evt_buf, chan_info);
  6168. }
  6169. /**
  6170. * target_if_extract_pdev_spectral_session_detector_info() - Wrapper
  6171. * function to extract detector information for a spectral scan session
  6172. * @psoc: Pointer to psoc object
  6173. * @evt_buf: Event buffer
  6174. * @det_info: Spectral session detector information data structure to be filled
  6175. * by this API
  6176. * @det_info_idx: index in the array of spectral scan detector info TLVs
  6177. *
  6178. * Return: QDF_STATUS of operation
  6179. */
  6180. static QDF_STATUS
  6181. target_if_extract_pdev_spectral_session_detector_info(
  6182. struct wlan_objmgr_psoc *psoc, void *evt_buf,
  6183. struct spectral_session_det_info *det_info,
  6184. uint8_t det_info_idx)
  6185. {
  6186. wmi_unified_t wmi_handle;
  6187. struct target_if_psoc_spectral *psoc_spectral;
  6188. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6189. if (!wmi_handle) {
  6190. spectral_err("WMI handle is null");
  6191. return QDF_STATUS_E_NULL_VALUE;
  6192. }
  6193. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6194. if (!psoc_spectral) {
  6195. spectral_err("spectral object is null");
  6196. return QDF_STATUS_E_NULL_VALUE;
  6197. }
  6198. return psoc_spectral->wmi_ops.
  6199. extract_pdev_spectral_session_detector_info(
  6200. wmi_handle, evt_buf, det_info, det_info_idx);
  6201. }
  6202. /**
  6203. * target_if_wmi_extract_spectral_caps_fixed_param() - Wrapper function to
  6204. * extract fixed params from Spectral capabilities WMI event
  6205. * @psoc: Pointer to psoc object
  6206. * @evt_buf: Event buffer
  6207. * @param: Spectral capabilities event parameters data structure to be filled
  6208. * by this API
  6209. *
  6210. * Return: QDF_STATUS of operation
  6211. */
  6212. QDF_STATUS
  6213. target_if_wmi_extract_spectral_caps_fixed_param(
  6214. struct wlan_objmgr_psoc *psoc,
  6215. uint8_t *evt_buf,
  6216. struct spectral_capabilities_event_params *param)
  6217. {
  6218. struct target_if_psoc_spectral *psoc_spectral;
  6219. wmi_unified_t wmi_handle;
  6220. if (!psoc) {
  6221. spectral_err("psoc is null");
  6222. return QDF_STATUS_E_NULL_VALUE;
  6223. }
  6224. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6225. if (!wmi_handle) {
  6226. spectral_err("WMI handle is null");
  6227. return QDF_STATUS_E_NULL_VALUE;
  6228. }
  6229. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6230. if (!psoc_spectral) {
  6231. spectral_err("spectral object is null");
  6232. return QDF_STATUS_E_FAILURE;
  6233. }
  6234. return psoc_spectral->wmi_ops.extract_spectral_caps_fixed_param(
  6235. wmi_handle, evt_buf, param);
  6236. }
  6237. /**
  6238. * target_if_wmi_extract_spectral_scan_bw_caps() - Wrapper function to
  6239. * extract bandwidth capabilities from Spectral capabilities WMI event
  6240. * @psoc: Pointer to psoc object
  6241. * @evt_buf: Event buffer
  6242. * @bw_caps: Data structure to be filled by this API after extraction
  6243. *
  6244. * Return: QDF_STATUS of operation
  6245. */
  6246. QDF_STATUS
  6247. target_if_wmi_extract_spectral_scan_bw_caps(
  6248. struct wlan_objmgr_psoc *psoc,
  6249. uint8_t *evt_buf,
  6250. struct spectral_scan_bw_capabilities *bw_caps)
  6251. {
  6252. struct target_if_psoc_spectral *psoc_spectral;
  6253. wmi_unified_t wmi_handle;
  6254. if (!psoc) {
  6255. spectral_err("psoc is null");
  6256. return QDF_STATUS_E_INVAL;
  6257. }
  6258. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6259. if (!wmi_handle) {
  6260. spectral_err("WMI handle is null");
  6261. return QDF_STATUS_E_INVAL;
  6262. }
  6263. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6264. if (!psoc_spectral) {
  6265. spectral_err("spectral object is null");
  6266. return QDF_STATUS_E_FAILURE;
  6267. }
  6268. return psoc_spectral->wmi_ops.extract_spectral_scan_bw_caps(
  6269. wmi_handle, evt_buf, bw_caps);
  6270. }
  6271. /**
  6272. * target_if_wmi_extract_spectral_fft_size_caps() - Wrapper function to
  6273. * extract fft size capabilities from Spectral capabilities WMI event
  6274. * @psoc: Pointer to psoc object
  6275. * @evt_buf: Event buffer
  6276. * @fft_size_caps: Data structure to be filled by this API after extraction
  6277. *
  6278. * Return: QDF_STATUS of operation
  6279. */
  6280. QDF_STATUS
  6281. target_if_wmi_extract_spectral_fft_size_caps(
  6282. struct wlan_objmgr_psoc *psoc,
  6283. uint8_t *evt_buf,
  6284. struct spectral_fft_size_capabilities *fft_size_caps)
  6285. {
  6286. struct target_if_psoc_spectral *psoc_spectral;
  6287. wmi_unified_t wmi_handle;
  6288. if (!psoc) {
  6289. spectral_err("psoc is null");
  6290. return QDF_STATUS_E_INVAL;
  6291. }
  6292. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6293. if (!wmi_handle) {
  6294. spectral_err("WMI handle is null");
  6295. return QDF_STATUS_E_INVAL;
  6296. }
  6297. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6298. if (!psoc_spectral) {
  6299. spectral_err("spectral object is null");
  6300. return QDF_STATUS_E_FAILURE;
  6301. }
  6302. return psoc_spectral->wmi_ops.extract_spectral_fft_size_caps(
  6303. wmi_handle, evt_buf, fft_size_caps);
  6304. }
  6305. #else
  6306. /**
  6307. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  6308. * register WMI event handler
  6309. * @psoc: Pointer to psoc object
  6310. * @event_id: Event id
  6311. * @handler_func: Handler function
  6312. * @rx_ctx: Context of WMI event processing
  6313. *
  6314. * Wrapper function to register WMI event handler
  6315. *
  6316. * Return: 0 for success else failure
  6317. */
  6318. static int
  6319. target_if_spectral_wmi_unified_register_event_handler(
  6320. struct wlan_objmgr_psoc *psoc,
  6321. wmi_conv_event_id event_id,
  6322. wmi_unified_event_handler handler_func,
  6323. uint8_t rx_ctx)
  6324. {
  6325. wmi_unified_t wmi_handle;
  6326. QDF_STATUS ret;
  6327. if (!psoc) {
  6328. spectral_err("psoc is null");
  6329. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6330. }
  6331. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6332. if (!wmi_handle) {
  6333. spectral_err("WMI handle is null");
  6334. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6335. }
  6336. ret = wmi_unified_register_event_handler(wmi_handle, event_id,
  6337. handler_func, rx_ctx);
  6338. return qdf_status_to_os_return(ret);
  6339. }
  6340. /**
  6341. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  6342. * to unregister WMI event handler
  6343. * @psoc: Pointer to psoc object
  6344. * @event_id: Event id
  6345. *
  6346. * Wrapper function to unregister WMI event handler
  6347. *
  6348. * Return: 0 for success else failure
  6349. */
  6350. static int
  6351. target_if_spectral_wmi_unified_unregister_event_handler(
  6352. struct wlan_objmgr_psoc *psoc,
  6353. wmi_conv_event_id event_id)
  6354. {
  6355. wmi_unified_t wmi_handle;
  6356. QDF_STATUS ret;
  6357. if (!psoc) {
  6358. spectral_err("psoc is null");
  6359. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6360. }
  6361. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6362. if (!wmi_handle) {
  6363. spectral_err("WMI handle is null");
  6364. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6365. }
  6366. ret = wmi_unified_unregister_event_handler(wmi_handle, event_id);
  6367. return qdf_status_to_os_return(ret);
  6368. }
  6369. /**
  6370. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  6371. * function to extract fixed parameters from start scan response event
  6372. * @psoc: Pointer to psoc object
  6373. * @evt_buf: Event buffer
  6374. * @param: Start scan response parameters
  6375. *
  6376. * Wrapper function to extract fixed parameters from start scan response event
  6377. *
  6378. * Return: QDF_STATUS
  6379. */
  6380. static QDF_STATUS
  6381. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6382. struct wlan_objmgr_psoc *psoc,
  6383. uint8_t *evt_buf,
  6384. struct spectral_startscan_resp_params *param)
  6385. {
  6386. wmi_unified_t wmi_handle;
  6387. if (!psoc) {
  6388. spectral_err("psoc is null");
  6389. return QDF_STATUS_E_INVAL;
  6390. }
  6391. if (!evt_buf) {
  6392. spectral_err("WMI event buffer is null");
  6393. return QDF_STATUS_E_INVAL;
  6394. }
  6395. if (!param) {
  6396. spectral_err("Spectral startscan response parameters is null");
  6397. return QDF_STATUS_E_INVAL;
  6398. }
  6399. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6400. if (!wmi_handle) {
  6401. spectral_err("WMI handle is null");
  6402. return QDF_STATUS_E_INVAL;
  6403. }
  6404. return wmi_extract_pdev_sscan_fw_cmd_fixed_param(wmi_handle, evt_buf,
  6405. param);
  6406. }
  6407. /**
  6408. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  6409. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  6410. * secondary 80 MHz FFT bins
  6411. * @psoc: Pointer to psoc object
  6412. * @evt_buf: Event buffer
  6413. * @param: FFT bin start and end indices
  6414. *
  6415. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  6416. * and secondary 80 MHz FFT bins
  6417. *
  6418. * Return: QDF_STATUS
  6419. */
  6420. static QDF_STATUS
  6421. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6422. struct wlan_objmgr_psoc *psoc,
  6423. uint8_t *evt_buf,
  6424. struct spectral_fft_bin_markers_160_165mhz *param)
  6425. {
  6426. wmi_unified_t wmi_handle;
  6427. if (!psoc) {
  6428. spectral_err("psoc is null");
  6429. return QDF_STATUS_E_INVAL;
  6430. }
  6431. if (!evt_buf) {
  6432. spectral_err("WMI event buffer is null");
  6433. return QDF_STATUS_E_INVAL;
  6434. }
  6435. if (!param) {
  6436. spectral_err("Spectral FFT bin markers is null");
  6437. return QDF_STATUS_E_INVAL;
  6438. }
  6439. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6440. if (!wmi_handle) {
  6441. spectral_err("WMI handle is null");
  6442. return QDF_STATUS_E_INVAL;
  6443. }
  6444. return wmi_extract_pdev_sscan_fft_bin_index(wmi_handle, evt_buf, param);
  6445. }
  6446. /**
  6447. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  6448. * object from scn handle
  6449. * @scn: scn handle
  6450. *
  6451. * Wrapper function to get psoc object from scn handle
  6452. *
  6453. * Return: Pointer to psoc object
  6454. */
  6455. static struct wlan_objmgr_psoc *
  6456. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  6457. {
  6458. if (!scn) {
  6459. spectral_err("scn is null");
  6460. return NULL;
  6461. }
  6462. return target_if_get_psoc_from_scn_hdl(scn);
  6463. }
  6464. /**
  6465. * target_if_extract_pdev_spectral_session_chan_info() - Wrapper
  6466. * function to extract channel information for a spectral scan session
  6467. * @psoc: Pointer to psoc object
  6468. * @evt_buf: Event buffer
  6469. * @chan_info: Spectral session channel information data structure to be filled
  6470. * by this API
  6471. *
  6472. * Return: QDF_STATUS of operation
  6473. */
  6474. static QDF_STATUS
  6475. target_if_extract_pdev_spectral_session_chan_info(
  6476. struct wlan_objmgr_psoc *psoc,
  6477. void *evt_buf,
  6478. struct spectral_session_chan_info *chan_info)
  6479. {
  6480. wmi_unified_t wmi_handle;
  6481. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6482. if (!wmi_handle) {
  6483. spectral_err("WMI handle is null");
  6484. return QDF_STATUS_E_NULL_VALUE;
  6485. }
  6486. return wmi_extract_pdev_spectral_session_chan_info(
  6487. wmi_handle, evt_buf, chan_info);
  6488. }
  6489. /**
  6490. * target_if_extract_pdev_spectral_session_detector_info() - Wrapper
  6491. * function to extract detector information for a spectral scan session
  6492. * @psoc: Pointer to psoc object
  6493. * @evt_buf: Event buffer
  6494. * @det_info: Spectral session detector information data structure to be filled
  6495. * by this API
  6496. * @det_info_idx: index in the array of spectral scan detector info TLVs
  6497. *
  6498. * Return: QDF_STATUS of operation
  6499. */
  6500. static QDF_STATUS
  6501. target_if_extract_pdev_spectral_session_detector_info(
  6502. struct wlan_objmgr_psoc *psoc, void *evt_buf,
  6503. struct spectral_session_det_info *det_info,
  6504. uint8_t det_info_idx)
  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_NULL_VALUE;
  6511. }
  6512. return wmi_extract_pdev_spectral_session_detector_info(
  6513. wmi_handle, evt_buf, det_info, det_info_idx);
  6514. }
  6515. QDF_STATUS
  6516. target_if_wmi_extract_spectral_caps_fixed_param(
  6517. struct wlan_objmgr_psoc *psoc,
  6518. uint8_t *evt_buf,
  6519. struct spectral_capabilities_event_params *param)
  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_caps_fixed_param(wmi_handle, evt_buf,
  6528. param);
  6529. }
  6530. QDF_STATUS
  6531. target_if_wmi_extract_spectral_scan_bw_caps(
  6532. struct wlan_objmgr_psoc *psoc,
  6533. uint8_t *evt_buf,
  6534. struct spectral_scan_bw_capabilities *bw_caps)
  6535. {
  6536. wmi_unified_t wmi_handle;
  6537. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6538. if (!wmi_handle) {
  6539. spectral_err("WMI handle is null");
  6540. return QDF_STATUS_E_INVAL;
  6541. }
  6542. return wmi_extract_spectral_scan_bw_caps(wmi_handle, evt_buf, bw_caps);
  6543. }
  6544. QDF_STATUS
  6545. target_if_wmi_extract_spectral_fft_size_caps(
  6546. struct wlan_objmgr_psoc *psoc,
  6547. uint8_t *evt_buf,
  6548. struct spectral_fft_size_capabilities *fft_size_caps)
  6549. {
  6550. wmi_unified_t wmi_handle;
  6551. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6552. if (!wmi_handle) {
  6553. spectral_err("WMI handle is null");
  6554. return QDF_STATUS_E_INVAL;
  6555. }
  6556. return wmi_extract_spectral_fft_size_caps(wmi_handle, evt_buf,
  6557. fft_size_caps);
  6558. }
  6559. #endif
  6560. /**
  6561. * target_if_update_det_info_in_spectral_session() - Update detector
  6562. * information in spectral scan session
  6563. * @spectral: Spectral LMAC object
  6564. * @det_info: Pointer to spectral session detector information
  6565. * @smode: Spectral scan mode
  6566. *
  6567. * Return: QDF_STATUS of operation
  6568. */
  6569. static QDF_STATUS
  6570. target_if_update_det_info_in_spectral_session(
  6571. struct target_if_spectral *spectral,
  6572. const struct spectral_session_det_info *det_info,
  6573. enum spectral_scan_mode smode)
  6574. {
  6575. struct per_session_det_map *det_map;
  6576. struct per_session_dest_det_info *dest_det_info;
  6577. if (!spectral) {
  6578. spectral_err_rl("Spectral LMAC object is null");
  6579. return QDF_STATUS_E_NULL_VALUE;
  6580. }
  6581. qdf_assert_always(det_info->det_id < MAX_DETECTORS_PER_PDEV);
  6582. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  6583. det_map = &spectral->det_map[det_info->det_id];
  6584. dest_det_info = &det_map->dest_det_info[0];
  6585. dest_det_info->start_freq = det_info->start_freq;
  6586. dest_det_info->end_freq = det_info->end_freq;
  6587. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  6588. /* This detector will be used for this smode throughout this session */
  6589. spectral->rparams.detid_mode_table[det_info->det_id] = smode;
  6590. return QDF_STATUS_SUCCESS;
  6591. }
  6592. /**
  6593. * target_if_update_chan_info_in_spectral_session() - Update channel information
  6594. * in spectral scan session
  6595. * @spectral: Spectral LMAC object
  6596. * @chan_info: Pointer to spectral session channel information
  6597. * @smode: Spectral scan mode
  6598. *
  6599. * Return: QDF_STATUS of operation
  6600. */
  6601. static QDF_STATUS
  6602. target_if_update_chan_info_in_spectral_session(
  6603. struct target_if_spectral *spectral,
  6604. const struct spectral_session_chan_info *chan_info,
  6605. enum spectral_scan_mode smode)
  6606. {
  6607. struct per_session_report_info *rpt_info;
  6608. if (!spectral) {
  6609. spectral_err_rl("Spectral LMAC object is null");
  6610. return QDF_STATUS_E_NULL_VALUE;
  6611. }
  6612. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6613. spectral_err_rl("Invalid Spectral scan mode :%u", smode);
  6614. return QDF_STATUS_E_FAILURE;
  6615. }
  6616. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  6617. rpt_info = &spectral->report_info[smode];
  6618. /* Update per-session report info */
  6619. rpt_info->pri20_freq = chan_info->operating_pri20_freq;
  6620. rpt_info->cfreq1 = chan_info->operating_cfreq1;
  6621. rpt_info->cfreq2 = chan_info->operating_cfreq2;
  6622. rpt_info->operating_bw = chan_info->operating_bw;
  6623. rpt_info->sscan_cfreq1 = chan_info->sscan_cfreq1;
  6624. rpt_info->sscan_cfreq2 = chan_info->sscan_cfreq2;
  6625. rpt_info->sscan_bw = chan_info->sscan_bw;
  6626. /* num_spans depends on sscan_bw, update it */
  6627. rpt_info->num_spans = target_if_spectral_get_num_spans(
  6628. spectral->pdev_obj,
  6629. rpt_info->sscan_bw);
  6630. qdf_assert_always(rpt_info->num_spans != INVALID_SPAN_NUM);
  6631. rpt_info->valid = true;
  6632. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  6633. return QDF_STATUS_SUCCESS;
  6634. }
  6635. /**
  6636. * target_if_spectral_fw_param_event_handler() - WMI event handler to
  6637. * process start scan response event
  6638. * @scn: Pointer to scn object
  6639. * @data_buf: Pointer to event buffer
  6640. * @data_len: Length of event buffer
  6641. *
  6642. * Return: 0 for success, else failure
  6643. */
  6644. static int
  6645. target_if_spectral_fw_param_event_handler(ol_scn_t scn, uint8_t *data_buf,
  6646. uint32_t data_len)
  6647. {
  6648. QDF_STATUS status;
  6649. struct wlan_objmgr_psoc *psoc;
  6650. struct wlan_objmgr_pdev *pdev;
  6651. struct wmi_unified *wmi_handle;
  6652. struct spectral_startscan_resp_params event_params = {0};
  6653. struct target_if_psoc_spectral *psoc_spectral;
  6654. struct target_if_spectral *spectral;
  6655. bool is_session_info_expected;
  6656. if (!scn) {
  6657. spectral_err("scn handle is null");
  6658. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6659. }
  6660. if (!data_buf) {
  6661. spectral_err("WMI event buffer null");
  6662. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6663. }
  6664. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  6665. if (!psoc) {
  6666. spectral_err("psoc is null");
  6667. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6668. }
  6669. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6670. if (!psoc_spectral) {
  6671. spectral_err("spectral object is null");
  6672. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6673. }
  6674. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6675. if (!wmi_handle) {
  6676. spectral_err("WMI handle is null");
  6677. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6678. }
  6679. status = target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6680. psoc, data_buf, &event_params);
  6681. if (QDF_IS_STATUS_ERROR(status)) {
  6682. spectral_err("unable to extract sscan fw fixed params");
  6683. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6684. }
  6685. if (event_params.smode >= SPECTRAL_SCAN_MODE_MAX ||
  6686. event_params.smode < SPECTRAL_SCAN_MODE_NORMAL) {
  6687. spectral_err("Invalid smode %d", event_params.smode);
  6688. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6689. }
  6690. pdev = wlan_objmgr_get_pdev_by_id(psoc, event_params.pdev_id,
  6691. WLAN_SPECTRAL_ID);
  6692. if (!pdev) {
  6693. spectral_err("pdev is null");
  6694. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6695. }
  6696. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  6697. if (!spectral) {
  6698. spectral_err("spectral object is null");
  6699. status = QDF_STATUS_E_FAILURE;
  6700. goto release_pdev_ref;
  6701. }
  6702. if (event_params.num_fft_bin_index == 1) {
  6703. status =
  6704. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6705. psoc, data_buf,
  6706. &spectral->rparams.marker[event_params.smode]);
  6707. if (QDF_IS_STATUS_ERROR(status)) {
  6708. spectral_err("unable to extract sscan fw fixed params");
  6709. goto release_pdev_ref;
  6710. }
  6711. } else {
  6712. spectral->rparams.marker[event_params.smode].is_valid = false;
  6713. }
  6714. status = spectral_is_session_info_expected_from_target(
  6715. pdev, &is_session_info_expected);
  6716. if (QDF_IS_STATUS_ERROR(status)) {
  6717. spectral_err("Failed to check if session info is expected");
  6718. goto release_pdev_ref;
  6719. }
  6720. if (is_session_info_expected) {
  6721. struct spectral_session_chan_info chan_info;
  6722. uint8_t det_info_idx = 0;
  6723. status = target_if_extract_pdev_spectral_session_chan_info(
  6724. psoc, data_buf, &chan_info);
  6725. if (QDF_IS_STATUS_ERROR(status)) {
  6726. spectral_err("Unable to extract spectral session channel info");
  6727. goto release_pdev_ref;
  6728. }
  6729. status = target_if_update_chan_info_in_spectral_session(
  6730. spectral, &chan_info, event_params.smode);
  6731. if (QDF_IS_STATUS_ERROR(status)) {
  6732. spectral_err("Unable to update channel info");
  6733. goto release_pdev_ref;
  6734. }
  6735. /* FFT bins info depends upon sscan_bw, update it */
  6736. status = target_if_populate_fft_bins_info(spectral,
  6737. event_params.smode);
  6738. if (QDF_IS_STATUS_ERROR(status)) {
  6739. spectral_err("Failed to populate FFT bins info");
  6740. goto release_pdev_ref;
  6741. }
  6742. /**
  6743. * per-session det info that depends on sscan_bw needs to be
  6744. * updated here
  6745. */
  6746. status = target_if_spectral_populate_session_det_host_info(
  6747. spectral, event_params.smode);
  6748. if (QDF_IS_STATUS_ERROR(status)) {
  6749. spectral_err("Failed to populate per-session det info");
  6750. goto release_pdev_ref;
  6751. }
  6752. for (; det_info_idx < event_params.num_det_info;
  6753. ++det_info_idx) {
  6754. struct spectral_session_det_info det_info;
  6755. status =
  6756. target_if_extract_pdev_spectral_session_detector_info
  6757. (psoc, data_buf, &det_info, det_info_idx);
  6758. if (QDF_IS_STATUS_ERROR(status)) {
  6759. spectral_err("Unable to extract spectral session detector info for %u",
  6760. det_info_idx);
  6761. goto release_pdev_ref;
  6762. }
  6763. status = target_if_update_det_info_in_spectral_session(
  6764. spectral, &det_info,
  6765. event_params.smode);
  6766. if (QDF_IS_STATUS_ERROR(status)) {
  6767. spectral_err("Unable to update detector info");
  6768. goto release_pdev_ref;
  6769. }
  6770. }
  6771. }
  6772. status = QDF_STATUS_SUCCESS;
  6773. release_pdev_ref:
  6774. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  6775. return qdf_status_to_os_return(status);
  6776. }
  6777. /**
  6778. * target_if_spectral_capabilities_event_handler() - Handler for the Spectral
  6779. * Capabilities event
  6780. * @scn: Pointer to scn object
  6781. * @data_buf: Pointer to event buffer
  6782. * @data_len: Length of event buffer
  6783. *
  6784. * Return: 0 for success, else failure
  6785. */
  6786. static int
  6787. target_if_spectral_capabilities_event_handler(ol_scn_t scn, uint8_t *data_buf,
  6788. uint32_t data_len)
  6789. {
  6790. QDF_STATUS status;
  6791. struct wlan_objmgr_psoc *psoc;
  6792. struct wmi_unified *wmi_handle;
  6793. struct spectral_capabilities_event_params event_params = {0};
  6794. struct spectral_scan_bw_capabilities *bw_caps;
  6795. struct spectral_fft_size_capabilities *fft_size_caps;
  6796. if (!scn) {
  6797. spectral_err("scn handle is null");
  6798. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6799. }
  6800. if (!data_buf) {
  6801. spectral_err("WMI event buffer null");
  6802. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6803. }
  6804. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  6805. if (!psoc) {
  6806. spectral_err("psoc is null");
  6807. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6808. }
  6809. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6810. if (!wmi_handle) {
  6811. spectral_err("WMI handle is null");
  6812. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6813. }
  6814. status = target_if_wmi_extract_spectral_caps_fixed_param(
  6815. psoc, data_buf, &event_params);
  6816. if (QDF_IS_STATUS_ERROR(status)) {
  6817. spectral_err("Failed to extract fixed parameters");
  6818. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6819. }
  6820. /* There should be atleast one capability */
  6821. qdf_assert(event_params.num_sscan_bw_caps > 0);
  6822. qdf_assert(event_params.num_fft_size_caps > 0);
  6823. bw_caps = qdf_mem_malloc(
  6824. sizeof(*bw_caps) * event_params.num_sscan_bw_caps);
  6825. if (!bw_caps) {
  6826. spectral_err("memory allocation failed");
  6827. return qdf_status_to_os_return(QDF_STATUS_E_NOMEM);
  6828. }
  6829. status = target_if_wmi_extract_spectral_scan_bw_caps(psoc, data_buf,
  6830. bw_caps);
  6831. if (QDF_IS_STATUS_ERROR(status)) {
  6832. spectral_err("Failed to extract BW caps");
  6833. status = QDF_STATUS_E_FAILURE;
  6834. goto free_bw_caps;
  6835. }
  6836. fft_size_caps = qdf_mem_malloc(
  6837. sizeof(*fft_size_caps) * event_params.num_fft_size_caps);
  6838. if (!fft_size_caps) {
  6839. spectral_err("memory allocation failed");
  6840. status = QDF_STATUS_E_NOMEM;
  6841. goto free_bw_caps;
  6842. }
  6843. status = target_if_wmi_extract_spectral_fft_size_caps(psoc, data_buf,
  6844. fft_size_caps);
  6845. if (QDF_IS_STATUS_ERROR(status)) {
  6846. spectral_err("Failed to extract fft size caps");
  6847. status = QDF_STATUS_E_FAILURE;
  6848. goto free_fft_size_caps;
  6849. }
  6850. status = QDF_STATUS_SUCCESS;
  6851. free_fft_size_caps:
  6852. qdf_mem_free(fft_size_caps);
  6853. free_bw_caps:
  6854. qdf_mem_free(bw_caps);
  6855. return qdf_status_to_os_return(status);
  6856. }
  6857. static QDF_STATUS
  6858. target_if_spectral_register_events(struct wlan_objmgr_psoc *psoc)
  6859. {
  6860. int ret;
  6861. if (!psoc) {
  6862. spectral_err("psoc is null");
  6863. return QDF_STATUS_E_INVAL;
  6864. }
  6865. ret = target_if_spectral_wmi_unified_register_event_handler(
  6866. psoc,
  6867. wmi_pdev_sscan_fw_param_eventid,
  6868. target_if_spectral_fw_param_event_handler,
  6869. WMI_RX_UMAC_CTX);
  6870. if (ret)
  6871. spectral_debug("event handler not supported, ret=%d", ret);
  6872. ret = target_if_spectral_wmi_unified_register_event_handler(
  6873. psoc,
  6874. wmi_spectral_capabilities_eventid,
  6875. target_if_spectral_capabilities_event_handler,
  6876. WMI_RX_UMAC_CTX);
  6877. if (ret)
  6878. spectral_debug("event handler not supported, ret=%d", ret);
  6879. return QDF_STATUS_SUCCESS;
  6880. }
  6881. static QDF_STATUS
  6882. target_if_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
  6883. {
  6884. int ret;
  6885. if (!psoc) {
  6886. spectral_err("psoc is null");
  6887. return QDF_STATUS_E_INVAL;
  6888. }
  6889. target_if_spectral_wmi_unified_unregister_event_handler(
  6890. psoc, wmi_spectral_capabilities_eventid);
  6891. ret = target_if_spectral_wmi_unified_unregister_event_handler(
  6892. psoc, wmi_pdev_sscan_fw_param_eventid);
  6893. if (ret)
  6894. spectral_debug("Unregister WMI event handler failed, ret = %d",
  6895. ret);
  6896. return QDF_STATUS_SUCCESS;
  6897. }
  6898. void
  6899. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  6900. {
  6901. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  6902. target_if_pdev_spectral_init;
  6903. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  6904. target_if_pdev_spectral_deinit;
  6905. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init =
  6906. target_if_psoc_spectral_init;
  6907. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit =
  6908. target_if_psoc_spectral_deinit;
  6909. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  6910. target_if_set_spectral_config;
  6911. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  6912. target_if_get_spectral_config;
  6913. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  6914. target_if_start_spectral_scan;
  6915. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  6916. target_if_stop_spectral_scan;
  6917. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  6918. target_if_is_spectral_active;
  6919. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  6920. target_if_is_spectral_enabled;
  6921. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  6922. target_if_set_debug_level;
  6923. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  6924. target_if_get_debug_level;
  6925. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  6926. target_if_get_spectral_capinfo;
  6927. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  6928. target_if_get_spectral_diagstats;
  6929. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_wmi_ops =
  6930. target_if_register_spectral_wmi_ops;
  6931. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_tgt_ops =
  6932. target_if_register_spectral_tgt_ops;
  6933. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  6934. target_if_register_netlink_cb;
  6935. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  6936. target_if_use_nl_bcast;
  6937. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  6938. target_if_deregister_netlink_cb;
  6939. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  6940. target_if_process_spectral_report;
  6941. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  6942. target_if_spectral_direct_dma_support;
  6943. tx_ops->sptrl_tx_ops.sptrlto_register_events =
  6944. target_if_spectral_register_events;
  6945. tx_ops->sptrl_tx_ops.sptrlto_unregister_events =
  6946. target_if_spectral_unregister_events;
  6947. tx_ops->sptrl_tx_ops.sptrlto_init_pdev_feature_caps =
  6948. target_if_spectral_init_pdev_feature_caps;
  6949. target_if_sptrl_debug_register_tx_ops(tx_ops);
  6950. }
  6951. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  6952. void
  6953. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  6954. uint16_t cw_int, uint32_t dcs_enabled)
  6955. {
  6956. struct spectral_samp_msg *msg = NULL;
  6957. struct target_if_spectral_ops *p_sops = NULL;
  6958. struct target_if_spectral *spectral = NULL;
  6959. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  6960. if (!spectral) {
  6961. spectral_err("SPECTRAL : Module doesn't exist");
  6962. return;
  6963. }
  6964. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  6965. if (!p_sops) {
  6966. spectral_err("p_sops is null");
  6967. return;
  6968. }
  6969. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  6970. spectral->pdev_obj,
  6971. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  6972. SPECTRAL_MSG_BUF_NEW);
  6973. if (msg) {
  6974. msg->int_type = cw_int ?
  6975. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  6976. msg->dcs_enabled = dcs_enabled;
  6977. msg->signature = SPECTRAL_SIGNATURE;
  6978. p_sops->get_mac_address(spectral, msg->macaddr);
  6979. if (spectral->send_phy_data
  6980. (pdev,
  6981. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  6982. spectral->spectral_sent_msg++;
  6983. }
  6984. }
  6985. qdf_export_symbol(target_if_spectral_send_intf_found_msg);
  6986. QDF_STATUS
  6987. target_if_spectral_is_finite_scan(struct target_if_spectral *spectral,
  6988. enum spectral_scan_mode smode,
  6989. bool *finite_spectral_scan)
  6990. {
  6991. struct target_if_finite_spectral_scan_params *finite_scan;
  6992. if (!spectral) {
  6993. spectral_err_rl("target if spectral object is null");
  6994. return QDF_STATUS_E_INVAL;
  6995. }
  6996. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6997. spectral_err_rl("invalid spectral mode %d", smode);
  6998. return QDF_STATUS_E_INVAL;
  6999. }
  7000. if (!finite_spectral_scan) {
  7001. spectral_err_rl("Invalid pointer");
  7002. return QDF_STATUS_E_INVAL;
  7003. }
  7004. finite_scan = &spectral->finite_scan[smode];
  7005. *finite_spectral_scan = finite_scan->finite_spectral_scan;
  7006. return QDF_STATUS_SUCCESS;
  7007. }
  7008. QDF_STATUS
  7009. target_if_spectral_finite_scan_update(struct target_if_spectral *spectral,
  7010. enum spectral_scan_mode smode)
  7011. {
  7012. struct target_if_finite_spectral_scan_params *finite_scan;
  7013. if (!spectral) {
  7014. spectral_err_rl("target if spectral object is null");
  7015. return QDF_STATUS_E_INVAL;
  7016. }
  7017. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  7018. spectral_err_rl("Invalid Spectral mode");
  7019. return QDF_STATUS_E_INVAL;
  7020. }
  7021. finite_scan = &spectral->finite_scan[smode];
  7022. if (!finite_scan->num_reports_expected) {
  7023. spectral_err_rl("Error, No reports expected");
  7024. return QDF_STATUS_E_FAILURE;
  7025. }
  7026. finite_scan->num_reports_expected--;
  7027. if (!finite_scan->num_reports_expected) {
  7028. QDF_STATUS status;
  7029. enum spectral_cp_error_code err;
  7030. /* received expected number of reports from target, stop scan */
  7031. status = target_if_stop_spectral_scan(spectral->pdev_obj, smode,
  7032. &err);
  7033. if (QDF_IS_STATUS_ERROR(status)) {
  7034. spectral_err_rl("Failed to stop finite Spectral scan");
  7035. return QDF_STATUS_E_FAILURE;
  7036. }
  7037. finite_scan->finite_spectral_scan = false;
  7038. }
  7039. return QDF_STATUS_SUCCESS;
  7040. }