target_if_spectral.c 196 KB

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