target_if_spectral.c 219 KB

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