target_if_spectral.c 216 KB

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