target_if_spectral.c 219 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059
  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 same as sscan_pdev */
  2988. if (sscan_pdev_phy_info->phy_id == cur_mac_phy_caps->phy_id)
  2989. return;
  2990. /**
  2991. * Compare the phy_id of both the SBS pdevs to figure out if
  2992. * the sscan_pdev using PHYA1
  2993. */
  2994. if (sscan_pdev_phy_info->phy_id > cur_mac_phy_caps->phy_id)
  2995. *sscan_pdev_phy_info->is_using_phya1 = true;
  2996. else
  2997. *sscan_pdev_phy_info->is_using_phya1 = false;
  2998. }
  2999. /**
  3000. * target_if_spectral_detector_list_init() - Initialize Spectral detector list
  3001. * based on target type
  3002. * @spectral: Pointer to Spectral target_if
  3003. *
  3004. * Function to initialize Spectral detector list for possible combinations of
  3005. * Spectral scan mode and channel width, based on target type.
  3006. *
  3007. * Return: Success/Failure
  3008. */
  3009. static QDF_STATUS
  3010. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  3011. {
  3012. struct sscan_detector_list *det_list;
  3013. enum spectral_scan_mode smode;
  3014. enum phy_ch_width ch_width;
  3015. QDF_STATUS ret;
  3016. bool is_hw_mode_sbs = false, is_using_phya1 = false;
  3017. if (!spectral) {
  3018. spectral_err_rl("Spectral LMAC object is null");
  3019. return QDF_STATUS_E_NULL_VALUE;
  3020. }
  3021. /**
  3022. * Special handling is required for SBS mode where the detector
  3023. * list should be the following.
  3024. * For the pdev that use PHYA0:
  3025. * detector 0 for normal mode
  3026. * detector 2 for agile mode
  3027. * For the pdev that use PHYA1:
  3028. * detector 1 for normal mode
  3029. * detector 2 for agile mode
  3030. *
  3031. * There is no direct way of knowing which pdevs are using PHYA0 or
  3032. * PHYA1. We need to look at the phy_id of a given pdev and compare
  3033. * against other pdevs on the same psoc to figure out whether the given
  3034. * pdev is operating using PHYA1.
  3035. */
  3036. /* First check whether this pdev is in SBS mode */
  3037. ret = target_if_spectral_is_hw_mode_sbs(spectral->pdev_obj,
  3038. &is_hw_mode_sbs);
  3039. if (QDF_IS_STATUS_ERROR(ret)) {
  3040. spectral_err("Failed to check whether hw mode is SBS");
  3041. return ret;
  3042. }
  3043. if (is_hw_mode_sbs) {
  3044. struct wlan_psoc_host_mac_phy_caps *mac_phy_caps;
  3045. struct target_if_sscan_pdev_phy_info pdev_phy_info;
  3046. mac_phy_caps =
  3047. target_if_get_pdev_mac_phy_caps(spectral->pdev_obj);
  3048. if (!mac_phy_caps) {
  3049. spectral_err("Failed to get MAC PHY Capabilities of"
  3050. "pdev %pK", spectral->pdev_obj);
  3051. return QDF_STATUS_E_FAILURE;
  3052. }
  3053. spectral_debug("bands: %0x phy_id: %d",
  3054. mac_phy_caps->supported_bands,
  3055. mac_phy_caps->phy_id);
  3056. pdev_phy_info.phy_id = mac_phy_caps->phy_id;
  3057. pdev_phy_info.is_using_phya1 = &is_using_phya1;
  3058. /* Iterate over all pdevs on this psoc */
  3059. wlan_objmgr_iterate_obj_list
  3060. (wlan_pdev_get_psoc(spectral->pdev_obj),
  3061. WLAN_PDEV_OP,
  3062. target_if_find_sscan_pdev_phya1,
  3063. &pdev_phy_info, 0,
  3064. WLAN_SPECTRAL_ID);
  3065. }
  3066. /**
  3067. * We assume there are 2 detectors. The Detector ID coming first will
  3068. * always be pri80 detector, and second detector for sec80.
  3069. */
  3070. ch_width = CH_WIDTH_20MHZ;
  3071. for (; ch_width < CH_WIDTH_MAX; ch_width++) {
  3072. /* Normal spectral scan */
  3073. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3074. spectral_debug("is_hw_mode_sbs: %d is_using_phya1:%d",
  3075. is_hw_mode_sbs, is_using_phya1);
  3076. qdf_spin_lock_bh(&spectral->detector_list_lock);
  3077. if (!spectral->supported_sscan_bw_list[smode][ch_width])
  3078. goto agile_handling;
  3079. det_list = &spectral->detector_list[smode][ch_width];
  3080. det_list->num_detectors = 1;
  3081. if (is_hw_mode_sbs && is_using_phya1)
  3082. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_1;
  3083. else
  3084. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_0;
  3085. if (is_ch_width_160_or_80p80(ch_width) &&
  3086. spectral->rparams.fragmentation_160[smode]) {
  3087. det_list->num_detectors += 1;
  3088. det_list->detectors[1] = SPECTRAL_DETECTOR_ID_1;
  3089. }
  3090. agile_handling:
  3091. /* Agile spectral scan */
  3092. smode = SPECTRAL_SCAN_MODE_AGILE;
  3093. if (!spectral->supported_sscan_bw_list[smode][ch_width]) {
  3094. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  3095. continue;
  3096. }
  3097. det_list = &spectral->detector_list[smode][ch_width];
  3098. det_list->num_detectors = 1;
  3099. if (spectral->rparams.fragmentation_160[smode])
  3100. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_2;
  3101. else
  3102. det_list->detectors[0] = SPECTRAL_DETECTOR_ID_1;
  3103. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  3104. }
  3105. return QDF_STATUS_SUCCESS;
  3106. }
  3107. #else
  3108. static QDF_STATUS
  3109. target_if_spectral_detector_list_init(struct target_if_spectral *spectral)
  3110. {
  3111. return QDF_STATUS_SUCCESS;
  3112. }
  3113. #endif /* OPTIMIZED_SAMP_MESSAGE */
  3114. /**
  3115. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  3116. * functionality for the given pdev
  3117. * @pdev: Pointer to pdev object
  3118. *
  3119. * Function to initialize pointer to spectral target_if internal private data
  3120. *
  3121. * Return: On success, pointer to Spectral target_if internal private data, on
  3122. * failure, NULL
  3123. */
  3124. void *
  3125. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  3126. {
  3127. struct target_if_spectral_ops *p_sops = NULL;
  3128. struct target_if_spectral *spectral = NULL;
  3129. uint32_t target_type;
  3130. uint32_t target_revision;
  3131. struct wlan_objmgr_psoc *psoc;
  3132. struct wlan_lmac_if_target_tx_ops *tgt_tx_ops;
  3133. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  3134. QDF_STATUS status;
  3135. struct wlan_lmac_if_tx_ops *tx_ops;
  3136. if (!pdev) {
  3137. spectral_err("SPECTRAL: pdev is NULL!");
  3138. return NULL;
  3139. }
  3140. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  3141. sizeof(struct target_if_spectral));
  3142. if (!spectral)
  3143. return spectral;
  3144. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  3145. /* Store pdev in Spectral */
  3146. spectral->pdev_obj = pdev;
  3147. spectral->vdev_id[SPECTRAL_SCAN_MODE_NORMAL] = WLAN_INVALID_VDEV_ID;
  3148. spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE] = WLAN_INVALID_VDEV_ID;
  3149. psoc = wlan_pdev_get_psoc(pdev);
  3150. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  3151. if (!tx_ops) {
  3152. spectral_err("tx_ops is NULL");
  3153. qdf_mem_free(spectral);
  3154. return NULL;
  3155. }
  3156. tgt_tx_ops = &tx_ops->target_tx_ops;
  3157. if (tgt_tx_ops->tgt_get_tgt_type) {
  3158. target_type = tgt_tx_ops->tgt_get_tgt_type(psoc);
  3159. } else {
  3160. qdf_mem_free(spectral);
  3161. return NULL;
  3162. }
  3163. if (tgt_tx_ops->tgt_get_tgt_revision) {
  3164. target_revision = tgt_tx_ops->tgt_get_tgt_revision(psoc);
  3165. } else {
  3166. qdf_mem_free(spectral);
  3167. return NULL;
  3168. }
  3169. /* init the function ptr table */
  3170. target_if_spectral_init_dummy_function_table(spectral);
  3171. /* get spectral function table */
  3172. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3173. /* TODO : Should this be called here of after ath_attach ? */
  3174. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  3175. spectral_info("HAL_CAP_PHYDIAG : Capable");
  3176. /* TODO: Need to fix the capablity check for RADAR */
  3177. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  3178. spectral_info("HAL_CAP_RADAR : Capable");
  3179. /* TODO : Need to fix the capablity check for SPECTRAL */
  3180. /* TODO : Should this be called here of after ath_attach ? */
  3181. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  3182. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  3183. qdf_spinlock_create(&spectral->spectral_lock);
  3184. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  3185. target_if_spectral_clear_stats(spectral);
  3186. if (target_type == TARGET_TYPE_QCA8074 ||
  3187. target_type == TARGET_TYPE_QCA8074V2 ||
  3188. target_type == TARGET_TYPE_QCA9574 ||
  3189. target_type == TARGET_TYPE_QCA6018 ||
  3190. target_type == TARGET_TYPE_QCA5018 ||
  3191. target_type == TARGET_TYPE_QCA6390 ||
  3192. target_type == TARGET_TYPE_QCN6122 ||
  3193. target_type == TARGET_TYPE_QCA6490 ||
  3194. target_type == TARGET_TYPE_QCN9000 ||
  3195. target_type == TARGET_TYPE_QCA6750 ||
  3196. target_type == TARGET_TYPE_QCN9224 ||
  3197. target_type == TARGET_TYPE_KIWI ||
  3198. target_type == TARGET_TYPE_MANGO)
  3199. spectral->direct_dma_support = true;
  3200. target_if_spectral_report_params_init(&spectral->rparams,
  3201. target_type);
  3202. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  3203. &spectral->rparams,
  3204. target_type);
  3205. if ((target_type == TARGET_TYPE_QCA8074) ||
  3206. (target_type == TARGET_TYPE_QCA8074V2) ||
  3207. (target_type == TARGET_TYPE_QCA9574) ||
  3208. (target_type == TARGET_TYPE_QCA6018) ||
  3209. (target_type == TARGET_TYPE_QCA5018) ||
  3210. (target_type == TARGET_TYPE_QCN6122) ||
  3211. (target_type == TARGET_TYPE_QCN9000) ||
  3212. (target_type == TARGET_TYPE_QCA6290) ||
  3213. (target_type == TARGET_TYPE_QCA6390) ||
  3214. (target_type == TARGET_TYPE_QCA6490) ||
  3215. (target_type == TARGET_TYPE_QCN9224) ||
  3216. (target_type == TARGET_TYPE_QCA6750) ||
  3217. (target_type == TARGET_TYPE_KIWI) ||
  3218. (target_type == TARGET_TYPE_MANGO)) {
  3219. spectral->spectral_gen = SPECTRAL_GEN3;
  3220. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  3221. spectral->tag_sscan_summary_exp =
  3222. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  3223. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  3224. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  3225. } else {
  3226. spectral->spectral_gen = SPECTRAL_GEN2;
  3227. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  3228. spectral->tag_sscan_summary_exp =
  3229. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  3230. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  3231. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  3232. }
  3233. status = target_if_init_spectral_param_min_max(
  3234. spectral,
  3235. spectral->spectral_gen, target_type);
  3236. if (QDF_IS_STATUS_ERROR(status)) {
  3237. spectral_err("Failed to initialize parameter min max values");
  3238. goto fail;
  3239. }
  3240. target_if_init_spectral_param_properties(spectral);
  3241. /* Init spectral capability */
  3242. if (target_if_init_spectral_capability(spectral, target_type) !=
  3243. QDF_STATUS_SUCCESS) {
  3244. qdf_mem_free(spectral);
  3245. return NULL;
  3246. }
  3247. if (target_if_spectral_attach_simulation(spectral) < 0)
  3248. return NULL;
  3249. target_if_init_spectral_ops(spectral);
  3250. target_if_spectral_timestamp_war_init(&spectral->timestamp_war);
  3251. /* Spectral mode specific init */
  3252. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  3253. spectral->params_valid[smode] = false;
  3254. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  3255. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  3256. }
  3257. target_if_spectral_register_funcs(spectral, &spectral_ops);
  3258. if (target_if_spectral_check_hw_capability(spectral) == false) {
  3259. goto fail;
  3260. } else {
  3261. /*
  3262. * TODO: Once the driver architecture transitions to chipset
  3263. * versioning based checks, reflect this here.
  3264. */
  3265. spectral->is_160_format = false;
  3266. spectral->is_lb_edge_extrabins_format = false;
  3267. spectral->is_rb_edge_extrabins_format = false;
  3268. if (target_type == TARGET_TYPE_QCA9984 ||
  3269. target_type == TARGET_TYPE_QCA9888) {
  3270. spectral->is_160_format = true;
  3271. spectral->is_lb_edge_extrabins_format = true;
  3272. spectral->is_rb_edge_extrabins_format = true;
  3273. } else if ((target_type == TARGET_TYPE_AR900B) &&
  3274. (target_revision == AR900B_REV_2)) {
  3275. spectral->is_rb_edge_extrabins_format = true;
  3276. }
  3277. if (target_type == TARGET_TYPE_QCA9984 ||
  3278. target_type == TARGET_TYPE_QCA9888)
  3279. spectral->is_sec80_rssi_war_required = true;
  3280. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  3281. if (spectral->spectral_gen == SPECTRAL_GEN3)
  3282. init_160mhz_delivery_state_machine(spectral);
  3283. }
  3284. qdf_spinlock_create(&spectral->detector_list_lock);
  3285. qdf_spinlock_create(&spectral->session_report_info_lock);
  3286. qdf_spinlock_create(&spectral->session_det_map_lock);
  3287. return spectral;
  3288. fail:
  3289. target_if_spectral_detach(spectral);
  3290. return NULL;
  3291. }
  3292. /**
  3293. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  3294. * functionality for the given pdev
  3295. * @pdev: Pointer to pdev object
  3296. *
  3297. * Function to de-initialize pointer to spectral target_if internal private data
  3298. *
  3299. * Return: None
  3300. */
  3301. void
  3302. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  3303. {
  3304. struct target_if_spectral *spectral = NULL;
  3305. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3306. if (!spectral) {
  3307. spectral_err("SPECTRAL : Module doesn't exist");
  3308. return;
  3309. }
  3310. target_if_spectral_detach(spectral);
  3311. return;
  3312. }
  3313. /**
  3314. * target_if_psoc_spectral_deinit() - De-initialize target_if Spectral
  3315. * functionality for the given psoc
  3316. * @psoc: Pointer to psoc object
  3317. *
  3318. * Function to de-initialize pointer to psoc spectral target_if internal
  3319. * private data
  3320. *
  3321. * Return: None
  3322. */
  3323. static void
  3324. target_if_psoc_spectral_deinit(struct wlan_objmgr_psoc *psoc)
  3325. {
  3326. struct target_if_psoc_spectral *psoc_spectral;
  3327. if (!psoc) {
  3328. spectral_err("psoc is null");
  3329. return;
  3330. }
  3331. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  3332. if (!psoc_spectral) {
  3333. spectral_err("Spectral target_if psoc object is null");
  3334. return;
  3335. }
  3336. qdf_mem_free(psoc_spectral);
  3337. }
  3338. /**
  3339. * target_if_psoc_spectral_init() - Initialize target_if Spectral
  3340. * functionality for the given psoc
  3341. * @psoc: Pointer to psoc object
  3342. *
  3343. * Function to initialize pointer to psoc spectral target_if internal
  3344. * private data
  3345. *
  3346. * Return: On success, pointer to Spectral psoc target_if internal
  3347. * private data, on failure, NULL
  3348. */
  3349. static void *
  3350. target_if_psoc_spectral_init(struct wlan_objmgr_psoc *psoc)
  3351. {
  3352. struct target_if_psoc_spectral *psoc_spectral = NULL;
  3353. if (!psoc) {
  3354. spectral_err("psoc is null");
  3355. goto fail;
  3356. }
  3357. psoc_spectral = (struct target_if_psoc_spectral *)qdf_mem_malloc(
  3358. sizeof(struct target_if_psoc_spectral));
  3359. if (!psoc_spectral) {
  3360. spectral_err("Spectral lmac psoc object allocation failed");
  3361. goto fail;
  3362. }
  3363. psoc_spectral->psoc_obj = psoc;
  3364. return psoc_spectral;
  3365. fail:
  3366. if (psoc_spectral)
  3367. target_if_psoc_spectral_deinit(psoc);
  3368. return psoc_spectral;
  3369. }
  3370. /**
  3371. * target_if_calculate_center_freq() - Helper routine to
  3372. * check whether given frequency is center frequency of a
  3373. * WLAN channel
  3374. *
  3375. * @spectral: Pointer to Spectral object
  3376. * @chan_freq: Center frequency of a WLAN channel
  3377. * @is_valid: Indicates whether given frequency is valid
  3378. *
  3379. * Return: QDF_STATUS
  3380. */
  3381. static QDF_STATUS
  3382. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  3383. uint32_t chan_freq,
  3384. bool *is_valid)
  3385. {
  3386. struct regulatory_channel *cur_chan_list;
  3387. int i;
  3388. if (!pdev) {
  3389. spectral_err("pdev object is null");
  3390. return QDF_STATUS_E_FAILURE;
  3391. }
  3392. if (!is_valid) {
  3393. spectral_err("is valid argument is null");
  3394. return QDF_STATUS_E_FAILURE;
  3395. }
  3396. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  3397. if (!cur_chan_list)
  3398. return QDF_STATUS_E_FAILURE;
  3399. if (wlan_reg_get_current_chan_list(
  3400. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  3401. spectral_err("Failed to get cur_chan list");
  3402. qdf_mem_free(cur_chan_list);
  3403. return QDF_STATUS_E_FAILURE;
  3404. }
  3405. *is_valid = false;
  3406. for (i = 0; i < NUM_CHANNELS; i++) {
  3407. uint32_t flags;
  3408. uint32_t center_freq;
  3409. flags = cur_chan_list[i].chan_flags;
  3410. center_freq = cur_chan_list[i].center_freq;
  3411. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  3412. (center_freq == chan_freq)) {
  3413. *is_valid = true;
  3414. break;
  3415. }
  3416. }
  3417. qdf_mem_free(cur_chan_list);
  3418. return QDF_STATUS_SUCCESS;
  3419. }
  3420. /**
  3421. * target_if_calculate_center_freq() - Helper routine to
  3422. * find the center frequency of the agile span from a
  3423. * WLAN channel center frequency
  3424. *
  3425. * @spectral: Pointer to Spectral object
  3426. * @ch_width: Channel width array
  3427. * @chan_freq: Center frequency of a WLAN channel
  3428. * @center_freq: Pointer to center frequency
  3429. *
  3430. * Return: QDF_STATUS
  3431. */
  3432. static QDF_STATUS
  3433. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  3434. enum phy_ch_width *ch_width,
  3435. uint16_t chan_freq,
  3436. uint16_t *center_freq)
  3437. {
  3438. enum phy_ch_width agile_ch_width;
  3439. if (!spectral) {
  3440. spectral_err("spectral target if object is null");
  3441. return QDF_STATUS_E_FAILURE;
  3442. }
  3443. if (!ch_width) {
  3444. spectral_err("Channel width array is null");
  3445. return QDF_STATUS_E_INVAL;
  3446. }
  3447. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3448. if (!center_freq) {
  3449. spectral_err("center_freq argument is null");
  3450. return QDF_STATUS_E_FAILURE;
  3451. }
  3452. if (agile_ch_width == CH_WIDTH_20MHZ) {
  3453. *center_freq = chan_freq;
  3454. } else {
  3455. uint16_t start_freq;
  3456. uint16_t end_freq;
  3457. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3458. enum channel_state state;
  3459. state = wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3460. (spectral->pdev_obj, chan_freq, agile_ch_width,
  3461. &bonded_chan_ptr, REG_CURRENT_PWR_MODE);
  3462. if (state == CHANNEL_STATE_DISABLE ||
  3463. state == CHANNEL_STATE_INVALID) {
  3464. spectral_err("Channel state is disable or invalid");
  3465. return QDF_STATUS_E_FAILURE;
  3466. }
  3467. if (!bonded_chan_ptr) {
  3468. spectral_err("Bonded channel is not found");
  3469. return QDF_STATUS_E_FAILURE;
  3470. }
  3471. start_freq = bonded_chan_ptr->start_freq;
  3472. end_freq = bonded_chan_ptr->end_freq;
  3473. *center_freq = (start_freq + end_freq) >> 1;
  3474. }
  3475. return QDF_STATUS_SUCCESS;
  3476. }
  3477. /**
  3478. * target_if_validate_center_freq() - Helper routine to
  3479. * validate user provided agile center frequency
  3480. *
  3481. * @spectral: Pointer to Spectral object
  3482. * @ch_width: Channel width array
  3483. * @center_freq: User provided agile span center frequency
  3484. * @is_valid: Indicates whether agile span center frequency is valid
  3485. *
  3486. * Return: QDF_STATUS
  3487. */
  3488. static QDF_STATUS
  3489. target_if_validate_center_freq(struct target_if_spectral *spectral,
  3490. enum phy_ch_width *ch_width,
  3491. uint16_t center_freq,
  3492. bool *is_valid)
  3493. {
  3494. enum phy_ch_width agile_ch_width;
  3495. struct wlan_objmgr_pdev *pdev;
  3496. QDF_STATUS status;
  3497. if (!spectral) {
  3498. spectral_err("spectral target if object is null");
  3499. return QDF_STATUS_E_FAILURE;
  3500. }
  3501. if (!ch_width) {
  3502. spectral_err("channel width array is null");
  3503. return QDF_STATUS_E_INVAL;
  3504. }
  3505. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3506. if (!is_valid) {
  3507. spectral_err("is_valid argument is null");
  3508. return QDF_STATUS_E_FAILURE;
  3509. }
  3510. pdev = spectral->pdev_obj;
  3511. if (agile_ch_width == CH_WIDTH_20MHZ) {
  3512. status = target_if_is_center_freq_of_any_chan
  3513. (pdev, center_freq, is_valid);
  3514. if (QDF_IS_STATUS_ERROR(status))
  3515. return QDF_STATUS_E_FAILURE;
  3516. } else {
  3517. uint16_t start_freq;
  3518. uint16_t end_freq;
  3519. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3520. bool is_chan;
  3521. status = target_if_is_center_freq_of_any_chan
  3522. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  3523. &is_chan);
  3524. if (QDF_IS_STATUS_ERROR(status))
  3525. return QDF_STATUS_E_FAILURE;
  3526. if (is_chan) {
  3527. uint32_t calulated_center_freq;
  3528. enum channel_state st;
  3529. st =
  3530. wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3531. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  3532. agile_ch_width,
  3533. &bonded_chan_ptr,
  3534. REG_CURRENT_PWR_MODE);
  3535. if (st == CHANNEL_STATE_DISABLE ||
  3536. st == CHANNEL_STATE_INVALID) {
  3537. spectral_err("Channel state disable/invalid");
  3538. return QDF_STATUS_E_FAILURE;
  3539. }
  3540. if (!bonded_chan_ptr) {
  3541. spectral_err("Bonded channel is not found");
  3542. return QDF_STATUS_E_FAILURE;
  3543. }
  3544. start_freq = bonded_chan_ptr->start_freq;
  3545. end_freq = bonded_chan_ptr->end_freq;
  3546. calulated_center_freq = (start_freq + end_freq) >> 1;
  3547. *is_valid = (center_freq == calulated_center_freq);
  3548. } else {
  3549. *is_valid = false;
  3550. }
  3551. }
  3552. return QDF_STATUS_SUCCESS;
  3553. }
  3554. /**
  3555. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  3556. * check whether agile span overlaps with current operating band.
  3557. *
  3558. * @spectral: Pointer to Spectral object
  3559. * @ch_width: Channel width array
  3560. * @center_freq: Agile span center frequency
  3561. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  3562. *
  3563. * Helper routine to check whether agile span overlaps with current
  3564. * operating band.
  3565. *
  3566. * Return: QDF_STATUS
  3567. */
  3568. static QDF_STATUS
  3569. target_if_is_agile_span_overlap_with_operating_span
  3570. (struct target_if_spectral *spectral,
  3571. enum phy_ch_width *ch_width,
  3572. struct spectral_config_frequency *center_freq,
  3573. bool *is_overlapping)
  3574. {
  3575. enum phy_ch_width op_ch_width;
  3576. enum phy_ch_width agile_ch_width;
  3577. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  3578. struct wlan_objmgr_vdev *vdev;
  3579. struct wlan_objmgr_pdev *pdev;
  3580. int16_t chan_freq;
  3581. uint32_t op_start_freq;
  3582. uint32_t op_end_freq;
  3583. uint32_t agile_start_freq;
  3584. uint32_t agile_end_freq;
  3585. uint32_t cfreq2;
  3586. if (!spectral) {
  3587. spectral_err("Spectral object is NULL");
  3588. return QDF_STATUS_E_FAILURE;
  3589. }
  3590. pdev = spectral->pdev_obj;
  3591. if (!pdev) {
  3592. spectral_err("pdev object is NULL");
  3593. return QDF_STATUS_E_FAILURE;
  3594. }
  3595. if (!ch_width) {
  3596. spectral_err("channel width array is null");
  3597. return QDF_STATUS_E_FAILURE;
  3598. }
  3599. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  3600. if (op_ch_width == CH_WIDTH_INVALID) {
  3601. spectral_err("Invalid channel width");
  3602. return QDF_STATUS_E_INVAL;
  3603. }
  3604. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3605. if (agile_ch_width == CH_WIDTH_INVALID) {
  3606. spectral_err("Invalid channel width");
  3607. return QDF_STATUS_E_INVAL;
  3608. }
  3609. if (!is_overlapping) {
  3610. spectral_err("Argument(is_overlapping) is NULL");
  3611. return QDF_STATUS_E_FAILURE;
  3612. }
  3613. *is_overlapping = false;
  3614. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  3615. if (!vdev) {
  3616. spectral_err("vdev is NULL");
  3617. return QDF_STATUS_E_FAILURE;
  3618. }
  3619. chan_freq = target_if_vdev_get_chan_freq(vdev);
  3620. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  3621. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3622. if (cfreq2 < 0) {
  3623. spectral_err("cfreq2 is invalid");
  3624. return QDF_STATUS_E_FAILURE;
  3625. }
  3626. if (op_ch_width == CH_WIDTH_20MHZ) {
  3627. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  3628. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  3629. } else {
  3630. enum channel_state state;
  3631. state = wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  3632. (pdev, chan_freq, op_ch_width, &bonded_chan_ptr,
  3633. REG_CURRENT_PWR_MODE);
  3634. if (state == CHANNEL_STATE_DISABLE ||
  3635. state == CHANNEL_STATE_INVALID) {
  3636. spectral_err("Channel state is disable or invalid");
  3637. return QDF_STATUS_E_FAILURE;
  3638. }
  3639. if (!bonded_chan_ptr) {
  3640. spectral_err("Bonded channel is not found");
  3641. return QDF_STATUS_E_FAILURE;
  3642. }
  3643. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  3644. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  3645. }
  3646. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3647. agile_start_freq = center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3648. agile_end_freq = center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3649. if (agile_end_freq > op_start_freq &&
  3650. op_end_freq > agile_start_freq)
  3651. *is_overlapping = true;
  3652. agile_start_freq = center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3653. agile_end_freq = center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3654. if (agile_end_freq > op_start_freq &&
  3655. op_end_freq > agile_start_freq)
  3656. *is_overlapping = true;
  3657. } else {
  3658. agile_start_freq = center_freq->cfreq1 -
  3659. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3660. agile_end_freq = center_freq->cfreq1 +
  3661. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3662. if (agile_end_freq > op_start_freq &&
  3663. op_end_freq > agile_start_freq)
  3664. *is_overlapping = true;
  3665. }
  3666. if (op_ch_width == CH_WIDTH_80P80MHZ) {
  3667. uint32_t sec80_start_feq;
  3668. uint32_t sec80_end_freq;
  3669. sec80_start_feq = cfreq2 - FREQ_OFFSET_40MHZ;
  3670. sec80_end_freq = cfreq2 + FREQ_OFFSET_40MHZ;
  3671. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  3672. agile_start_freq =
  3673. center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  3674. agile_end_freq =
  3675. center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  3676. if (agile_end_freq > sec80_start_feq &&
  3677. sec80_end_freq > agile_start_freq)
  3678. *is_overlapping = true;
  3679. agile_start_freq =
  3680. center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  3681. agile_end_freq =
  3682. center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  3683. if (agile_end_freq > sec80_start_feq &&
  3684. sec80_end_freq > agile_start_freq)
  3685. *is_overlapping = true;
  3686. } else {
  3687. agile_start_freq = center_freq->cfreq1 -
  3688. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3689. agile_end_freq = center_freq->cfreq1 +
  3690. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  3691. if (agile_end_freq > sec80_start_feq &&
  3692. sec80_end_freq > agile_start_freq)
  3693. *is_overlapping = true;
  3694. }
  3695. }
  3696. return QDF_STATUS_SUCCESS;
  3697. }
  3698. /**
  3699. * target_if_spectral_populate_chwidth() - Helper routine to
  3700. * populate channel width for different Spectral modes
  3701. *
  3702. * @spectral: Pointer to Spectral object
  3703. * @ch_width: Channel width array
  3704. * @is_80_80_agile: Indicates whether 80+80 agile scan is requested
  3705. *
  3706. * Helper routine to populate channel width for different Spectral modes
  3707. *
  3708. * Return: QDF_STATUS
  3709. */
  3710. static QDF_STATUS
  3711. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral,
  3712. enum phy_ch_width *ch_width,
  3713. bool is_80_80_agile)
  3714. {
  3715. enum spectral_scan_mode smode;
  3716. qdf_assert_always(spectral);
  3717. smode = SPECTRAL_SCAN_MODE_NORMAL;
  3718. for (; smode < SPECTRAL_SCAN_MODE_MAX; ++smode) {
  3719. /* If user has configured sscan bandwidth, use it */
  3720. if (spectral->sscan_width_configured[smode]) {
  3721. ch_width[smode] = spectral->params[smode].ss_bandwidth;
  3722. } else {
  3723. /* Otherwise, derive the default sscan bandwidth */
  3724. ch_width[smode] = get_default_sscan_bw(spectral, smode,
  3725. is_80_80_agile);
  3726. if (ch_width[smode] >= CH_WIDTH_INVALID) {
  3727. spectral_err("Invalid sscan BW %u",
  3728. ch_width[smode]);
  3729. return QDF_STATUS_E_FAILURE;
  3730. }
  3731. spectral->params[smode].ss_bandwidth = ch_width[smode];
  3732. }
  3733. }
  3734. return QDF_STATUS_SUCCESS;
  3735. }
  3736. /**
  3737. * target_if_spectral_is_valid_80p80_freq() - API to check whether given
  3738. * (cfreq1, cfreq2) pair forms a valid 80+80 combination
  3739. * @pdev: pointer to pdev
  3740. * @cfreq1: center frequency 1
  3741. * @cfreq2: center frequency 2
  3742. *
  3743. * API to check whether given (cfreq1, cfreq2) pair forms a valid 80+80
  3744. * combination
  3745. *
  3746. * Return: true or false
  3747. */
  3748. static bool
  3749. target_if_spectral_is_valid_80p80_freq(struct wlan_objmgr_pdev *pdev,
  3750. uint32_t cfreq1, uint32_t cfreq2)
  3751. {
  3752. struct ch_params ch_params = {0};
  3753. enum channel_state chan_state1;
  3754. enum channel_state chan_state2;
  3755. struct wlan_objmgr_psoc *psoc;
  3756. struct ch_params temp_params = {0};
  3757. qdf_assert_always(pdev);
  3758. psoc = wlan_pdev_get_psoc(pdev);
  3759. qdf_assert_always(psoc);
  3760. /* In restricted 80P80 MHz enabled, only one 80+80 MHz
  3761. * channel is supported with cfreq=5690 and cfreq=5775.
  3762. */
  3763. if (wlan_psoc_nif_fw_ext_cap_get(
  3764. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  3765. return CHAN_WITHIN_RESTRICTED_80P80(cfreq1, cfreq2);
  3766. ch_params.center_freq_seg1 = wlan_reg_freq_to_chan(pdev, cfreq2);
  3767. ch_params.mhz_freq_seg1 = cfreq2;
  3768. ch_params.ch_width = CH_WIDTH_80P80MHZ;
  3769. wlan_reg_set_channel_params_for_pwrmode(
  3770. pdev,
  3771. cfreq1 - FREQ_OFFSET_10MHZ,
  3772. 0,
  3773. &ch_params,
  3774. REG_CURRENT_PWR_MODE);
  3775. if (ch_params.ch_width != CH_WIDTH_80P80MHZ)
  3776. return false;
  3777. if (ch_params.mhz_freq_seg0 != cfreq1 ||
  3778. ch_params.mhz_freq_seg1 != cfreq2)
  3779. return false;
  3780. temp_params.ch_width = CH_WIDTH_80MHZ;
  3781. chan_state1 = wlan_reg_get_5g_bonded_channel_state_for_pwrmode(
  3782. pdev,
  3783. ch_params.mhz_freq_seg0 - FREQ_OFFSET_10MHZ,
  3784. &temp_params,
  3785. REG_CURRENT_PWR_MODE);
  3786. if ((chan_state1 == CHANNEL_STATE_DISABLE) ||
  3787. (chan_state1 == CHANNEL_STATE_INVALID))
  3788. return false;
  3789. temp_params.ch_width = CH_WIDTH_80MHZ;
  3790. chan_state2 = wlan_reg_get_5g_bonded_channel_state_for_pwrmode(
  3791. pdev,
  3792. ch_params.mhz_freq_seg1 - FREQ_OFFSET_10MHZ,
  3793. &temp_params,
  3794. REG_CURRENT_PWR_MODE);
  3795. if ((chan_state2 == CHANNEL_STATE_DISABLE) ||
  3796. (chan_state2 == CHANNEL_STATE_INVALID))
  3797. return false;
  3798. if (abs(ch_params.mhz_freq_seg0 - ch_params.mhz_freq_seg1) <=
  3799. FREQ_OFFSET_80MHZ)
  3800. return false;
  3801. return true;
  3802. }
  3803. /**
  3804. * _target_if_set_spectral_config() - Set spectral config
  3805. * @spectral: Pointer to spectral object
  3806. * @param: Spectral parameter id and value
  3807. * @smode: Spectral scan mode
  3808. * @err: Spectral error code
  3809. *
  3810. * API to set spectral configurations
  3811. *
  3812. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3813. */
  3814. static QDF_STATUS
  3815. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  3816. const struct spectral_cp_param *param,
  3817. const enum spectral_scan_mode smode,
  3818. enum spectral_cp_error_code *err)
  3819. {
  3820. struct spectral_config params;
  3821. struct target_if_spectral_ops *p_sops;
  3822. struct spectral_config *sparams;
  3823. QDF_STATUS status;
  3824. bool is_overlapping;
  3825. uint16_t agile_cfreq;
  3826. bool is_valid_chan;
  3827. struct spectral_param_min_max *param_min_max;
  3828. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  3829. enum spectral_scan_mode m;
  3830. struct spectral_config_frequency center_freq = {0};
  3831. bool is_bw_supported;
  3832. struct wlan_objmgr_vdev *vdev;
  3833. enum phy_ch_width op_bw;
  3834. if (!err) {
  3835. spectral_err("Error code argument is null");
  3836. QDF_ASSERT(0);
  3837. return QDF_STATUS_E_FAILURE;
  3838. }
  3839. *err = SPECTRAL_SCAN_ERR_INVALID;
  3840. if (!param) {
  3841. spectral_err("Parameter object is null");
  3842. return QDF_STATUS_E_FAILURE;
  3843. }
  3844. if (!spectral) {
  3845. spectral_err("spectral object is NULL");
  3846. return QDF_STATUS_E_FAILURE;
  3847. }
  3848. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3849. param_min_max = &spectral->param_min_max;
  3850. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3851. spectral_err("Invalid Spectral mode %u", smode);
  3852. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3853. return QDF_STATUS_E_FAILURE;
  3854. }
  3855. sparams = &spectral->params[smode];
  3856. m = SPECTRAL_SCAN_MODE_NORMAL;
  3857. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  3858. ch_width[m] = CH_WIDTH_INVALID;
  3859. if (!spectral->params_valid[smode]) {
  3860. target_if_spectral_info_read(spectral,
  3861. smode,
  3862. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3863. &spectral->params[smode],
  3864. sizeof(spectral->params[smode]));
  3865. spectral->params_valid[smode] = true;
  3866. }
  3867. switch (param->id) {
  3868. case SPECTRAL_PARAM_FFT_PERIOD:
  3869. sparams->ss_fft_period = param->value;
  3870. break;
  3871. case SPECTRAL_PARAM_SCAN_PERIOD:
  3872. sparams->ss_period = param->value;
  3873. if (sparams->ss_recapture && ((sparams->ss_period <
  3874. SPECTRAL_RECAPTURE_SCAN_PERIOD_THRESHOLD) ||
  3875. (smode == SPECTRAL_SCAN_MODE_AGILE))) {
  3876. sparams->ss_recapture = false;
  3877. spectral_err("FFT recapture cannot be enabled due to scan period: %d us or spectral scan mode: %d",
  3878. sparams->ss_period, smode);
  3879. }
  3880. break;
  3881. case SPECTRAL_PARAM_FFT_RECAPTURE:
  3882. if (param->value) {
  3883. if (sparams->ss_period >=
  3884. SPECTRAL_RECAPTURE_SCAN_PERIOD_THRESHOLD &&
  3885. smode == SPECTRAL_SCAN_MODE_NORMAL) {
  3886. sparams->ss_recapture = true;
  3887. } else {
  3888. spectral_err("FFT recapture cannot be enabled due to scan period: %d us or spectral scan mode: %d",
  3889. sparams->ss_period, smode);
  3890. sparams->ss_recapture = false;
  3891. }
  3892. } else {
  3893. sparams->ss_recapture = false;
  3894. }
  3895. break;
  3896. case SPECTRAL_PARAM_SCAN_COUNT:
  3897. sparams->ss_count = param->value;
  3898. break;
  3899. case SPECTRAL_PARAM_SHORT_REPORT:
  3900. sparams->ss_short_report = (!!param->value) ? true : false;
  3901. break;
  3902. case SPECTRAL_PARAM_SPECT_PRI:
  3903. sparams->ss_spectral_pri = (!!param->value) ? true : false;
  3904. break;
  3905. case SPECTRAL_PARAM_FFT_SIZE:
  3906. status = target_if_spectral_populate_chwidth
  3907. (spectral, ch_width, spectral->params
  3908. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  3909. if (QDF_IS_STATUS_ERROR(status))
  3910. return QDF_STATUS_E_FAILURE;
  3911. if ((param->value < param_min_max->fft_size_min) ||
  3912. (param->value > param_min_max->fft_size_max
  3913. [ch_width[smode]])) {
  3914. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3915. return QDF_STATUS_E_FAILURE;
  3916. }
  3917. sparams->ss_fft_size = param->value;
  3918. break;
  3919. case SPECTRAL_PARAM_GC_ENA:
  3920. sparams->ss_gc_ena = !!param->value;
  3921. break;
  3922. case SPECTRAL_PARAM_RESTART_ENA:
  3923. sparams->ss_restart_ena = !!param->value;
  3924. break;
  3925. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  3926. sparams->ss_noise_floor_ref = param->value;
  3927. break;
  3928. case SPECTRAL_PARAM_INIT_DELAY:
  3929. sparams->ss_init_delay = param->value;
  3930. break;
  3931. case SPECTRAL_PARAM_NB_TONE_THR:
  3932. sparams->ss_nb_tone_thr = param->value;
  3933. break;
  3934. case SPECTRAL_PARAM_STR_BIN_THR:
  3935. sparams->ss_str_bin_thr = param->value;
  3936. break;
  3937. case SPECTRAL_PARAM_WB_RPT_MODE:
  3938. sparams->ss_wb_rpt_mode = !!param->value;
  3939. break;
  3940. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  3941. sparams->ss_rssi_rpt_mode = !!param->value;
  3942. break;
  3943. case SPECTRAL_PARAM_RSSI_THR:
  3944. sparams->ss_rssi_thr = param->value;
  3945. break;
  3946. case SPECTRAL_PARAM_PWR_FORMAT:
  3947. sparams->ss_pwr_format = !!param->value;
  3948. break;
  3949. case SPECTRAL_PARAM_RPT_MODE:
  3950. if ((param->value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  3951. (param->value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  3952. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3953. return QDF_STATUS_E_FAILURE;
  3954. }
  3955. sparams->ss_rpt_mode = param->value;
  3956. break;
  3957. case SPECTRAL_PARAM_BIN_SCALE:
  3958. sparams->ss_bin_scale = param->value;
  3959. break;
  3960. case SPECTRAL_PARAM_DBM_ADJ:
  3961. sparams->ss_dbm_adj = !!param->value;
  3962. break;
  3963. case SPECTRAL_PARAM_CHN_MASK:
  3964. sparams->ss_chn_mask = param->value;
  3965. break;
  3966. case SPECTRAL_PARAM_FREQUENCY:
  3967. status = target_if_spectral_populate_chwidth(
  3968. spectral, ch_width, param->freq.cfreq2 > 0);
  3969. if (QDF_IS_STATUS_ERROR(status)) {
  3970. spectral_err("Failed to populate channel width");
  3971. return QDF_STATUS_E_FAILURE;
  3972. }
  3973. if (ch_width[smode] != CH_WIDTH_80P80MHZ &&
  3974. param->freq.cfreq2) {
  3975. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3976. spectral_err("Non zero cfreq2 expected for 80p80 only");
  3977. return QDF_STATUS_E_INVAL;
  3978. }
  3979. if (ch_width[smode] == CH_WIDTH_80P80MHZ &&
  3980. !param->freq.cfreq2) {
  3981. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3982. spectral_err("Non zero cfreq2 expected for 80p80");
  3983. return QDF_STATUS_E_INVAL;
  3984. }
  3985. status = target_if_is_center_freq_of_any_chan
  3986. (spectral->pdev_obj, param->freq.cfreq1,
  3987. &is_valid_chan);
  3988. if (QDF_IS_STATUS_ERROR(status))
  3989. return QDF_STATUS_E_FAILURE;
  3990. if (is_valid_chan) {
  3991. status = target_if_calculate_center_freq(
  3992. spectral, ch_width,
  3993. param->freq.cfreq1,
  3994. &agile_cfreq);
  3995. if (QDF_IS_STATUS_ERROR(status)) {
  3996. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3997. return QDF_STATUS_E_FAILURE;
  3998. }
  3999. } else {
  4000. bool is_valid_agile_cfreq;
  4001. status = target_if_validate_center_freq
  4002. (spectral, ch_width, param->freq.cfreq1,
  4003. &is_valid_agile_cfreq);
  4004. if (QDF_IS_STATUS_ERROR(status))
  4005. return QDF_STATUS_E_FAILURE;
  4006. if (!is_valid_agile_cfreq) {
  4007. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4008. spectral_err("Invalid agile center frequency");
  4009. return QDF_STATUS_E_FAILURE;
  4010. }
  4011. agile_cfreq = param->freq.cfreq1;
  4012. }
  4013. center_freq.cfreq1 = agile_cfreq;
  4014. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  4015. status = target_if_is_center_freq_of_any_chan
  4016. (spectral->pdev_obj, param->freq.cfreq2,
  4017. &is_valid_chan);
  4018. if (QDF_IS_STATUS_ERROR(status))
  4019. return QDF_STATUS_E_FAILURE;
  4020. if (is_valid_chan) {
  4021. status = target_if_calculate_center_freq(
  4022. spectral, ch_width,
  4023. param->freq.cfreq2,
  4024. &agile_cfreq);
  4025. if (QDF_IS_STATUS_ERROR(status)) {
  4026. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4027. return QDF_STATUS_E_FAILURE;
  4028. }
  4029. } else {
  4030. bool is_valid_agile_cfreq;
  4031. status = target_if_validate_center_freq
  4032. (spectral, ch_width, param->freq.cfreq2,
  4033. &is_valid_agile_cfreq);
  4034. if (QDF_IS_STATUS_ERROR(status))
  4035. return QDF_STATUS_E_FAILURE;
  4036. if (!is_valid_agile_cfreq) {
  4037. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4038. spectral_err("Invalid agile center frequency");
  4039. return QDF_STATUS_E_FAILURE;
  4040. }
  4041. agile_cfreq = param->freq.cfreq2;
  4042. }
  4043. center_freq.cfreq2 = agile_cfreq;
  4044. }
  4045. status = target_if_is_agile_span_overlap_with_operating_span
  4046. (spectral, ch_width,
  4047. &center_freq, &is_overlapping);
  4048. if (QDF_IS_STATUS_ERROR(status))
  4049. return QDF_STATUS_E_FAILURE;
  4050. if (is_overlapping) {
  4051. spectral_err("Agile freq %u, %u overlaps with operating span",
  4052. center_freq.cfreq1, center_freq.cfreq2);
  4053. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4054. return QDF_STATUS_E_FAILURE;
  4055. }
  4056. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  4057. bool is_valid_80p80;
  4058. is_valid_80p80 = target_if_spectral_is_valid_80p80_freq(
  4059. spectral->pdev_obj,
  4060. center_freq.cfreq1,
  4061. center_freq.cfreq2);
  4062. if (!is_valid_80p80) {
  4063. spectral_err("Agile freq %u, %u is invalid 80+80 combination",
  4064. center_freq.cfreq1,
  4065. center_freq.cfreq2);
  4066. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4067. return QDF_STATUS_E_FAILURE;
  4068. }
  4069. }
  4070. sparams->ss_frequency.cfreq1 = center_freq.cfreq1;
  4071. sparams->ss_frequency.cfreq2 = center_freq.cfreq2;
  4072. break;
  4073. case SPECTRAL_PARAM_CHAN_WIDTH:
  4074. if (param->value >= CH_WIDTH_INVALID) {
  4075. spectral_err("invalid sscan width: %u", param->value);
  4076. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4077. return QDF_STATUS_E_FAILURE;
  4078. }
  4079. vdev = target_if_spectral_get_vdev(spectral, smode);
  4080. if (!vdev) {
  4081. spectral_err("vdev is null");
  4082. return QDF_STATUS_E_NULL_VALUE;
  4083. }
  4084. op_bw = target_if_vdev_get_ch_width(vdev);
  4085. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4086. /* Validate the bandwidth */
  4087. status = target_if_is_sscan_bw_supported(
  4088. spectral, smode,
  4089. param->value, op_bw, &is_bw_supported,
  4090. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  4091. ss_frequency.cfreq2 > 0);
  4092. if (QDF_IS_STATUS_ERROR(status)) {
  4093. spectral_err("Unable to check if given sscan_bw is supported");
  4094. return QDF_STATUS_E_FAILURE;
  4095. }
  4096. if (!is_bw_supported) {
  4097. spectral_err("sscan bw(%u) is not supported for the current operating width(%u) and sscan mode(%u)",
  4098. param->value, op_bw, smode);
  4099. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  4100. return QDF_STATUS_E_FAILURE;
  4101. }
  4102. sparams->ss_bandwidth = param->value;
  4103. spectral->sscan_width_configured[smode] = true;
  4104. break;
  4105. }
  4106. p_sops->configure_spectral(spectral, sparams, smode);
  4107. /* only to validate the writes */
  4108. p_sops->get_spectral_config(spectral, &params, smode);
  4109. return QDF_STATUS_SUCCESS;
  4110. }
  4111. QDF_STATUS
  4112. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  4113. const struct spectral_cp_param *param,
  4114. const enum spectral_scan_mode smode,
  4115. enum spectral_cp_error_code *err)
  4116. {
  4117. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  4118. struct target_if_spectral *spectral;
  4119. QDF_STATUS status;
  4120. if (!err) {
  4121. spectral_err("Error code argument is null");
  4122. QDF_ASSERT(0);
  4123. return QDF_STATUS_E_FAILURE;
  4124. }
  4125. *err = SPECTRAL_SCAN_ERR_INVALID;
  4126. if (!pdev) {
  4127. spectral_err("pdev object is NULL");
  4128. return QDF_STATUS_E_FAILURE;
  4129. }
  4130. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4131. if (!spectral) {
  4132. spectral_err("spectral object is NULL");
  4133. return QDF_STATUS_E_FAILURE;
  4134. }
  4135. if (!param) {
  4136. spectral_err("parameter object is NULL");
  4137. return QDF_STATUS_E_FAILURE;
  4138. }
  4139. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4140. spectral_err("Invalid Spectral mode %u", smode);
  4141. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  4142. return QDF_STATUS_E_FAILURE;
  4143. }
  4144. if (!spectral->properties[smode][param->id].supported) {
  4145. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  4146. param->id, smode);
  4147. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  4148. return QDF_STATUS_E_FAILURE;
  4149. }
  4150. if (spectral->properties[smode][param->id].common_all_modes) {
  4151. spectral_warn("Setting Spectral parameter %u for all modes",
  4152. param->id);
  4153. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  4154. status = _target_if_set_spectral_config
  4155. (spectral, param, mode, err);
  4156. if (QDF_IS_STATUS_ERROR(status))
  4157. return QDF_STATUS_E_FAILURE;
  4158. }
  4159. return QDF_STATUS_SUCCESS;
  4160. }
  4161. return _target_if_set_spectral_config(spectral, param, smode, err);
  4162. }
  4163. /**
  4164. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  4165. * @fft_len: FFT length
  4166. * @pdev: Pointer to pdev object
  4167. *
  4168. * API to get fft bin count for a given fft length
  4169. *
  4170. * Return: FFt bin count
  4171. */
  4172. static int
  4173. target_if_get_fft_bin_count(int fft_len)
  4174. {
  4175. int bin_count = 0;
  4176. switch (fft_len) {
  4177. case 5:
  4178. bin_count = 16;
  4179. break;
  4180. case 6:
  4181. bin_count = 32;
  4182. break;
  4183. case 7:
  4184. bin_count = 64;
  4185. break;
  4186. case 8:
  4187. bin_count = 128;
  4188. break;
  4189. case 9:
  4190. bin_count = 256;
  4191. break;
  4192. default:
  4193. break;
  4194. }
  4195. return bin_count;
  4196. }
  4197. /**
  4198. * target_if_init_upper_lower_flags() - Initializes control and extension
  4199. * segment flags
  4200. * @spectral: pointer to target if spectral object
  4201. * @smode: Spectral scan mode
  4202. *
  4203. * API to initialize the control and extension flags with the lower/upper
  4204. * segment based on the HT mode
  4205. *
  4206. * Return: FFt bin count
  4207. */
  4208. static void
  4209. target_if_init_upper_lower_flags(struct target_if_spectral *spectral,
  4210. enum spectral_scan_mode smode)
  4211. {
  4212. int current_channel = 0;
  4213. int ext_channel = 0;
  4214. struct target_if_spectral_ops *p_sops =
  4215. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4216. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4217. spectral_err("Invalid Spectral mode %u", smode);
  4218. return;
  4219. }
  4220. current_channel = p_sops->get_current_channel(spectral, smode);
  4221. ext_channel = p_sops->get_extension_channel(spectral, smode);
  4222. if ((current_channel == 0) || (ext_channel == 0))
  4223. return;
  4224. if (spectral->sc_spectral_20_40_mode) {
  4225. /* HT40 mode */
  4226. if (ext_channel < current_channel) {
  4227. spectral->lower_is_extension = 1;
  4228. spectral->upper_is_control = 1;
  4229. spectral->lower_is_control = 0;
  4230. spectral->upper_is_extension = 0;
  4231. } else {
  4232. spectral->lower_is_extension = 0;
  4233. spectral->upper_is_control = 0;
  4234. spectral->lower_is_control = 1;
  4235. spectral->upper_is_extension = 1;
  4236. }
  4237. } else {
  4238. /* HT20 mode, lower is always control */
  4239. spectral->lower_is_extension = 0;
  4240. spectral->upper_is_control = 0;
  4241. spectral->lower_is_control = 1;
  4242. spectral->upper_is_extension = 0;
  4243. }
  4244. }
  4245. /**
  4246. * target_if_get_spectral_config() - Get spectral configuration
  4247. * @pdev: Pointer to pdev object
  4248. * @param: Pointer to spectral_config structure in which the configuration
  4249. * should be returned
  4250. * @smode: Spectral scan mode
  4251. *
  4252. * API to get the current spectral configuration
  4253. *
  4254. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4255. */
  4256. QDF_STATUS
  4257. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  4258. struct spectral_config *param,
  4259. enum spectral_scan_mode smode)
  4260. {
  4261. struct target_if_spectral_ops *p_sops = NULL;
  4262. struct target_if_spectral *spectral = NULL;
  4263. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4264. if (!spectral) {
  4265. spectral_err("SPECTRAL : Module doesn't exist");
  4266. return QDF_STATUS_E_FAILURE;
  4267. }
  4268. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4269. if (!p_sops) {
  4270. spectral_err("p_sops is null");
  4271. return QDF_STATUS_E_FAILURE;
  4272. }
  4273. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4274. spectral_err("Invalid Spectral mode %u", smode);
  4275. return QDF_STATUS_E_FAILURE;
  4276. }
  4277. qdf_mem_zero(param, sizeof(struct spectral_config));
  4278. p_sops->get_spectral_config(spectral, param, smode);
  4279. return QDF_STATUS_SUCCESS;
  4280. }
  4281. #ifdef WLAN_FEATURE_11BE
  4282. /**
  4283. * target_if_spectral_get_num_detectors_for_higher_bws() - Get number of
  4284. * Spectral detectors for higher bandwidths
  4285. * @spectral: Pointer to target if Spectral object
  4286. * @ch_width: channel width
  4287. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  4288. *
  4289. * API to get number of Spectral detectors used for scan in the given channel
  4290. * width.
  4291. *
  4292. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  4293. */
  4294. static QDF_STATUS
  4295. target_if_spectral_get_num_detectors_for_higher_bws(
  4296. struct target_if_spectral *spectral,
  4297. enum phy_ch_width ch_width,
  4298. uint32_t *num_detectors)
  4299. {
  4300. switch (ch_width) {
  4301. case CH_WIDTH_320MHZ:
  4302. *num_detectors = spectral->capability.num_detectors_320mhz;
  4303. break;
  4304. default:
  4305. spectral_err("Unsupported channel width %d", ch_width);
  4306. return QDF_STATUS_E_INVAL;
  4307. }
  4308. return QDF_STATUS_SUCCESS;
  4309. }
  4310. #else
  4311. static QDF_STATUS
  4312. target_if_spectral_get_num_detectors_for_higher_bws(
  4313. struct target_if_spectral *spectral,
  4314. enum phy_ch_width ch_width,
  4315. uint32_t *num_detectors)
  4316. {
  4317. spectral_err("Unsupported channel width %d", ch_width);
  4318. return QDF_STATUS_E_INVAL;
  4319. }
  4320. #endif
  4321. /**
  4322. * target_if_spectral_get_num_detectors() - Get number of Spectral detectors
  4323. * @spectral: Pointer to target if Spectral object
  4324. * @ch_width: channel width
  4325. * @num_detectors: Pointer to the variable to store number of Spectral detectors
  4326. *
  4327. * API to get number of Spectral detectors used for scan in the given channel
  4328. * width.
  4329. *
  4330. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL on failure
  4331. */
  4332. static QDF_STATUS
  4333. target_if_spectral_get_num_detectors(struct target_if_spectral *spectral,
  4334. enum phy_ch_width ch_width,
  4335. uint32_t *num_detectors)
  4336. {
  4337. if (!spectral) {
  4338. spectral_err("target if spectral object is null");
  4339. return QDF_STATUS_E_INVAL;
  4340. }
  4341. if (ch_width >= CH_WIDTH_INVALID) {
  4342. spectral_err("Invalid channel width %d", ch_width);
  4343. return QDF_STATUS_E_INVAL;
  4344. }
  4345. if (!num_detectors) {
  4346. spectral_err("Invalid argument, number of detectors");
  4347. return QDF_STATUS_E_INVAL;
  4348. }
  4349. switch (ch_width) {
  4350. case CH_WIDTH_20MHZ:
  4351. *num_detectors = spectral->capability.num_detectors_20mhz;
  4352. break;
  4353. case CH_WIDTH_40MHZ:
  4354. *num_detectors = spectral->capability.num_detectors_40mhz;
  4355. break;
  4356. case CH_WIDTH_80MHZ:
  4357. *num_detectors = spectral->capability.num_detectors_80mhz;
  4358. break;
  4359. case CH_WIDTH_160MHZ:
  4360. *num_detectors = spectral->capability.num_detectors_160mhz;
  4361. break;
  4362. case CH_WIDTH_80P80MHZ:
  4363. *num_detectors = spectral->capability.num_detectors_80p80mhz;
  4364. break;
  4365. default:
  4366. return target_if_spectral_get_num_detectors_for_higher_bws(
  4367. spectral, ch_width, num_detectors);
  4368. }
  4369. return QDF_STATUS_SUCCESS;
  4370. }
  4371. /**
  4372. * target_if_spectral_finite_scan_init() - Initializations required for finite
  4373. * Spectral scan
  4374. * @spectral: Pointer to target of Spctral object
  4375. * @smode: Spectral scan mode
  4376. *
  4377. * This routine initializes the finite Spectral scan. Finite Spectral scan is
  4378. * triggered by configuring a non zero scan count.
  4379. *
  4380. * Return: QDF_STATUS_SUCCESS on success
  4381. */
  4382. static QDF_STATUS
  4383. target_if_spectral_finite_scan_init(struct target_if_spectral *spectral,
  4384. enum spectral_scan_mode smode)
  4385. {
  4386. struct target_if_finite_spectral_scan_params *finite_scan;
  4387. enum phy_ch_width ch_width;
  4388. uint32_t num_detectors;
  4389. QDF_STATUS status;
  4390. uint16_t sscan_count;
  4391. if (!spectral) {
  4392. spectral_err("target if spectral object is null");
  4393. return QDF_STATUS_E_INVAL;
  4394. }
  4395. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4396. spectral_err("Invalid Spectral mode");
  4397. return QDF_STATUS_E_INVAL;
  4398. }
  4399. ch_width = spectral->ch_width[smode];
  4400. status = target_if_spectral_get_num_detectors(spectral, ch_width,
  4401. &num_detectors);
  4402. if (QDF_IS_STATUS_ERROR(status)) {
  4403. spectral_err("Failed to get number of detectors");
  4404. return QDF_STATUS_E_FAILURE;
  4405. }
  4406. finite_scan = &spectral->finite_scan[smode];
  4407. sscan_count = spectral->params[smode].ss_count;
  4408. finite_scan->finite_spectral_scan = true;
  4409. finite_scan->num_reports_expected = num_detectors * sscan_count;
  4410. return QDF_STATUS_SUCCESS;
  4411. }
  4412. /**
  4413. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  4414. * parameters
  4415. * @spectral: Pointer to Spectral target_if internal private data
  4416. * @spectral_params: Pointer to Spectral parameters
  4417. * @smode: Spectral scan mode
  4418. * @err: Spectral error code
  4419. *
  4420. * Enable use of desired Spectral parameters by configuring them into HW, and
  4421. * starting Spectral scan
  4422. *
  4423. * Return: 0 on success, 1 on failure
  4424. */
  4425. int
  4426. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  4427. struct spectral_config *spectral_params,
  4428. enum spectral_scan_mode smode,
  4429. enum spectral_cp_error_code *err)
  4430. {
  4431. int extension_channel = 0;
  4432. int current_channel = 0;
  4433. struct target_if_spectral_ops *p_sops = NULL;
  4434. QDF_STATUS status;
  4435. struct wlan_objmgr_pdev *pdev;
  4436. struct wlan_objmgr_psoc *psoc;
  4437. if (!spectral) {
  4438. spectral_err("Spectral LMAC object is NULL");
  4439. return 1;
  4440. }
  4441. pdev = spectral->pdev_obj;
  4442. if (!pdev) {
  4443. spectral_err("pdev is null");
  4444. return QDF_STATUS_E_INVAL;
  4445. }
  4446. psoc = wlan_pdev_get_psoc(pdev);
  4447. if (!psoc) {
  4448. spectral_err("psoc is null");
  4449. return QDF_STATUS_E_INVAL;
  4450. }
  4451. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  4452. spectral_err("Invalid Spectral mode %u", smode);
  4453. return 1;
  4454. }
  4455. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4456. if (!p_sops) {
  4457. spectral_err("p_sops is NULL");
  4458. return 1;
  4459. }
  4460. spectral->sc_spectral_noise_pwr_cal =
  4461. spectral_params->ss_spectral_pri ? 1 : 0;
  4462. /* check if extension channel is present */
  4463. extension_channel = p_sops->get_extension_channel(spectral, smode);
  4464. current_channel = p_sops->get_current_channel(spectral, smode);
  4465. if (spectral->capability.advncd_spectral_cap) {
  4466. spectral->lb_edge_extrabins = 0;
  4467. spectral->rb_edge_extrabins = 0;
  4468. if (spectral->is_lb_edge_extrabins_format &&
  4469. spectral->params[smode].ss_rpt_mode == 2) {
  4470. spectral->lb_edge_extrabins = 4;
  4471. }
  4472. if (spectral->is_rb_edge_extrabins_format &&
  4473. spectral->params[smode].ss_rpt_mode == 2) {
  4474. spectral->rb_edge_extrabins = 4;
  4475. }
  4476. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  4477. spectral->sc_spectral_20_40_mode = 0;
  4478. spectral->spectral_numbins =
  4479. target_if_get_fft_bin_count(
  4480. spectral->params[smode].ss_fft_size);
  4481. spectral->spectral_fft_len =
  4482. target_if_get_fft_bin_count(
  4483. spectral->params[smode].ss_fft_size);
  4484. spectral->spectral_data_len =
  4485. target_if_get_fft_bin_count(
  4486. spectral->params[smode].ss_fft_size);
  4487. /*
  4488. * Initialize classifier params to be sent to user
  4489. * space classifier
  4490. */
  4491. spectral->classifier_params.lower_chan_in_mhz =
  4492. current_channel;
  4493. spectral->classifier_params.upper_chan_in_mhz = 0;
  4494. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  4495. /* TODO : Remove this variable */
  4496. spectral->sc_spectral_20_40_mode = 1;
  4497. spectral->spectral_numbins =
  4498. target_if_get_fft_bin_count(
  4499. spectral->params[smode].ss_fft_size);
  4500. spectral->spectral_fft_len =
  4501. target_if_get_fft_bin_count(
  4502. spectral->params[smode].ss_fft_size);
  4503. spectral->spectral_data_len =
  4504. target_if_get_fft_bin_count(
  4505. spectral->params[smode].ss_fft_size);
  4506. /*
  4507. * Initialize classifier params to be sent to user
  4508. * space classifier
  4509. */
  4510. if (extension_channel < current_channel) {
  4511. spectral->classifier_params.lower_chan_in_mhz =
  4512. extension_channel;
  4513. spectral->classifier_params.upper_chan_in_mhz =
  4514. current_channel;
  4515. } else {
  4516. spectral->classifier_params.lower_chan_in_mhz =
  4517. current_channel;
  4518. spectral->classifier_params.upper_chan_in_mhz =
  4519. extension_channel;
  4520. }
  4521. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  4522. /* Set the FFT Size */
  4523. /* TODO : Remove this variable */
  4524. spectral->sc_spectral_20_40_mode = 0;
  4525. spectral->spectral_numbins =
  4526. target_if_get_fft_bin_count(
  4527. spectral->params[smode].ss_fft_size);
  4528. spectral->spectral_fft_len =
  4529. target_if_get_fft_bin_count(
  4530. spectral->params[smode].ss_fft_size);
  4531. spectral->spectral_data_len =
  4532. target_if_get_fft_bin_count(
  4533. spectral->params[smode].ss_fft_size);
  4534. /*
  4535. * Initialize classifier params to be sent to user
  4536. * space classifier
  4537. */
  4538. spectral->classifier_params.lower_chan_in_mhz =
  4539. current_channel;
  4540. spectral->classifier_params.upper_chan_in_mhz = 0;
  4541. /*
  4542. * Initialize classifier params to be sent to user
  4543. * space classifier
  4544. */
  4545. if (extension_channel < current_channel) {
  4546. spectral->classifier_params.lower_chan_in_mhz =
  4547. extension_channel;
  4548. spectral->classifier_params.upper_chan_in_mhz =
  4549. current_channel;
  4550. } else {
  4551. spectral->classifier_params.lower_chan_in_mhz =
  4552. current_channel;
  4553. spectral->classifier_params.upper_chan_in_mhz =
  4554. extension_channel;
  4555. }
  4556. } else if (is_ch_width_160_or_80p80(
  4557. spectral->ch_width[smode])) {
  4558. /* Set the FFT Size */
  4559. /* The below applies to both 160 and 80+80 cases */
  4560. /* TODO : Remove this variable */
  4561. spectral->sc_spectral_20_40_mode = 0;
  4562. spectral->spectral_numbins =
  4563. target_if_get_fft_bin_count(
  4564. spectral->params[smode].ss_fft_size);
  4565. spectral->spectral_fft_len =
  4566. target_if_get_fft_bin_count(
  4567. spectral->params[smode].ss_fft_size);
  4568. spectral->spectral_data_len =
  4569. target_if_get_fft_bin_count(
  4570. spectral->params[smode].ss_fft_size);
  4571. /*
  4572. * Initialize classifier params to be sent to user
  4573. * space classifier
  4574. */
  4575. spectral->classifier_params.lower_chan_in_mhz =
  4576. current_channel;
  4577. spectral->classifier_params.upper_chan_in_mhz = 0;
  4578. /*
  4579. * Initialize classifier params to be sent to user
  4580. * space classifier
  4581. */
  4582. if (extension_channel < current_channel) {
  4583. spectral->classifier_params.lower_chan_in_mhz =
  4584. extension_channel;
  4585. spectral->classifier_params.upper_chan_in_mhz =
  4586. current_channel;
  4587. } else {
  4588. spectral->classifier_params.lower_chan_in_mhz =
  4589. current_channel;
  4590. spectral->classifier_params.upper_chan_in_mhz =
  4591. extension_channel;
  4592. }
  4593. }
  4594. if (spectral->spectral_numbins) {
  4595. spectral->spectral_numbins +=
  4596. spectral->lb_edge_extrabins;
  4597. spectral->spectral_numbins +=
  4598. spectral->rb_edge_extrabins;
  4599. }
  4600. if (spectral->spectral_fft_len) {
  4601. spectral->spectral_fft_len +=
  4602. spectral->lb_edge_extrabins;
  4603. spectral->spectral_fft_len +=
  4604. spectral->rb_edge_extrabins;
  4605. }
  4606. if (spectral->spectral_data_len) {
  4607. spectral->spectral_data_len +=
  4608. spectral->lb_edge_extrabins;
  4609. spectral->spectral_data_len +=
  4610. spectral->rb_edge_extrabins;
  4611. }
  4612. } else {
  4613. /*
  4614. * The decision to find 20/40 mode is found based on the
  4615. * presence of extension channel
  4616. * instead of channel width, as the channel width can
  4617. * dynamically change
  4618. */
  4619. if (extension_channel == 0) {
  4620. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  4621. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  4622. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  4623. spectral->spectral_data_len =
  4624. SPECTRAL_HT20_TOTAL_DATA_LEN;
  4625. /* only valid in 20-40 mode */
  4626. spectral->spectral_lower_max_index_offset = -1;
  4627. /* only valid in 20-40 mode */
  4628. spectral->spectral_upper_max_index_offset = -1;
  4629. spectral->spectral_max_index_offset =
  4630. spectral->spectral_fft_len + 2;
  4631. spectral->sc_spectral_20_40_mode = 0;
  4632. /*
  4633. * Initialize classifier params to be sent to user
  4634. * space classifier
  4635. */
  4636. spectral->classifier_params.lower_chan_in_mhz =
  4637. current_channel;
  4638. spectral->classifier_params.upper_chan_in_mhz = 0;
  4639. } else {
  4640. spectral->spectral_numbins =
  4641. SPECTRAL_HT40_TOTAL_NUM_BINS;
  4642. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  4643. spectral->spectral_data_len =
  4644. SPECTRAL_HT40_TOTAL_DATA_LEN;
  4645. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  4646. /* only valid in 20 mode */
  4647. spectral->spectral_max_index_offset = -1;
  4648. spectral->spectral_lower_max_index_offset =
  4649. spectral->spectral_fft_len + 2;
  4650. spectral->spectral_upper_max_index_offset =
  4651. spectral->spectral_fft_len + 5;
  4652. spectral->sc_spectral_20_40_mode = 1;
  4653. /*
  4654. * Initialize classifier params to be sent to user
  4655. * space classifier
  4656. */
  4657. if (extension_channel < current_channel) {
  4658. spectral->classifier_params.lower_chan_in_mhz =
  4659. extension_channel;
  4660. spectral->classifier_params.upper_chan_in_mhz =
  4661. current_channel;
  4662. } else {
  4663. spectral->classifier_params.lower_chan_in_mhz =
  4664. current_channel;
  4665. spectral->classifier_params.upper_chan_in_mhz =
  4666. extension_channel;
  4667. }
  4668. }
  4669. }
  4670. spectral->send_single_packet = 0;
  4671. spectral->classifier_params.spectral_20_40_mode =
  4672. spectral->sc_spectral_20_40_mode;
  4673. spectral->classifier_params.spectral_dc_index =
  4674. spectral->spectral_dc_index;
  4675. spectral->spectral_sent_msg = 0;
  4676. spectral->classify_scan = 0;
  4677. spectral->num_spectral_data = 0;
  4678. if (!p_sops->is_spectral_active(spectral, smode)) {
  4679. p_sops->configure_spectral(spectral, spectral_params, smode);
  4680. spectral->rparams.marker[smode].is_valid = false;
  4681. if (spectral->params[smode].ss_count) {
  4682. status = target_if_spectral_finite_scan_init(spectral,
  4683. smode);
  4684. if (QDF_IS_STATUS_ERROR(status)) {
  4685. spectral_err("Failed to init finite scan");
  4686. return 1;
  4687. }
  4688. }
  4689. p_sops->start_spectral_scan(spectral, smode, err);
  4690. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  4691. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  4692. }
  4693. /* get current spectral configuration */
  4694. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  4695. target_if_init_upper_lower_flags(spectral, smode);
  4696. return 0;
  4697. }
  4698. /**
  4699. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  4700. * Agile DFS
  4701. * @psoc: Pointer to psoc
  4702. * @object: Pointer to pdev
  4703. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  4704. *
  4705. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  4706. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  4707. *
  4708. * Return: void
  4709. */
  4710. static void
  4711. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  4712. void *object, void *arg)
  4713. {
  4714. bool *is_aspectral_prohibited = arg;
  4715. struct wlan_objmgr_pdev *cur_pdev = object;
  4716. bool is_agile_precac_enabled_cur_pdev = false;
  4717. bool is_agile_rcac_enabled_cur_pdev = false;
  4718. QDF_STATUS status;
  4719. qdf_assert_always(is_aspectral_prohibited);
  4720. if (*is_aspectral_prohibited)
  4721. return;
  4722. qdf_assert_always(psoc);
  4723. qdf_assert_always(cur_pdev);
  4724. status = ucfg_dfs_get_agile_precac_enable
  4725. (cur_pdev,
  4726. &is_agile_precac_enabled_cur_pdev);
  4727. if (QDF_IS_STATUS_ERROR(status)) {
  4728. spectral_err("Get agile precac failed, prohibiting aSpectral");
  4729. *is_aspectral_prohibited = true;
  4730. return;
  4731. }
  4732. status = ucfg_dfs_get_rcac_enable(cur_pdev,
  4733. &is_agile_rcac_enabled_cur_pdev);
  4734. if (QDF_IS_STATUS_ERROR(status)) {
  4735. spectral_err("Get agile RCAC failed, prohibiting aSpectral");
  4736. *is_aspectral_prohibited = true;
  4737. return;
  4738. }
  4739. if (is_agile_precac_enabled_cur_pdev) {
  4740. spectral_err("aDFS preCAC is in progress on one of the pdevs");
  4741. *is_aspectral_prohibited = true;
  4742. } else if (is_agile_rcac_enabled_cur_pdev) {
  4743. spectral_err("aDFS RCAC is in progress on one of the pdevs");
  4744. *is_aspectral_prohibited = true;
  4745. }
  4746. }
  4747. /**
  4748. * target_if_get_curr_band() - Get current operating band of pdev
  4749. *
  4750. * @pdev: pointer to pdev object
  4751. *
  4752. * API to get current operating band of a given pdev.
  4753. *
  4754. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  4755. */
  4756. static enum reg_wifi_band
  4757. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id)
  4758. {
  4759. struct wlan_objmgr_vdev *vdev;
  4760. int16_t chan_freq;
  4761. enum reg_wifi_band cur_band;
  4762. if (!pdev) {
  4763. spectral_err("pdev is NULL");
  4764. return REG_BAND_UNKNOWN;
  4765. }
  4766. if (vdev_id == WLAN_INVALID_VDEV_ID)
  4767. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  4768. else
  4769. vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, vdev_id,
  4770. WLAN_SPECTRAL_ID);
  4771. if (!vdev) {
  4772. spectral_debug("vdev is NULL");
  4773. return REG_BAND_UNKNOWN;
  4774. }
  4775. chan_freq = target_if_vdev_get_chan_freq(vdev);
  4776. cur_band = wlan_reg_freq_to_band(chan_freq);
  4777. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4778. return cur_band;
  4779. }
  4780. /**
  4781. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  4782. * any of the 5G pdevs
  4783. * @psoc: Pointer to psoc
  4784. * @object: Pointer to pdev
  4785. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  4786. * progress in any 5G pdevs
  4787. *
  4788. * Return: void
  4789. */
  4790. static void
  4791. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  4792. void *object, void *arg)
  4793. {
  4794. enum reg_wifi_band band;
  4795. bool *is_agile_scan_inprog_5g_pdev = arg;
  4796. struct target_if_spectral *spectral;
  4797. struct wlan_objmgr_pdev *cur_pdev = object;
  4798. struct target_if_spectral_ops *p_sops;
  4799. if (*is_agile_scan_inprog_5g_pdev)
  4800. return;
  4801. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  4802. if (!spectral) {
  4803. spectral_err("target if spectral handle is NULL");
  4804. return;
  4805. }
  4806. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4807. band = target_if_get_curr_band(
  4808. cur_pdev, spectral->vdev_id[SPECTRAL_SCAN_MODE_AGILE]);
  4809. if (band == REG_BAND_UNKNOWN) {
  4810. spectral_debug("Failed to get current band");
  4811. return;
  4812. }
  4813. if (band == REG_BAND_5G &&
  4814. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  4815. *is_agile_scan_inprog_5g_pdev = true;
  4816. }
  4817. /**
  4818. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  4819. * for current vdev rx chainmask.
  4820. *
  4821. * @spectral: Pointer to Spectral object
  4822. * @is_supported: Pointer to is_supported
  4823. *
  4824. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4825. */
  4826. static QDF_STATUS
  4827. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  4828. bool *is_supported)
  4829. {
  4830. struct wlan_objmgr_vdev *vdev;
  4831. uint8_t vdev_rxchainmask;
  4832. struct wlan_objmgr_psoc *psoc;
  4833. struct wlan_objmgr_pdev *pdev;
  4834. struct target_psoc_info *tgt_psoc_info;
  4835. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  4836. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  4837. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  4838. struct wlan_psoc_host_chainmask_table *table;
  4839. int j;
  4840. uint32_t table_id;
  4841. enum phy_ch_width ch_width;
  4842. uint8_t pdev_id;
  4843. if (!spectral) {
  4844. spectral_err("spectral target if object is null");
  4845. return QDF_STATUS_E_FAILURE;
  4846. }
  4847. if (!is_supported) {
  4848. spectral_err("is supported argument is null");
  4849. return QDF_STATUS_E_FAILURE;
  4850. }
  4851. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  4852. spectral_err("HW Agile mode is not supported up to gen 2");
  4853. return QDF_STATUS_E_FAILURE;
  4854. }
  4855. pdev = spectral->pdev_obj;
  4856. if (!pdev) {
  4857. spectral_err("pdev is null");
  4858. return QDF_STATUS_E_FAILURE;
  4859. }
  4860. psoc = wlan_pdev_get_psoc(pdev);
  4861. if (!psoc) {
  4862. spectral_err("psoc is null");
  4863. return QDF_STATUS_E_FAILURE;
  4864. }
  4865. vdev = target_if_spectral_get_vdev(spectral, SPECTRAL_SCAN_MODE_AGILE);
  4866. if (!vdev) {
  4867. spectral_err("First vdev is NULL");
  4868. return QDF_STATUS_E_FAILURE;
  4869. }
  4870. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  4871. if (!vdev_rxchainmask) {
  4872. spectral_err("vdev rx chainmask is zero");
  4873. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4874. return QDF_STATUS_E_FAILURE;
  4875. }
  4876. ch_width = target_if_vdev_get_ch_width(vdev);
  4877. if (ch_width == CH_WIDTH_INVALID) {
  4878. spectral_err("Invalid channel width");
  4879. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4880. return QDF_STATUS_E_FAILURE;
  4881. }
  4882. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  4883. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  4884. if (!tgt_psoc_info) {
  4885. spectral_err("target_psoc_info is null");
  4886. return QDF_STATUS_E_FAILURE;
  4887. }
  4888. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  4889. if (!ext_svc_param) {
  4890. spectral_err("Extended service ready param null");
  4891. return QDF_STATUS_E_FAILURE;
  4892. }
  4893. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  4894. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  4895. if (!mac_phy_cap_arr) {
  4896. spectral_err("mac phy cap array is null");
  4897. return QDF_STATUS_E_FAILURE;
  4898. }
  4899. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  4900. if (!mac_phy_cap) {
  4901. spectral_err("mac phy cap is null");
  4902. return QDF_STATUS_E_FAILURE;
  4903. }
  4904. table_id = mac_phy_cap->chainmask_table_id;
  4905. table = &ext_svc_param->chainmask_table[table_id];
  4906. if (!table) {
  4907. spectral_err("chainmask table not found");
  4908. return QDF_STATUS_E_FAILURE;
  4909. }
  4910. for (j = 0; j < table->num_valid_chainmasks; j++) {
  4911. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  4912. if (ch_width <= CH_WIDTH_80MHZ)
  4913. *is_supported =
  4914. table->cap_list[j].supports_aSpectral;
  4915. else
  4916. *is_supported =
  4917. table->cap_list[j].supports_aSpectral_160;
  4918. break;
  4919. }
  4920. }
  4921. if (j == table->num_valid_chainmasks) {
  4922. spectral_err("vdev rx chainmask %u not found in table id = %u",
  4923. vdev_rxchainmask, table_id);
  4924. return QDF_STATUS_E_FAILURE;
  4925. }
  4926. return QDF_STATUS_SUCCESS;
  4927. }
  4928. #define INVALID_SPAN_NUM (-1)
  4929. /**
  4930. * target_if_spectral_get_num_spans() - Get number of spans for a given sscan_bw
  4931. * @pdev: Pointer to pdev object
  4932. * @sscan_bw: Spectral scan bandwidth
  4933. *
  4934. * Return: Number of spans on success, INVALID_SPAN_NUM on failure
  4935. */
  4936. static int
  4937. target_if_spectral_get_num_spans(
  4938. struct wlan_objmgr_pdev *pdev,
  4939. enum phy_ch_width sscan_bw)
  4940. {
  4941. struct wlan_objmgr_psoc *psoc;
  4942. int num_spans;
  4943. if (!pdev) {
  4944. spectral_err_rl("pdev is null");
  4945. return INVALID_SPAN_NUM;
  4946. }
  4947. psoc = wlan_pdev_get_psoc(pdev);
  4948. if (!psoc) {
  4949. spectral_err_rl("psoc is null");
  4950. return INVALID_SPAN_NUM;
  4951. }
  4952. if (sscan_bw == CH_WIDTH_80P80MHZ) {
  4953. num_spans = 2;
  4954. if (wlan_psoc_nif_fw_ext_cap_get(
  4955. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  4956. /* 5 MHz frequency span in restricted 80p80 case */
  4957. num_spans += 1;
  4958. } else {
  4959. num_spans = 1;
  4960. }
  4961. return num_spans;
  4962. }
  4963. #ifdef OPTIMIZED_SAMP_MESSAGE
  4964. /**
  4965. * target_if_spectral_populate_session_report_info() - Populate per-session
  4966. * report level information.
  4967. *
  4968. * @spectral: Pointer to Spectral object
  4969. * @smode: Spectral scan mode
  4970. *
  4971. * Return: Success/Failure
  4972. */
  4973. static QDF_STATUS
  4974. target_if_spectral_populate_session_report_info(
  4975. struct target_if_spectral *spectral,
  4976. enum spectral_scan_mode smode)
  4977. {
  4978. struct per_session_report_info *rpt_info;
  4979. if (!spectral) {
  4980. spectral_err_rl("Spectral LMAC object is null");
  4981. return QDF_STATUS_E_NULL_VALUE;
  4982. }
  4983. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  4984. spectral_err_rl("Invalid Spectral scan mode");
  4985. return QDF_STATUS_E_FAILURE;
  4986. }
  4987. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  4988. /* Fill per-session report information, based on the spectral mode */
  4989. rpt_info = &spectral->report_info[smode];
  4990. rpt_info->operating_bw = spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  4991. rpt_info->sscan_bw = spectral->ch_width[smode];
  4992. rpt_info->sscan_cfreq1 = spectral->params[smode].ss_frequency.cfreq1;
  4993. rpt_info->sscan_cfreq2 = spectral->params[smode].ss_frequency.cfreq2;
  4994. rpt_info->num_spans = target_if_spectral_get_num_spans(
  4995. spectral->pdev_obj,
  4996. rpt_info->sscan_bw);
  4997. qdf_assert_always(rpt_info->num_spans != INVALID_SPAN_NUM);
  4998. rpt_info->valid = true;
  4999. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5000. return QDF_STATUS_SUCCESS;
  5001. }
  5002. /**
  5003. * target_if_spectral_populate_session_det_host_info() - Populate per-session
  5004. * detector level information that is known to the Host
  5005. *
  5006. * @spectral: Pointer to Spectral object
  5007. * @smode: Spectral scan mode
  5008. *
  5009. * Return: Success/Failure
  5010. */
  5011. static QDF_STATUS
  5012. target_if_spectral_populate_session_det_host_info(
  5013. struct target_if_spectral *spectral,
  5014. enum spectral_scan_mode smode)
  5015. {
  5016. struct per_session_report_info *rpt_info;
  5017. struct sscan_detector_list *detector_list;
  5018. struct wlan_objmgr_psoc *psoc;
  5019. uint16_t dest_det_idx = 0;
  5020. uint16_t dest_span_idx = 0;
  5021. bool is_sec80 = false;
  5022. uint8_t det, dest_det;
  5023. if (!spectral) {
  5024. spectral_err_rl("Spectral LMAC object is null");
  5025. return QDF_STATUS_E_NULL_VALUE;
  5026. }
  5027. if (smode > SPECTRAL_SCAN_MODE_MAX) {
  5028. spectral_err_rl("Invalid Spectral scan mode");
  5029. return QDF_STATUS_E_FAILURE;
  5030. }
  5031. if (!spectral->pdev_obj) {
  5032. spectral_err_rl("Spectral PDEV is null");
  5033. return QDF_STATUS_E_NULL_VALUE;
  5034. }
  5035. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  5036. if (!psoc) {
  5037. spectral_err_rl("psoc is null");
  5038. return QDF_STATUS_E_NULL_VALUE;
  5039. }
  5040. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5041. rpt_info = &spectral->report_info[smode];
  5042. qdf_spin_lock_bh(&spectral->detector_list_lock);
  5043. /* Fill per-sesion detector-level information */
  5044. detector_list = &spectral->detector_list[smode][rpt_info->sscan_bw];
  5045. for (det = 0; det < detector_list->num_detectors; det++) {
  5046. struct per_session_det_map *det_map;
  5047. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  5048. det_map = &spectral->det_map[detector_list->detectors[det]];
  5049. if (detector_list->num_detectors > 1) {
  5050. if (det == 0) {
  5051. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  5052. det_map->send_to_upper_layers = false;
  5053. } else if (det == detector_list->num_detectors - 1) {
  5054. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  5055. det_map->send_to_upper_layers = true;
  5056. } else {
  5057. /* middle fragments */
  5058. det_map->buf_type = SPECTRAL_MSG_BUF_SAVED;
  5059. det_map->send_to_upper_layers = false;
  5060. }
  5061. } else {
  5062. det_map->buf_type = SPECTRAL_MSG_BUF_NEW;
  5063. det_map->send_to_upper_layers = true;
  5064. }
  5065. det_map->num_dest_det_info = 1;
  5066. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ &&
  5067. wlan_psoc_nif_fw_ext_cap_get(
  5068. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  5069. /**
  5070. * In 165MHz case, 1 Spectral HW detector maps to 3
  5071. * detectors in SAMP msg.
  5072. */
  5073. det_map->num_dest_det_info += 2;
  5074. }
  5075. for (dest_det = 0; dest_det < det_map->num_dest_det_info;
  5076. dest_det++) {
  5077. struct per_session_dest_det_info *map_det_info;
  5078. map_det_info = &det_map->dest_det_info[dest_det];
  5079. map_det_info->freq_span_id = dest_span_idx;
  5080. map_det_info->det_id = dest_det_idx;
  5081. map_det_info->is_sec80 = is_sec80;
  5082. if (rpt_info->sscan_bw == CH_WIDTH_80P80MHZ) {
  5083. /* Increment span ID for non-contiguous modes */
  5084. dest_det_idx = 0;
  5085. dest_span_idx++;
  5086. } else {
  5087. /* Increment detector ID for contiguous modes */
  5088. dest_det_idx++;
  5089. }
  5090. is_sec80 = !is_sec80;
  5091. }
  5092. det_map->det_map_valid[smode] = true;
  5093. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  5094. }
  5095. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  5096. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5097. return QDF_STATUS_SUCCESS;
  5098. }
  5099. #else
  5100. static QDF_STATUS
  5101. target_if_spectral_populate_session_report_info(
  5102. struct target_if_spectral *spectral,
  5103. enum spectral_scan_mode smode)
  5104. {
  5105. return QDF_STATUS_SUCCESS;
  5106. }
  5107. static QDF_STATUS
  5108. target_if_spectral_populate_session_det_host_info(
  5109. struct target_if_spectral *spectral,
  5110. enum spectral_scan_mode smode)
  5111. {
  5112. return QDF_STATUS_SUCCESS;
  5113. }
  5114. #endif /* OPTIMIZED_SAMP_MESSAGE */
  5115. QDF_STATUS
  5116. spectral_is_session_info_expected_from_target(struct wlan_objmgr_pdev *pdev,
  5117. bool *is_session_info_expected)
  5118. {
  5119. struct wlan_objmgr_psoc *psoc;
  5120. struct wmi_unified *wmi_handle;
  5121. if (!pdev) {
  5122. spectral_err("pdev is null");
  5123. return QDF_STATUS_E_NULL_VALUE;
  5124. }
  5125. psoc = wlan_pdev_get_psoc(pdev);
  5126. if (!psoc) {
  5127. spectral_err("psoc is null");
  5128. return QDF_STATUS_E_NULL_VALUE;
  5129. }
  5130. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  5131. if (!wmi_handle) {
  5132. spectral_err("wmi handle is null");
  5133. return QDF_STATUS_E_NULL_VALUE;
  5134. }
  5135. *is_session_info_expected = target_if_spectral_wmi_service_enabled(
  5136. psoc, wmi_handle,
  5137. wmi_service_spectral_session_info_support);
  5138. return QDF_STATUS_SUCCESS;
  5139. }
  5140. QDF_STATUS
  5141. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  5142. uint8_t vdev_id,
  5143. const enum spectral_scan_mode smode,
  5144. enum spectral_cp_error_code *err)
  5145. {
  5146. struct target_if_spectral_ops *p_sops;
  5147. struct target_if_spectral *spectral;
  5148. struct wlan_objmgr_psoc *psoc;
  5149. enum reg_wifi_band band;
  5150. QDF_STATUS ret;
  5151. bool is_session_info_expected;
  5152. if (!err) {
  5153. spectral_err("Error code argument is null");
  5154. QDF_ASSERT(0);
  5155. return QDF_STATUS_E_FAILURE;
  5156. }
  5157. *err = SPECTRAL_SCAN_ERR_INVALID;
  5158. if (!pdev) {
  5159. spectral_err("pdev object is NUll");
  5160. return QDF_STATUS_E_FAILURE;
  5161. }
  5162. psoc = wlan_pdev_get_psoc(pdev);
  5163. if (!psoc) {
  5164. spectral_err("psoc is null");
  5165. return QDF_STATUS_E_FAILURE;
  5166. }
  5167. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5168. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5169. spectral_err("Invalid Spectral mode %u", smode);
  5170. return QDF_STATUS_E_FAILURE;
  5171. }
  5172. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5173. if (!spectral) {
  5174. spectral_err("Spectral LMAC object is NUll");
  5175. return QDF_STATUS_E_FAILURE;
  5176. }
  5177. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5178. if (!p_sops) {
  5179. spectral_err("p_sops is null");
  5180. return QDF_STATUS_E_FAILURE;
  5181. }
  5182. if (p_sops->is_spectral_active(spectral, smode)) {
  5183. spectral_err("spectral in progress in current pdev, mode %d",
  5184. smode);
  5185. return QDF_STATUS_E_FAILURE;
  5186. }
  5187. spectral->vdev_id[smode] = vdev_id;
  5188. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5189. QDF_STATUS status;
  5190. bool is_supported = false;
  5191. status = target_if_is_agile_supported_cur_chmask(spectral,
  5192. &is_supported);
  5193. if (QDF_IS_STATUS_ERROR(status)) {
  5194. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5195. return QDF_STATUS_E_FAILURE;
  5196. }
  5197. if (!is_supported) {
  5198. spectral_err("aSpectral unsupported for cur chainmask");
  5199. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5200. return QDF_STATUS_E_FAILURE;
  5201. }
  5202. }
  5203. band = target_if_get_curr_band(spectral->pdev_obj, vdev_id);
  5204. if (band == REG_BAND_UNKNOWN) {
  5205. spectral_err("Failed to get current band");
  5206. return QDF_STATUS_E_FAILURE;
  5207. }
  5208. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  5209. struct target_psoc_info *tgt_hdl;
  5210. enum wmi_host_hw_mode_config_type mode;
  5211. bool is_agile_scan_inprog_5g_pdev;
  5212. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  5213. if (!tgt_hdl) {
  5214. target_if_err("target_psoc_info is null");
  5215. return QDF_STATUS_E_FAILURE;
  5216. }
  5217. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  5218. switch (mode) {
  5219. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  5220. case WMI_HOST_HW_MODE_SBS:
  5221. case WMI_HOST_HW_MODE_DBS_SBS:
  5222. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  5223. is_agile_scan_inprog_5g_pdev = false;
  5224. wlan_objmgr_iterate_obj_list
  5225. (psoc, WLAN_PDEV_OP,
  5226. target_if_is_agile_scan_active_in_5g,
  5227. &is_agile_scan_inprog_5g_pdev, 0,
  5228. WLAN_SPECTRAL_ID);
  5229. break;
  5230. default:
  5231. is_agile_scan_inprog_5g_pdev = false;
  5232. break;
  5233. }
  5234. if (is_agile_scan_inprog_5g_pdev) {
  5235. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  5236. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5237. return QDF_STATUS_E_FAILURE;
  5238. }
  5239. }
  5240. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5241. bool is_aspectral_prohibited = false;
  5242. QDF_STATUS status;
  5243. status = wlan_objmgr_iterate_obj_list
  5244. (psoc, WLAN_PDEV_OP,
  5245. target_if_is_aspectral_prohibited_by_adfs,
  5246. &is_aspectral_prohibited, 0,
  5247. WLAN_SPECTRAL_ID);
  5248. if (QDF_IS_STATUS_ERROR(status)) {
  5249. spectral_err("Failed to iterate over pdevs");
  5250. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5251. return QDF_STATUS_E_FAILURE;
  5252. }
  5253. if (is_aspectral_prohibited) {
  5254. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5255. return QDF_STATUS_E_FAILURE;
  5256. }
  5257. }
  5258. if (!spectral->params_valid[smode]) {
  5259. target_if_spectral_info_read(spectral,
  5260. smode,
  5261. TARGET_IF_SPECTRAL_INFO_PARAMS,
  5262. &spectral->params[smode],
  5263. sizeof(spectral->params[smode]));
  5264. spectral->params_valid[smode] = true;
  5265. }
  5266. qdf_spin_lock_bh(&spectral->spectral_lock);
  5267. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  5268. QDF_STATUS status;
  5269. bool is_overlapping;
  5270. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  5271. enum spectral_scan_mode m;
  5272. enum phy_ch_width op_ch_width;
  5273. enum phy_ch_width agile_ch_width;
  5274. m = SPECTRAL_SCAN_MODE_NORMAL;
  5275. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  5276. ch_width[m] = CH_WIDTH_INVALID;
  5277. status = target_if_spectral_populate_chwidth
  5278. (spectral, ch_width, spectral->params
  5279. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  5280. if (QDF_IS_STATUS_ERROR(status)) {
  5281. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5282. spectral_err("Failed to populate channel width");
  5283. return QDF_STATUS_E_FAILURE;
  5284. }
  5285. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  5286. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  5287. if (!spectral->params[smode].ss_frequency.cfreq1) {
  5288. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  5289. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5290. spectral_err("Agile Spectral cfreq1 is 0");
  5291. return QDF_STATUS_E_FAILURE;
  5292. } else if (agile_ch_width == CH_WIDTH_80P80MHZ &&
  5293. !spectral->params[smode].ss_frequency.cfreq2) {
  5294. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  5295. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5296. spectral_err("Agile Spectral cfreq2 is 0");
  5297. return QDF_STATUS_E_FAILURE;
  5298. }
  5299. status = target_if_is_agile_span_overlap_with_operating_span
  5300. (spectral, ch_width,
  5301. &spectral->params[smode].ss_frequency,
  5302. &is_overlapping);
  5303. if (QDF_IS_STATUS_ERROR(status)) {
  5304. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5305. return QDF_STATUS_E_FAILURE;
  5306. }
  5307. if (is_overlapping) {
  5308. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  5309. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5310. return QDF_STATUS_E_FAILURE;
  5311. }
  5312. }
  5313. /* Populate detectot list first */
  5314. ret = target_if_spectral_detector_list_init(spectral);
  5315. if (QDF_IS_STATUS_ERROR(ret)) {
  5316. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5317. spectral_err("Failed to initialize detector list");
  5318. return ret;
  5319. }
  5320. ret = target_if_spectral_populate_chwidth(
  5321. spectral, spectral->ch_width,
  5322. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  5323. ss_frequency.cfreq2 > 0);
  5324. if (QDF_IS_STATUS_ERROR(ret)) {
  5325. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5326. spectral_err("Failed to get channel widths");
  5327. return ret;
  5328. }
  5329. ret = spectral_is_session_info_expected_from_target(
  5330. spectral->pdev_obj,
  5331. &is_session_info_expected);
  5332. if (QDF_IS_STATUS_ERROR(ret)) {
  5333. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5334. spectral_err("Failed to check if session info is expected");
  5335. return ret;
  5336. }
  5337. /* If FW doesn't send session info, populate it */
  5338. if (!is_session_info_expected) {
  5339. ret = target_if_spectral_populate_session_report_info(spectral,
  5340. smode);
  5341. if (QDF_IS_STATUS_ERROR(ret)) {
  5342. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5343. spectral_err("Failed to populate per-session report info");
  5344. return QDF_STATUS_E_FAILURE;
  5345. }
  5346. ret = target_if_spectral_populate_session_det_host_info(
  5347. spectral, smode);
  5348. if (QDF_IS_STATUS_ERROR(ret)) {
  5349. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5350. spectral_err("Failed to populate per-session detector info");
  5351. return QDF_STATUS_E_FAILURE;
  5352. }
  5353. }
  5354. target_if_spectral_scan_enable_params(spectral,
  5355. &spectral->params[smode], smode,
  5356. err);
  5357. spectral->sscan_width_configured[smode] = false;
  5358. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5359. return QDF_STATUS_SUCCESS;
  5360. }
  5361. QDF_STATUS
  5362. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  5363. const enum spectral_scan_mode smode,
  5364. enum spectral_cp_error_code *err)
  5365. {
  5366. struct target_if_spectral_ops *p_sops;
  5367. struct target_if_spectral *spectral;
  5368. uint8_t det;
  5369. if (!pdev) {
  5370. spectral_err("pdev object is NULL");
  5371. return QDF_STATUS_E_INVAL;
  5372. }
  5373. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  5374. spectral_info("Spectral feature is disabled");
  5375. return QDF_STATUS_COMP_DISABLED;
  5376. }
  5377. if (!err) {
  5378. spectral_err("Error code argument is null");
  5379. QDF_ASSERT(0);
  5380. return QDF_STATUS_E_FAILURE;
  5381. }
  5382. *err = SPECTRAL_SCAN_ERR_INVALID;
  5383. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5384. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  5385. spectral_err("Invalid Spectral mode %u", smode);
  5386. return QDF_STATUS_E_FAILURE;
  5387. }
  5388. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5389. if (!spectral) {
  5390. spectral_err("Spectral LMAC object is NUll ");
  5391. return QDF_STATUS_E_FAILURE;
  5392. }
  5393. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5394. qdf_spin_lock_bh(&spectral->spectral_lock);
  5395. p_sops->stop_spectral_scan(spectral, smode);
  5396. if (spectral->classify_scan) {
  5397. /* TODO : Check if this logic is necessary */
  5398. spectral->detects_control_channel = 0;
  5399. spectral->detects_extension_channel = 0;
  5400. spectral->detects_above_dc = 0;
  5401. spectral->detects_below_dc = 0;
  5402. spectral->classify_scan = 0;
  5403. }
  5404. spectral->send_single_packet = 0;
  5405. spectral->sc_spectral_scan = 0;
  5406. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  5407. for (det = 0; det < MAX_DETECTORS_PER_PDEV; det++)
  5408. spectral->det_map[det].det_map_valid[smode] = false;
  5409. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  5410. /* Mark report info as invalid */
  5411. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  5412. spectral->report_info[smode].valid = false;
  5413. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  5414. qdf_spin_unlock_bh(&spectral->spectral_lock);
  5415. return QDF_STATUS_SUCCESS;
  5416. }
  5417. /**
  5418. * target_if_is_spectral_active() - Get whether Spectral is active
  5419. * @pdev: Pointer to pdev object
  5420. * @smode: Spectral scan mode
  5421. *
  5422. * API to get whether Spectral is active
  5423. *
  5424. * Return: True if Spectral is active, false if Spectral is not active
  5425. */
  5426. bool
  5427. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  5428. const enum spectral_scan_mode smode)
  5429. {
  5430. struct target_if_spectral *spectral = NULL;
  5431. struct target_if_spectral_ops *p_sops = NULL;
  5432. if (!pdev) {
  5433. spectral_err("pdev is null");
  5434. return false;
  5435. }
  5436. if (target_if_spectral_is_feature_disabled_pdev(pdev)) {
  5437. spectral_info("Spectral feature is disabled");
  5438. return false;
  5439. }
  5440. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5441. if (!spectral) {
  5442. spectral_err("SPECTRAL : Module doesn't exist");
  5443. return false;
  5444. }
  5445. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5446. if (!p_sops) {
  5447. spectral_err("p_sops is null");
  5448. return false;
  5449. }
  5450. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5451. spectral_err("Invalid Spectral mode %u", smode);
  5452. return false;
  5453. }
  5454. return p_sops->is_spectral_active(spectral, smode);
  5455. }
  5456. /**
  5457. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  5458. * @pdev: Pointer to pdev object
  5459. * @smode: Spectral scan mode
  5460. *
  5461. * API to get whether Spectral is enabled
  5462. *
  5463. * Return: True if Spectral is enabled, false if Spectral is not enabled
  5464. */
  5465. bool
  5466. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  5467. enum spectral_scan_mode smode)
  5468. {
  5469. struct target_if_spectral *spectral = NULL;
  5470. struct target_if_spectral_ops *p_sops = NULL;
  5471. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5472. if (!spectral) {
  5473. spectral_err("SPECTRAL : Module doesn't exist");
  5474. return false;
  5475. }
  5476. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5477. if (!p_sops) {
  5478. spectral_err("p_sops is null");
  5479. return false;
  5480. }
  5481. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  5482. spectral_err("Invalid Spectral mode %u", smode);
  5483. return false;
  5484. }
  5485. return p_sops->is_spectral_enabled(spectral, smode);
  5486. }
  5487. #ifdef DIRECT_BUF_RX_DEBUG
  5488. /**
  5489. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  5490. * @pdev: Pointer to pdev object
  5491. * @enable: Enable/Disable Spectral DMA ring debug
  5492. *
  5493. * Start/stop Spectral DMA ring debug based on @enable.
  5494. * Also save the state for future use.
  5495. *
  5496. * Return: QDF_STATUS of operation
  5497. */
  5498. static QDF_STATUS
  5499. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  5500. {
  5501. struct target_if_spectral *spectral;
  5502. struct wlan_lmac_if_tx_ops *tx_ops;
  5503. struct wlan_objmgr_psoc *psoc;
  5504. if (!pdev)
  5505. return QDF_STATUS_E_FAILURE;
  5506. psoc = wlan_pdev_get_psoc(pdev);
  5507. if (!psoc) {
  5508. spectral_err("psoc is null");
  5509. return QDF_STATUS_E_INVAL;
  5510. }
  5511. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5512. if (!tx_ops) {
  5513. spectral_err("tx_ops is NULL");
  5514. return QDF_STATUS_E_INVAL;
  5515. }
  5516. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5517. if (!spectral) {
  5518. spectral_err("Spectal LMAC object is NULL");
  5519. return QDF_STATUS_E_INVAL;
  5520. }
  5521. /* Save the state */
  5522. spectral->dbr_ring_debug = enable;
  5523. if (enable)
  5524. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  5525. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  5526. else
  5527. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  5528. pdev, 0);
  5529. return QDF_STATUS_SUCCESS;
  5530. }
  5531. /**
  5532. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  5533. * @pdev: Pointer to pdev object
  5534. * @enable: Enable/Disable Spectral DMA buffer debug
  5535. *
  5536. * Start/stop Spectral DMA buffer debug based on @enable.
  5537. * Also save the state for future use.
  5538. *
  5539. * Return: QDF_STATUS of operation
  5540. */
  5541. static QDF_STATUS
  5542. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  5543. {
  5544. struct target_if_spectral *spectral;
  5545. struct wlan_lmac_if_tx_ops *tx_ops;
  5546. struct wlan_objmgr_psoc *psoc;
  5547. if (!pdev)
  5548. return QDF_STATUS_E_FAILURE;
  5549. psoc = wlan_pdev_get_psoc(pdev);
  5550. if (!psoc) {
  5551. spectral_err("psoc is null");
  5552. return QDF_STATUS_E_INVAL;
  5553. }
  5554. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5555. if (!tx_ops) {
  5556. spectral_err("tx_ops is NULL");
  5557. return QDF_STATUS_E_INVAL;
  5558. }
  5559. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5560. if (!spectral) {
  5561. spectral_err("Spectal LMAC object is NULL");
  5562. return QDF_STATUS_E_INVAL;
  5563. }
  5564. /* Save the state */
  5565. spectral->dbr_buff_debug = enable;
  5566. if (enable)
  5567. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  5568. pdev, 0, MEM_POISON_SIGNATURE);
  5569. else
  5570. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  5571. pdev, 0);
  5572. }
  5573. /**
  5574. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  5575. * debug based on the previous state
  5576. * @pdev: Pointer to pdev object
  5577. *
  5578. * Return: QDF_STATUS of operation
  5579. */
  5580. static QDF_STATUS
  5581. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  5582. {
  5583. struct target_if_spectral *spectral;
  5584. if (!pdev) {
  5585. spectral_err("pdev is NULL!");
  5586. return QDF_STATUS_E_FAILURE;
  5587. }
  5588. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5589. if (!spectral) {
  5590. spectral_err("Spectal LMAC object is NULL");
  5591. return QDF_STATUS_E_INVAL;
  5592. }
  5593. if (spectral->dbr_buff_debug)
  5594. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  5595. else
  5596. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  5597. }
  5598. /**
  5599. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  5600. * debug based on the previous state
  5601. * @pdev: Pointer to pdev object
  5602. *
  5603. * Return: QDF_STATUS of operation
  5604. */
  5605. static QDF_STATUS
  5606. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  5607. {
  5608. struct target_if_spectral *spectral;
  5609. if (!pdev) {
  5610. spectral_err("pdev is NULL!");
  5611. return QDF_STATUS_E_FAILURE;
  5612. }
  5613. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5614. if (!spectral) {
  5615. spectral_err("Spectal LMAC object is NULL");
  5616. return QDF_STATUS_E_INVAL;
  5617. }
  5618. if (spectral->dbr_ring_debug)
  5619. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  5620. else
  5621. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  5622. }
  5623. /**
  5624. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  5625. * @pdev: Pointer to pdev object
  5626. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  5627. * @debug_value: Value to be set for @dma_debug_type
  5628. *
  5629. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  5630. * based on @debug_value
  5631. *
  5632. * Return: QDF_STATUS of operation
  5633. */
  5634. static QDF_STATUS
  5635. target_if_spectral_set_dma_debug(
  5636. struct wlan_objmgr_pdev *pdev,
  5637. enum spectral_dma_debug dma_debug_type,
  5638. bool debug_value)
  5639. {
  5640. struct target_if_spectral_ops *p_sops;
  5641. struct wlan_objmgr_psoc *psoc;
  5642. struct wlan_lmac_if_tx_ops *tx_ops;
  5643. struct target_if_spectral *spectral;
  5644. if (!pdev)
  5645. return QDF_STATUS_E_FAILURE;
  5646. psoc = wlan_pdev_get_psoc(pdev);
  5647. if (!psoc) {
  5648. spectral_err("psoc is null");
  5649. return QDF_STATUS_E_INVAL;
  5650. }
  5651. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  5652. if (!tx_ops) {
  5653. spectral_err("tx_ops is NULL");
  5654. return QDF_STATUS_E_FAILURE;
  5655. }
  5656. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  5657. spectral_err("Unable to fetch target type");
  5658. return QDF_STATUS_E_FAILURE;
  5659. }
  5660. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5661. if (!spectral) {
  5662. spectral_err("Spectal LMAC object is NULL");
  5663. return QDF_STATUS_E_INVAL;
  5664. }
  5665. if (spectral->direct_dma_support) {
  5666. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5667. if (p_sops->is_spectral_active(spectral,
  5668. SPECTRAL_SCAN_MODE_NORMAL) ||
  5669. p_sops->is_spectral_active(spectral,
  5670. SPECTRAL_SCAN_MODE_AGILE)) {
  5671. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  5672. return QDF_STATUS_E_FAILURE;
  5673. }
  5674. switch (dma_debug_type) {
  5675. case SPECTRAL_DMA_RING_DEBUG:
  5676. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  5677. break;
  5678. case SPECTRAL_DMA_BUFFER_DEBUG:
  5679. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  5680. break;
  5681. default:
  5682. spectral_err("Unsupported DMA debug type : %d",
  5683. dma_debug_type);
  5684. return QDF_STATUS_E_FAILURE;
  5685. }
  5686. }
  5687. return QDF_STATUS_SUCCESS;
  5688. }
  5689. #endif /* DIRECT_BUF_RX_DEBUG */
  5690. /**
  5691. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  5692. * @pdev: Pointer to pdev object
  5693. *
  5694. * Return: Whether Direct-DMA is supported on this radio
  5695. */
  5696. static bool
  5697. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  5698. {
  5699. struct target_if_spectral *spectral;
  5700. if (!pdev) {
  5701. spectral_err("pdev is NULL!");
  5702. return false;
  5703. }
  5704. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5705. if (!spectral) {
  5706. spectral_err("Spectral LMAC object is NULL");
  5707. return false;
  5708. }
  5709. return spectral->direct_dma_support;
  5710. }
  5711. /**
  5712. * target_if_set_debug_level() - Set debug level for Spectral
  5713. * @pdev: Pointer to pdev object
  5714. * @debug_level: Debug level
  5715. *
  5716. * API to set the debug level for Spectral
  5717. *
  5718. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5719. */
  5720. QDF_STATUS
  5721. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  5722. {
  5723. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  5724. return QDF_STATUS_SUCCESS;
  5725. }
  5726. /**
  5727. * target_if_get_debug_level() - Get debug level for Spectral
  5728. * @pdev: Pointer to pdev object
  5729. *
  5730. * API to get the debug level for Spectral
  5731. *
  5732. * Return: Current debug level
  5733. */
  5734. uint32_t
  5735. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  5736. {
  5737. return spectral_debug_level;
  5738. }
  5739. /**
  5740. * target_if_get_spectral_capinfo() - Get Spectral capability information
  5741. * @pdev: Pointer to pdev object
  5742. * @scaps: Buffer into which data should be copied
  5743. *
  5744. * API to get the spectral capability information
  5745. *
  5746. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5747. */
  5748. QDF_STATUS
  5749. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  5750. struct spectral_caps *scaps)
  5751. {
  5752. struct target_if_spectral *spectral = NULL;
  5753. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5754. if (!spectral) {
  5755. spectral_err("SPECTRAL : Module doesn't exist");
  5756. return QDF_STATUS_E_FAILURE;
  5757. }
  5758. qdf_mem_copy(scaps, &spectral->capability,
  5759. sizeof(struct spectral_caps));
  5760. return QDF_STATUS_SUCCESS;
  5761. }
  5762. /**
  5763. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  5764. * @pdev: Pointer to pdev object
  5765. * @stats: Buffer into which data should be copied
  5766. *
  5767. * API to get the spectral diagnostic statistics
  5768. *
  5769. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  5770. */
  5771. QDF_STATUS
  5772. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  5773. struct spectral_diag_stats *stats)
  5774. {
  5775. struct target_if_spectral *spectral = NULL;
  5776. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5777. if (!spectral) {
  5778. spectral_err("SPECTRAL : Module doesn't exist");
  5779. return QDF_STATUS_E_FAILURE;
  5780. }
  5781. qdf_mem_copy(stats, &spectral->diag_stats,
  5782. sizeof(struct spectral_diag_stats));
  5783. return QDF_STATUS_SUCCESS;
  5784. }
  5785. /**
  5786. * target_if_register_spectral_wmi_ops() - Register Spectral WMI operations
  5787. * @psoc: Pointer to psoc object
  5788. * @wmi_ops: Pointer to the structure having Spectral WMI operations
  5789. *
  5790. * API for registering Spectral WMI operations in
  5791. * spectral internal data structure
  5792. *
  5793. * Return: QDF_STATUS
  5794. */
  5795. static QDF_STATUS
  5796. target_if_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
  5797. struct spectral_wmi_ops *wmi_ops)
  5798. {
  5799. struct target_if_psoc_spectral *psoc_spectral;
  5800. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5801. if (!psoc_spectral) {
  5802. spectral_err("Spectral LMAC object is null");
  5803. return QDF_STATUS_E_INVAL;
  5804. }
  5805. psoc_spectral->wmi_ops = *wmi_ops;
  5806. return QDF_STATUS_SUCCESS;
  5807. }
  5808. /**
  5809. * target_if_register_spectral_tgt_ops() - Register Spectral target operations
  5810. * @psoc: Pointer to psoc object
  5811. * @tgt_ops: Pointer to the structure having Spectral target operations
  5812. *
  5813. * API for registering Spectral target operations in
  5814. * spectral internal data structure
  5815. *
  5816. * Return: QDF_STATUS
  5817. */
  5818. static QDF_STATUS
  5819. target_if_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
  5820. struct spectral_tgt_ops *tgt_ops)
  5821. {
  5822. if (!psoc) {
  5823. spectral_err("psoc is null");
  5824. return QDF_STATUS_E_INVAL;
  5825. }
  5826. ops_tgt = *tgt_ops;
  5827. return QDF_STATUS_SUCCESS;
  5828. }
  5829. /**
  5830. * target_if_register_netlink_cb() - Register Netlink callbacks
  5831. * @pdev: Pointer to pdev object
  5832. * @nl_cb: Netlink callbacks to register
  5833. *
  5834. * Return: void
  5835. */
  5836. static void
  5837. target_if_register_netlink_cb(
  5838. struct wlan_objmgr_pdev *pdev,
  5839. struct spectral_nl_cb *nl_cb)
  5840. {
  5841. struct target_if_spectral *spectral = NULL;
  5842. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5843. if (!spectral) {
  5844. spectral_err("SPECTRAL : Module doesn't exist");
  5845. return;
  5846. }
  5847. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  5848. if (spectral->use_nl_bcast)
  5849. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  5850. else
  5851. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  5852. }
  5853. /**
  5854. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  5855. * Netlink messages to the application layer
  5856. * @pdev: Pointer to pdev object
  5857. *
  5858. * Return: true for broadcast, false for unicast
  5859. */
  5860. static bool
  5861. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  5862. {
  5863. struct target_if_spectral *spectral = NULL;
  5864. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5865. if (!spectral) {
  5866. spectral_err("SPECTRAL : Module doesn't exist");
  5867. return false;
  5868. }
  5869. return spectral->use_nl_bcast;
  5870. }
  5871. /**
  5872. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  5873. * @pdev: Pointer to pdev object
  5874. *
  5875. * Return: void
  5876. */
  5877. static void
  5878. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  5879. {
  5880. struct target_if_spectral *spectral = NULL;
  5881. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5882. if (!spectral) {
  5883. spectral_err("SPECTRAL : Module doesn't exist");
  5884. return;
  5885. }
  5886. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  5887. }
  5888. static int
  5889. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  5890. void *payload)
  5891. {
  5892. struct target_if_spectral *spectral = NULL;
  5893. struct target_if_spectral_ops *p_sops = NULL;
  5894. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  5895. if (!spectral) {
  5896. spectral_err("SPECTRAL : Module doesn't exist");
  5897. return -EPERM;
  5898. }
  5899. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  5900. if (!p_sops) {
  5901. spectral_err("p_sops is null");
  5902. return -EPERM;
  5903. }
  5904. return p_sops->process_spectral_report(pdev, payload);
  5905. }
  5906. #ifdef DIRECT_BUF_RX_DEBUG
  5907. static inline void
  5908. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5909. {
  5910. if (!tx_ops) {
  5911. spectral_err("tx_ops is NULL");
  5912. return;
  5913. }
  5914. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  5915. target_if_spectral_set_dma_debug;
  5916. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  5917. target_if_spectral_check_and_do_dbr_ring_debug;
  5918. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  5919. target_if_spectral_check_and_do_dbr_buff_debug;
  5920. }
  5921. #else
  5922. static inline void
  5923. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  5924. {
  5925. }
  5926. #endif
  5927. #if defined(WLAN_CONV_SPECTRAL_ENABLE) && defined(SPECTRAL_MODULIZED_ENABLE)
  5928. /**
  5929. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  5930. * register WMI event handler
  5931. * @psoc: Pointer to psoc object
  5932. * @event_id: Event id
  5933. * @handler_func: Handler function
  5934. * @rx_ctx: Context of WMI event processing
  5935. *
  5936. * Wrapper function to register WMI event handler
  5937. *
  5938. * Return: 0 for success else failure
  5939. */
  5940. static int
  5941. target_if_spectral_wmi_unified_register_event_handler(
  5942. struct wlan_objmgr_psoc *psoc,
  5943. wmi_conv_event_id event_id,
  5944. wmi_unified_event_handler handler_func,
  5945. uint8_t rx_ctx)
  5946. {
  5947. wmi_unified_t wmi_handle;
  5948. struct target_if_psoc_spectral *psoc_spectral;
  5949. QDF_STATUS ret;
  5950. if (!psoc) {
  5951. spectral_err("psoc is null");
  5952. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5953. }
  5954. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5955. if (!wmi_handle) {
  5956. spectral_err("WMI handle is null");
  5957. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5958. }
  5959. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5960. if (!psoc_spectral) {
  5961. spectral_err("spectral object is null");
  5962. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5963. }
  5964. ret = psoc_spectral->wmi_ops.wmi_unified_register_event_handler(
  5965. wmi_handle, event_id, handler_func, rx_ctx);
  5966. return qdf_status_to_os_return(ret);
  5967. }
  5968. /**
  5969. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  5970. * to unregister WMI event handler
  5971. * @psoc: Pointer to psoc object
  5972. * @event_id: Event id
  5973. *
  5974. * Wrapper function to unregister WMI event handler
  5975. *
  5976. * Return: 0 for success else failure
  5977. */
  5978. static int
  5979. target_if_spectral_wmi_unified_unregister_event_handler(
  5980. struct wlan_objmgr_psoc *psoc,
  5981. wmi_conv_event_id event_id)
  5982. {
  5983. wmi_unified_t wmi_handle;
  5984. struct target_if_psoc_spectral *psoc_spectral;
  5985. QDF_STATUS ret;
  5986. if (!psoc) {
  5987. spectral_err("psoc is null");
  5988. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5989. }
  5990. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  5991. if (!wmi_handle) {
  5992. spectral_err("WMI handle is null");
  5993. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  5994. }
  5995. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  5996. if (!psoc_spectral) {
  5997. spectral_err("spectral object is null");
  5998. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  5999. }
  6000. ret = psoc_spectral->wmi_ops.wmi_unified_unregister_event_handler(
  6001. wmi_handle, event_id);
  6002. return qdf_status_to_os_return(ret);
  6003. }
  6004. /**
  6005. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  6006. * function to extract fixed parameters from start scan response event
  6007. * @psoc: Pointer to psoc object
  6008. * @evt_buf: Event buffer
  6009. * @param: Start scan response parameters
  6010. *
  6011. * Wrapper function to extract fixed parameters from start scan response event
  6012. *
  6013. * Return: QDF_STATUS
  6014. */
  6015. static QDF_STATUS
  6016. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6017. struct wlan_objmgr_psoc *psoc,
  6018. uint8_t *evt_buf,
  6019. struct spectral_startscan_resp_params *param)
  6020. {
  6021. wmi_unified_t wmi_handle;
  6022. struct target_if_psoc_spectral *psoc_spectral;
  6023. if (!psoc) {
  6024. spectral_err("psoc is null");
  6025. return QDF_STATUS_E_INVAL;
  6026. }
  6027. if (!evt_buf) {
  6028. spectral_err("WMI event buffer is null");
  6029. return QDF_STATUS_E_INVAL;
  6030. }
  6031. if (!param) {
  6032. spectral_err("Spectral startscan response parameters is null");
  6033. return QDF_STATUS_E_INVAL;
  6034. }
  6035. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6036. if (!wmi_handle) {
  6037. spectral_err("WMI handle is null");
  6038. return QDF_STATUS_E_INVAL;
  6039. }
  6040. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6041. if (!psoc_spectral) {
  6042. spectral_err("spectral object is null");
  6043. return QDF_STATUS_E_FAILURE;
  6044. }
  6045. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6046. wmi_handle, evt_buf, param);
  6047. }
  6048. /**
  6049. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  6050. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  6051. * secondary 80 MHz FFT bins
  6052. * @psoc: Pointer to psoc object
  6053. * @evt_buf: Event buffer
  6054. * @param: FFT bin start and end indices
  6055. *
  6056. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  6057. * and secondary 80 MHz FFT bins
  6058. *
  6059. * Return: QDF_STATUS
  6060. */
  6061. static QDF_STATUS
  6062. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6063. struct wlan_objmgr_psoc *psoc,
  6064. uint8_t *evt_buf,
  6065. struct spectral_fft_bin_markers_160_165mhz *param)
  6066. {
  6067. wmi_unified_t wmi_handle;
  6068. struct target_if_psoc_spectral *psoc_spectral;
  6069. if (!psoc) {
  6070. spectral_err("psoc is null");
  6071. return QDF_STATUS_E_INVAL;
  6072. }
  6073. if (!evt_buf) {
  6074. spectral_err("WMI event buffer is null");
  6075. return QDF_STATUS_E_INVAL;
  6076. }
  6077. if (!param) {
  6078. spectral_err("Spectral FFT bin markers is null");
  6079. return QDF_STATUS_E_INVAL;
  6080. }
  6081. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6082. if (!wmi_handle) {
  6083. spectral_err("WMI handle is null");
  6084. return QDF_STATUS_E_INVAL;
  6085. }
  6086. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6087. if (!psoc_spectral) {
  6088. spectral_err("spectral object is null");
  6089. return QDF_STATUS_E_FAILURE;
  6090. }
  6091. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fft_bin_index(
  6092. wmi_handle, evt_buf, param);
  6093. }
  6094. /**
  6095. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  6096. * object from scn handle
  6097. * @scn: scn handle
  6098. *
  6099. * Wrapper function to get psoc object from scn handle
  6100. *
  6101. * Return: Pointer to psoc object
  6102. */
  6103. static struct wlan_objmgr_psoc *
  6104. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  6105. {
  6106. if (!scn) {
  6107. spectral_err("scn is null");
  6108. return NULL;
  6109. }
  6110. return ops_tgt.tgt_get_psoc_from_scn_hdl(scn);
  6111. }
  6112. /**
  6113. * target_if_extract_pdev_spectral_session_chan_info() - Wrapper
  6114. * function to extract channel information for a spectral scan session
  6115. * @psoc: Pointer to psoc object
  6116. * @evt_buf: Event buffer
  6117. * @chan_info: Spectral session channel information data structure to be filled
  6118. * by this API
  6119. *
  6120. * Return: QDF_STATUS of operation
  6121. */
  6122. static QDF_STATUS
  6123. target_if_extract_pdev_spectral_session_chan_info(
  6124. struct wlan_objmgr_psoc *psoc,
  6125. void *evt_buf,
  6126. struct spectral_session_chan_info *chan_info)
  6127. {
  6128. wmi_unified_t wmi_handle;
  6129. struct target_if_psoc_spectral *psoc_spectral;
  6130. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6131. if (!wmi_handle) {
  6132. spectral_err("WMI handle is null");
  6133. return QDF_STATUS_E_NULL_VALUE;
  6134. }
  6135. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6136. if (!psoc_spectral) {
  6137. spectral_err("spectral object is null");
  6138. return QDF_STATUS_E_NULL_VALUE;
  6139. }
  6140. return psoc_spectral->wmi_ops.extract_pdev_spectral_session_chan_info(
  6141. wmi_handle, evt_buf, chan_info);
  6142. }
  6143. /**
  6144. * target_if_extract_pdev_spectral_session_detector_info() - Wrapper
  6145. * function to extract detector information for a spectral scan session
  6146. * @psoc: Pointer to psoc object
  6147. * @evt_buf: Event buffer
  6148. * @det_info: Spectral session detector information data structure to be filled
  6149. * by this API
  6150. * @det_info_idx: index in the array of spectral scan detector info TLVs
  6151. *
  6152. * Return: QDF_STATUS of operation
  6153. */
  6154. static QDF_STATUS
  6155. target_if_extract_pdev_spectral_session_detector_info(
  6156. struct wlan_objmgr_psoc *psoc, void *evt_buf,
  6157. struct spectral_session_det_info *det_info,
  6158. uint8_t det_info_idx)
  6159. {
  6160. wmi_unified_t wmi_handle;
  6161. struct target_if_psoc_spectral *psoc_spectral;
  6162. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6163. if (!wmi_handle) {
  6164. spectral_err("WMI handle is null");
  6165. return QDF_STATUS_E_NULL_VALUE;
  6166. }
  6167. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6168. if (!psoc_spectral) {
  6169. spectral_err("spectral object is null");
  6170. return QDF_STATUS_E_NULL_VALUE;
  6171. }
  6172. return psoc_spectral->wmi_ops.
  6173. extract_pdev_spectral_session_detector_info(
  6174. wmi_handle, evt_buf, det_info, det_info_idx);
  6175. }
  6176. /**
  6177. * target_if_wmi_extract_spectral_caps_fixed_param() - Wrapper function to
  6178. * extract fixed params from Spectral capabilities WMI event
  6179. * @psoc: Pointer to psoc object
  6180. * @evt_buf: Event buffer
  6181. * @param: Spectral capabilities event parameters data structure to be filled
  6182. * by this API
  6183. *
  6184. * Return: QDF_STATUS of operation
  6185. */
  6186. QDF_STATUS
  6187. target_if_wmi_extract_spectral_caps_fixed_param(
  6188. struct wlan_objmgr_psoc *psoc,
  6189. uint8_t *evt_buf,
  6190. struct spectral_capabilities_event_params *param)
  6191. {
  6192. struct target_if_psoc_spectral *psoc_spectral;
  6193. wmi_unified_t wmi_handle;
  6194. if (!psoc) {
  6195. spectral_err("psoc is null");
  6196. return QDF_STATUS_E_NULL_VALUE;
  6197. }
  6198. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6199. if (!wmi_handle) {
  6200. spectral_err("WMI handle is null");
  6201. return QDF_STATUS_E_NULL_VALUE;
  6202. }
  6203. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6204. if (!psoc_spectral) {
  6205. spectral_err("spectral object is null");
  6206. return QDF_STATUS_E_FAILURE;
  6207. }
  6208. return psoc_spectral->wmi_ops.extract_spectral_caps_fixed_param(
  6209. wmi_handle, evt_buf, param);
  6210. }
  6211. /**
  6212. * target_if_wmi_extract_spectral_scan_bw_caps() - Wrapper function to
  6213. * extract bandwidth capabilities from Spectral capabilities WMI event
  6214. * @psoc: Pointer to psoc object
  6215. * @evt_buf: Event buffer
  6216. * @bw_caps: Data structure to be filled by this API after extraction
  6217. *
  6218. * Return: QDF_STATUS of operation
  6219. */
  6220. QDF_STATUS
  6221. target_if_wmi_extract_spectral_scan_bw_caps(
  6222. struct wlan_objmgr_psoc *psoc,
  6223. uint8_t *evt_buf,
  6224. struct spectral_scan_bw_capabilities *bw_caps)
  6225. {
  6226. struct target_if_psoc_spectral *psoc_spectral;
  6227. wmi_unified_t wmi_handle;
  6228. if (!psoc) {
  6229. spectral_err("psoc is null");
  6230. return QDF_STATUS_E_INVAL;
  6231. }
  6232. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6233. if (!wmi_handle) {
  6234. spectral_err("WMI handle is null");
  6235. return QDF_STATUS_E_INVAL;
  6236. }
  6237. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6238. if (!psoc_spectral) {
  6239. spectral_err("spectral object is null");
  6240. return QDF_STATUS_E_FAILURE;
  6241. }
  6242. return psoc_spectral->wmi_ops.extract_spectral_scan_bw_caps(
  6243. wmi_handle, evt_buf, bw_caps);
  6244. }
  6245. /**
  6246. * target_if_wmi_extract_spectral_fft_size_caps() - Wrapper function to
  6247. * extract fft size capabilities from Spectral capabilities WMI event
  6248. * @psoc: Pointer to psoc object
  6249. * @evt_buf: Event buffer
  6250. * @fft_size_caps: Data structure to be filled by this API after extraction
  6251. *
  6252. * Return: QDF_STATUS of operation
  6253. */
  6254. QDF_STATUS
  6255. target_if_wmi_extract_spectral_fft_size_caps(
  6256. struct wlan_objmgr_psoc *psoc,
  6257. uint8_t *evt_buf,
  6258. struct spectral_fft_size_capabilities *fft_size_caps)
  6259. {
  6260. struct target_if_psoc_spectral *psoc_spectral;
  6261. wmi_unified_t wmi_handle;
  6262. if (!psoc) {
  6263. spectral_err("psoc is null");
  6264. return QDF_STATUS_E_INVAL;
  6265. }
  6266. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6267. if (!wmi_handle) {
  6268. spectral_err("WMI handle is null");
  6269. return QDF_STATUS_E_INVAL;
  6270. }
  6271. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6272. if (!psoc_spectral) {
  6273. spectral_err("spectral object is null");
  6274. return QDF_STATUS_E_FAILURE;
  6275. }
  6276. return psoc_spectral->wmi_ops.extract_spectral_fft_size_caps(
  6277. wmi_handle, evt_buf, fft_size_caps);
  6278. }
  6279. #else
  6280. /**
  6281. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  6282. * register WMI event handler
  6283. * @psoc: Pointer to psoc object
  6284. * @event_id: Event id
  6285. * @handler_func: Handler function
  6286. * @rx_ctx: Context of WMI event processing
  6287. *
  6288. * Wrapper function to register WMI event handler
  6289. *
  6290. * Return: 0 for success else failure
  6291. */
  6292. static int
  6293. target_if_spectral_wmi_unified_register_event_handler(
  6294. struct wlan_objmgr_psoc *psoc,
  6295. wmi_conv_event_id event_id,
  6296. wmi_unified_event_handler handler_func,
  6297. uint8_t rx_ctx)
  6298. {
  6299. wmi_unified_t wmi_handle;
  6300. QDF_STATUS ret;
  6301. if (!psoc) {
  6302. spectral_err("psoc is null");
  6303. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6304. }
  6305. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6306. if (!wmi_handle) {
  6307. spectral_err("WMI handle is null");
  6308. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6309. }
  6310. ret = wmi_unified_register_event_handler(wmi_handle, event_id,
  6311. handler_func, rx_ctx);
  6312. return qdf_status_to_os_return(ret);
  6313. }
  6314. /**
  6315. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  6316. * to unregister WMI event handler
  6317. * @psoc: Pointer to psoc object
  6318. * @event_id: Event id
  6319. *
  6320. * Wrapper function to unregister WMI event handler
  6321. *
  6322. * Return: 0 for success else failure
  6323. */
  6324. static int
  6325. target_if_spectral_wmi_unified_unregister_event_handler(
  6326. struct wlan_objmgr_psoc *psoc,
  6327. wmi_conv_event_id event_id)
  6328. {
  6329. wmi_unified_t wmi_handle;
  6330. QDF_STATUS ret;
  6331. if (!psoc) {
  6332. spectral_err("psoc is null");
  6333. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6334. }
  6335. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6336. if (!wmi_handle) {
  6337. spectral_err("WMI handle is null");
  6338. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6339. }
  6340. ret = wmi_unified_unregister_event_handler(wmi_handle, event_id);
  6341. return qdf_status_to_os_return(ret);
  6342. }
  6343. /**
  6344. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  6345. * function to extract fixed parameters from start scan response event
  6346. * @psoc: Pointer to psoc object
  6347. * @evt_buf: Event buffer
  6348. * @param: Start scan response parameters
  6349. *
  6350. * Wrapper function to extract fixed parameters from start scan response event
  6351. *
  6352. * Return: QDF_STATUS
  6353. */
  6354. static QDF_STATUS
  6355. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6356. struct wlan_objmgr_psoc *psoc,
  6357. uint8_t *evt_buf,
  6358. struct spectral_startscan_resp_params *param)
  6359. {
  6360. wmi_unified_t wmi_handle;
  6361. if (!psoc) {
  6362. spectral_err("psoc is null");
  6363. return QDF_STATUS_E_INVAL;
  6364. }
  6365. if (!evt_buf) {
  6366. spectral_err("WMI event buffer is null");
  6367. return QDF_STATUS_E_INVAL;
  6368. }
  6369. if (!param) {
  6370. spectral_err("Spectral startscan response parameters is null");
  6371. return QDF_STATUS_E_INVAL;
  6372. }
  6373. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6374. if (!wmi_handle) {
  6375. spectral_err("WMI handle is null");
  6376. return QDF_STATUS_E_INVAL;
  6377. }
  6378. return wmi_extract_pdev_sscan_fw_cmd_fixed_param(wmi_handle, evt_buf,
  6379. param);
  6380. }
  6381. /**
  6382. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  6383. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  6384. * secondary 80 MHz FFT bins
  6385. * @psoc: Pointer to psoc object
  6386. * @evt_buf: Event buffer
  6387. * @param: FFT bin start and end indices
  6388. *
  6389. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  6390. * and secondary 80 MHz FFT bins
  6391. *
  6392. * Return: QDF_STATUS
  6393. */
  6394. static QDF_STATUS
  6395. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6396. struct wlan_objmgr_psoc *psoc,
  6397. uint8_t *evt_buf,
  6398. struct spectral_fft_bin_markers_160_165mhz *param)
  6399. {
  6400. wmi_unified_t wmi_handle;
  6401. if (!psoc) {
  6402. spectral_err("psoc is null");
  6403. return QDF_STATUS_E_INVAL;
  6404. }
  6405. if (!evt_buf) {
  6406. spectral_err("WMI event buffer is null");
  6407. return QDF_STATUS_E_INVAL;
  6408. }
  6409. if (!param) {
  6410. spectral_err("Spectral FFT bin markers is null");
  6411. return QDF_STATUS_E_INVAL;
  6412. }
  6413. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6414. if (!wmi_handle) {
  6415. spectral_err("WMI handle is null");
  6416. return QDF_STATUS_E_INVAL;
  6417. }
  6418. return wmi_extract_pdev_sscan_fft_bin_index(wmi_handle, evt_buf, param);
  6419. }
  6420. /**
  6421. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  6422. * object from scn handle
  6423. * @scn: scn handle
  6424. *
  6425. * Wrapper function to get psoc object from scn handle
  6426. *
  6427. * Return: Pointer to psoc object
  6428. */
  6429. static struct wlan_objmgr_psoc *
  6430. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  6431. {
  6432. if (!scn) {
  6433. spectral_err("scn is null");
  6434. return NULL;
  6435. }
  6436. return target_if_get_psoc_from_scn_hdl(scn);
  6437. }
  6438. /**
  6439. * target_if_extract_pdev_spectral_session_chan_info() - Wrapper
  6440. * function to extract channel information for a spectral scan session
  6441. * @psoc: Pointer to psoc object
  6442. * @evt_buf: Event buffer
  6443. * @chan_info: Spectral session channel information data structure to be fille
  6444. * by this API
  6445. *
  6446. * Return: QDF_STATUS of operation
  6447. */
  6448. static QDF_STATUS
  6449. target_if_extract_pdev_spectral_session_chan_info(
  6450. struct wlan_objmgr_psoc *psoc,
  6451. void *evt_buf,
  6452. struct spectral_session_chan_info *chan_info)
  6453. {
  6454. wmi_unified_t wmi_handle;
  6455. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6456. if (!wmi_handle) {
  6457. spectral_err("WMI handle is null");
  6458. return QDF_STATUS_E_NULL_VALUE;
  6459. }
  6460. return wmi_extract_pdev_spectral_session_chan_info(
  6461. wmi_handle, evt_buf, chan_info);
  6462. }
  6463. /**
  6464. * target_if_extract_pdev_spectral_session_detector_info() - Wrapper
  6465. * function to extract detector information for a spectral scan session
  6466. * @psoc: Pointer to psoc object
  6467. * @evt_buf: Event buffer
  6468. * @det_info: Spectral session detector information data structure to be filled
  6469. * by this API
  6470. * @det_info_idx: index in the array of spectral scan detector info TLVs
  6471. *
  6472. * Return: QDF_STATUS of operation
  6473. */
  6474. static QDF_STATUS
  6475. target_if_extract_pdev_spectral_session_detector_info(
  6476. struct wlan_objmgr_psoc *psoc, void *evt_buf,
  6477. struct spectral_session_det_info *det_info,
  6478. uint8_t det_info_idx)
  6479. {
  6480. wmi_unified_t wmi_handle;
  6481. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6482. if (!wmi_handle) {
  6483. spectral_err("WMI handle is null");
  6484. return QDF_STATUS_E_NULL_VALUE;
  6485. }
  6486. return wmi_extract_pdev_spectral_session_detector_info(
  6487. wmi_handle, evt_buf, det_info, det_info_idx);
  6488. }
  6489. QDF_STATUS
  6490. target_if_wmi_extract_spectral_caps_fixed_param(
  6491. struct wlan_objmgr_psoc *psoc,
  6492. uint8_t *evt_buf,
  6493. struct spectral_capabilities_event_params *param)
  6494. {
  6495. wmi_unified_t wmi_handle;
  6496. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6497. if (!wmi_handle) {
  6498. spectral_err("WMI handle is null");
  6499. return QDF_STATUS_E_INVAL;
  6500. }
  6501. return wmi_extract_spectral_caps_fixed_param(wmi_handle, evt_buf,
  6502. param);
  6503. }
  6504. QDF_STATUS
  6505. target_if_wmi_extract_spectral_scan_bw_caps(
  6506. struct wlan_objmgr_psoc *psoc,
  6507. uint8_t *evt_buf,
  6508. struct spectral_scan_bw_capabilities *bw_caps)
  6509. {
  6510. wmi_unified_t wmi_handle;
  6511. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6512. if (!wmi_handle) {
  6513. spectral_err("WMI handle is null");
  6514. return QDF_STATUS_E_INVAL;
  6515. }
  6516. return wmi_extract_spectral_scan_bw_caps(wmi_handle, evt_buf, bw_caps);
  6517. }
  6518. QDF_STATUS
  6519. target_if_wmi_extract_spectral_fft_size_caps(
  6520. struct wlan_objmgr_psoc *psoc,
  6521. uint8_t *evt_buf,
  6522. struct spectral_fft_size_capabilities *fft_size_caps)
  6523. {
  6524. wmi_unified_t wmi_handle;
  6525. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6526. if (!wmi_handle) {
  6527. spectral_err("WMI handle is null");
  6528. return QDF_STATUS_E_INVAL;
  6529. }
  6530. return wmi_extract_spectral_fft_size_caps(wmi_handle, evt_buf,
  6531. fft_size_caps);
  6532. }
  6533. #endif
  6534. /**
  6535. * target_if_update_det_info_in_spectral_session() - Update detector
  6536. * information in spectral scan session
  6537. * @spectral: Spectral LMAC object
  6538. * @det_info: Pointer to spectral session detector information
  6539. * @smode: Spectral scan mode
  6540. *
  6541. * Return: QDF_STATUS of operation
  6542. */
  6543. static QDF_STATUS
  6544. target_if_update_det_info_in_spectral_session(
  6545. struct target_if_spectral *spectral,
  6546. const struct spectral_session_det_info *det_info,
  6547. enum spectral_scan_mode smode)
  6548. {
  6549. struct per_session_det_map *det_map;
  6550. struct per_session_dest_det_info *dest_det_info;
  6551. if (!spectral) {
  6552. spectral_err_rl("Spectral LMAC object is null");
  6553. return QDF_STATUS_E_NULL_VALUE;
  6554. }
  6555. qdf_assert_always(det_info->det_id < MAX_DETECTORS_PER_PDEV);
  6556. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  6557. det_map = &spectral->det_map[det_info->det_id];
  6558. dest_det_info = &det_map->dest_det_info[0];
  6559. dest_det_info->start_freq = det_info->start_freq;
  6560. dest_det_info->end_freq = det_info->end_freq;
  6561. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  6562. /* This detector will be used for this smode throughout this session */
  6563. spectral->rparams.detid_mode_table[det_info->det_id] = smode;
  6564. return QDF_STATUS_SUCCESS;
  6565. }
  6566. /**
  6567. * target_if_update_chan_info_in_spectral_session() - Update channel information
  6568. * in spectral scan session
  6569. * @spectral: Spectral LMAC object
  6570. * @chan_info: Pointer to spectral session channel information
  6571. * @smode: Spectral scan mode
  6572. *
  6573. * Return: QDF_STATUS of operation
  6574. */
  6575. static QDF_STATUS
  6576. target_if_update_chan_info_in_spectral_session(
  6577. struct target_if_spectral *spectral,
  6578. const struct spectral_session_chan_info *chan_info,
  6579. enum spectral_scan_mode smode)
  6580. {
  6581. struct per_session_report_info *rpt_info;
  6582. if (!spectral) {
  6583. spectral_err_rl("Spectral LMAC object is null");
  6584. return QDF_STATUS_E_NULL_VALUE;
  6585. }
  6586. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6587. spectral_err_rl("Invalid Spectral scan mode :%u", smode);
  6588. return QDF_STATUS_E_FAILURE;
  6589. }
  6590. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  6591. rpt_info = &spectral->report_info[smode];
  6592. /* Update per-session report info */
  6593. rpt_info->pri20_freq = chan_info->operating_pri20_freq;
  6594. rpt_info->cfreq1 = chan_info->operating_cfreq1;
  6595. rpt_info->cfreq2 = chan_info->operating_cfreq2;
  6596. rpt_info->operating_bw = chan_info->operating_bw;
  6597. rpt_info->sscan_cfreq1 = chan_info->sscan_cfreq1;
  6598. rpt_info->sscan_cfreq2 = chan_info->sscan_cfreq2;
  6599. rpt_info->sscan_bw = chan_info->sscan_bw;
  6600. /* num_spans depends on sscan_bw, update it */
  6601. rpt_info->num_spans = target_if_spectral_get_num_spans(
  6602. spectral->pdev_obj,
  6603. rpt_info->sscan_bw);
  6604. qdf_assert_always(rpt_info->num_spans != INVALID_SPAN_NUM);
  6605. rpt_info->valid = true;
  6606. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  6607. return QDF_STATUS_SUCCESS;
  6608. }
  6609. /**
  6610. * target_if_spectral_fw_param_event_handler() - WMI event handler to
  6611. * process start scan response event
  6612. * @scn: Pointer to scn object
  6613. * @data_buf: Pointer to event buffer
  6614. * @data_len: Length of event buffer
  6615. *
  6616. * Return: 0 for success, else failure
  6617. */
  6618. static int
  6619. target_if_spectral_fw_param_event_handler(ol_scn_t scn, uint8_t *data_buf,
  6620. uint32_t data_len)
  6621. {
  6622. QDF_STATUS status;
  6623. struct wlan_objmgr_psoc *psoc;
  6624. struct wlan_objmgr_pdev *pdev;
  6625. struct wmi_unified *wmi_handle;
  6626. struct spectral_startscan_resp_params event_params = {0};
  6627. struct target_if_psoc_spectral *psoc_spectral;
  6628. struct target_if_spectral *spectral;
  6629. bool is_session_info_expected;
  6630. if (!scn) {
  6631. spectral_err("scn handle is null");
  6632. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6633. }
  6634. if (!data_buf) {
  6635. spectral_err("WMI event buffer null");
  6636. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6637. }
  6638. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  6639. if (!psoc) {
  6640. spectral_err("psoc is null");
  6641. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6642. }
  6643. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  6644. if (!psoc_spectral) {
  6645. spectral_err("spectral object is null");
  6646. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6647. }
  6648. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6649. if (!wmi_handle) {
  6650. spectral_err("WMI handle is null");
  6651. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6652. }
  6653. status = target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  6654. psoc, data_buf, &event_params);
  6655. if (QDF_IS_STATUS_ERROR(status)) {
  6656. spectral_err("unable to extract sscan fw fixed params");
  6657. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6658. }
  6659. if (event_params.smode >= SPECTRAL_SCAN_MODE_MAX ||
  6660. event_params.smode < SPECTRAL_SCAN_MODE_NORMAL) {
  6661. spectral_err("Invalid smode %d", event_params.smode);
  6662. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6663. }
  6664. pdev = wlan_objmgr_get_pdev_by_id(psoc, event_params.pdev_id,
  6665. WLAN_SPECTRAL_ID);
  6666. if (!pdev) {
  6667. spectral_err("pdev is null");
  6668. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6669. }
  6670. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  6671. if (!spectral) {
  6672. spectral_err("spectral object is null");
  6673. status = QDF_STATUS_E_FAILURE;
  6674. goto release_pdev_ref;
  6675. }
  6676. if (event_params.num_fft_bin_index == 1) {
  6677. status =
  6678. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  6679. psoc, data_buf,
  6680. &spectral->rparams.marker[event_params.smode]);
  6681. if (QDF_IS_STATUS_ERROR(status)) {
  6682. spectral_err("unable to extract sscan fw fixed params");
  6683. goto release_pdev_ref;
  6684. }
  6685. } else {
  6686. spectral->rparams.marker[event_params.smode].is_valid = false;
  6687. }
  6688. status = spectral_is_session_info_expected_from_target(
  6689. pdev, &is_session_info_expected);
  6690. if (QDF_IS_STATUS_ERROR(status)) {
  6691. spectral_err("Failed to check if session info is expected");
  6692. goto release_pdev_ref;
  6693. }
  6694. if (is_session_info_expected) {
  6695. struct spectral_session_chan_info chan_info;
  6696. uint8_t det_info_idx = 0;
  6697. status = target_if_extract_pdev_spectral_session_chan_info(
  6698. psoc, data_buf, &chan_info);
  6699. if (QDF_IS_STATUS_ERROR(status)) {
  6700. spectral_err("Unable to extract spectral session channel info");
  6701. goto release_pdev_ref;
  6702. }
  6703. status = target_if_update_chan_info_in_spectral_session(
  6704. spectral, &chan_info, event_params.smode);
  6705. if (QDF_IS_STATUS_ERROR(status)) {
  6706. spectral_err("Unable to update channel info");
  6707. goto release_pdev_ref;
  6708. }
  6709. /* FFT bins info depends upon sscan_bw, update it */
  6710. status = target_if_populate_fft_bins_info(spectral,
  6711. event_params.smode);
  6712. if (QDF_IS_STATUS_ERROR(status)) {
  6713. spectral_err("Failed to populate FFT bins info");
  6714. goto release_pdev_ref;
  6715. }
  6716. /**
  6717. * per-session det info that depends on sscan_bw needs to be
  6718. * updated here
  6719. */
  6720. status = target_if_spectral_populate_session_det_host_info(
  6721. spectral, event_params.smode);
  6722. if (QDF_IS_STATUS_ERROR(status)) {
  6723. spectral_err("Failed to populate per-session det info");
  6724. goto release_pdev_ref;
  6725. }
  6726. for (; det_info_idx < event_params.num_det_info;
  6727. ++det_info_idx) {
  6728. struct spectral_session_det_info det_info;
  6729. status =
  6730. target_if_extract_pdev_spectral_session_detector_info
  6731. (psoc, data_buf, &det_info, det_info_idx);
  6732. if (QDF_IS_STATUS_ERROR(status)) {
  6733. spectral_err("Unable to extract spectral session detector info for %u",
  6734. det_info_idx);
  6735. goto release_pdev_ref;
  6736. }
  6737. status = target_if_update_det_info_in_spectral_session(
  6738. spectral, &det_info,
  6739. event_params.smode);
  6740. if (QDF_IS_STATUS_ERROR(status)) {
  6741. spectral_err("Unable to update detector info");
  6742. goto release_pdev_ref;
  6743. }
  6744. }
  6745. }
  6746. status = QDF_STATUS_SUCCESS;
  6747. release_pdev_ref:
  6748. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  6749. return qdf_status_to_os_return(status);
  6750. }
  6751. /**
  6752. * target_if_spectral_capabilities_event_handler() - Handler for the Spectral
  6753. * Capabilities event
  6754. * @scn: Pointer to scn object
  6755. * @data_buf: Pointer to event buffer
  6756. * @data_len: Length of event buffer
  6757. *
  6758. * Return: 0 for success, else failure
  6759. */
  6760. static int
  6761. target_if_spectral_capabilities_event_handler(ol_scn_t scn, uint8_t *data_buf,
  6762. uint32_t data_len)
  6763. {
  6764. QDF_STATUS status;
  6765. struct wlan_objmgr_psoc *psoc;
  6766. struct wmi_unified *wmi_handle;
  6767. struct spectral_capabilities_event_params event_params = {0};
  6768. struct spectral_scan_bw_capabilities *bw_caps;
  6769. struct spectral_fft_size_capabilities *fft_size_caps;
  6770. if (!scn) {
  6771. spectral_err("scn handle is null");
  6772. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6773. }
  6774. if (!data_buf) {
  6775. spectral_err("WMI event buffer null");
  6776. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  6777. }
  6778. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  6779. if (!psoc) {
  6780. spectral_err("psoc is null");
  6781. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6782. }
  6783. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  6784. if (!wmi_handle) {
  6785. spectral_err("WMI handle is null");
  6786. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6787. }
  6788. status = target_if_wmi_extract_spectral_caps_fixed_param(
  6789. psoc, data_buf, &event_params);
  6790. if (QDF_IS_STATUS_ERROR(status)) {
  6791. spectral_err("Failed to extract fixed parameters");
  6792. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  6793. }
  6794. /* There should be atleast one capability */
  6795. qdf_assert(event_params.num_sscan_bw_caps > 0);
  6796. qdf_assert(event_params.num_fft_size_caps > 0);
  6797. bw_caps = qdf_mem_malloc(
  6798. sizeof(*bw_caps) * event_params.num_sscan_bw_caps);
  6799. if (!bw_caps) {
  6800. spectral_err("memory allocation failed");
  6801. return qdf_status_to_os_return(QDF_STATUS_E_NOMEM);
  6802. }
  6803. status = target_if_wmi_extract_spectral_scan_bw_caps(psoc, data_buf,
  6804. bw_caps);
  6805. if (QDF_IS_STATUS_ERROR(status)) {
  6806. spectral_err("Failed to extract BW caps");
  6807. status = QDF_STATUS_E_FAILURE;
  6808. goto free_bw_caps;
  6809. }
  6810. fft_size_caps = qdf_mem_malloc(
  6811. sizeof(*fft_size_caps) * event_params.num_fft_size_caps);
  6812. if (!fft_size_caps) {
  6813. spectral_err("memory allocation failed");
  6814. status = QDF_STATUS_E_NOMEM;
  6815. goto free_bw_caps;
  6816. }
  6817. status = target_if_wmi_extract_spectral_fft_size_caps(psoc, data_buf,
  6818. fft_size_caps);
  6819. if (QDF_IS_STATUS_ERROR(status)) {
  6820. spectral_err("Failed to extract fft size caps");
  6821. status = QDF_STATUS_E_FAILURE;
  6822. goto free_fft_size_caps;
  6823. }
  6824. status = QDF_STATUS_SUCCESS;
  6825. free_fft_size_caps:
  6826. qdf_mem_free(fft_size_caps);
  6827. free_bw_caps:
  6828. qdf_mem_free(bw_caps);
  6829. return qdf_status_to_os_return(status);
  6830. }
  6831. static QDF_STATUS
  6832. target_if_spectral_register_events(struct wlan_objmgr_psoc *psoc)
  6833. {
  6834. int ret;
  6835. if (!psoc) {
  6836. spectral_err("psoc is null");
  6837. return QDF_STATUS_E_INVAL;
  6838. }
  6839. ret = target_if_spectral_wmi_unified_register_event_handler(
  6840. psoc,
  6841. wmi_pdev_sscan_fw_param_eventid,
  6842. target_if_spectral_fw_param_event_handler,
  6843. WMI_RX_UMAC_CTX);
  6844. if (ret)
  6845. spectral_debug("event handler not supported, ret=%d", ret);
  6846. ret = target_if_spectral_wmi_unified_register_event_handler(
  6847. psoc,
  6848. wmi_spectral_capabilities_eventid,
  6849. target_if_spectral_capabilities_event_handler,
  6850. WMI_RX_UMAC_CTX);
  6851. if (ret) {
  6852. spectral_debug("event handler not supported, ret=%d", ret);
  6853. return QDF_STATUS_E_FAILURE;
  6854. }
  6855. return QDF_STATUS_SUCCESS;
  6856. }
  6857. static QDF_STATUS
  6858. target_if_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
  6859. {
  6860. int ret;
  6861. if (!psoc) {
  6862. spectral_err("psoc is null");
  6863. return QDF_STATUS_E_INVAL;
  6864. }
  6865. target_if_spectral_wmi_unified_unregister_event_handler(
  6866. psoc, wmi_spectral_capabilities_eventid);
  6867. ret = target_if_spectral_wmi_unified_unregister_event_handler(
  6868. psoc, wmi_pdev_sscan_fw_param_eventid);
  6869. if (ret)
  6870. spectral_debug("Unregister WMI event handler failed, ret = %d",
  6871. ret);
  6872. return QDF_STATUS_SUCCESS;
  6873. }
  6874. void
  6875. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  6876. {
  6877. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  6878. target_if_pdev_spectral_init;
  6879. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  6880. target_if_pdev_spectral_deinit;
  6881. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init =
  6882. target_if_psoc_spectral_init;
  6883. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit =
  6884. target_if_psoc_spectral_deinit;
  6885. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  6886. target_if_set_spectral_config;
  6887. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  6888. target_if_get_spectral_config;
  6889. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  6890. target_if_start_spectral_scan;
  6891. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  6892. target_if_stop_spectral_scan;
  6893. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  6894. target_if_is_spectral_active;
  6895. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  6896. target_if_is_spectral_enabled;
  6897. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  6898. target_if_set_debug_level;
  6899. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  6900. target_if_get_debug_level;
  6901. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  6902. target_if_get_spectral_capinfo;
  6903. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  6904. target_if_get_spectral_diagstats;
  6905. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_wmi_ops =
  6906. target_if_register_spectral_wmi_ops;
  6907. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_tgt_ops =
  6908. target_if_register_spectral_tgt_ops;
  6909. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  6910. target_if_register_netlink_cb;
  6911. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  6912. target_if_use_nl_bcast;
  6913. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  6914. target_if_deregister_netlink_cb;
  6915. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  6916. target_if_process_spectral_report;
  6917. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  6918. target_if_spectral_direct_dma_support;
  6919. tx_ops->sptrl_tx_ops.sptrlto_register_events =
  6920. target_if_spectral_register_events;
  6921. tx_ops->sptrl_tx_ops.sptrlto_unregister_events =
  6922. target_if_spectral_unregister_events;
  6923. tx_ops->sptrl_tx_ops.sptrlto_init_pdev_feature_caps =
  6924. target_if_spectral_init_pdev_feature_caps;
  6925. target_if_sptrl_debug_register_tx_ops(tx_ops);
  6926. }
  6927. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  6928. void
  6929. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  6930. uint16_t cw_int, uint32_t dcs_enabled)
  6931. {
  6932. struct spectral_samp_msg *msg = NULL;
  6933. struct target_if_spectral_ops *p_sops = NULL;
  6934. struct target_if_spectral *spectral = NULL;
  6935. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  6936. if (!spectral) {
  6937. spectral_err("SPECTRAL : Module doesn't exist");
  6938. return;
  6939. }
  6940. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  6941. if (!p_sops) {
  6942. spectral_err("p_sops is null");
  6943. return;
  6944. }
  6945. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  6946. spectral->pdev_obj,
  6947. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  6948. SPECTRAL_MSG_BUF_NEW);
  6949. if (msg) {
  6950. msg->int_type = cw_int ?
  6951. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  6952. msg->dcs_enabled = dcs_enabled;
  6953. msg->signature = SPECTRAL_SIGNATURE;
  6954. p_sops->get_mac_address(spectral, msg->macaddr);
  6955. if (spectral->send_phy_data
  6956. (pdev,
  6957. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  6958. spectral->spectral_sent_msg++;
  6959. }
  6960. }
  6961. qdf_export_symbol(target_if_spectral_send_intf_found_msg);
  6962. QDF_STATUS
  6963. target_if_spectral_is_finite_scan(struct target_if_spectral *spectral,
  6964. enum spectral_scan_mode smode,
  6965. bool *finite_spectral_scan)
  6966. {
  6967. struct target_if_finite_spectral_scan_params *finite_scan;
  6968. if (!spectral) {
  6969. spectral_err_rl("target if spectral object is null");
  6970. return QDF_STATUS_E_INVAL;
  6971. }
  6972. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6973. spectral_err_rl("invalid spectral mode %d", smode);
  6974. return QDF_STATUS_E_INVAL;
  6975. }
  6976. if (!finite_spectral_scan) {
  6977. spectral_err_rl("Invalid pointer");
  6978. return QDF_STATUS_E_INVAL;
  6979. }
  6980. finite_scan = &spectral->finite_scan[smode];
  6981. *finite_spectral_scan = finite_scan->finite_spectral_scan;
  6982. return QDF_STATUS_SUCCESS;
  6983. }
  6984. QDF_STATUS
  6985. target_if_spectral_finite_scan_update(struct target_if_spectral *spectral,
  6986. enum spectral_scan_mode smode)
  6987. {
  6988. struct target_if_finite_spectral_scan_params *finite_scan;
  6989. if (!spectral) {
  6990. spectral_err_rl("target if spectral object is null");
  6991. return QDF_STATUS_E_INVAL;
  6992. }
  6993. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  6994. spectral_err_rl("Invalid Spectral mode");
  6995. return QDF_STATUS_E_INVAL;
  6996. }
  6997. finite_scan = &spectral->finite_scan[smode];
  6998. if (!finite_scan->num_reports_expected) {
  6999. spectral_err_rl("Error, No reports expected");
  7000. return QDF_STATUS_E_FAILURE;
  7001. }
  7002. finite_scan->num_reports_expected--;
  7003. if (!finite_scan->num_reports_expected) {
  7004. QDF_STATUS status;
  7005. enum spectral_cp_error_code err;
  7006. /* received expected number of reports from target, stop scan */
  7007. status = target_if_stop_spectral_scan(spectral->pdev_obj, smode,
  7008. &err);
  7009. if (QDF_IS_STATUS_ERROR(status)) {
  7010. spectral_err_rl("Failed to stop finite Spectral scan");
  7011. return QDF_STATUS_E_FAILURE;
  7012. }
  7013. finite_scan->finite_spectral_scan = false;
  7014. }
  7015. return QDF_STATUS_SUCCESS;
  7016. }