target_if_spectral.c 210 KB

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