target_if_spectral.c 205 KB

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