target_if_spectral.c 152 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578
  1. /*
  2. * Copyright (c) 2011,2017-2020 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. static void target_if_spectral_get_firstvdev_pdev(struct wlan_objmgr_pdev *pdev,
  44. void *obj, void *arg)
  45. {
  46. struct wlan_objmgr_vdev *vdev = obj;
  47. struct wlan_objmgr_vdev **first_vdev = arg;
  48. if (!(*first_vdev))
  49. *first_vdev = vdev;
  50. }
  51. struct wlan_objmgr_vdev *
  52. target_if_spectral_get_vdev(struct target_if_spectral *spectral)
  53. {
  54. struct wlan_objmgr_pdev *pdev = NULL;
  55. struct wlan_objmgr_vdev *first_vdev = NULL;
  56. qdf_assert_always(spectral);
  57. pdev = spectral->pdev_obj;
  58. qdf_assert_always(pdev);
  59. if (wlan_objmgr_pdev_try_get_ref(pdev, WLAN_SPECTRAL_ID) !=
  60. QDF_STATUS_SUCCESS) {
  61. spectral_err("Unable to get pdev reference.");
  62. return NULL;
  63. }
  64. wlan_objmgr_pdev_iterate_obj_list(pdev, WLAN_VDEV_OP,
  65. target_if_spectral_get_firstvdev_pdev,
  66. &first_vdev, 0, WLAN_SPECTRAL_ID);
  67. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  68. if (!first_vdev)
  69. return NULL;
  70. if (wlan_objmgr_vdev_try_get_ref(first_vdev, WLAN_SPECTRAL_ID) !=
  71. QDF_STATUS_SUCCESS)
  72. first_vdev = NULL;
  73. return first_vdev;
  74. }
  75. /**
  76. * target_if_send_vdev_spectral_configure_cmd() - Send WMI command to configure
  77. * spectral parameters
  78. * @spectral: Pointer to Spectral target_if internal private data
  79. * @smode: Spectral scan mode
  80. * @param: Pointer to spectral_config giving the Spectral configuration
  81. *
  82. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  83. */
  84. static int
  85. target_if_send_vdev_spectral_configure_cmd(struct target_if_spectral *spectral,
  86. enum spectral_scan_mode smode,
  87. struct spectral_config *param)
  88. {
  89. struct vdev_spectral_configure_params sparam;
  90. struct wlan_objmgr_psoc *psoc;
  91. struct wlan_objmgr_pdev *pdev = NULL;
  92. struct wlan_objmgr_vdev *vdev = NULL;
  93. struct target_if_psoc_spectral *psoc_spectral;
  94. qdf_assert_always(spectral && param);
  95. pdev = spectral->pdev_obj;
  96. qdf_assert_always(pdev);
  97. psoc = wlan_pdev_get_psoc(pdev);
  98. if (!psoc) {
  99. spectral_err("psoc is null");
  100. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  101. }
  102. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  103. if (!psoc_spectral) {
  104. spectral_err("psoc spectral object is null");
  105. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  106. }
  107. vdev = target_if_spectral_get_vdev(spectral);
  108. if (!vdev)
  109. return QDF_STATUS_E_NOENT;
  110. qdf_mem_zero(&sparam, sizeof(sparam));
  111. sparam.vdev_id = wlan_vdev_get_id(vdev);
  112. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  113. sparam.count = param->ss_count;
  114. sparam.period = param->ss_period;
  115. sparam.spectral_pri = param->ss_spectral_pri;
  116. sparam.fft_size = param->ss_fft_size;
  117. sparam.gc_enable = param->ss_gc_ena;
  118. sparam.restart_enable = param->ss_restart_ena;
  119. sparam.noise_floor_ref = param->ss_noise_floor_ref;
  120. sparam.init_delay = param->ss_init_delay;
  121. sparam.nb_tone_thr = param->ss_nb_tone_thr;
  122. sparam.str_bin_thr = param->ss_str_bin_thr;
  123. sparam.wb_rpt_mode = param->ss_wb_rpt_mode;
  124. sparam.rssi_rpt_mode = param->ss_rssi_rpt_mode;
  125. sparam.rssi_thr = param->ss_rssi_thr;
  126. sparam.pwr_format = param->ss_pwr_format;
  127. sparam.rpt_mode = param->ss_rpt_mode;
  128. sparam.bin_scale = param->ss_bin_scale;
  129. sparam.dbm_adj = param->ss_dbm_adj;
  130. sparam.chn_mask = param->ss_chn_mask;
  131. sparam.mode = smode;
  132. sparam.center_freq1 = param->ss_frequency.cfreq1;
  133. sparam.center_freq2 = param->ss_frequency.cfreq2;
  134. sparam.chan_width = spectral->ch_width[smode];
  135. return psoc_spectral->wmi_ops.wmi_spectral_configure_cmd_send(
  136. GET_WMI_HDL_FROM_PDEV(pdev), &sparam);
  137. }
  138. /**
  139. * target_if_send_vdev_spectral_enable_cmd() - Send WMI command to
  140. * enable/disable Spectral
  141. * @spectral: Pointer to Spectral target_if internal private data
  142. * @smode: Spectral scan mode
  143. * @is_spectral_active_valid: Flag to indicate if spectral activate (trigger) is
  144. * valid
  145. * @is_spectral_active: Value of spectral activate
  146. * @is_spectral_enabled_valid: Flag to indicate if spectral enable is valid
  147. * @is_spectral_enabled: Value of spectral enable
  148. *
  149. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  150. */
  151. static int
  152. target_if_send_vdev_spectral_enable_cmd(struct target_if_spectral *spectral,
  153. enum spectral_scan_mode smode,
  154. uint8_t is_spectral_active_valid,
  155. uint8_t is_spectral_active,
  156. uint8_t is_spectral_enabled_valid,
  157. uint8_t is_spectral_enabled)
  158. {
  159. struct vdev_spectral_enable_params param;
  160. struct wlan_objmgr_psoc *psoc;
  161. struct wlan_objmgr_pdev *pdev = NULL;
  162. struct wlan_objmgr_vdev *vdev = NULL;
  163. struct target_if_psoc_spectral *psoc_spectral;
  164. qdf_assert_always(spectral);
  165. pdev = spectral->pdev_obj;
  166. qdf_assert_always(pdev);
  167. psoc = wlan_pdev_get_psoc(pdev);
  168. if (!psoc) {
  169. spectral_err("psoc is null");
  170. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  171. }
  172. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  173. if (!psoc_spectral) {
  174. spectral_err("psoc spectral object is null");
  175. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  176. }
  177. vdev = target_if_spectral_get_vdev(spectral);
  178. if (!vdev)
  179. return QDF_STATUS_E_NOENT;
  180. qdf_mem_zero(&param, sizeof(param));
  181. param.vdev_id = wlan_vdev_get_id(vdev);
  182. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  183. param.active_valid = is_spectral_active_valid;
  184. param.enabled_valid = is_spectral_enabled_valid;
  185. param.active = is_spectral_active;
  186. param.enabled = is_spectral_enabled;
  187. param.mode = smode;
  188. return psoc_spectral->wmi_ops.wmi_spectral_enable_cmd_send(
  189. GET_WMI_HDL_FROM_PDEV(pdev), &param);
  190. }
  191. /**
  192. * target_if_spectral_info_init_defaults() - Helper function to load defaults
  193. * for Spectral information (parameters and state) into cache.
  194. * @spectral: Pointer to Spectral target_if internal private data
  195. * @smode: Spectral scan mode
  196. *
  197. * It is assumed that the caller has obtained the requisite lock if applicable.
  198. * Note that this is currently treated as a temporary function. Ideally, we
  199. * would like to get defaults from the firmware.
  200. *
  201. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  202. */
  203. static QDF_STATUS
  204. target_if_spectral_info_init_defaults(struct target_if_spectral *spectral,
  205. enum spectral_scan_mode smode)
  206. {
  207. struct target_if_spectral_param_state_info *info;
  208. struct wlan_objmgr_vdev *vdev = NULL;
  209. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  210. spectral_err("Invalid Spectral mode %u", smode);
  211. return QDF_STATUS_E_FAILURE;
  212. }
  213. info = &spectral->param_info[smode];
  214. /* State */
  215. info->osps_cache.osc_spectral_active = SPECTRAL_SCAN_ACTIVE_DEFAULT;
  216. info->osps_cache.osc_spectral_enabled = SPECTRAL_SCAN_ENABLE_DEFAULT;
  217. /* Parameters */
  218. info->osps_cache.osc_params.ss_count = SPECTRAL_SCAN_COUNT_DEFAULT;
  219. if (spectral->spectral_gen == SPECTRAL_GEN3)
  220. info->osps_cache.osc_params.ss_period =
  221. SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT;
  222. else
  223. info->osps_cache.osc_params.ss_period =
  224. SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT;
  225. info->osps_cache.osc_params.ss_spectral_pri =
  226. SPECTRAL_SCAN_PRIORITY_DEFAULT;
  227. info->osps_cache.osc_params.ss_fft_size =
  228. SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  229. info->osps_cache.osc_params.ss_gc_ena = SPECTRAL_SCAN_GC_ENA_DEFAULT;
  230. info->osps_cache.osc_params.ss_restart_ena =
  231. SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  232. info->osps_cache.osc_params.ss_noise_floor_ref =
  233. SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  234. info->osps_cache.osc_params.ss_init_delay =
  235. SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  236. info->osps_cache.osc_params.ss_nb_tone_thr =
  237. SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  238. info->osps_cache.osc_params.ss_str_bin_thr =
  239. SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  240. info->osps_cache.osc_params.ss_wb_rpt_mode =
  241. SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  242. info->osps_cache.osc_params.ss_rssi_rpt_mode =
  243. SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  244. info->osps_cache.osc_params.ss_rssi_thr =
  245. SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  246. info->osps_cache.osc_params.ss_pwr_format =
  247. SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  248. info->osps_cache.osc_params.ss_rpt_mode =
  249. SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  250. info->osps_cache.osc_params.ss_bin_scale =
  251. SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  252. info->osps_cache.osc_params.ss_dbm_adj = SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  253. vdev = target_if_spectral_get_vdev(spectral);
  254. if (!vdev)
  255. return QDF_STATUS_E_NOENT;
  256. info->osps_cache.osc_params.ss_chn_mask =
  257. wlan_vdev_mlme_get_rxchainmask(vdev);
  258. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  259. info->osps_cache.osc_params.ss_short_report =
  260. SPECTRAL_SCAN_SHORT_REPORT_DEFAULT;
  261. info->osps_cache.osc_params.ss_fft_period =
  262. SPECTRAL_SCAN_FFT_PERIOD_DEFAULT;
  263. info->osps_cache.osc_params.ss_frequency.cfreq1 =
  264. SPECTRAL_SCAN_FREQUENCY_DEFAULT;
  265. info->osps_cache.osc_params.ss_frequency.cfreq2 =
  266. SPECTRAL_SCAN_FREQUENCY_DEFAULT;
  267. /* The cache is now valid */
  268. info->osps_cache.osc_is_valid = 1;
  269. return QDF_STATUS_SUCCESS;
  270. }
  271. /**
  272. * target_if_log_read_spectral_active() - Helper function to log whether
  273. * spectral is active after reading cache
  274. * @function_name: Function name
  275. * @output: whether spectral is active or not
  276. *
  277. * Helper function to log whether spectral is active after reading cache
  278. *
  279. * Return: none
  280. */
  281. static void
  282. target_if_log_read_spectral_active(
  283. const char *function_name,
  284. unsigned char output)
  285. {
  286. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE. Returning val=%u",
  287. function_name, output);
  288. }
  289. /**
  290. * target_if_log_read_spectral_enabled() - Helper function to log whether
  291. * spectral is enabled after reading cache
  292. * @function_name: Function name
  293. * @output: whether spectral is enabled or not
  294. *
  295. * Helper function to log whether spectral is enabled after reading cache
  296. *
  297. * Return: none
  298. */
  299. static void
  300. target_if_log_read_spectral_enabled(
  301. const char *function_name,
  302. unsigned char output)
  303. {
  304. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED. Returning val=%u",
  305. function_name, output);
  306. }
  307. /**
  308. * target_if_log_read_spectral_enabled() - Helper function to log spectral
  309. * parameters after reading cache
  310. * @function_name: Function name
  311. * @pparam: Spectral parameters
  312. *
  313. * Helper function to log spectral parameters after reading cache
  314. *
  315. * Return: none
  316. */
  317. static void
  318. target_if_log_read_spectral_params(
  319. const char *function_name,
  320. struct spectral_config *pparam)
  321. {
  322. 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",
  323. function_name,
  324. pparam->ss_count,
  325. pparam->ss_period,
  326. pparam->ss_spectral_pri,
  327. pparam->ss_fft_size,
  328. pparam->ss_gc_ena,
  329. pparam->ss_restart_ena,
  330. (int8_t)pparam->ss_noise_floor_ref,
  331. pparam->ss_init_delay,
  332. pparam->ss_nb_tone_thr,
  333. pparam->ss_str_bin_thr,
  334. pparam->ss_wb_rpt_mode,
  335. pparam->ss_rssi_rpt_mode,
  336. (int8_t)pparam->ss_rssi_thr,
  337. pparam->ss_pwr_format,
  338. pparam->ss_rpt_mode,
  339. pparam->ss_bin_scale,
  340. pparam->ss_dbm_adj,
  341. pparam->ss_chn_mask,
  342. pparam->ss_frequency.cfreq1,
  343. pparam->ss_frequency.cfreq2);
  344. }
  345. /**
  346. * target_if_log_read_spectral_active_catch_validate() - Helper function to
  347. * log whether spectral is active after intializing the cache
  348. * @function_name: Function name
  349. * @output: whether spectral is active or not
  350. *
  351. * Helper function to log whether spectral is active after intializing cache
  352. *
  353. * Return: none
  354. */
  355. static void
  356. target_if_log_read_spectral_active_catch_validate(
  357. const char *function_name,
  358. unsigned char output)
  359. {
  360. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE on initial cache validation\nReturning val=%u",
  361. function_name, output);
  362. }
  363. /**
  364. * target_if_log_read_spectral_enabled_catch_validate() - Helper function to
  365. * log whether spectral is enabled after intializing the cache
  366. * @function_name: Function name
  367. * @output: whether spectral is enabled or not
  368. *
  369. * Helper function to log whether spectral is enabled after intializing cache
  370. *
  371. * Return: none
  372. */
  373. static void
  374. target_if_log_read_spectral_enabled_catch_validate(
  375. const char *function_name,
  376. unsigned char output)
  377. {
  378. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED on initial cache validation\nReturning val=%u\n",
  379. function_name, output);
  380. }
  381. /**
  382. * target_if_log_read_spectral_params_catch_validate() - Helper function to
  383. * log spectral parameters after intializing the cache
  384. * @function_name: Function name
  385. * @pparam: Spectral parameters
  386. *
  387. * Helper function to log spectral parameters after intializing the cache
  388. *
  389. * Return: none
  390. */
  391. static void
  392. target_if_log_read_spectral_params_catch_validate(
  393. const char *function_name,
  394. struct spectral_config *pparam)
  395. {
  396. 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",
  397. function_name,
  398. pparam->ss_count,
  399. pparam->ss_period,
  400. pparam->ss_spectral_pri,
  401. pparam->ss_fft_size,
  402. pparam->ss_gc_ena,
  403. pparam->ss_restart_ena,
  404. (int8_t)pparam->ss_noise_floor_ref,
  405. pparam->ss_init_delay,
  406. pparam->ss_nb_tone_thr,
  407. pparam->ss_str_bin_thr,
  408. pparam->ss_wb_rpt_mode,
  409. pparam->ss_rssi_rpt_mode,
  410. (int8_t)pparam->ss_rssi_thr,
  411. pparam->ss_pwr_format,
  412. pparam->ss_rpt_mode,
  413. pparam->ss_bin_scale,
  414. pparam->ss_dbm_adj, pparam->ss_chn_mask);
  415. }
  416. /**
  417. * target_if_spectral_info_read() - Read spectral information from the cache.
  418. * @spectral: Pointer to Spectral target_if internal private data
  419. * @smode: Spectral scan mode
  420. * @specifier: target_if_spectral_info enumeration specifying which
  421. * information is required
  422. * @output: Void output pointer into which the information will be read
  423. * @output_len: size of object pointed to by output pointer
  424. *
  425. * Read spectral parameters or the desired state information from the cache.
  426. *
  427. * Return: 0 on success, negative error code on failure
  428. */
  429. static int
  430. target_if_spectral_info_read(
  431. struct target_if_spectral *spectral,
  432. enum spectral_scan_mode smode,
  433. enum target_if_spectral_info specifier,
  434. void *output, int output_len)
  435. {
  436. /*
  437. * Note: This function is designed to be able to accommodate
  438. * WMI reads for defaults, non-cacheable information, etc
  439. * if required.
  440. */
  441. struct target_if_spectral_param_state_info *info;
  442. int is_cacheable = 0;
  443. int init_def_retval = 0;
  444. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  445. spectral_err("Invalid Spectral mode %u", smode);
  446. return -EINVAL;
  447. }
  448. info = &spectral->param_info[smode];
  449. if (!output)
  450. return -EINVAL;
  451. switch (specifier) {
  452. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  453. if (output_len != sizeof(info->osps_cache.osc_spectral_active))
  454. return -EINVAL;
  455. is_cacheable = 1;
  456. break;
  457. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  458. if (output_len != sizeof(info->osps_cache.osc_spectral_enabled))
  459. return -EINVAL;
  460. is_cacheable = 1;
  461. break;
  462. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  463. if (output_len != sizeof(info->osps_cache.osc_params))
  464. return -EINVAL;
  465. is_cacheable = 1;
  466. break;
  467. default:
  468. spectral_err("Unknown target_if_spectral_info specifier");
  469. return -EINVAL;
  470. }
  471. qdf_spin_lock(&info->osps_lock);
  472. if (is_cacheable) {
  473. if (info->osps_cache.osc_is_valid) {
  474. switch (specifier) {
  475. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  476. qdf_mem_copy(
  477. output,
  478. &info->osps_cache.osc_spectral_active,
  479. sizeof(info->osps_cache.osc_spectral_active));
  480. target_if_log_read_spectral_active(
  481. __func__,
  482. *((unsigned char *)output));
  483. break;
  484. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  485. qdf_mem_copy(
  486. output,
  487. &info->osps_cache.osc_spectral_enabled,
  488. sizeof(
  489. info->osps_cache.osc_spectral_enabled));
  490. target_if_log_read_spectral_enabled(
  491. __func__,
  492. *((unsigned char *)output));
  493. break;
  494. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  495. qdf_mem_copy(
  496. output,
  497. &info->osps_cache.osc_params,
  498. sizeof(info->osps_cache.osc_params));
  499. target_if_log_read_spectral_params(
  500. __func__,
  501. (struct spectral_config *)output);
  502. break;
  503. default:
  504. /* We can't reach this point */
  505. break;
  506. }
  507. qdf_spin_unlock(&info->osps_lock);
  508. return 0;
  509. }
  510. }
  511. /* Cache is invalid */
  512. /*
  513. * If WMI Reads are implemented to fetch defaults/non-cacheable info,
  514. * then the below implementation will change
  515. */
  516. init_def_retval =
  517. target_if_spectral_info_init_defaults(spectral, smode);
  518. if (init_def_retval != QDF_STATUS_SUCCESS) {
  519. qdf_spin_unlock(&info->osps_lock);
  520. if (init_def_retval == QDF_STATUS_E_NOENT)
  521. return -ENOENT;
  522. else
  523. return -EINVAL;
  524. }
  525. /* target_if_spectral_info_init_defaults() has set cache to valid */
  526. switch (specifier) {
  527. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  528. qdf_mem_copy(output,
  529. &info->osps_cache.osc_spectral_active,
  530. sizeof(info->osps_cache.osc_spectral_active));
  531. target_if_log_read_spectral_active_catch_validate(
  532. __func__,
  533. *((unsigned char *)output));
  534. break;
  535. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  536. qdf_mem_copy(output,
  537. &info->osps_cache.osc_spectral_enabled,
  538. sizeof(info->osps_cache.osc_spectral_enabled));
  539. target_if_log_read_spectral_enabled_catch_validate(
  540. __func__,
  541. *((unsigned char *)output));
  542. break;
  543. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  544. qdf_mem_copy(output,
  545. &info->osps_cache.osc_params,
  546. sizeof(info->osps_cache.osc_params));
  547. target_if_log_read_spectral_params_catch_validate(
  548. __func__,
  549. (struct spectral_config *)output);
  550. break;
  551. default:
  552. /* We can't reach this point */
  553. break;
  554. }
  555. qdf_spin_unlock(&info->osps_lock);
  556. return 0;
  557. }
  558. /**
  559. * target_if_log_write_spectral_active() - Helper function to log inputs and
  560. * return value of call to configure the Spectral 'active' configuration,
  561. * TARGET_IF_SPECTRAL_INFO_ACTIVE into firmware
  562. * @function_name: Function name in which this is called
  563. * @pval: whether spectral is active or not
  564. * @ret: return value of the firmware write function
  565. *
  566. * Return: none
  567. */
  568. static void
  569. target_if_log_write_spectral_active(
  570. const char *function_name,
  571. uint8_t pval,
  572. int ret)
  573. {
  574. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE with val=%u status=%d",
  575. function_name, pval, ret);
  576. }
  577. /**
  578. * target_if_log_write_spectral_enabled() - Helper function to log inputs and
  579. * return value of call to configure the Spectral 'enabled' configuration,
  580. * TARGET_IF_SPECTRAL_INFO_ENABLED into firmware
  581. * @function_name: Function name in which this is called
  582. * @pval: whether spectral is enabled or not
  583. * @ret: return value of the firmware write function
  584. *
  585. * Return: none
  586. */
  587. static void
  588. target_if_log_write_spectral_enabled(
  589. const char *function_name,
  590. uint8_t pval,
  591. int ret)
  592. {
  593. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED with val=%u status=%d",
  594. function_name, pval, ret);
  595. }
  596. /**
  597. * target_if_log_write_spectral_params() - Helper function to log inputs and
  598. * return value of call to configure Spectral parameters,
  599. * TARGET_IF_SPECTRAL_INFO_PARAMS into firmware
  600. * @param: Spectral parameters
  601. * @function_name: Function name in which this is called
  602. * @ret: return value of the firmware write function
  603. *
  604. * Return: none
  605. */
  606. static void
  607. target_if_log_write_spectral_params(
  608. struct spectral_config *param,
  609. const char *function_name,
  610. int ret)
  611. {
  612. 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",
  613. function_name,
  614. param->ss_count,
  615. param->ss_period,
  616. param->ss_spectral_pri,
  617. param->ss_fft_size,
  618. param->ss_gc_ena,
  619. param->ss_restart_ena,
  620. (int8_t)param->ss_noise_floor_ref,
  621. param->ss_init_delay,
  622. param->ss_nb_tone_thr,
  623. param->ss_str_bin_thr,
  624. param->ss_wb_rpt_mode,
  625. param->ss_rssi_rpt_mode,
  626. (int8_t)param->ss_rssi_thr,
  627. param->ss_pwr_format,
  628. param->ss_rpt_mode,
  629. param->ss_bin_scale,
  630. param->ss_dbm_adj,
  631. param->ss_chn_mask,
  632. param->ss_frequency.cfreq1,
  633. param->ss_frequency.cfreq2,
  634. ret);
  635. }
  636. /**
  637. * target_if_spectral_info_write() - Write Spectral information to the
  638. * firmware, and update cache
  639. * @spectral: Pointer to Spectral target_if internal private data
  640. * @smode: Spectral scan mode
  641. * @specifier: target_if_spectral_info enumeration specifying which
  642. * information is involved
  643. * @input: void input pointer containing the information to be written
  644. * @input_len: size of object pointed to by input pointer
  645. *
  646. * Write Spectral parameters or the desired state information to
  647. * the firmware, and update cache
  648. *
  649. * Return: 0 on success, negative error code on failure
  650. */
  651. static int
  652. target_if_spectral_info_write(
  653. struct target_if_spectral *spectral,
  654. enum spectral_scan_mode smode,
  655. enum target_if_spectral_info specifier,
  656. void *input, int input_len)
  657. {
  658. struct target_if_spectral_param_state_info *info;
  659. int ret;
  660. uint8_t *pval = NULL;
  661. struct spectral_config *param = NULL;
  662. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  663. spectral_err("Invalid Spectral mode %u", smode);
  664. return -EINVAL;
  665. }
  666. info = &spectral->param_info[smode];
  667. if (!input)
  668. return -EINVAL;
  669. switch (specifier) {
  670. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  671. if (input_len != sizeof(info->osps_cache.osc_spectral_active))
  672. return -EINVAL;
  673. pval = (uint8_t *)input;
  674. qdf_spin_lock(&info->osps_lock);
  675. ret = target_if_send_vdev_spectral_enable_cmd(spectral, smode,
  676. 1, *pval, 0, 0);
  677. target_if_log_write_spectral_active(
  678. __func__,
  679. *pval,
  680. ret);
  681. if (ret < 0) {
  682. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  683. ret);
  684. qdf_spin_unlock(&info->osps_lock);
  685. return ret;
  686. }
  687. info->osps_cache.osc_spectral_active = *pval;
  688. /* The cache is now valid */
  689. info->osps_cache.osc_is_valid = 1;
  690. qdf_spin_unlock(&info->osps_lock);
  691. break;
  692. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  693. if (input_len != sizeof(info->osps_cache.osc_spectral_enabled))
  694. return -EINVAL;
  695. pval = (uint8_t *)input;
  696. qdf_spin_lock(&info->osps_lock);
  697. ret = target_if_send_vdev_spectral_enable_cmd(spectral, smode,
  698. 0, 0, 1, *pval);
  699. target_if_log_write_spectral_enabled(
  700. __func__,
  701. *pval,
  702. ret);
  703. if (ret < 0) {
  704. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  705. ret);
  706. qdf_spin_unlock(&info->osps_lock);
  707. return ret;
  708. }
  709. info->osps_cache.osc_spectral_enabled = *pval;
  710. /* The cache is now valid */
  711. info->osps_cache.osc_is_valid = 1;
  712. qdf_spin_unlock(&info->osps_lock);
  713. break;
  714. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  715. if (input_len != sizeof(info->osps_cache.osc_params))
  716. return -EINVAL;
  717. param = (struct spectral_config *)input;
  718. qdf_spin_lock(&info->osps_lock);
  719. ret = target_if_send_vdev_spectral_configure_cmd(spectral,
  720. smode, param);
  721. target_if_log_write_spectral_params(
  722. param,
  723. __func__,
  724. ret);
  725. if (ret < 0) {
  726. spectral_err("target_if_send_vdev_spectral_configure_cmd failed with error=%d",
  727. ret);
  728. qdf_spin_unlock(&info->osps_lock);
  729. return ret;
  730. }
  731. qdf_mem_copy(&info->osps_cache.osc_params,
  732. param, sizeof(info->osps_cache.osc_params));
  733. /* The cache is now valid */
  734. info->osps_cache.osc_is_valid = 1;
  735. qdf_spin_unlock(&info->osps_lock);
  736. break;
  737. default:
  738. spectral_err("Unknown target_if_spectral_info specifier");
  739. return -EINVAL;
  740. }
  741. return 0;
  742. }
  743. /**
  744. * target_if_spectral_get_tsf64() - Function to get the TSF value
  745. * @arg: Pointer to handle for Spectral target_if internal private data
  746. *
  747. * Get the last TSF received in WMI buffer
  748. *
  749. * Return: TSF value
  750. */
  751. static uint64_t
  752. target_if_spectral_get_tsf64(void *arg)
  753. {
  754. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  755. return spectral->tsf64;
  756. }
  757. /**
  758. * target_if_spectral_get_capability() - Function to get whether a
  759. * given Spectral hardware capability is available
  760. * @arg: Pointer to handle for Spectral target_if internal private data
  761. * @type: Spectral hardware capability type
  762. *
  763. * Get whether a given Spectral hardware capability is available
  764. *
  765. * Return: True if the capability is available, false if the capability is not
  766. * available
  767. */
  768. uint32_t
  769. target_if_spectral_get_capability(void *arg, enum spectral_capability_type type)
  770. {
  771. int status = STATUS_FAIL;
  772. switch (type) {
  773. case SPECTRAL_CAP_PHYDIAG:
  774. case SPECTRAL_CAP_RADAR:
  775. case SPECTRAL_CAP_SPECTRAL_SCAN:
  776. case SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN:
  777. status = STATUS_PASS;
  778. break;
  779. default:
  780. status = STATUS_FAIL;
  781. }
  782. return status;
  783. }
  784. /**
  785. * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
  786. * @arg: Pointer to handle for Spectral target_if internal private data
  787. * @rxfilter: Rx filter to be used
  788. *
  789. * Note: This is only a placeholder function. It is not currently required since
  790. * FW should be taking care of setting the required filters.
  791. *
  792. * Return: 0
  793. */
  794. uint32_t
  795. target_if_spectral_set_rxfilter(void *arg, int rxfilter)
  796. {
  797. /*
  798. * Will not be required since enabling of spectral in firmware
  799. * will take care of this
  800. */
  801. return 0;
  802. }
  803. /**
  804. * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
  805. * @arg: Pointer to handle for Spectral target_if internal private data
  806. *
  807. * Note: This is only a placeholder function. It is not currently required since
  808. * FW should be taking care of setting the required filters.
  809. *
  810. * Return: 0
  811. */
  812. uint32_t
  813. target_if_spectral_get_rxfilter(void *arg)
  814. {
  815. /*
  816. * Will not be required since enabling of spectral in firmware
  817. * will take care of this
  818. */
  819. return 0;
  820. }
  821. /**
  822. * target_if_sops_is_spectral_active() - Get whether Spectral is active
  823. * @arg: Pointer to handle for Spectral target_if internal private data
  824. * @smode: Spectral scan mode
  825. *
  826. * Function to check whether Spectral is active
  827. *
  828. * Return: True if Spectral is active, false if Spectral is not active
  829. */
  830. uint32_t
  831. target_if_sops_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  832. {
  833. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  834. uint8_t val = 0;
  835. int ret;
  836. ret = target_if_spectral_info_read(
  837. spectral,
  838. smode,
  839. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  840. &val, sizeof(val));
  841. if (ret != 0) {
  842. /*
  843. * Could not determine if Spectral is active.
  844. * Return false as a safe value.
  845. * XXX: Consider changing the function prototype
  846. * to be able to indicate failure to fetch value.
  847. */
  848. return 0;
  849. }
  850. return val;
  851. }
  852. /**
  853. * target_if_sops_is_spectral_enabled() - Get whether Spectral is enabled
  854. * @arg: Pointer to handle for Spectral target_if internal private data
  855. * @smode: Spectral scan mode
  856. *
  857. * Function to check whether Spectral is enabled
  858. *
  859. * Return: True if Spectral is enabled, false if Spectral is not enabled
  860. */
  861. uint32_t
  862. target_if_sops_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  863. {
  864. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  865. uint8_t val = 0;
  866. int ret;
  867. ret = target_if_spectral_info_read(
  868. spectral,
  869. smode,
  870. TARGET_IF_SPECTRAL_INFO_ENABLED,
  871. &val, sizeof(val));
  872. if (ret != 0) {
  873. /*
  874. * Could not determine if Spectral is enabled.
  875. * Return false as a safe value.
  876. * XXX: Consider changing the function prototype
  877. * to be able to indicate failure to fetch value.
  878. */
  879. return 0;
  880. }
  881. return val;
  882. }
  883. /**
  884. * target_if_sops_start_spectral_scan() - Start Spectral scan
  885. * @arg: Pointer to handle for Spectral target_if internal private data
  886. * @smode: Spectral scan mode
  887. * @err: Spectral error code
  888. *
  889. * Function to start spectral scan
  890. *
  891. * Return: 0 on success else failure
  892. */
  893. uint32_t
  894. target_if_sops_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  895. enum spectral_cp_error_code *err)
  896. {
  897. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  898. uint8_t val = 1;
  899. uint8_t enabled = 0;
  900. int ret;
  901. ret = target_if_spectral_info_read(
  902. spectral,
  903. smode,
  904. TARGET_IF_SPECTRAL_INFO_ENABLED,
  905. &enabled, sizeof(enabled));
  906. if (ret != 0) {
  907. /*
  908. * Could not determine if Spectral is enabled. Assume we need
  909. * to enable it
  910. */
  911. enabled = 0;
  912. }
  913. if (!enabled) {
  914. ret = target_if_spectral_info_write(
  915. spectral,
  916. smode,
  917. TARGET_IF_SPECTRAL_INFO_ENABLED,
  918. &val, sizeof(val));
  919. if (ret != 0)
  920. return ret;
  921. }
  922. ret = target_if_spectral_info_write(
  923. spectral,
  924. smode,
  925. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  926. &val, sizeof(val));
  927. if (ret != 0)
  928. return ret;
  929. return 0;
  930. }
  931. /**
  932. * target_if_sops_stop_spectral_scan() - Stop Spectral scan
  933. * @arg: Pointer to handle for Spectral target_if internal private data
  934. * @smode: Spectral scan mode
  935. *
  936. * Function to stop spectral scan
  937. *
  938. * Return: 0 on success else failure
  939. */
  940. uint32_t
  941. target_if_sops_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  942. {
  943. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  944. uint8_t val = 0;
  945. int tempret, ret = 0;
  946. uint8_t enabled = 0;
  947. tempret = target_if_spectral_info_read(
  948. spectral,
  949. smode,
  950. TARGET_IF_SPECTRAL_INFO_ENABLED,
  951. &enabled, sizeof(enabled));
  952. if (tempret)
  953. /*
  954. * Could not determine if Spectral is enabled. Assume scan is
  955. * not in progress
  956. */
  957. enabled = 0;
  958. /* if scan is not enabled, no need to send stop to FW */
  959. if (!enabled)
  960. return -EPERM;
  961. tempret = target_if_spectral_info_write(
  962. spectral,
  963. smode,
  964. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  965. &val, sizeof(val));
  966. if (tempret != 0)
  967. ret = tempret;
  968. tempret = target_if_spectral_info_write(
  969. spectral,
  970. smode,
  971. TARGET_IF_SPECTRAL_INFO_ENABLED,
  972. &val, sizeof(val));
  973. if (tempret != 0)
  974. ret = tempret;
  975. return ret;
  976. }
  977. /**
  978. * target_if_spectral_get_extension_channel() - Get the Extension channel
  979. * @arg: Pointer to handle for Spectral target_if internal private data
  980. *
  981. * Function to get the current Extension channel (in MHz)
  982. *
  983. * Return: Current Extension channel (in MHz) on success, 0 on failure or if
  984. * extension channel is not present.
  985. */
  986. uint32_t
  987. target_if_spectral_get_extension_channel(void *arg)
  988. {
  989. /*
  990. * XXX: Once we expand to use cases where Spectral could be activated
  991. * without a channel being set to VDEV, we need to consider returning a
  992. * negative value in case of failure and having all callers handle this.
  993. */
  994. struct target_if_spectral *spectral = NULL;
  995. struct wlan_objmgr_vdev *vdev = NULL;
  996. uint16_t sec20chan_freq = 0;
  997. qdf_assert_always(arg);
  998. spectral = (struct target_if_spectral *)arg;
  999. vdev = target_if_spectral_get_vdev(spectral);
  1000. if (!vdev)
  1001. return 0;
  1002. if (target_if_vdev_get_sec20chan_freq_mhz(vdev, &sec20chan_freq) < 0) {
  1003. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1004. return 0;
  1005. }
  1006. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1007. return sec20chan_freq;
  1008. }
  1009. /**
  1010. * target_if_spectral_get_current_channel() - Get the current channel
  1011. * @arg: Pointer to handle for Spectral target_if internal private data
  1012. *
  1013. * Function to get the current channel (in MHz)
  1014. *
  1015. * Return: Current channel (in MHz) on success, 0 on failure
  1016. */
  1017. uint32_t
  1018. target_if_spectral_get_current_channel(void *arg)
  1019. {
  1020. /*
  1021. * XXX: Once we expand to use cases where Spectral could be activated
  1022. * without a channel being set to VDEV, we need to consider returning a
  1023. * negative value in case of failure and having all callers handle this.
  1024. */
  1025. struct target_if_spectral *spectral = NULL;
  1026. int16_t chan_freq = 0;
  1027. struct wlan_objmgr_vdev *vdev = NULL;
  1028. qdf_assert_always(arg);
  1029. spectral = (struct target_if_spectral *)arg;
  1030. vdev = target_if_spectral_get_vdev(spectral);
  1031. if (!vdev)
  1032. return 0;
  1033. chan_freq = target_if_vdev_get_chan_freq(vdev);
  1034. if (chan_freq < 0) {
  1035. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1036. return 0;
  1037. }
  1038. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1039. return chan_freq;
  1040. }
  1041. /**
  1042. * target_if_spectral_reset_hw() - Reset the hardware
  1043. * @arg: Pointer to handle for Spectral target_if internal private data
  1044. *
  1045. * This is only a placeholder since it is not currently required in the offload
  1046. * case.
  1047. *
  1048. * Return: 0
  1049. */
  1050. uint32_t
  1051. target_if_spectral_reset_hw(void *arg)
  1052. {
  1053. not_yet_implemented();
  1054. return 0;
  1055. }
  1056. /**
  1057. * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
  1058. * Noisefloor history buffer
  1059. * @arg: Pointer to handle for Spectral target_if internal private data
  1060. * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
  1061. *
  1062. * This is only a placeholder since it is not currently required in the offload
  1063. * case.
  1064. *
  1065. * Return: 0
  1066. */
  1067. uint32_t
  1068. target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1069. {
  1070. not_yet_implemented();
  1071. return 0;
  1072. }
  1073. /**
  1074. * target_if_spectral_get_ext_noisefloor() - Get the extension channel
  1075. * noisefloor
  1076. * @arg: Pointer to handle for Spectral target_if internal private data
  1077. *
  1078. * This is only a placeholder since it is not currently required in the offload
  1079. * case.
  1080. *
  1081. * Return: 0
  1082. */
  1083. int8_t
  1084. target_if_spectral_get_ext_noisefloor(void *arg)
  1085. {
  1086. not_yet_implemented();
  1087. return 0;
  1088. }
  1089. /**
  1090. * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
  1091. * @arg: Pointer to handle for Spectral target_if internal private data
  1092. *
  1093. * This is only a placeholder since it is not currently required in the offload
  1094. * case.
  1095. *
  1096. * Return: 0
  1097. */
  1098. int8_t
  1099. target_if_spectral_get_ctl_noisefloor(void *arg)
  1100. {
  1101. not_yet_implemented();
  1102. return 0;
  1103. }
  1104. /**
  1105. * target_if_spectral_sops_configure_params() - Configure user supplied Spectral
  1106. * parameters
  1107. * @arg: Pointer to handle for Spectral target_if internal private data
  1108. * @params: Spectral parameters
  1109. * @smode: Spectral scan mode
  1110. *
  1111. * Function to configure spectral parameters
  1112. *
  1113. * Return: 0 on success else failure
  1114. */
  1115. uint32_t
  1116. target_if_spectral_sops_configure_params(
  1117. void *arg, struct spectral_config *params,
  1118. enum spectral_scan_mode smode)
  1119. {
  1120. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1121. return target_if_spectral_info_write(
  1122. spectral,
  1123. smode,
  1124. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1125. params, sizeof(*params));
  1126. }
  1127. /**
  1128. * target_if_spectral_sops_get_params() - Get user configured Spectral
  1129. * parameters
  1130. * @arg: Pointer to handle for Spectral target_if internal private data
  1131. * @params: Pointer to buffer into which Spectral parameters should be copied
  1132. * @smode: Spectral scan mode
  1133. *
  1134. * Function to get the configured spectral parameters
  1135. *
  1136. * Return: 0 on success else failure
  1137. */
  1138. uint32_t
  1139. target_if_spectral_sops_get_params(void *arg, struct spectral_config *params,
  1140. enum spectral_scan_mode smode)
  1141. {
  1142. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1143. return target_if_spectral_info_read(
  1144. spectral,
  1145. smode,
  1146. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1147. params, sizeof(*params));
  1148. }
  1149. /**
  1150. * target_if_spectral_get_ent_mask() - Get enterprise mask
  1151. * @arg: Pointer to handle for Spectral target_if internal private data
  1152. *
  1153. * This is only a placeholder since it is not currently required in the offload
  1154. * case.
  1155. *
  1156. * Return: 0
  1157. */
  1158. static uint32_t
  1159. target_if_spectral_get_ent_mask(void *arg)
  1160. {
  1161. not_yet_implemented();
  1162. return 0;
  1163. }
  1164. /**
  1165. * target_if_spectral_get_macaddr() - Get radio MAC address
  1166. * @arg: Pointer to handle for Spectral target_if internal private data
  1167. * @addr: Pointer to buffer into which MAC address should be copied
  1168. *
  1169. * Function to get the MAC address of the pdev
  1170. *
  1171. * Return: 0 on success, -1 on failure
  1172. */
  1173. static uint32_t
  1174. target_if_spectral_get_macaddr(void *arg, char *addr)
  1175. {
  1176. uint8_t *myaddr = NULL;
  1177. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1178. struct wlan_objmgr_pdev *pdev = NULL;
  1179. pdev = spectral->pdev_obj;
  1180. wlan_pdev_obj_lock(pdev);
  1181. myaddr = wlan_pdev_get_hw_macaddr(pdev);
  1182. wlan_pdev_obj_unlock(pdev);
  1183. qdf_mem_copy(addr, myaddr, QDF_MAC_ADDR_SIZE);
  1184. return 0;
  1185. }
  1186. /**
  1187. * target_if_init_spectral_param_min_max() - Initialize Spectral parameter
  1188. * min and max values
  1189. *
  1190. * @param_min_max: Pointer to Spectral parameter min and max structure
  1191. * @gen: Spectral HW generation
  1192. * @target_type: Target type
  1193. *
  1194. * Initialize Spectral parameter min and max values
  1195. *
  1196. * Return: QDF_STATUS
  1197. */
  1198. static QDF_STATUS
  1199. target_if_init_spectral_param_min_max(
  1200. struct spectral_param_min_max *param_min_max,
  1201. enum spectral_gen gen, uint32_t target_type)
  1202. {
  1203. switch (gen) {
  1204. case SPECTRAL_GEN3:
  1205. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3;
  1206. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1207. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1208. if (target_type == TARGET_TYPE_QCN9000) {
  1209. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1210. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1211. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1212. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1213. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1214. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1215. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1216. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1217. } else {
  1218. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1219. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1220. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1221. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1222. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1223. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1224. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1225. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1226. }
  1227. break;
  1228. case SPECTRAL_GEN2:
  1229. param_min_max->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1230. param_min_max->fft_size_max[CH_WIDTH_20MHZ] =
  1231. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1232. param_min_max->fft_size_max[CH_WIDTH_40MHZ] =
  1233. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1234. param_min_max->fft_size_max[CH_WIDTH_80MHZ] =
  1235. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1236. param_min_max->fft_size_max[CH_WIDTH_80P80MHZ] =
  1237. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1238. param_min_max->fft_size_max[CH_WIDTH_160MHZ] =
  1239. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1240. break;
  1241. default:
  1242. spectral_err("Invalid spectral generation %d", gen);
  1243. return QDF_STATUS_E_INVAL;
  1244. }
  1245. return QDF_STATUS_SUCCESS;
  1246. }
  1247. /**
  1248. * target_if_init_spectral_param_properties() - Initialize Spectral parameter
  1249. * properties
  1250. * @spectral: Pointer to Spectral target_if internal private data
  1251. *
  1252. * Initialize Spectral parameter properties
  1253. *
  1254. * Return: QDF_STATUS
  1255. */
  1256. static QDF_STATUS
  1257. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1258. {
  1259. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1260. int param;
  1261. /* Initialize default values for properties.
  1262. * Default values are supported for all the parameters for all modes
  1263. * and allows different values for each mode for all the parameters .
  1264. */
  1265. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1266. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1267. spectral->properties[smode][param].supported = true;
  1268. spectral->properties[smode][param].common_all_modes =
  1269. false;
  1270. }
  1271. }
  1272. /* Once FW advertisement is in place remove this hard coding */
  1273. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1274. spectral->properties[SPECTRAL_SCAN_MODE_NORMAL]
  1275. [SPECTRAL_PARAM_FREQUENCY].supported = false;
  1276. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1277. spectral->properties[smode]
  1278. [SPECTRAL_PARAM_SPECT_PRI].common_all_modes = true;
  1279. spectral->properties[smode]
  1280. [SPECTRAL_PARAM_SCAN_PERIOD].common_all_modes = true;
  1281. spectral->properties[smode]
  1282. [SPECTRAL_PARAM_INIT_DELAY].common_all_modes = true;
  1283. }
  1284. return QDF_STATUS_SUCCESS;
  1285. }
  1286. QDF_STATUS
  1287. target_if_init_spectral_capability(struct target_if_spectral *spectral,
  1288. uint32_t target_type)
  1289. {
  1290. struct wlan_objmgr_psoc *psoc;
  1291. struct wlan_objmgr_pdev *pdev;
  1292. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  1293. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  1294. struct target_psoc_info *tgt_psoc_info;
  1295. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  1296. struct spectral_caps *pcap = &spectral->capability;
  1297. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  1298. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  1299. struct wlan_psoc_host_chainmask_table *table;
  1300. int j;
  1301. uint32_t table_id;
  1302. pdev = spectral->pdev_obj;
  1303. psoc = wlan_pdev_get_psoc(pdev);
  1304. if (!psoc) {
  1305. spectral_err("psoc is null");
  1306. return QDF_STATUS_E_FAILURE;
  1307. }
  1308. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  1309. if (!tgt_psoc_info) {
  1310. spectral_err("target_psoc_info is null");
  1311. return QDF_STATUS_E_FAILURE;
  1312. }
  1313. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  1314. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  1315. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  1316. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  1317. /* XXX : Workaround: Set Spectral capability */
  1318. pcap = &spectral->capability;
  1319. pcap->phydiag_cap = 1;
  1320. pcap->radar_cap = 1;
  1321. pcap->spectral_cap = 1;
  1322. pcap->advncd_spectral_cap = 1;
  1323. pcap->hw_gen = spectral->spectral_gen;
  1324. if (spectral->spectral_gen >= SPECTRAL_GEN3) {
  1325. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  1326. if (!mac_phy_cap_arr) {
  1327. spectral_err("mac phy cap array is null");
  1328. return QDF_STATUS_E_FAILURE;
  1329. }
  1330. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  1331. if (!mac_phy_cap) {
  1332. spectral_err("mac phy cap is null");
  1333. return QDF_STATUS_E_FAILURE;
  1334. }
  1335. table_id = mac_phy_cap->chainmask_table_id;
  1336. table = &ext_svc_param->chainmask_table[table_id];
  1337. if (!table) {
  1338. spectral_err("chainmask table not found");
  1339. return QDF_STATUS_E_FAILURE;
  1340. }
  1341. for (j = 0; j < table->num_valid_chainmasks; j++) {
  1342. pcap->agile_spectral_cap |=
  1343. table->cap_list[j].supports_aSpectral;
  1344. pcap->agile_spectral_cap_160 |=
  1345. table->cap_list[j].supports_aSpectral_160;
  1346. }
  1347. pcap->agile_spectral_cap_80p80 = pcap->agile_spectral_cap_160;
  1348. } else {
  1349. pcap->agile_spectral_cap = false;
  1350. pcap->agile_spectral_cap_160 = false;
  1351. pcap->agile_spectral_cap_80p80 = false;
  1352. }
  1353. if (scaling_params) {
  1354. for (param_idx = 0; param_idx < num_bin_scaling_params;
  1355. param_idx++) {
  1356. if (scaling_params[param_idx].pdev_id == pdev_id) {
  1357. pcap->is_scaling_params_populated = true;
  1358. pcap->formula_id =
  1359. scaling_params[param_idx].formula_id;
  1360. pcap->low_level_offset =
  1361. scaling_params[param_idx].low_level_offset;
  1362. pcap->high_level_offset =
  1363. scaling_params[param_idx].high_level_offset;
  1364. pcap->rssi_thr =
  1365. scaling_params[param_idx].rssi_thr;
  1366. pcap->default_agc_max_gain =
  1367. scaling_params[param_idx].default_agc_max_gain;
  1368. break;
  1369. }
  1370. }
  1371. }
  1372. pcap->num_detectors_20mhz = 1;
  1373. pcap->num_detectors_40mhz = 1;
  1374. pcap->num_detectors_80mhz = 1;
  1375. if (target_type == TARGET_TYPE_QCN9000) {
  1376. pcap->num_detectors_160mhz = 1;
  1377. pcap->num_detectors_80p80mhz = 1;
  1378. } else {
  1379. pcap->num_detectors_160mhz = 2;
  1380. pcap->num_detectors_80p80mhz = 2;
  1381. }
  1382. return QDF_STATUS_SUCCESS;
  1383. }
  1384. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1385. /**
  1386. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1387. * internal operations with functions related to spectral simulation
  1388. * @p_sops: spectral low level ops table
  1389. *
  1390. * Initialize spectral target_if internal operations with functions
  1391. * related to spectral simulation
  1392. *
  1393. * Return: None
  1394. */
  1395. static void
  1396. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1397. {
  1398. /*
  1399. * Spectral simulation is currently intended for platform transitions
  1400. * where underlying HW support may not be available for some time.
  1401. * Hence, we do not currently provide a runtime switch to turn the
  1402. * simulation on or off.
  1403. * In case of future requirements where runtime switches are required,
  1404. * this can be added. But it is suggested to use application layer
  1405. * simulation as far as possible in such cases, since the main
  1406. * use of record and replay of samples would concern higher
  1407. * level sample processing rather than lower level delivery.
  1408. */
  1409. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  1410. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  1411. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  1412. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  1413. p_sops->configure_spectral =
  1414. target_if_spectral_sops_sim_configure_params;
  1415. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  1416. }
  1417. #else
  1418. /**
  1419. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1420. * internal operations
  1421. * @p_sops: spectral low level ops table
  1422. *
  1423. * Return: None
  1424. */
  1425. static void
  1426. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1427. {
  1428. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  1429. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  1430. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  1431. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  1432. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  1433. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  1434. }
  1435. #endif
  1436. /**
  1437. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  1438. * operations common to all Spectral chipset generations
  1439. *
  1440. * Initializes target_if_spectral_ops common to all chipset generations
  1441. *
  1442. * Return: None
  1443. */
  1444. static void
  1445. target_if_init_spectral_ops_common(void)
  1446. {
  1447. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1448. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  1449. p_sops->get_capability = target_if_spectral_get_capability;
  1450. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  1451. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  1452. target_if_init_spectral_simulation_ops(p_sops);
  1453. p_sops->get_extension_channel =
  1454. target_if_spectral_get_extension_channel;
  1455. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  1456. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  1457. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  1458. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  1459. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  1460. p_sops->reset_hw = target_if_spectral_reset_hw;
  1461. p_sops->get_chain_noise_floor =
  1462. target_if_spectral_get_chain_noise_floor;
  1463. }
  1464. /**
  1465. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  1466. * operations specific to Spectral chipset generation 2.
  1467. *
  1468. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  1469. *
  1470. * Return: None
  1471. */
  1472. static void
  1473. target_if_init_spectral_ops_gen2(void)
  1474. {
  1475. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1476. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  1477. }
  1478. /**
  1479. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  1480. * operations specific to Spectral chipset generation 3.
  1481. *
  1482. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  1483. *
  1484. * Return: None
  1485. */
  1486. static void
  1487. target_if_init_spectral_ops_gen3(void)
  1488. {
  1489. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1490. p_sops->process_spectral_report =
  1491. target_if_spectral_process_report_gen3;
  1492. return;
  1493. }
  1494. /**
  1495. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  1496. * operations.
  1497. * @spectral: Pointer to Spectral target_if internal private data
  1498. *
  1499. * Initializes all function pointers in target_if_spectral_ops for
  1500. * all generations
  1501. *
  1502. * Return: None
  1503. */
  1504. static void
  1505. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  1506. {
  1507. target_if_init_spectral_ops_common();
  1508. if (spectral->spectral_gen == SPECTRAL_GEN2)
  1509. target_if_init_spectral_ops_gen2();
  1510. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  1511. target_if_init_spectral_ops_gen3();
  1512. else
  1513. spectral_err("Invalid Spectral generation");
  1514. }
  1515. /*
  1516. * Dummy Functions:
  1517. * These functions are initially registered to avoid any crashes due to
  1518. * invocation of spectral functions before they are registered.
  1519. */
  1520. static uint64_t
  1521. null_get_tsf64(void *arg)
  1522. {
  1523. spectral_ops_not_registered("get_tsf64");
  1524. return 0;
  1525. }
  1526. static uint32_t
  1527. null_get_capability(void *arg, enum spectral_capability_type type)
  1528. {
  1529. /*
  1530. * TODO : We should have conditional compilation to get the capability
  1531. * : We have not yet attahced ATH layer here, so there is no
  1532. * : way to check the HAL capbalities
  1533. */
  1534. spectral_ops_not_registered("get_capability");
  1535. /* TODO : For the time being, we are returning TRUE */
  1536. return true;
  1537. }
  1538. static uint32_t
  1539. null_set_rxfilter(void *arg, int rxfilter)
  1540. {
  1541. spectral_ops_not_registered("set_rxfilter");
  1542. return 1;
  1543. }
  1544. static uint32_t
  1545. null_get_rxfilter(void *arg)
  1546. {
  1547. spectral_ops_not_registered("get_rxfilter");
  1548. return 0;
  1549. }
  1550. static uint32_t
  1551. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  1552. {
  1553. spectral_ops_not_registered("is_spectral_active");
  1554. return 1;
  1555. }
  1556. static uint32_t
  1557. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  1558. {
  1559. spectral_ops_not_registered("is_spectral_enabled");
  1560. return 1;
  1561. }
  1562. static uint32_t
  1563. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  1564. enum spectral_cp_error_code *err)
  1565. {
  1566. spectral_ops_not_registered("start_spectral_scan");
  1567. return 1;
  1568. }
  1569. static uint32_t
  1570. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  1571. {
  1572. spectral_ops_not_registered("stop_spectral_scan");
  1573. return 1;
  1574. }
  1575. static uint32_t
  1576. null_get_extension_channel(void *arg)
  1577. {
  1578. spectral_ops_not_registered("get_extension_channel");
  1579. return 1;
  1580. }
  1581. static int8_t
  1582. null_get_ctl_noisefloor(void *arg)
  1583. {
  1584. spectral_ops_not_registered("get_ctl_noisefloor");
  1585. return 1;
  1586. }
  1587. static int8_t
  1588. null_get_ext_noisefloor(void *arg)
  1589. {
  1590. spectral_ops_not_registered("get_ext_noisefloor");
  1591. return 0;
  1592. }
  1593. static uint32_t
  1594. null_configure_spectral(void *arg, struct spectral_config *params,
  1595. enum spectral_scan_mode smode)
  1596. {
  1597. spectral_ops_not_registered("configure_spectral");
  1598. return 0;
  1599. }
  1600. static uint32_t
  1601. null_get_spectral_config(void *arg, struct spectral_config *params,
  1602. enum spectral_scan_mode smode)
  1603. {
  1604. spectral_ops_not_registered("get_spectral_config");
  1605. return 0;
  1606. }
  1607. static uint32_t
  1608. null_get_ent_spectral_mask(void *arg)
  1609. {
  1610. spectral_ops_not_registered("get_ent_spectral_mask");
  1611. return 0;
  1612. }
  1613. static uint32_t
  1614. null_get_mac_address(void *arg, char *addr)
  1615. {
  1616. spectral_ops_not_registered("get_mac_address");
  1617. return 0;
  1618. }
  1619. static uint32_t
  1620. null_get_current_channel(void *arg)
  1621. {
  1622. spectral_ops_not_registered("get_current_channel");
  1623. return 0;
  1624. }
  1625. static uint32_t
  1626. null_reset_hw(void *arg)
  1627. {
  1628. spectral_ops_not_registered("get_current_channel");
  1629. return 0;
  1630. }
  1631. static uint32_t
  1632. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1633. {
  1634. spectral_ops_not_registered("get_chain_noise_floor");
  1635. return 0;
  1636. }
  1637. static int
  1638. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  1639. uint8_t *data,
  1640. uint32_t datalen,
  1641. struct target_if_spectral_rfqual_info *p_rfqual,
  1642. struct target_if_spectral_chan_info *p_chaninfo,
  1643. uint64_t tsf64,
  1644. struct target_if_spectral_acs_stats *acs_stats)
  1645. {
  1646. spectral_ops_not_registered("spectral_process_phyerr");
  1647. return 0;
  1648. }
  1649. static int
  1650. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  1651. void *payload)
  1652. {
  1653. spectral_ops_not_registered("process_spectral_report");
  1654. return 0;
  1655. }
  1656. /**
  1657. * target_if_spectral_init_dummy_function_table() -
  1658. * Initialize target_if internal
  1659. * Spectral operations to dummy functions
  1660. * @ps: Pointer to Spectral target_if internal private data
  1661. *
  1662. * Initialize all the function pointers in target_if_spectral_ops with
  1663. * dummy functions.
  1664. *
  1665. * Return: None
  1666. */
  1667. static void
  1668. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  1669. {
  1670. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  1671. p_sops->get_tsf64 = null_get_tsf64;
  1672. p_sops->get_capability = null_get_capability;
  1673. p_sops->set_rxfilter = null_set_rxfilter;
  1674. p_sops->get_rxfilter = null_get_rxfilter;
  1675. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  1676. p_sops->is_spectral_active = null_is_spectral_active;
  1677. p_sops->start_spectral_scan = null_start_spectral_scan;
  1678. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  1679. p_sops->get_extension_channel = null_get_extension_channel;
  1680. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  1681. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  1682. p_sops->configure_spectral = null_configure_spectral;
  1683. p_sops->get_spectral_config = null_get_spectral_config;
  1684. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  1685. p_sops->get_mac_address = null_get_mac_address;
  1686. p_sops->get_current_channel = null_get_current_channel;
  1687. p_sops->reset_hw = null_reset_hw;
  1688. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  1689. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  1690. p_sops->process_spectral_report = null_process_spectral_report;
  1691. }
  1692. /**
  1693. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  1694. * operations
  1695. * @spectral: Pointer to Spectral target_if internal private data
  1696. * @p: Pointer to Spectral function table
  1697. *
  1698. * Return: None
  1699. */
  1700. static void
  1701. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  1702. struct target_if_spectral_ops *p)
  1703. {
  1704. struct target_if_spectral_ops *p_sops =
  1705. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1706. p_sops->get_tsf64 = p->get_tsf64;
  1707. p_sops->get_capability = p->get_capability;
  1708. p_sops->set_rxfilter = p->set_rxfilter;
  1709. p_sops->get_rxfilter = p->get_rxfilter;
  1710. p_sops->is_spectral_enabled = p->is_spectral_enabled;
  1711. p_sops->is_spectral_active = p->is_spectral_active;
  1712. p_sops->start_spectral_scan = p->start_spectral_scan;
  1713. p_sops->stop_spectral_scan = p->stop_spectral_scan;
  1714. p_sops->get_extension_channel = p->get_extension_channel;
  1715. p_sops->get_ctl_noisefloor = p->get_ctl_noisefloor;
  1716. p_sops->get_ext_noisefloor = p->get_ext_noisefloor;
  1717. p_sops->configure_spectral = p->configure_spectral;
  1718. p_sops->get_spectral_config = p->get_spectral_config;
  1719. p_sops->get_ent_spectral_mask = p->get_ent_spectral_mask;
  1720. p_sops->get_mac_address = p->get_mac_address;
  1721. p_sops->get_current_channel = p->get_current_channel;
  1722. p_sops->reset_hw = p->reset_hw;
  1723. p_sops->get_chain_noise_floor = p->get_chain_noise_floor;
  1724. p_sops->spectral_process_phyerr = p->spectral_process_phyerr;
  1725. p_sops->process_spectral_report = p->process_spectral_report;
  1726. }
  1727. /**
  1728. * target_if_spectral_clear_stats() - Clear Spectral stats
  1729. * @spectral: Pointer to Spectral target_if internal private data
  1730. *
  1731. * Function to clear spectral stats
  1732. *
  1733. * Return: None
  1734. */
  1735. static void
  1736. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  1737. {
  1738. struct target_if_spectral_ops *p_sops =
  1739. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1740. qdf_mem_zero(&spectral->spectral_stats,
  1741. sizeof(struct target_if_spectral_stats));
  1742. spectral->spectral_stats.last_reset_tstamp =
  1743. p_sops->get_tsf64(spectral);
  1744. }
  1745. /**
  1746. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  1747. * @spectral: Pointer to Spectral target_if internal private data
  1748. *
  1749. * Function to check whether hardware supports spectral
  1750. *
  1751. * Return: True if HW supports Spectral, false if HW does not support Spectral
  1752. */
  1753. static int
  1754. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  1755. {
  1756. struct target_if_spectral_ops *p_sops = NULL;
  1757. struct spectral_caps *pcap = NULL;
  1758. int is_spectral_supported = true;
  1759. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1760. pcap = &spectral->capability;
  1761. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  1762. is_spectral_supported = false;
  1763. spectral_info("SPECTRAL : No PHYDIAG support");
  1764. return is_spectral_supported;
  1765. }
  1766. pcap->phydiag_cap = 1;
  1767. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  1768. is_spectral_supported = false;
  1769. spectral_info("SPECTRAL : No RADAR support");
  1770. return is_spectral_supported;
  1771. }
  1772. pcap->radar_cap = 1;
  1773. if (p_sops->get_capability(spectral,
  1774. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  1775. is_spectral_supported = false;
  1776. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  1777. return is_spectral_supported;
  1778. }
  1779. pcap->spectral_cap = 1;
  1780. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  1781. == false) {
  1782. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  1783. } else {
  1784. pcap->advncd_spectral_cap = 1;
  1785. }
  1786. return is_spectral_supported;
  1787. }
  1788. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1789. /**
  1790. * target_if_spectral_detach_simulation() - De-initialize Spectral
  1791. * Simulation functionality
  1792. * @spectral: Pointer to Spectral target_if internal private data
  1793. *
  1794. * Function to de-initialize Spectral Simulation functionality
  1795. *
  1796. * Return: None
  1797. */
  1798. static void
  1799. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1800. {
  1801. target_if_spectral_sim_detach(spectral);
  1802. }
  1803. #else
  1804. static void
  1805. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1806. {
  1807. }
  1808. #endif
  1809. /**
  1810. * target_if_spectral_detach() - De-initialize target_if Spectral
  1811. * @pdev: Pointer to pdev object
  1812. *
  1813. * Function to detach target_if spectral
  1814. *
  1815. * Return: None
  1816. */
  1817. static void
  1818. target_if_spectral_detach(struct target_if_spectral *spectral)
  1819. {
  1820. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1821. spectral_info("spectral detach");
  1822. if (spectral) {
  1823. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1824. qdf_spinlock_destroy
  1825. (&spectral->param_info[smode].osps_lock);
  1826. target_if_spectral_detach_simulation(spectral);
  1827. qdf_spinlock_destroy(&spectral->spectral_lock);
  1828. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  1829. qdf_mem_free(spectral);
  1830. spectral = NULL;
  1831. }
  1832. }
  1833. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1834. /**
  1835. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  1836. * functionality
  1837. * @spectral: Pointer to Spectral target_if internal private data
  1838. *
  1839. * Function to initialize spectral simulation functionality
  1840. *
  1841. * Return: 0 on success, negative error code on failure
  1842. */
  1843. static int
  1844. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1845. {
  1846. if (target_if_spectral_sim_attach(spectral)) {
  1847. qdf_mem_free(spectral);
  1848. return -EPERM;
  1849. }
  1850. return 0;
  1851. }
  1852. #else
  1853. static int
  1854. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1855. {
  1856. return 0;
  1857. }
  1858. #endif
  1859. /**
  1860. * target_if_spectral_len_adj_swar_init() - Initialize FFT bin length adjustment
  1861. * related info
  1862. * @swar: Pointer to Spectral FFT bin length adjustment SWAR params
  1863. * @target_type: Target type
  1864. *
  1865. * Function to Initialize parameters related to Spectral FFT bin
  1866. * length adjustment SWARs.
  1867. *
  1868. * Return: void
  1869. */
  1870. static void
  1871. target_if_spectral_len_adj_swar_init(struct spectral_fft_bin_len_adj_swar *swar,
  1872. uint32_t target_type)
  1873. {
  1874. if (target_type == TARGET_TYPE_QCA8074V2 ||
  1875. target_type == TARGET_TYPE_QCN9000 ||
  1876. target_type == TARGET_TYPE_QCA6750)
  1877. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  1878. else if (target_type == TARGET_TYPE_QCA8074 ||
  1879. target_type == TARGET_TYPE_QCA6018 ||
  1880. target_type == TARGET_TYPE_QCA6390)
  1881. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  1882. else
  1883. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  1884. if (target_type == TARGET_TYPE_QCA8074 ||
  1885. target_type == TARGET_TYPE_QCA8074V2 ||
  1886. target_type == TARGET_TYPE_QCA6018 ||
  1887. target_type == TARGET_TYPE_QCN9000) {
  1888. swar->inband_fftbin_size_adj = 1;
  1889. swar->null_fftbin_adj = 1;
  1890. } else {
  1891. swar->inband_fftbin_size_adj = 0;
  1892. swar->null_fftbin_adj = 0;
  1893. }
  1894. if (target_type == TARGET_TYPE_QCA8074V2)
  1895. swar->packmode_fftbin_size_adj = 1;
  1896. else
  1897. swar->packmode_fftbin_size_adj = 0;
  1898. }
  1899. /**
  1900. * target_if_spectral_report_params_init() - Initialize parameters which
  1901. * describes the structure of Spectral reports
  1902. *
  1903. * @rparams: Pointer to Spectral report parameter object
  1904. * @target_type: target type
  1905. *
  1906. * Function to Initialize parameters related to the structure of Spectral
  1907. * reports.
  1908. *
  1909. * Return: void
  1910. */
  1911. static void
  1912. target_if_spectral_report_params_init(
  1913. struct spectral_report_params *rparams,
  1914. uint32_t target_type)
  1915. {
  1916. enum spectral_scan_mode smode;
  1917. /* This entries are currently used by gen3 chipsets only. Hence
  1918. * initialization is done for gen3 alone. In future if other generations
  1919. * needs to use them they have to add proper initial values.
  1920. */
  1921. if (target_type == TARGET_TYPE_QCN9000 ||
  1922. target_type == TARGET_TYPE_QCA6750) {
  1923. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_2;
  1924. rparams->num_spectral_detectors =
  1925. NUM_SPECTRAL_DETECTORS_GEN3_V2;
  1926. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1927. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1928. rparams->fragmentation_160[smode] = false;
  1929. rparams->max_agile_ch_width = CH_WIDTH_80P80MHZ;
  1930. } else {
  1931. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_1;
  1932. rparams->num_spectral_detectors =
  1933. NUM_SPECTRAL_DETECTORS_GEN3_V1;
  1934. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1935. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1936. rparams->fragmentation_160[smode] = true;
  1937. rparams->max_agile_ch_width = CH_WIDTH_80MHZ;
  1938. }
  1939. switch (rparams->version) {
  1940. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1941. rparams->ssumaary_padding_bytes =
  1942. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1;
  1943. rparams->fft_report_hdr_len =
  1944. FFT_REPORT_HEADER_LENGTH_GEN3_V1;
  1945. break;
  1946. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1947. rparams->ssumaary_padding_bytes =
  1948. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2;
  1949. rparams->fft_report_hdr_len =
  1950. FFT_REPORT_HEADER_LENGTH_GEN3_V2;
  1951. break;
  1952. default:
  1953. qdf_assert_always(0);
  1954. }
  1955. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_0] =
  1956. SPECTRAL_SCAN_MODE_NORMAL;
  1957. if (target_type == TARGET_TYPE_QCN9000) {
  1958. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  1959. SPECTRAL_SCAN_MODE_AGILE;
  1960. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  1961. SPECTRAL_SCAN_MODE_INVALID;
  1962. } else {
  1963. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  1964. SPECTRAL_SCAN_MODE_NORMAL;
  1965. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  1966. SPECTRAL_SCAN_MODE_AGILE;
  1967. }
  1968. }
  1969. /**
  1970. * target_if_spectral_timestamp_war_init() - Initialize Spectral timestamp WAR
  1971. * related info
  1972. * @twar: Pointer to Spectral timstamp WAR related info
  1973. *
  1974. * Function to Initialize parameters related to Spectral timestamp WAR
  1975. *
  1976. * Return: void
  1977. */
  1978. static void
  1979. target_if_spectral_timestamp_war_init(struct spectral_timestamp_war *twar)
  1980. {
  1981. enum spectral_scan_mode smode;
  1982. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1983. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1984. twar->last_fft_timestamp[smode] = 0;
  1985. twar->timestamp_war_offset[smode] = 0;
  1986. }
  1987. twar->target_reset_count = 0;
  1988. }
  1989. /**
  1990. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  1991. * functionality for the given pdev
  1992. * @pdev: Pointer to pdev object
  1993. *
  1994. * Function to initialize pointer to spectral target_if internal private data
  1995. *
  1996. * Return: On success, pointer to Spectral target_if internal private data, on
  1997. * failure, NULL
  1998. */
  1999. void *
  2000. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  2001. {
  2002. struct target_if_spectral_ops *p_sops = NULL;
  2003. struct target_if_spectral *spectral = NULL;
  2004. uint32_t target_type;
  2005. uint32_t target_revision;
  2006. struct wlan_objmgr_psoc *psoc;
  2007. struct wlan_lmac_if_target_tx_ops *tgt_tx_ops;
  2008. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  2009. QDF_STATUS status;
  2010. struct wlan_lmac_if_tx_ops *tx_ops;
  2011. if (!pdev) {
  2012. spectral_err("SPECTRAL: pdev is NULL!");
  2013. return NULL;
  2014. }
  2015. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  2016. sizeof(struct target_if_spectral));
  2017. if (!spectral)
  2018. return spectral;
  2019. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  2020. /* Store pdev in Spectral */
  2021. spectral->pdev_obj = pdev;
  2022. psoc = wlan_pdev_get_psoc(pdev);
  2023. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  2024. if (!tx_ops) {
  2025. spectral_err("tx_ops is NULL");
  2026. qdf_mem_free(spectral);
  2027. return NULL;
  2028. }
  2029. tgt_tx_ops = &tx_ops->target_tx_ops;
  2030. if (tgt_tx_ops->tgt_get_tgt_type) {
  2031. target_type = tgt_tx_ops->tgt_get_tgt_type(psoc);
  2032. } else {
  2033. qdf_mem_free(spectral);
  2034. return NULL;
  2035. }
  2036. if (tgt_tx_ops->tgt_get_tgt_revision) {
  2037. target_revision = tgt_tx_ops->tgt_get_tgt_revision(psoc);
  2038. } else {
  2039. qdf_mem_free(spectral);
  2040. return NULL;
  2041. }
  2042. /* init the function ptr table */
  2043. target_if_spectral_init_dummy_function_table(spectral);
  2044. /* get spectral function table */
  2045. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2046. /* TODO : Should this be called here of after ath_attach ? */
  2047. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  2048. spectral_info("HAL_CAP_PHYDIAG : Capable");
  2049. /* TODO: Need to fix the capablity check for RADAR */
  2050. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  2051. spectral_info("HAL_CAP_RADAR : Capable");
  2052. /* TODO : Need to fix the capablity check for SPECTRAL */
  2053. /* TODO : Should this be called here of after ath_attach ? */
  2054. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  2055. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  2056. qdf_spinlock_create(&spectral->spectral_lock);
  2057. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  2058. target_if_spectral_clear_stats(spectral);
  2059. if (target_type == TARGET_TYPE_QCA8074 ||
  2060. target_type == TARGET_TYPE_QCA8074V2 ||
  2061. target_type == TARGET_TYPE_QCA6018 ||
  2062. target_type == TARGET_TYPE_QCA6390 ||
  2063. target_type == TARGET_TYPE_QCN9000 ||
  2064. target_type == TARGET_TYPE_QCA6750)
  2065. spectral->direct_dma_support = true;
  2066. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  2067. target_type);
  2068. target_if_spectral_report_params_init(&spectral->rparams, target_type);
  2069. if ((target_type == TARGET_TYPE_QCA8074) ||
  2070. (target_type == TARGET_TYPE_QCA8074V2) ||
  2071. (target_type == TARGET_TYPE_QCA6018) ||
  2072. (target_type == TARGET_TYPE_QCA5018) ||
  2073. (target_type == TARGET_TYPE_QCN9000) ||
  2074. (target_type == TARGET_TYPE_QCA6290) ||
  2075. (target_type == TARGET_TYPE_QCA6390) ||
  2076. (target_type == TARGET_TYPE_QCA6750)) {
  2077. spectral->spectral_gen = SPECTRAL_GEN3;
  2078. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  2079. spectral->tag_sscan_summary_exp =
  2080. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  2081. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  2082. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  2083. } else {
  2084. spectral->spectral_gen = SPECTRAL_GEN2;
  2085. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  2086. spectral->tag_sscan_summary_exp =
  2087. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  2088. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  2089. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  2090. }
  2091. status = target_if_init_spectral_param_min_max(
  2092. &spectral->param_min_max,
  2093. spectral->spectral_gen, target_type);
  2094. if (QDF_IS_STATUS_ERROR(status)) {
  2095. spectral_err("Failed to initialize parameter min max values");
  2096. goto fail;
  2097. }
  2098. target_if_init_spectral_param_properties(spectral);
  2099. /* Init spectral capability */
  2100. if (target_if_init_spectral_capability(spectral, target_type) !=
  2101. QDF_STATUS_SUCCESS) {
  2102. qdf_mem_free(spectral);
  2103. return NULL;
  2104. }
  2105. if (target_if_spectral_attach_simulation(spectral) < 0)
  2106. return NULL;
  2107. target_if_init_spectral_ops(spectral);
  2108. target_if_spectral_timestamp_war_init(&spectral->timestamp_war);
  2109. /* Spectral mode specific init */
  2110. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2111. spectral->params_valid[smode] = false;
  2112. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  2113. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  2114. }
  2115. target_if_spectral_register_funcs(spectral, &spectral_ops);
  2116. if (target_if_spectral_check_hw_capability(spectral) == false) {
  2117. goto fail;
  2118. } else {
  2119. /*
  2120. * TODO: Once the driver architecture transitions to chipset
  2121. * versioning based checks, reflect this here.
  2122. */
  2123. spectral->is_160_format = false;
  2124. spectral->is_lb_edge_extrabins_format = false;
  2125. spectral->is_rb_edge_extrabins_format = false;
  2126. if (target_type == TARGET_TYPE_QCA9984 ||
  2127. target_type == TARGET_TYPE_QCA9888) {
  2128. spectral->is_160_format = true;
  2129. spectral->is_lb_edge_extrabins_format = true;
  2130. spectral->is_rb_edge_extrabins_format = true;
  2131. } else if ((target_type == TARGET_TYPE_AR900B) &&
  2132. (target_revision == AR900B_REV_2)) {
  2133. spectral->is_rb_edge_extrabins_format = true;
  2134. }
  2135. if (target_type == TARGET_TYPE_QCA9984 ||
  2136. target_type == TARGET_TYPE_QCA9888)
  2137. spectral->is_sec80_rssi_war_required = true;
  2138. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  2139. if (spectral->spectral_gen == SPECTRAL_GEN3)
  2140. init_160mhz_delivery_state_machine(spectral);
  2141. }
  2142. return spectral;
  2143. fail:
  2144. target_if_spectral_detach(spectral);
  2145. return NULL;
  2146. }
  2147. /**
  2148. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  2149. * functionality for the given pdev
  2150. * @pdev: Pointer to pdev object
  2151. *
  2152. * Function to de-initialize pointer to spectral target_if internal private data
  2153. *
  2154. * Return: None
  2155. */
  2156. void
  2157. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  2158. {
  2159. struct target_if_spectral *spectral = NULL;
  2160. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2161. if (!spectral) {
  2162. spectral_err("SPECTRAL : Module doesn't exist");
  2163. return;
  2164. }
  2165. target_if_spectral_detach(spectral);
  2166. return;
  2167. }
  2168. /**
  2169. * target_if_psoc_spectral_deinit() - De-initialize target_if Spectral
  2170. * functionality for the given psoc
  2171. * @psoc: Pointer to psoc object
  2172. *
  2173. * Function to de-initialize pointer to psoc spectral target_if internal
  2174. * private data
  2175. *
  2176. * Return: None
  2177. */
  2178. static void
  2179. target_if_psoc_spectral_deinit(struct wlan_objmgr_psoc *psoc)
  2180. {
  2181. struct target_if_psoc_spectral *psoc_spectral;
  2182. if (!psoc) {
  2183. spectral_err("psoc is null");
  2184. return;
  2185. }
  2186. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  2187. if (!psoc_spectral) {
  2188. spectral_err("Spectral target_if psoc object is null");
  2189. return;
  2190. }
  2191. qdf_mem_free(psoc_spectral);
  2192. }
  2193. /**
  2194. * target_if_psoc_spectral_init() - Initialize target_if Spectral
  2195. * functionality for the given psoc
  2196. * @psoc: Pointer to psoc object
  2197. *
  2198. * Function to initialize pointer to psoc spectral target_if internal
  2199. * private data
  2200. *
  2201. * Return: On success, pointer to Spectral psoc target_if internal
  2202. * private data, on failure, NULL
  2203. */
  2204. static void *
  2205. target_if_psoc_spectral_init(struct wlan_objmgr_psoc *psoc)
  2206. {
  2207. struct target_if_psoc_spectral *psoc_spectral = NULL;
  2208. if (!psoc) {
  2209. spectral_err("psoc is null");
  2210. goto fail;
  2211. }
  2212. psoc_spectral = (struct target_if_psoc_spectral *)qdf_mem_malloc(
  2213. sizeof(struct target_if_psoc_spectral));
  2214. if (!psoc_spectral) {
  2215. spectral_err("Spectral lmac psoc object allocation failed");
  2216. goto fail;
  2217. }
  2218. psoc_spectral->psoc_obj = psoc;
  2219. return psoc_spectral;
  2220. fail:
  2221. if (psoc_spectral)
  2222. target_if_psoc_spectral_deinit(psoc);
  2223. return psoc_spectral;
  2224. }
  2225. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  2226. * corresponding translation for Agile channel width.
  2227. * @spectral: pointer to Spectral object
  2228. * @chwidth: operating channel width
  2229. * @is_80_80_agile: Indicates an 80+80 agile Scan request
  2230. *
  2231. * Return: The translated channel width enum.
  2232. */
  2233. static enum phy_ch_width
  2234. target_if_spectral_find_agile_width(struct target_if_spectral *spectral,
  2235. enum phy_ch_width chwidth,
  2236. bool is_80_80_agile)
  2237. {
  2238. enum phy_ch_width agile_width;
  2239. struct wlan_objmgr_pdev *pdev;
  2240. struct wlan_objmgr_psoc *psoc;
  2241. if (!spectral) {
  2242. spectral_err("Spectral object is null");
  2243. return CH_WIDTH_INVALID;
  2244. }
  2245. pdev = spectral->pdev_obj;
  2246. if (!pdev) {
  2247. spectral_err("pdev is null");
  2248. return CH_WIDTH_INVALID;
  2249. }
  2250. psoc = wlan_pdev_get_psoc(pdev);
  2251. if (!psoc) {
  2252. spectral_err("psoc is null");
  2253. return CH_WIDTH_INVALID;
  2254. }
  2255. switch (chwidth) {
  2256. case CH_WIDTH_20MHZ:
  2257. agile_width = CH_WIDTH_20MHZ;
  2258. break;
  2259. case CH_WIDTH_40MHZ:
  2260. agile_width = CH_WIDTH_40MHZ;
  2261. break;
  2262. case CH_WIDTH_80MHZ:
  2263. agile_width = CH_WIDTH_80MHZ;
  2264. break;
  2265. case CH_WIDTH_80P80MHZ:
  2266. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  2267. WLAN_SOC_RESTRICTED_80P80_SUPPORT) && !is_80_80_agile)
  2268. agile_width = CH_WIDTH_160MHZ;
  2269. else
  2270. agile_width = CH_WIDTH_80P80MHZ;
  2271. if (agile_width > spectral->rparams.max_agile_ch_width)
  2272. agile_width = spectral->rparams.max_agile_ch_width;
  2273. break;
  2274. case CH_WIDTH_160MHZ:
  2275. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  2276. WLAN_SOC_RESTRICTED_80P80_SUPPORT) && is_80_80_agile)
  2277. agile_width = CH_WIDTH_80P80MHZ;
  2278. else
  2279. agile_width = CH_WIDTH_160MHZ;
  2280. if (agile_width > spectral->rparams.max_agile_ch_width)
  2281. agile_width = spectral->rparams.max_agile_ch_width;
  2282. break;
  2283. default:
  2284. spectral_err("Invalid channel width %d", chwidth);
  2285. agile_width = CH_WIDTH_INVALID;
  2286. break;
  2287. }
  2288. return agile_width;
  2289. }
  2290. /**
  2291. * target_if_calculate_center_freq() - Helper routine to
  2292. * check whether given frequency is center frequency of a
  2293. * WLAN channel
  2294. *
  2295. * @spectral: Pointer to Spectral object
  2296. * @chan_freq: Center frequency of a WLAN channel
  2297. * @is_valid: Indicates whether given frequency is valid
  2298. *
  2299. * Return: QDF_STATUS
  2300. */
  2301. static QDF_STATUS
  2302. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  2303. uint32_t chan_freq,
  2304. bool *is_valid)
  2305. {
  2306. struct regulatory_channel *cur_chan_list;
  2307. int i;
  2308. if (!pdev) {
  2309. spectral_err("pdev object is null");
  2310. return QDF_STATUS_E_FAILURE;
  2311. }
  2312. if (!is_valid) {
  2313. spectral_err("is valid argument is null");
  2314. return QDF_STATUS_E_FAILURE;
  2315. }
  2316. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  2317. if (!cur_chan_list)
  2318. return QDF_STATUS_E_FAILURE;
  2319. if (wlan_reg_get_current_chan_list(
  2320. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  2321. spectral_err("Failed to get cur_chan list");
  2322. qdf_mem_free(cur_chan_list);
  2323. return QDF_STATUS_E_FAILURE;
  2324. }
  2325. *is_valid = false;
  2326. for (i = 0; i < NUM_CHANNELS; i++) {
  2327. uint32_t flags;
  2328. uint32_t center_freq;
  2329. flags = cur_chan_list[i].chan_flags;
  2330. center_freq = cur_chan_list[i].center_freq;
  2331. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  2332. (center_freq == chan_freq)) {
  2333. *is_valid = true;
  2334. break;
  2335. }
  2336. }
  2337. qdf_mem_free(cur_chan_list);
  2338. return QDF_STATUS_SUCCESS;
  2339. }
  2340. /**
  2341. * target_if_calculate_center_freq() - Helper routine to
  2342. * find the center frequency of the agile span from a
  2343. * WLAN channel center frequency
  2344. *
  2345. * @spectral: Pointer to Spectral object
  2346. * @ch_width: Channel width array
  2347. * @chan_freq: Center frequency of a WLAN channel
  2348. * @center_freq: Pointer to center frequency
  2349. *
  2350. * Return: QDF_STATUS
  2351. */
  2352. static QDF_STATUS
  2353. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  2354. enum phy_ch_width *ch_width,
  2355. uint16_t chan_freq,
  2356. uint16_t *center_freq)
  2357. {
  2358. enum phy_ch_width agile_ch_width;
  2359. if (!spectral) {
  2360. spectral_err("spectral target if object is null");
  2361. return QDF_STATUS_E_FAILURE;
  2362. }
  2363. if (!ch_width) {
  2364. spectral_err("Channel width array is null");
  2365. return QDF_STATUS_E_INVAL;
  2366. }
  2367. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2368. if (!center_freq) {
  2369. spectral_err("center_freq argument is null");
  2370. return QDF_STATUS_E_FAILURE;
  2371. }
  2372. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2373. *center_freq = chan_freq;
  2374. } else {
  2375. uint16_t start_freq;
  2376. uint16_t end_freq;
  2377. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2378. enum channel_state state;
  2379. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2380. (spectral->pdev_obj, chan_freq, agile_ch_width,
  2381. &bonded_chan_ptr);
  2382. if (state == CHANNEL_STATE_DISABLE ||
  2383. state == CHANNEL_STATE_INVALID) {
  2384. spectral_err("Channel state is disable or invalid");
  2385. return QDF_STATUS_E_FAILURE;
  2386. }
  2387. if (!bonded_chan_ptr) {
  2388. spectral_err("Bonded channel is not found");
  2389. return QDF_STATUS_E_FAILURE;
  2390. }
  2391. start_freq = bonded_chan_ptr->start_freq;
  2392. end_freq = bonded_chan_ptr->end_freq;
  2393. *center_freq = (start_freq + end_freq) >> 1;
  2394. }
  2395. return QDF_STATUS_SUCCESS;
  2396. }
  2397. /**
  2398. * target_if_validate_center_freq() - Helper routine to
  2399. * validate user provided agile center frequency
  2400. *
  2401. * @spectral: Pointer to Spectral object
  2402. * @ch_width: Channel width array
  2403. * @center_freq: User provided agile span center frequency
  2404. * @is_valid: Indicates whether agile span center frequency is valid
  2405. *
  2406. * Return: QDF_STATUS
  2407. */
  2408. static QDF_STATUS
  2409. target_if_validate_center_freq(struct target_if_spectral *spectral,
  2410. enum phy_ch_width *ch_width,
  2411. uint16_t center_freq,
  2412. bool *is_valid)
  2413. {
  2414. enum phy_ch_width agile_ch_width;
  2415. struct wlan_objmgr_pdev *pdev;
  2416. QDF_STATUS status;
  2417. if (!spectral) {
  2418. spectral_err("spectral target if object is null");
  2419. return QDF_STATUS_E_FAILURE;
  2420. }
  2421. if (!ch_width) {
  2422. spectral_err("channel width array is null");
  2423. return QDF_STATUS_E_INVAL;
  2424. }
  2425. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2426. if (!is_valid) {
  2427. spectral_err("is_valid argument is null");
  2428. return QDF_STATUS_E_FAILURE;
  2429. }
  2430. pdev = spectral->pdev_obj;
  2431. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2432. status = target_if_is_center_freq_of_any_chan
  2433. (pdev, center_freq, is_valid);
  2434. if (QDF_IS_STATUS_ERROR(status))
  2435. return QDF_STATUS_E_FAILURE;
  2436. } else {
  2437. uint16_t start_freq;
  2438. uint16_t end_freq;
  2439. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2440. bool is_chan;
  2441. status = target_if_is_center_freq_of_any_chan
  2442. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2443. &is_chan);
  2444. if (QDF_IS_STATUS_ERROR(status))
  2445. return QDF_STATUS_E_FAILURE;
  2446. if (is_chan) {
  2447. uint32_t calulated_center_freq;
  2448. enum channel_state st;
  2449. st = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2450. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2451. agile_ch_width,
  2452. &bonded_chan_ptr);
  2453. if (st == CHANNEL_STATE_DISABLE ||
  2454. st == CHANNEL_STATE_INVALID) {
  2455. spectral_err("Channel state disable/invalid");
  2456. return QDF_STATUS_E_FAILURE;
  2457. }
  2458. if (!bonded_chan_ptr) {
  2459. spectral_err("Bonded channel is not found");
  2460. return QDF_STATUS_E_FAILURE;
  2461. }
  2462. start_freq = bonded_chan_ptr->start_freq;
  2463. end_freq = bonded_chan_ptr->end_freq;
  2464. calulated_center_freq = (start_freq + end_freq) >> 1;
  2465. *is_valid = (center_freq == calulated_center_freq);
  2466. } else {
  2467. *is_valid = false;
  2468. }
  2469. }
  2470. return QDF_STATUS_SUCCESS;
  2471. }
  2472. /**
  2473. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  2474. * check whether agile span overlaps with current operating band.
  2475. *
  2476. * @spectral: Pointer to Spectral object
  2477. * @ch_width: Channel width array
  2478. * @center_freq: Agile span center frequency
  2479. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  2480. *
  2481. * Helper routine to check whether agile span overlaps with current
  2482. * operating band.
  2483. *
  2484. * Return: QDF_STATUS
  2485. */
  2486. static QDF_STATUS
  2487. target_if_is_agile_span_overlap_with_operating_span
  2488. (struct target_if_spectral *spectral,
  2489. enum phy_ch_width *ch_width,
  2490. struct spectral_config_frequency *center_freq,
  2491. bool *is_overlapping)
  2492. {
  2493. enum phy_ch_width op_ch_width;
  2494. enum phy_ch_width agile_ch_width;
  2495. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2496. struct wlan_objmgr_vdev *vdev;
  2497. struct wlan_objmgr_pdev *pdev;
  2498. int16_t chan_freq;
  2499. uint32_t op_start_freq;
  2500. uint32_t op_end_freq;
  2501. uint32_t agile_start_freq;
  2502. uint32_t agile_end_freq;
  2503. uint32_t cfreq2;
  2504. if (!spectral) {
  2505. spectral_err("Spectral object is NULL");
  2506. return QDF_STATUS_E_FAILURE;
  2507. }
  2508. pdev = spectral->pdev_obj;
  2509. if (!pdev) {
  2510. spectral_err("pdev object is NULL");
  2511. return QDF_STATUS_E_FAILURE;
  2512. }
  2513. if (!ch_width) {
  2514. spectral_err("channel width array is null");
  2515. return QDF_STATUS_E_FAILURE;
  2516. }
  2517. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  2518. if (op_ch_width == CH_WIDTH_INVALID) {
  2519. spectral_err("Invalid channel width");
  2520. return QDF_STATUS_E_INVAL;
  2521. }
  2522. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2523. if (agile_ch_width == CH_WIDTH_INVALID) {
  2524. spectral_err("Invalid channel width");
  2525. return QDF_STATUS_E_INVAL;
  2526. }
  2527. if (!is_overlapping) {
  2528. spectral_err("Argument(is_overlapping) is NULL");
  2529. return QDF_STATUS_E_FAILURE;
  2530. }
  2531. *is_overlapping = false;
  2532. vdev = target_if_spectral_get_vdev(spectral);
  2533. if (!vdev) {
  2534. spectral_err("vdev is NULL");
  2535. return QDF_STATUS_E_FAILURE;
  2536. }
  2537. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2538. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2539. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2540. if (cfreq2 < 0) {
  2541. spectral_err("cfreq2 is invalid");
  2542. return QDF_STATUS_E_FAILURE;
  2543. }
  2544. if (op_ch_width == CH_WIDTH_20MHZ) {
  2545. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  2546. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  2547. } else {
  2548. enum channel_state state;
  2549. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2550. (pdev, chan_freq, op_ch_width, &bonded_chan_ptr);
  2551. if (state == CHANNEL_STATE_DISABLE ||
  2552. state == CHANNEL_STATE_INVALID) {
  2553. spectral_err("Channel state is disable or invalid");
  2554. return QDF_STATUS_E_FAILURE;
  2555. }
  2556. if (!bonded_chan_ptr) {
  2557. spectral_err("Bonded channel is not found");
  2558. return QDF_STATUS_E_FAILURE;
  2559. }
  2560. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  2561. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  2562. }
  2563. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  2564. agile_start_freq = center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  2565. agile_end_freq = center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  2566. if (agile_end_freq > op_start_freq &&
  2567. op_end_freq > agile_start_freq)
  2568. *is_overlapping = true;
  2569. agile_start_freq = center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  2570. agile_end_freq = center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  2571. if (agile_end_freq > op_start_freq &&
  2572. op_end_freq > agile_start_freq)
  2573. *is_overlapping = true;
  2574. } else {
  2575. agile_start_freq = center_freq->cfreq1 -
  2576. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2577. agile_end_freq = center_freq->cfreq1 +
  2578. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2579. if (agile_end_freq > op_start_freq &&
  2580. op_end_freq > agile_start_freq)
  2581. *is_overlapping = true;
  2582. }
  2583. if (op_ch_width == CH_WIDTH_80P80MHZ) {
  2584. uint32_t sec80_start_feq;
  2585. uint32_t sec80_end_freq;
  2586. sec80_start_feq = cfreq2 - FREQ_OFFSET_40MHZ;
  2587. sec80_end_freq = cfreq2 + FREQ_OFFSET_40MHZ;
  2588. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  2589. agile_start_freq =
  2590. center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  2591. agile_end_freq =
  2592. center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  2593. if (agile_end_freq > sec80_start_feq &&
  2594. sec80_end_freq > agile_start_freq)
  2595. *is_overlapping = true;
  2596. agile_start_freq =
  2597. center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  2598. agile_end_freq =
  2599. center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  2600. if (agile_end_freq > sec80_start_feq &&
  2601. sec80_end_freq > agile_start_freq)
  2602. *is_overlapping = true;
  2603. } else {
  2604. agile_start_freq = center_freq->cfreq1 -
  2605. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2606. agile_end_freq = center_freq->cfreq1 +
  2607. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2608. if (agile_end_freq > sec80_start_feq &&
  2609. sec80_end_freq > agile_start_freq)
  2610. *is_overlapping = true;
  2611. }
  2612. }
  2613. return QDF_STATUS_SUCCESS;
  2614. }
  2615. /**
  2616. * target_if_spectral_populate_chwidth() - Helper routine to
  2617. * populate channel width for different Spectral modes
  2618. *
  2619. * @spectral: Pointer to Spectral object
  2620. * @ch_width: Channel width array
  2621. * @is_80_80_agile: Indicates whether 80+80 agile scan is requested
  2622. *
  2623. * Helper routine to populate channel width for different Spectral modes
  2624. *
  2625. * Return: QDF_STATUS
  2626. */
  2627. static QDF_STATUS
  2628. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral,
  2629. enum phy_ch_width *ch_width,
  2630. bool is_80_80_agile) {
  2631. struct wlan_objmgr_vdev *vdev;
  2632. enum spectral_scan_mode smode;
  2633. enum phy_ch_width vdev_ch_width;
  2634. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2635. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2636. ch_width[smode] = CH_WIDTH_INVALID;
  2637. if (!spectral) {
  2638. spectral_err("Spectral object is null");
  2639. return QDF_STATUS_E_INVAL;
  2640. }
  2641. vdev = target_if_spectral_get_vdev(spectral);
  2642. if (!vdev) {
  2643. spectral_err("vdev is null");
  2644. return QDF_STATUS_E_FAILURE;
  2645. }
  2646. vdev_ch_width = target_if_vdev_get_ch_width(vdev);
  2647. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2648. if (vdev_ch_width == CH_WIDTH_INVALID) {
  2649. spectral_err("Invalid channel width %d", vdev_ch_width);
  2650. return QDF_STATUS_E_FAILURE;
  2651. }
  2652. ch_width[SPECTRAL_SCAN_MODE_NORMAL] = vdev_ch_width;
  2653. ch_width[SPECTRAL_SCAN_MODE_AGILE] =
  2654. target_if_spectral_find_agile_width(spectral, vdev_ch_width,
  2655. is_80_80_agile);
  2656. return QDF_STATUS_SUCCESS;
  2657. }
  2658. /**
  2659. * target_if_spectral_is_valid_80p80_freq() - API to check whether given
  2660. * (cfreq1, cfreq2) pair forms a valid 80+80 combination
  2661. * @pdev: pointer to pdev
  2662. * @cfreq1: center frequency 1
  2663. * @cfreq2: center frequency 2
  2664. *
  2665. * API to check whether given (cfreq1, cfreq2) pair forms a valid 80+80
  2666. * combination
  2667. *
  2668. * Return: true or false
  2669. */
  2670. static bool
  2671. target_if_spectral_is_valid_80p80_freq(struct wlan_objmgr_pdev *pdev,
  2672. uint32_t cfreq1, uint32_t cfreq2)
  2673. {
  2674. struct ch_params ch_params;
  2675. enum channel_state chan_state1;
  2676. enum channel_state chan_state2;
  2677. struct wlan_objmgr_psoc *psoc;
  2678. qdf_assert_always(pdev);
  2679. psoc = wlan_pdev_get_psoc(pdev);
  2680. qdf_assert_always(psoc);
  2681. /* In restricted 80P80 MHz enabled, only one 80+80 MHz
  2682. * channel is supported with cfreq=5690 and cfreq=5775.
  2683. */
  2684. if (wlan_psoc_nif_fw_ext_cap_get(
  2685. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT))
  2686. return CHAN_WITHIN_RESTRICTED_80P80(cfreq1, cfreq2);
  2687. ch_params.center_freq_seg1 = wlan_reg_freq_to_chan(pdev, cfreq2);
  2688. ch_params.mhz_freq_seg1 = cfreq2;
  2689. ch_params.ch_width = CH_WIDTH_80P80MHZ;
  2690. wlan_reg_set_channel_params_for_freq(pdev, cfreq1 - FREQ_OFFSET_10MHZ,
  2691. 0, &ch_params);
  2692. if (ch_params.ch_width != CH_WIDTH_80P80MHZ)
  2693. return false;
  2694. if (ch_params.mhz_freq_seg0 != cfreq1 ||
  2695. ch_params.mhz_freq_seg1 != cfreq2)
  2696. return false;
  2697. chan_state1 = wlan_reg_get_5g_bonded_channel_state_for_freq(
  2698. pdev,
  2699. ch_params.mhz_freq_seg0 - FREQ_OFFSET_10MHZ,
  2700. CH_WIDTH_80MHZ);
  2701. if ((chan_state1 == CHANNEL_STATE_DISABLE) ||
  2702. (chan_state1 == CHANNEL_STATE_INVALID))
  2703. return false;
  2704. chan_state2 = wlan_reg_get_5g_bonded_channel_state_for_freq(
  2705. pdev,
  2706. ch_params.mhz_freq_seg1 - FREQ_OFFSET_10MHZ,
  2707. CH_WIDTH_80MHZ);
  2708. if ((chan_state2 == CHANNEL_STATE_DISABLE) ||
  2709. (chan_state2 == CHANNEL_STATE_INVALID))
  2710. return false;
  2711. if (abs(ch_params.mhz_freq_seg0 - ch_params.mhz_freq_seg1) <=
  2712. FREQ_OFFSET_80MHZ)
  2713. return false;
  2714. return true;
  2715. }
  2716. /**
  2717. * _target_if_set_spectral_config() - Set spectral config
  2718. * @spectral: Pointer to spectral object
  2719. * @param: Spectral parameter id and value
  2720. * @smode: Spectral scan mode
  2721. * @err: Spectral error code
  2722. *
  2723. * API to set spectral configurations
  2724. *
  2725. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2726. */
  2727. static QDF_STATUS
  2728. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  2729. const struct spectral_cp_param *param,
  2730. const enum spectral_scan_mode smode,
  2731. enum spectral_cp_error_code *err)
  2732. {
  2733. struct spectral_config params;
  2734. struct target_if_spectral_ops *p_sops;
  2735. struct spectral_config *sparams;
  2736. QDF_STATUS status;
  2737. bool is_overlapping;
  2738. uint16_t agile_cfreq;
  2739. bool is_valid_chan;
  2740. struct spectral_param_min_max *param_min_max;
  2741. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  2742. enum spectral_scan_mode m;
  2743. struct spectral_config_frequency center_freq = {0};
  2744. if (!err) {
  2745. spectral_err("Error code argument is null");
  2746. QDF_ASSERT(0);
  2747. return QDF_STATUS_E_FAILURE;
  2748. }
  2749. *err = SPECTRAL_SCAN_ERR_INVALID;
  2750. if (!param) {
  2751. spectral_err("Parameter object is null");
  2752. return QDF_STATUS_E_FAILURE;
  2753. }
  2754. if (!spectral) {
  2755. spectral_err("spectral object is NULL");
  2756. return QDF_STATUS_E_FAILURE;
  2757. }
  2758. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2759. param_min_max = &spectral->param_min_max;
  2760. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2761. spectral_err("Invalid Spectral mode %u", smode);
  2762. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2763. return QDF_STATUS_E_FAILURE;
  2764. }
  2765. sparams = &spectral->params[smode];
  2766. m = SPECTRAL_SCAN_MODE_NORMAL;
  2767. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  2768. ch_width[m] = CH_WIDTH_INVALID;
  2769. if (!spectral->params_valid[smode]) {
  2770. target_if_spectral_info_read(spectral,
  2771. smode,
  2772. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2773. &spectral->params[smode],
  2774. sizeof(spectral->params[smode]));
  2775. spectral->params_valid[smode] = true;
  2776. }
  2777. switch (param->id) {
  2778. case SPECTRAL_PARAM_FFT_PERIOD:
  2779. sparams->ss_fft_period = param->value;
  2780. break;
  2781. case SPECTRAL_PARAM_SCAN_PERIOD:
  2782. sparams->ss_period = param->value;
  2783. break;
  2784. case SPECTRAL_PARAM_SCAN_COUNT:
  2785. sparams->ss_count = param->value;
  2786. break;
  2787. case SPECTRAL_PARAM_SHORT_REPORT:
  2788. sparams->ss_short_report = (!!param->value) ? true : false;
  2789. break;
  2790. case SPECTRAL_PARAM_SPECT_PRI:
  2791. sparams->ss_spectral_pri = (!!param->value) ? true : false;
  2792. break;
  2793. case SPECTRAL_PARAM_FFT_SIZE:
  2794. status = target_if_spectral_populate_chwidth
  2795. (spectral, ch_width, spectral->params
  2796. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  2797. if (QDF_IS_STATUS_ERROR(status))
  2798. return QDF_STATUS_E_FAILURE;
  2799. if ((param->value < param_min_max->fft_size_min) ||
  2800. (param->value > param_min_max->fft_size_max
  2801. [ch_width[smode]])) {
  2802. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2803. return QDF_STATUS_E_FAILURE;
  2804. }
  2805. sparams->ss_fft_size = param->value;
  2806. break;
  2807. case SPECTRAL_PARAM_GC_ENA:
  2808. sparams->ss_gc_ena = !!param->value;
  2809. break;
  2810. case SPECTRAL_PARAM_RESTART_ENA:
  2811. sparams->ss_restart_ena = !!param->value;
  2812. break;
  2813. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  2814. sparams->ss_noise_floor_ref = param->value;
  2815. break;
  2816. case SPECTRAL_PARAM_INIT_DELAY:
  2817. sparams->ss_init_delay = param->value;
  2818. break;
  2819. case SPECTRAL_PARAM_NB_TONE_THR:
  2820. sparams->ss_nb_tone_thr = param->value;
  2821. break;
  2822. case SPECTRAL_PARAM_STR_BIN_THR:
  2823. sparams->ss_str_bin_thr = param->value;
  2824. break;
  2825. case SPECTRAL_PARAM_WB_RPT_MODE:
  2826. sparams->ss_wb_rpt_mode = !!param->value;
  2827. break;
  2828. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  2829. sparams->ss_rssi_rpt_mode = !!param->value;
  2830. break;
  2831. case SPECTRAL_PARAM_RSSI_THR:
  2832. sparams->ss_rssi_thr = param->value;
  2833. break;
  2834. case SPECTRAL_PARAM_PWR_FORMAT:
  2835. sparams->ss_pwr_format = !!param->value;
  2836. break;
  2837. case SPECTRAL_PARAM_RPT_MODE:
  2838. if ((param->value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  2839. (param->value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  2840. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2841. return QDF_STATUS_E_FAILURE;
  2842. }
  2843. sparams->ss_rpt_mode = param->value;
  2844. break;
  2845. case SPECTRAL_PARAM_BIN_SCALE:
  2846. sparams->ss_bin_scale = param->value;
  2847. break;
  2848. case SPECTRAL_PARAM_DBM_ADJ:
  2849. sparams->ss_dbm_adj = !!param->value;
  2850. break;
  2851. case SPECTRAL_PARAM_CHN_MASK:
  2852. sparams->ss_chn_mask = param->value;
  2853. break;
  2854. case SPECTRAL_PARAM_FREQUENCY:
  2855. status = target_if_spectral_populate_chwidth(
  2856. spectral, ch_width, param->freq.cfreq2 > 0);
  2857. if (QDF_IS_STATUS_ERROR(status)) {
  2858. spectral_err("Failed to populate channel width");
  2859. return QDF_STATUS_E_FAILURE;
  2860. }
  2861. if (ch_width[smode] != CH_WIDTH_80P80MHZ &&
  2862. param->freq.cfreq2) {
  2863. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2864. spectral_err("Non zero cfreq2 expected for 80p80 only");
  2865. return QDF_STATUS_E_INVAL;
  2866. }
  2867. if (ch_width[smode] == CH_WIDTH_80P80MHZ &&
  2868. !param->freq.cfreq2) {
  2869. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2870. spectral_err("Non zero cfreq2 expected for 80p80");
  2871. return QDF_STATUS_E_INVAL;
  2872. }
  2873. status = target_if_is_center_freq_of_any_chan
  2874. (spectral->pdev_obj, param->freq.cfreq1,
  2875. &is_valid_chan);
  2876. if (QDF_IS_STATUS_ERROR(status))
  2877. return QDF_STATUS_E_FAILURE;
  2878. if (is_valid_chan) {
  2879. status = target_if_calculate_center_freq(
  2880. spectral, ch_width,
  2881. param->freq.cfreq1,
  2882. &agile_cfreq);
  2883. if (QDF_IS_STATUS_ERROR(status)) {
  2884. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2885. return QDF_STATUS_E_FAILURE;
  2886. }
  2887. } else {
  2888. bool is_valid_agile_cfreq;
  2889. status = target_if_validate_center_freq
  2890. (spectral, ch_width, param->freq.cfreq1,
  2891. &is_valid_agile_cfreq);
  2892. if (QDF_IS_STATUS_ERROR(status))
  2893. return QDF_STATUS_E_FAILURE;
  2894. if (!is_valid_agile_cfreq) {
  2895. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2896. spectral_err("Invalid agile center frequency");
  2897. return QDF_STATUS_E_FAILURE;
  2898. }
  2899. agile_cfreq = param->freq.cfreq1;
  2900. }
  2901. center_freq.cfreq1 = agile_cfreq;
  2902. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  2903. status = target_if_is_center_freq_of_any_chan
  2904. (spectral->pdev_obj, param->freq.cfreq2,
  2905. &is_valid_chan);
  2906. if (QDF_IS_STATUS_ERROR(status))
  2907. return QDF_STATUS_E_FAILURE;
  2908. if (is_valid_chan) {
  2909. status = target_if_calculate_center_freq(
  2910. spectral, ch_width,
  2911. param->freq.cfreq2,
  2912. &agile_cfreq);
  2913. if (QDF_IS_STATUS_ERROR(status)) {
  2914. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2915. return QDF_STATUS_E_FAILURE;
  2916. }
  2917. } else {
  2918. bool is_valid_agile_cfreq;
  2919. status = target_if_validate_center_freq
  2920. (spectral, ch_width, param->freq.cfreq2,
  2921. &is_valid_agile_cfreq);
  2922. if (QDF_IS_STATUS_ERROR(status))
  2923. return QDF_STATUS_E_FAILURE;
  2924. if (!is_valid_agile_cfreq) {
  2925. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2926. spectral_err("Invalid agile center frequency");
  2927. return QDF_STATUS_E_FAILURE;
  2928. }
  2929. agile_cfreq = param->freq.cfreq2;
  2930. }
  2931. center_freq.cfreq2 = agile_cfreq;
  2932. }
  2933. status = target_if_is_agile_span_overlap_with_operating_span
  2934. (spectral, ch_width,
  2935. &center_freq, &is_overlapping);
  2936. if (QDF_IS_STATUS_ERROR(status))
  2937. return QDF_STATUS_E_FAILURE;
  2938. if (is_overlapping) {
  2939. spectral_err("Agile freq %u, %u overlaps with operating span",
  2940. center_freq.cfreq1, center_freq.cfreq2);
  2941. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2942. return QDF_STATUS_E_FAILURE;
  2943. }
  2944. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  2945. bool is_valid_80p80;
  2946. is_valid_80p80 = target_if_spectral_is_valid_80p80_freq(
  2947. spectral->pdev_obj,
  2948. center_freq.cfreq1,
  2949. center_freq.cfreq2);
  2950. if (!is_valid_80p80) {
  2951. spectral_err("Agile freq %u, %u is invalid 80+80 combination",
  2952. center_freq.cfreq1,
  2953. center_freq.cfreq2);
  2954. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2955. return QDF_STATUS_E_FAILURE;
  2956. }
  2957. }
  2958. sparams->ss_frequency.cfreq1 = center_freq.cfreq1;
  2959. sparams->ss_frequency.cfreq2 = center_freq.cfreq2;
  2960. break;
  2961. }
  2962. p_sops->configure_spectral(spectral, sparams, smode);
  2963. /* only to validate the writes */
  2964. p_sops->get_spectral_config(spectral, &params, smode);
  2965. return QDF_STATUS_SUCCESS;
  2966. }
  2967. QDF_STATUS
  2968. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  2969. const struct spectral_cp_param *param,
  2970. const enum spectral_scan_mode smode,
  2971. enum spectral_cp_error_code *err)
  2972. {
  2973. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  2974. struct target_if_spectral *spectral;
  2975. QDF_STATUS status;
  2976. if (!err) {
  2977. spectral_err("Error code argument is null");
  2978. QDF_ASSERT(0);
  2979. return QDF_STATUS_E_FAILURE;
  2980. }
  2981. *err = SPECTRAL_SCAN_ERR_INVALID;
  2982. if (!pdev) {
  2983. spectral_err("pdev object is NULL");
  2984. return QDF_STATUS_E_FAILURE;
  2985. }
  2986. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2987. if (!spectral) {
  2988. spectral_err("spectral object is NULL");
  2989. return QDF_STATUS_E_FAILURE;
  2990. }
  2991. if (!param) {
  2992. spectral_err("parameter object is NULL");
  2993. return QDF_STATUS_E_FAILURE;
  2994. }
  2995. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2996. spectral_err("Invalid Spectral mode %u", smode);
  2997. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2998. return QDF_STATUS_E_FAILURE;
  2999. }
  3000. if (!spectral->properties[smode][param->id].supported) {
  3001. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  3002. param->id, smode);
  3003. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  3004. return QDF_STATUS_E_FAILURE;
  3005. }
  3006. if (spectral->properties[smode][param->id].common_all_modes) {
  3007. spectral_warn("Setting Spectral parameter %u for all modes",
  3008. param->id);
  3009. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  3010. status = _target_if_set_spectral_config
  3011. (spectral, param, mode, err);
  3012. if (QDF_IS_STATUS_ERROR(status))
  3013. return QDF_STATUS_E_FAILURE;
  3014. }
  3015. return QDF_STATUS_SUCCESS;
  3016. }
  3017. return _target_if_set_spectral_config(spectral, param, smode, err);
  3018. }
  3019. /**
  3020. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  3021. * @fft_len: FFT length
  3022. * @pdev: Pointer to pdev object
  3023. *
  3024. * API to get fft bin count for a given fft length
  3025. *
  3026. * Return: FFt bin count
  3027. */
  3028. static int
  3029. target_if_get_fft_bin_count(int fft_len)
  3030. {
  3031. int bin_count = 0;
  3032. switch (fft_len) {
  3033. case 5:
  3034. bin_count = 16;
  3035. break;
  3036. case 6:
  3037. bin_count = 32;
  3038. break;
  3039. case 7:
  3040. bin_count = 64;
  3041. break;
  3042. case 8:
  3043. bin_count = 128;
  3044. break;
  3045. case 9:
  3046. bin_count = 256;
  3047. break;
  3048. default:
  3049. break;
  3050. }
  3051. return bin_count;
  3052. }
  3053. /**
  3054. * target_if_init_upper_lower_flags() - Initializes control and extension
  3055. * segment flags
  3056. * @fft_len: FFT length
  3057. * @pdev: Pointer to pdev object
  3058. *
  3059. * API to initialize the control and extension flags with the lower/upper
  3060. * segment based on the HT mode
  3061. *
  3062. * Return: FFt bin count
  3063. */
  3064. static void
  3065. target_if_init_upper_lower_flags(struct target_if_spectral *spectral)
  3066. {
  3067. int current_channel = 0;
  3068. int ext_channel = 0;
  3069. struct target_if_spectral_ops *p_sops =
  3070. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3071. current_channel = p_sops->get_current_channel(spectral);
  3072. ext_channel = p_sops->get_extension_channel(spectral);
  3073. if ((current_channel == 0) || (ext_channel == 0))
  3074. return;
  3075. if (spectral->sc_spectral_20_40_mode) {
  3076. /* HT40 mode */
  3077. if (ext_channel < current_channel) {
  3078. spectral->lower_is_extension = 1;
  3079. spectral->upper_is_control = 1;
  3080. spectral->lower_is_control = 0;
  3081. spectral->upper_is_extension = 0;
  3082. } else {
  3083. spectral->lower_is_extension = 0;
  3084. spectral->upper_is_control = 0;
  3085. spectral->lower_is_control = 1;
  3086. spectral->upper_is_extension = 1;
  3087. }
  3088. } else {
  3089. /* HT20 mode, lower is always control */
  3090. spectral->lower_is_extension = 0;
  3091. spectral->upper_is_control = 0;
  3092. spectral->lower_is_control = 1;
  3093. spectral->upper_is_extension = 0;
  3094. }
  3095. }
  3096. /**
  3097. * target_if_get_spectral_config() - Get spectral configuration
  3098. * @pdev: Pointer to pdev object
  3099. * @param: Pointer to spectral_config structure in which the configuration
  3100. * should be returned
  3101. * @smode: Spectral scan mode
  3102. *
  3103. * API to get the current spectral configuration
  3104. *
  3105. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3106. */
  3107. QDF_STATUS
  3108. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  3109. struct spectral_config *param,
  3110. enum spectral_scan_mode smode)
  3111. {
  3112. struct target_if_spectral_ops *p_sops = NULL;
  3113. struct target_if_spectral *spectral = NULL;
  3114. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3115. if (!spectral) {
  3116. spectral_err("SPECTRAL : Module doesn't exist");
  3117. return QDF_STATUS_E_FAILURE;
  3118. }
  3119. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3120. if (!p_sops) {
  3121. spectral_err("p_sops is null");
  3122. return QDF_STATUS_E_FAILURE;
  3123. }
  3124. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3125. spectral_err("Invalid Spectral mode %u", smode);
  3126. return QDF_STATUS_E_FAILURE;
  3127. }
  3128. qdf_mem_zero(param, sizeof(struct spectral_config));
  3129. p_sops->get_spectral_config(spectral, param, smode);
  3130. return QDF_STATUS_SUCCESS;
  3131. }
  3132. /**
  3133. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  3134. * parameters
  3135. * @spectral: Pointer to Spectral target_if internal private data
  3136. * @spectral_params: Pointer to Spectral parameters
  3137. * @smode: Spectral scan mode
  3138. * @err: Spectral error code
  3139. *
  3140. * Enable use of desired Spectral parameters by configuring them into HW, and
  3141. * starting Spectral scan
  3142. *
  3143. * Return: 0 on success, 1 on failure
  3144. */
  3145. int
  3146. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  3147. struct spectral_config *spectral_params,
  3148. enum spectral_scan_mode smode,
  3149. enum spectral_cp_error_code *err)
  3150. {
  3151. int extension_channel = 0;
  3152. int current_channel = 0;
  3153. struct target_if_spectral_ops *p_sops = NULL;
  3154. QDF_STATUS status;
  3155. struct wlan_objmgr_pdev *pdev;
  3156. struct wlan_objmgr_psoc *psoc;
  3157. if (!spectral) {
  3158. spectral_err("Spectral LMAC object is NULL");
  3159. return 1;
  3160. }
  3161. pdev = spectral->pdev_obj;
  3162. if (!pdev) {
  3163. spectral_err("pdev is null");
  3164. return QDF_STATUS_E_INVAL;
  3165. }
  3166. psoc = wlan_pdev_get_psoc(pdev);
  3167. if (!psoc) {
  3168. spectral_err("psoc is null");
  3169. return QDF_STATUS_E_INVAL;
  3170. }
  3171. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3172. spectral_err("Invalid Spectral mode %u", smode);
  3173. return 1;
  3174. }
  3175. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3176. if (!p_sops) {
  3177. spectral_err("p_sops is NULL");
  3178. return 1;
  3179. }
  3180. spectral->sc_spectral_noise_pwr_cal =
  3181. spectral_params->ss_spectral_pri ? 1 : 0;
  3182. /* check if extension channel is present */
  3183. extension_channel = p_sops->get_extension_channel(spectral);
  3184. current_channel = p_sops->get_current_channel(spectral);
  3185. status = target_if_spectral_populate_chwidth(
  3186. spectral, spectral->ch_width,
  3187. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  3188. ss_frequency.cfreq2 > 0);
  3189. if (QDF_IS_STATUS_ERROR(status)) {
  3190. spectral_err("Failed to get channel widths");
  3191. return 1;
  3192. }
  3193. if (spectral->capability.advncd_spectral_cap) {
  3194. spectral->lb_edge_extrabins = 0;
  3195. spectral->rb_edge_extrabins = 0;
  3196. if (spectral->is_lb_edge_extrabins_format &&
  3197. spectral->params[smode].ss_rpt_mode == 2) {
  3198. spectral->lb_edge_extrabins = 4;
  3199. }
  3200. if (spectral->is_rb_edge_extrabins_format &&
  3201. spectral->params[smode].ss_rpt_mode == 2) {
  3202. spectral->rb_edge_extrabins = 4;
  3203. }
  3204. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  3205. spectral->sc_spectral_20_40_mode = 0;
  3206. spectral->spectral_numbins =
  3207. target_if_get_fft_bin_count(
  3208. spectral->params[smode].ss_fft_size);
  3209. spectral->spectral_fft_len =
  3210. target_if_get_fft_bin_count(
  3211. spectral->params[smode].ss_fft_size);
  3212. spectral->spectral_data_len =
  3213. target_if_get_fft_bin_count(
  3214. spectral->params[smode].ss_fft_size);
  3215. /*
  3216. * Initialize classifier params to be sent to user
  3217. * space classifier
  3218. */
  3219. spectral->classifier_params.lower_chan_in_mhz =
  3220. current_channel;
  3221. spectral->classifier_params.upper_chan_in_mhz = 0;
  3222. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  3223. /* TODO : Remove this variable */
  3224. spectral->sc_spectral_20_40_mode = 1;
  3225. spectral->spectral_numbins =
  3226. target_if_get_fft_bin_count(
  3227. spectral->params[smode].ss_fft_size);
  3228. spectral->spectral_fft_len =
  3229. target_if_get_fft_bin_count(
  3230. spectral->params[smode].ss_fft_size);
  3231. spectral->spectral_data_len =
  3232. target_if_get_fft_bin_count(
  3233. spectral->params[smode].ss_fft_size);
  3234. /*
  3235. * Initialize classifier params to be sent to user
  3236. * space classifier
  3237. */
  3238. if (extension_channel < current_channel) {
  3239. spectral->classifier_params.lower_chan_in_mhz =
  3240. extension_channel;
  3241. spectral->classifier_params.upper_chan_in_mhz =
  3242. current_channel;
  3243. } else {
  3244. spectral->classifier_params.lower_chan_in_mhz =
  3245. current_channel;
  3246. spectral->classifier_params.upper_chan_in_mhz =
  3247. extension_channel;
  3248. }
  3249. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  3250. /* Set the FFT Size */
  3251. /* TODO : Remove this variable */
  3252. spectral->sc_spectral_20_40_mode = 0;
  3253. spectral->spectral_numbins =
  3254. target_if_get_fft_bin_count(
  3255. spectral->params[smode].ss_fft_size);
  3256. spectral->spectral_fft_len =
  3257. target_if_get_fft_bin_count(
  3258. spectral->params[smode].ss_fft_size);
  3259. spectral->spectral_data_len =
  3260. target_if_get_fft_bin_count(
  3261. spectral->params[smode].ss_fft_size);
  3262. /*
  3263. * Initialize classifier params to be sent to user
  3264. * space classifier
  3265. */
  3266. spectral->classifier_params.lower_chan_in_mhz =
  3267. current_channel;
  3268. spectral->classifier_params.upper_chan_in_mhz = 0;
  3269. /*
  3270. * Initialize classifier params to be sent to user
  3271. * space classifier
  3272. */
  3273. if (extension_channel < current_channel) {
  3274. spectral->classifier_params.lower_chan_in_mhz =
  3275. extension_channel;
  3276. spectral->classifier_params.upper_chan_in_mhz =
  3277. current_channel;
  3278. } else {
  3279. spectral->classifier_params.lower_chan_in_mhz =
  3280. current_channel;
  3281. spectral->classifier_params.upper_chan_in_mhz =
  3282. extension_channel;
  3283. }
  3284. } else if (is_ch_width_160_or_80p80(
  3285. spectral->ch_width[smode])) {
  3286. /* Set the FFT Size */
  3287. /* The below applies to both 160 and 80+80 cases */
  3288. /* TODO : Remove this variable */
  3289. spectral->sc_spectral_20_40_mode = 0;
  3290. spectral->spectral_numbins =
  3291. target_if_get_fft_bin_count(
  3292. spectral->params[smode].ss_fft_size);
  3293. spectral->spectral_fft_len =
  3294. target_if_get_fft_bin_count(
  3295. spectral->params[smode].ss_fft_size);
  3296. spectral->spectral_data_len =
  3297. target_if_get_fft_bin_count(
  3298. spectral->params[smode].ss_fft_size);
  3299. /*
  3300. * Initialize classifier params to be sent to user
  3301. * space classifier
  3302. */
  3303. spectral->classifier_params.lower_chan_in_mhz =
  3304. current_channel;
  3305. spectral->classifier_params.upper_chan_in_mhz = 0;
  3306. /*
  3307. * Initialize classifier params to be sent to user
  3308. * space classifier
  3309. */
  3310. if (extension_channel < current_channel) {
  3311. spectral->classifier_params.lower_chan_in_mhz =
  3312. extension_channel;
  3313. spectral->classifier_params.upper_chan_in_mhz =
  3314. current_channel;
  3315. } else {
  3316. spectral->classifier_params.lower_chan_in_mhz =
  3317. current_channel;
  3318. spectral->classifier_params.upper_chan_in_mhz =
  3319. extension_channel;
  3320. }
  3321. }
  3322. if (spectral->spectral_numbins) {
  3323. spectral->spectral_numbins +=
  3324. spectral->lb_edge_extrabins;
  3325. spectral->spectral_numbins +=
  3326. spectral->rb_edge_extrabins;
  3327. }
  3328. if (spectral->spectral_fft_len) {
  3329. spectral->spectral_fft_len +=
  3330. spectral->lb_edge_extrabins;
  3331. spectral->spectral_fft_len +=
  3332. spectral->rb_edge_extrabins;
  3333. }
  3334. if (spectral->spectral_data_len) {
  3335. spectral->spectral_data_len +=
  3336. spectral->lb_edge_extrabins;
  3337. spectral->spectral_data_len +=
  3338. spectral->rb_edge_extrabins;
  3339. }
  3340. } else {
  3341. /*
  3342. * The decision to find 20/40 mode is found based on the
  3343. * presence of extension channel
  3344. * instead of channel width, as the channel width can
  3345. * dynamically change
  3346. */
  3347. if (extension_channel == 0) {
  3348. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  3349. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  3350. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  3351. spectral->spectral_data_len =
  3352. SPECTRAL_HT20_TOTAL_DATA_LEN;
  3353. /* only valid in 20-40 mode */
  3354. spectral->spectral_lower_max_index_offset = -1;
  3355. /* only valid in 20-40 mode */
  3356. spectral->spectral_upper_max_index_offset = -1;
  3357. spectral->spectral_max_index_offset =
  3358. spectral->spectral_fft_len + 2;
  3359. spectral->sc_spectral_20_40_mode = 0;
  3360. /*
  3361. * Initialize classifier params to be sent to user
  3362. * space classifier
  3363. */
  3364. spectral->classifier_params.lower_chan_in_mhz =
  3365. current_channel;
  3366. spectral->classifier_params.upper_chan_in_mhz = 0;
  3367. } else {
  3368. spectral->spectral_numbins =
  3369. SPECTRAL_HT40_TOTAL_NUM_BINS;
  3370. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  3371. spectral->spectral_data_len =
  3372. SPECTRAL_HT40_TOTAL_DATA_LEN;
  3373. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  3374. /* only valid in 20 mode */
  3375. spectral->spectral_max_index_offset = -1;
  3376. spectral->spectral_lower_max_index_offset =
  3377. spectral->spectral_fft_len + 2;
  3378. spectral->spectral_upper_max_index_offset =
  3379. spectral->spectral_fft_len + 5;
  3380. spectral->sc_spectral_20_40_mode = 1;
  3381. /*
  3382. * Initialize classifier params to be sent to user
  3383. * space classifier
  3384. */
  3385. if (extension_channel < current_channel) {
  3386. spectral->classifier_params.lower_chan_in_mhz =
  3387. extension_channel;
  3388. spectral->classifier_params.upper_chan_in_mhz =
  3389. current_channel;
  3390. } else {
  3391. spectral->classifier_params.lower_chan_in_mhz =
  3392. current_channel;
  3393. spectral->classifier_params.upper_chan_in_mhz =
  3394. extension_channel;
  3395. }
  3396. }
  3397. }
  3398. spectral->send_single_packet = 0;
  3399. spectral->classifier_params.spectral_20_40_mode =
  3400. spectral->sc_spectral_20_40_mode;
  3401. spectral->classifier_params.spectral_dc_index =
  3402. spectral->spectral_dc_index;
  3403. spectral->spectral_sent_msg = 0;
  3404. spectral->classify_scan = 0;
  3405. spectral->num_spectral_data = 0;
  3406. if (!p_sops->is_spectral_active(spectral, smode)) {
  3407. p_sops->configure_spectral(spectral, spectral_params, smode);
  3408. spectral->rparams.marker[smode].is_valid = false;
  3409. p_sops->start_spectral_scan(spectral, smode, err);
  3410. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  3411. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  3412. }
  3413. /* get current spectral configuration */
  3414. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  3415. target_if_init_upper_lower_flags(spectral);
  3416. return 0;
  3417. }
  3418. /**
  3419. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  3420. * Agile DFS
  3421. * @psoc: Pointer to psoc
  3422. * @object: Pointer to pdev
  3423. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  3424. *
  3425. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  3426. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  3427. *
  3428. * Return: void
  3429. */
  3430. static void
  3431. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  3432. void *object, void *arg)
  3433. {
  3434. bool *is_aspectral_prohibited = arg;
  3435. struct wlan_objmgr_pdev *cur_pdev = object;
  3436. bool is_agile_dfs_enabled_cur_pdev = false;
  3437. QDF_STATUS status;
  3438. qdf_assert_always(is_aspectral_prohibited);
  3439. if (*is_aspectral_prohibited)
  3440. return;
  3441. qdf_assert_always(psoc);
  3442. qdf_assert_always(cur_pdev);
  3443. status = ucfg_dfs_get_agile_precac_enable
  3444. (cur_pdev,
  3445. &is_agile_dfs_enabled_cur_pdev);
  3446. if (QDF_IS_STATUS_ERROR(status)) {
  3447. spectral_err("Get agile precac failed, prohibiting aSpectral");
  3448. *is_aspectral_prohibited = true;
  3449. return;
  3450. }
  3451. if (is_agile_dfs_enabled_cur_pdev) {
  3452. spectral_err("aDFS is in progress on one of the pdevs");
  3453. *is_aspectral_prohibited = true;
  3454. }
  3455. }
  3456. /**
  3457. * target_if_get_curr_band() - Get current operating band of pdev
  3458. *
  3459. * @spectral: pointer to spectral object
  3460. *
  3461. * API to get current operating band of a given pdev.
  3462. *
  3463. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  3464. */
  3465. static enum reg_wifi_band
  3466. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev)
  3467. {
  3468. struct wlan_objmgr_vdev *vdev;
  3469. int16_t chan_freq;
  3470. enum reg_wifi_band cur_band;
  3471. if (!pdev) {
  3472. spectral_err("pdev is NULL");
  3473. return REG_BAND_UNKNOWN;
  3474. }
  3475. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  3476. if (!vdev) {
  3477. spectral_debug("vdev is NULL");
  3478. return REG_BAND_UNKNOWN;
  3479. }
  3480. chan_freq = target_if_vdev_get_chan_freq(vdev);
  3481. cur_band = wlan_reg_freq_to_band(chan_freq);
  3482. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3483. return cur_band;
  3484. }
  3485. /**
  3486. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  3487. * any of the 5G pdevs
  3488. * @psoc: Pointer to psoc
  3489. * @object: Pointer to pdev
  3490. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  3491. * progress in any 5G pdevs
  3492. *
  3493. * Return: void
  3494. */
  3495. static void
  3496. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  3497. void *object, void *arg)
  3498. {
  3499. enum reg_wifi_band band;
  3500. bool *is_agile_scan_inprog_5g_pdev = arg;
  3501. struct target_if_spectral *spectral;
  3502. struct wlan_objmgr_pdev *cur_pdev = object;
  3503. struct target_if_spectral_ops *p_sops;
  3504. if (*is_agile_scan_inprog_5g_pdev)
  3505. return;
  3506. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  3507. if (!spectral) {
  3508. spectral_err("target if spectral handle is NULL");
  3509. return;
  3510. }
  3511. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3512. band = target_if_get_curr_band(cur_pdev);
  3513. if (band == REG_BAND_UNKNOWN) {
  3514. spectral_debug("Failed to get current band");
  3515. return;
  3516. }
  3517. if (band == REG_BAND_5G &&
  3518. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  3519. *is_agile_scan_inprog_5g_pdev = true;
  3520. }
  3521. /**
  3522. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  3523. * for current vdev rx chainmask.
  3524. *
  3525. * @spectral: Pointer to Spectral object
  3526. * @is_supported: Pointer to is_supported
  3527. *
  3528. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3529. */
  3530. static QDF_STATUS
  3531. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  3532. bool *is_supported)
  3533. {
  3534. struct wlan_objmgr_vdev *vdev;
  3535. uint8_t vdev_rxchainmask;
  3536. struct wlan_objmgr_psoc *psoc;
  3537. struct wlan_objmgr_pdev *pdev;
  3538. struct target_psoc_info *tgt_psoc_info;
  3539. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  3540. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  3541. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  3542. struct wlan_psoc_host_chainmask_table *table;
  3543. int j;
  3544. uint32_t table_id;
  3545. enum phy_ch_width ch_width;
  3546. uint8_t pdev_id;
  3547. if (!spectral) {
  3548. spectral_err("spectral target if object is null");
  3549. return QDF_STATUS_E_FAILURE;
  3550. }
  3551. if (!is_supported) {
  3552. spectral_err("is supported argument is null");
  3553. return QDF_STATUS_E_FAILURE;
  3554. }
  3555. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  3556. spectral_err("HW Agile mode is not supported up to gen 2");
  3557. return QDF_STATUS_E_FAILURE;
  3558. }
  3559. pdev = spectral->pdev_obj;
  3560. if (!pdev) {
  3561. spectral_err("pdev is null");
  3562. return QDF_STATUS_E_FAILURE;
  3563. }
  3564. psoc = wlan_pdev_get_psoc(pdev);
  3565. if (!psoc) {
  3566. spectral_err("psoc is null");
  3567. return QDF_STATUS_E_FAILURE;
  3568. }
  3569. vdev = target_if_spectral_get_vdev(spectral);
  3570. if (!vdev) {
  3571. spectral_err("First vdev is NULL");
  3572. return QDF_STATUS_E_FAILURE;
  3573. }
  3574. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  3575. if (!vdev_rxchainmask) {
  3576. spectral_err("vdev rx chainmask is zero");
  3577. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3578. return QDF_STATUS_E_FAILURE;
  3579. }
  3580. ch_width = target_if_vdev_get_ch_width(vdev);
  3581. if (ch_width == CH_WIDTH_INVALID) {
  3582. spectral_err("Invalid channel width");
  3583. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3584. return QDF_STATUS_E_FAILURE;
  3585. }
  3586. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3587. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  3588. if (!tgt_psoc_info) {
  3589. spectral_err("target_psoc_info is null");
  3590. return QDF_STATUS_E_FAILURE;
  3591. }
  3592. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  3593. if (!ext_svc_param) {
  3594. spectral_err("Extended service ready param null");
  3595. return QDF_STATUS_E_FAILURE;
  3596. }
  3597. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  3598. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  3599. if (!mac_phy_cap_arr) {
  3600. spectral_err("mac phy cap array is null");
  3601. return QDF_STATUS_E_FAILURE;
  3602. }
  3603. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  3604. if (!mac_phy_cap) {
  3605. spectral_err("mac phy cap is null");
  3606. return QDF_STATUS_E_FAILURE;
  3607. }
  3608. table_id = mac_phy_cap->chainmask_table_id;
  3609. table = &ext_svc_param->chainmask_table[table_id];
  3610. if (!table) {
  3611. spectral_err("chainmask table not found");
  3612. return QDF_STATUS_E_FAILURE;
  3613. }
  3614. for (j = 0; j < table->num_valid_chainmasks; j++) {
  3615. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  3616. if (ch_width <= CH_WIDTH_80MHZ)
  3617. *is_supported =
  3618. table->cap_list[j].supports_aSpectral;
  3619. else
  3620. *is_supported =
  3621. table->cap_list[j].supports_aSpectral_160;
  3622. break;
  3623. }
  3624. }
  3625. if (j == table->num_valid_chainmasks) {
  3626. spectral_err("vdev rx chainmask %u not found in table id = %u",
  3627. vdev_rxchainmask, table_id);
  3628. return QDF_STATUS_E_FAILURE;
  3629. }
  3630. return QDF_STATUS_SUCCESS;
  3631. }
  3632. QDF_STATUS
  3633. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3634. const enum spectral_scan_mode smode,
  3635. enum spectral_cp_error_code *err)
  3636. {
  3637. struct target_if_spectral_ops *p_sops;
  3638. struct target_if_spectral *spectral;
  3639. struct wlan_objmgr_psoc *psoc;
  3640. enum reg_wifi_band band;
  3641. if (!err) {
  3642. spectral_err("Error code argument is null");
  3643. QDF_ASSERT(0);
  3644. return QDF_STATUS_E_FAILURE;
  3645. }
  3646. *err = SPECTRAL_SCAN_ERR_INVALID;
  3647. if (!pdev) {
  3648. spectral_err("pdev object is NUll");
  3649. return QDF_STATUS_E_FAILURE;
  3650. }
  3651. psoc = wlan_pdev_get_psoc(pdev);
  3652. if (!psoc) {
  3653. spectral_err("psoc is null");
  3654. return QDF_STATUS_E_FAILURE;
  3655. }
  3656. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3657. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3658. spectral_err("Invalid Spectral mode %u", smode);
  3659. return QDF_STATUS_E_FAILURE;
  3660. }
  3661. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3662. if (!spectral) {
  3663. spectral_err("Spectral LMAC object is NUll");
  3664. return QDF_STATUS_E_FAILURE;
  3665. }
  3666. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3667. if (!p_sops) {
  3668. spectral_err("p_sops is null");
  3669. return QDF_STATUS_E_FAILURE;
  3670. }
  3671. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3672. QDF_STATUS status;
  3673. bool is_supported = false;
  3674. status = target_if_is_agile_supported_cur_chmask(spectral,
  3675. &is_supported);
  3676. if (QDF_IS_STATUS_ERROR(status)) {
  3677. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3678. return QDF_STATUS_E_FAILURE;
  3679. }
  3680. if (!is_supported) {
  3681. spectral_err("aSpectral unsupported for cur chainmask");
  3682. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3683. return QDF_STATUS_E_FAILURE;
  3684. }
  3685. }
  3686. band = target_if_get_curr_band(spectral->pdev_obj);
  3687. if (band == REG_BAND_UNKNOWN) {
  3688. spectral_err("Failed to get current band");
  3689. return QDF_STATUS_E_FAILURE;
  3690. }
  3691. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  3692. struct target_psoc_info *tgt_hdl;
  3693. enum wmi_host_hw_mode_config_type mode;
  3694. bool is_agile_scan_inprog_5g_pdev;
  3695. if (p_sops->is_spectral_active(spectral,
  3696. SPECTRAL_SCAN_MODE_AGILE)) {
  3697. spectral_err("Agile Scan in progress in current pdev");
  3698. return QDF_STATUS_E_FAILURE;
  3699. }
  3700. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  3701. if (!tgt_hdl) {
  3702. target_if_err("target_psoc_info is null");
  3703. return QDF_STATUS_E_FAILURE;
  3704. }
  3705. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  3706. switch (mode) {
  3707. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  3708. case WMI_HOST_HW_MODE_SBS:
  3709. case WMI_HOST_HW_MODE_DBS_SBS:
  3710. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  3711. is_agile_scan_inprog_5g_pdev = false;
  3712. wlan_objmgr_iterate_obj_list
  3713. (psoc, WLAN_PDEV_OP,
  3714. target_if_is_agile_scan_active_in_5g,
  3715. &is_agile_scan_inprog_5g_pdev, 0,
  3716. WLAN_SPECTRAL_ID);
  3717. break;
  3718. default:
  3719. is_agile_scan_inprog_5g_pdev = false;
  3720. break;
  3721. }
  3722. if (is_agile_scan_inprog_5g_pdev) {
  3723. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  3724. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3725. return QDF_STATUS_E_FAILURE;
  3726. }
  3727. }
  3728. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3729. bool is_aspectral_prohibited = false;
  3730. QDF_STATUS status;
  3731. status = wlan_objmgr_iterate_obj_list
  3732. (psoc, WLAN_PDEV_OP,
  3733. target_if_is_aspectral_prohibited_by_adfs,
  3734. &is_aspectral_prohibited, 0,
  3735. WLAN_SPECTRAL_ID);
  3736. if (QDF_IS_STATUS_ERROR(status)) {
  3737. spectral_err("Failed to iterate over pdevs");
  3738. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3739. return QDF_STATUS_E_FAILURE;
  3740. }
  3741. if (is_aspectral_prohibited) {
  3742. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3743. return QDF_STATUS_E_FAILURE;
  3744. }
  3745. }
  3746. if (!spectral->params_valid[smode]) {
  3747. target_if_spectral_info_read(spectral,
  3748. smode,
  3749. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3750. &spectral->params[smode],
  3751. sizeof(spectral->params[smode]));
  3752. spectral->params_valid[smode] = true;
  3753. }
  3754. qdf_spin_lock(&spectral->spectral_lock);
  3755. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3756. QDF_STATUS status;
  3757. bool is_overlapping;
  3758. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  3759. enum spectral_scan_mode m;
  3760. enum phy_ch_width op_ch_width;
  3761. enum phy_ch_width agile_ch_width;
  3762. m = SPECTRAL_SCAN_MODE_NORMAL;
  3763. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  3764. ch_width[m] = CH_WIDTH_INVALID;
  3765. status = target_if_spectral_populate_chwidth
  3766. (spectral, ch_width, spectral->params
  3767. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  3768. if (QDF_IS_STATUS_ERROR(status)) {
  3769. qdf_spin_unlock(&spectral->spectral_lock);
  3770. spectral_err("Failed to populate channel width");
  3771. return QDF_STATUS_E_FAILURE;
  3772. }
  3773. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  3774. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3775. if (!spectral->params[smode].ss_frequency.cfreq1 ||
  3776. (agile_ch_width == CH_WIDTH_80P80MHZ &&
  3777. !spectral->params[smode].ss_frequency.cfreq2)) {
  3778. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  3779. qdf_spin_unlock(&spectral->spectral_lock);
  3780. return QDF_STATUS_E_FAILURE;
  3781. }
  3782. status = target_if_is_agile_span_overlap_with_operating_span
  3783. (spectral, ch_width,
  3784. &spectral->params[smode].ss_frequency,
  3785. &is_overlapping);
  3786. if (QDF_IS_STATUS_ERROR(status)) {
  3787. qdf_spin_unlock(&spectral->spectral_lock);
  3788. return QDF_STATUS_E_FAILURE;
  3789. }
  3790. if (is_overlapping) {
  3791. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3792. qdf_spin_unlock(&spectral->spectral_lock);
  3793. return QDF_STATUS_E_FAILURE;
  3794. }
  3795. }
  3796. target_if_spectral_scan_enable_params(spectral,
  3797. &spectral->params[smode], smode,
  3798. err);
  3799. qdf_spin_unlock(&spectral->spectral_lock);
  3800. return QDF_STATUS_SUCCESS;
  3801. }
  3802. QDF_STATUS
  3803. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3804. const enum spectral_scan_mode smode,
  3805. enum spectral_cp_error_code *err)
  3806. {
  3807. struct target_if_spectral_ops *p_sops;
  3808. struct target_if_spectral *spectral;
  3809. if (!err) {
  3810. spectral_err("Error code argument is null");
  3811. QDF_ASSERT(0);
  3812. return QDF_STATUS_E_FAILURE;
  3813. }
  3814. *err = SPECTRAL_SCAN_ERR_INVALID;
  3815. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3816. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3817. spectral_err("Invalid Spectral mode %u", smode);
  3818. return QDF_STATUS_E_FAILURE;
  3819. }
  3820. if (!pdev) {
  3821. spectral_err("pdev object is NUll ");
  3822. return QDF_STATUS_E_FAILURE;
  3823. }
  3824. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3825. if (!spectral) {
  3826. spectral_err("Spectral LMAC object is NUll ");
  3827. return QDF_STATUS_E_FAILURE;
  3828. }
  3829. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3830. qdf_spin_lock(&spectral->spectral_lock);
  3831. p_sops->stop_spectral_scan(spectral, smode);
  3832. if (spectral->classify_scan) {
  3833. /* TODO : Check if this logic is necessary */
  3834. spectral->detects_control_channel = 0;
  3835. spectral->detects_extension_channel = 0;
  3836. spectral->detects_above_dc = 0;
  3837. spectral->detects_below_dc = 0;
  3838. spectral->classify_scan = 0;
  3839. }
  3840. spectral->send_single_packet = 0;
  3841. spectral->sc_spectral_scan = 0;
  3842. qdf_spin_unlock(&spectral->spectral_lock);
  3843. return QDF_STATUS_SUCCESS;
  3844. }
  3845. /**
  3846. * target_if_is_spectral_active() - Get whether Spectral is active
  3847. * @pdev: Pointer to pdev object
  3848. * @smode: Spectral scan mode
  3849. *
  3850. * API to get whether Spectral is active
  3851. *
  3852. * Return: True if Spectral is active, false if Spectral is not active
  3853. */
  3854. bool
  3855. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  3856. const enum spectral_scan_mode smode)
  3857. {
  3858. struct target_if_spectral *spectral = NULL;
  3859. struct target_if_spectral_ops *p_sops = NULL;
  3860. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3861. if (!spectral) {
  3862. spectral_err("SPECTRAL : Module doesn't exist");
  3863. return QDF_STATUS_E_FAILURE;
  3864. }
  3865. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3866. if (!p_sops) {
  3867. spectral_err("p_sops is null");
  3868. return QDF_STATUS_E_FAILURE;
  3869. }
  3870. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3871. spectral_err("Invalid Spectral mode %u", smode);
  3872. return QDF_STATUS_E_FAILURE;
  3873. }
  3874. return p_sops->is_spectral_active(spectral, smode);
  3875. }
  3876. /**
  3877. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  3878. * @pdev: Pointer to pdev object
  3879. * @smode: Spectral scan mode
  3880. *
  3881. * API to get whether Spectral is enabled
  3882. *
  3883. * Return: True if Spectral is enabled, false if Spectral is not enabled
  3884. */
  3885. bool
  3886. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  3887. enum spectral_scan_mode smode)
  3888. {
  3889. struct target_if_spectral *spectral = NULL;
  3890. struct target_if_spectral_ops *p_sops = NULL;
  3891. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3892. if (!spectral) {
  3893. spectral_err("SPECTRAL : Module doesn't exist");
  3894. return QDF_STATUS_E_FAILURE;
  3895. }
  3896. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3897. if (!p_sops) {
  3898. spectral_err("p_sops is null");
  3899. return QDF_STATUS_E_FAILURE;
  3900. }
  3901. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3902. spectral_err("Invalid Spectral mode %u", smode);
  3903. return QDF_STATUS_E_FAILURE;
  3904. }
  3905. return p_sops->is_spectral_enabled(spectral, smode);
  3906. }
  3907. #ifdef DIRECT_BUF_RX_DEBUG
  3908. /**
  3909. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  3910. * @pdev: Pointer to pdev object
  3911. * @enable: Enable/Disable Spectral DMA ring debug
  3912. *
  3913. * Start/stop Spectral DMA ring debug based on @enable.
  3914. * Also save the state for future use.
  3915. *
  3916. * Return: QDF_STATUS of operation
  3917. */
  3918. static QDF_STATUS
  3919. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3920. {
  3921. struct target_if_spectral *spectral;
  3922. struct wlan_lmac_if_tx_ops *tx_ops;
  3923. struct wlan_objmgr_psoc *psoc;
  3924. if (!pdev)
  3925. return QDF_STATUS_E_FAILURE;
  3926. psoc = wlan_pdev_get_psoc(pdev);
  3927. if (!psoc) {
  3928. spectral_err("psoc is null");
  3929. return QDF_STATUS_E_INVAL;
  3930. }
  3931. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  3932. if (!tx_ops) {
  3933. spectral_err("tx_ops is NULL");
  3934. return QDF_STATUS_E_INVAL;
  3935. }
  3936. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3937. if (!spectral) {
  3938. spectral_err("Spectal LMAC object is NULL");
  3939. return QDF_STATUS_E_INVAL;
  3940. }
  3941. /* Save the state */
  3942. spectral->dbr_ring_debug = enable;
  3943. if (enable)
  3944. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  3945. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  3946. else
  3947. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  3948. pdev, 0);
  3949. return QDF_STATUS_SUCCESS;
  3950. }
  3951. /**
  3952. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  3953. * @pdev: Pointer to pdev object
  3954. * @enable: Enable/Disable Spectral DMA buffer debug
  3955. *
  3956. * Start/stop Spectral DMA buffer debug based on @enable.
  3957. * Also save the state for future use.
  3958. *
  3959. * Return: QDF_STATUS of operation
  3960. */
  3961. static QDF_STATUS
  3962. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3963. {
  3964. struct target_if_spectral *spectral;
  3965. struct wlan_lmac_if_tx_ops *tx_ops;
  3966. struct wlan_objmgr_psoc *psoc;
  3967. if (!pdev)
  3968. return QDF_STATUS_E_FAILURE;
  3969. psoc = wlan_pdev_get_psoc(pdev);
  3970. if (!psoc) {
  3971. spectral_err("psoc is null");
  3972. return QDF_STATUS_E_INVAL;
  3973. }
  3974. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  3975. if (!tx_ops) {
  3976. spectral_err("tx_ops is NULL");
  3977. return QDF_STATUS_E_INVAL;
  3978. }
  3979. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3980. if (!spectral) {
  3981. spectral_err("Spectal LMAC object is NULL");
  3982. return QDF_STATUS_E_INVAL;
  3983. }
  3984. /* Save the state */
  3985. spectral->dbr_buff_debug = enable;
  3986. if (enable)
  3987. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  3988. pdev, 0, MEM_POISON_SIGNATURE);
  3989. else
  3990. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  3991. pdev, 0);
  3992. }
  3993. /**
  3994. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  3995. * debug based on the previous state
  3996. * @pdev: Pointer to pdev object
  3997. *
  3998. * Return: QDF_STATUS of operation
  3999. */
  4000. static QDF_STATUS
  4001. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  4002. {
  4003. struct target_if_spectral *spectral;
  4004. if (!pdev) {
  4005. spectral_err("pdev is NULL!");
  4006. return QDF_STATUS_E_FAILURE;
  4007. }
  4008. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4009. if (!spectral) {
  4010. spectral_err("Spectal LMAC object is NULL");
  4011. return QDF_STATUS_E_INVAL;
  4012. }
  4013. if (spectral->dbr_buff_debug)
  4014. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  4015. else
  4016. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  4017. }
  4018. /**
  4019. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  4020. * debug based on the previous state
  4021. * @pdev: Pointer to pdev object
  4022. *
  4023. * Return: QDF_STATUS of operation
  4024. */
  4025. static QDF_STATUS
  4026. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  4027. {
  4028. struct target_if_spectral *spectral;
  4029. if (!pdev) {
  4030. spectral_err("pdev is NULL!");
  4031. return QDF_STATUS_E_FAILURE;
  4032. }
  4033. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4034. if (!spectral) {
  4035. spectral_err("Spectal LMAC object is NULL");
  4036. return QDF_STATUS_E_INVAL;
  4037. }
  4038. if (spectral->dbr_ring_debug)
  4039. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  4040. else
  4041. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  4042. }
  4043. /**
  4044. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  4045. * @pdev: Pointer to pdev object
  4046. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  4047. * @debug_value: Value to be set for @dma_debug_type
  4048. *
  4049. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  4050. * based on @debug_value
  4051. *
  4052. * Return: QDF_STATUS of operation
  4053. */
  4054. static QDF_STATUS
  4055. target_if_spectral_set_dma_debug(
  4056. struct wlan_objmgr_pdev *pdev,
  4057. enum spectral_dma_debug dma_debug_type,
  4058. bool debug_value)
  4059. {
  4060. struct target_if_spectral_ops *p_sops;
  4061. struct wlan_objmgr_psoc *psoc;
  4062. struct wlan_lmac_if_tx_ops *tx_ops;
  4063. struct target_if_spectral *spectral;
  4064. if (!pdev)
  4065. return QDF_STATUS_E_FAILURE;
  4066. psoc = wlan_pdev_get_psoc(pdev);
  4067. if (!psoc) {
  4068. spectral_err("psoc is null");
  4069. return QDF_STATUS_E_INVAL;
  4070. }
  4071. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  4072. if (!tx_ops) {
  4073. spectral_err("tx_ops is NULL");
  4074. return QDF_STATUS_E_FAILURE;
  4075. }
  4076. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  4077. spectral_err("Unable to fetch target type");
  4078. return QDF_STATUS_E_FAILURE;
  4079. }
  4080. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4081. if (!spectral) {
  4082. spectral_err("Spectal LMAC object is NULL");
  4083. return QDF_STATUS_E_INVAL;
  4084. }
  4085. if (spectral->direct_dma_support) {
  4086. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4087. if (p_sops->is_spectral_active(spectral,
  4088. SPECTRAL_SCAN_MODE_NORMAL) ||
  4089. p_sops->is_spectral_active(spectral,
  4090. SPECTRAL_SCAN_MODE_AGILE)) {
  4091. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  4092. return QDF_STATUS_E_FAILURE;
  4093. }
  4094. switch (dma_debug_type) {
  4095. case SPECTRAL_DMA_RING_DEBUG:
  4096. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  4097. break;
  4098. case SPECTRAL_DMA_BUFFER_DEBUG:
  4099. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  4100. break;
  4101. default:
  4102. spectral_err("Unsupported DMA debug type : %d",
  4103. dma_debug_type);
  4104. return QDF_STATUS_E_FAILURE;
  4105. }
  4106. }
  4107. return QDF_STATUS_SUCCESS;
  4108. }
  4109. #endif /* DIRECT_BUF_RX_DEBUG */
  4110. /**
  4111. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  4112. * @pdev: Pointer to pdev object
  4113. *
  4114. * Return: Whether Direct-DMA is supported on this radio
  4115. */
  4116. static bool
  4117. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  4118. {
  4119. struct target_if_spectral *spectral;
  4120. if (!pdev) {
  4121. spectral_err("pdev is NULL!");
  4122. return false;
  4123. }
  4124. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4125. if (!spectral) {
  4126. spectral_err("Spectral LMAC object is NULL");
  4127. return false;
  4128. }
  4129. return spectral->direct_dma_support;
  4130. }
  4131. /**
  4132. * target_if_set_debug_level() - Set debug level for Spectral
  4133. * @pdev: Pointer to pdev object
  4134. * @debug_level: Debug level
  4135. *
  4136. * API to set the debug level for Spectral
  4137. *
  4138. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4139. */
  4140. QDF_STATUS
  4141. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  4142. {
  4143. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  4144. return QDF_STATUS_SUCCESS;
  4145. }
  4146. /**
  4147. * target_if_get_debug_level() - Get debug level for Spectral
  4148. * @pdev: Pointer to pdev object
  4149. *
  4150. * API to get the debug level for Spectral
  4151. *
  4152. * Return: Current debug level
  4153. */
  4154. uint32_t
  4155. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  4156. {
  4157. return spectral_debug_level;
  4158. }
  4159. /**
  4160. * target_if_get_spectral_capinfo() - Get Spectral capability information
  4161. * @pdev: Pointer to pdev object
  4162. * @scaps: Buffer into which data should be copied
  4163. *
  4164. * API to get the spectral capability information
  4165. *
  4166. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4167. */
  4168. QDF_STATUS
  4169. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  4170. struct spectral_caps *scaps)
  4171. {
  4172. struct target_if_spectral *spectral = NULL;
  4173. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4174. if (!spectral) {
  4175. spectral_err("SPECTRAL : Module doesn't exist");
  4176. return QDF_STATUS_E_FAILURE;
  4177. }
  4178. qdf_mem_copy(scaps, &spectral->capability,
  4179. sizeof(struct spectral_caps));
  4180. return QDF_STATUS_SUCCESS;
  4181. }
  4182. /**
  4183. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  4184. * @pdev: Pointer to pdev object
  4185. * @stats: Buffer into which data should be copied
  4186. *
  4187. * API to get the spectral diagnostic statistics
  4188. *
  4189. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4190. */
  4191. QDF_STATUS
  4192. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  4193. struct spectral_diag_stats *stats)
  4194. {
  4195. struct target_if_spectral *spectral = NULL;
  4196. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4197. if (!spectral) {
  4198. spectral_err("SPECTRAL : Module doesn't exist");
  4199. return QDF_STATUS_E_FAILURE;
  4200. }
  4201. qdf_mem_copy(stats, &spectral->diag_stats,
  4202. sizeof(struct spectral_diag_stats));
  4203. return QDF_STATUS_SUCCESS;
  4204. }
  4205. /**
  4206. * target_if_register_spectral_wmi_ops() - Register Spectral WMI operations
  4207. * @psoc: Pointer to psoc object
  4208. * @wmi_ops: Pointer to the structure having Spectral WMI operations
  4209. *
  4210. * API for registering Spectral WMI operations in
  4211. * spectral internal data structure
  4212. *
  4213. * Return: QDF_STATUS
  4214. */
  4215. static QDF_STATUS
  4216. target_if_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
  4217. struct spectral_wmi_ops *wmi_ops)
  4218. {
  4219. struct target_if_psoc_spectral *psoc_spectral;
  4220. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4221. if (!psoc_spectral) {
  4222. spectral_err("Spectral LMAC object is null");
  4223. return QDF_STATUS_E_INVAL;
  4224. }
  4225. psoc_spectral->wmi_ops = *wmi_ops;
  4226. return QDF_STATUS_SUCCESS;
  4227. }
  4228. /**
  4229. * target_if_register_spectral_tgt_ops() - Register Spectral target operations
  4230. * @psoc: Pointer to psoc object
  4231. * @tgt_ops: Pointer to the structure having Spectral target operations
  4232. *
  4233. * API for registering Spectral target operations in
  4234. * spectral internal data structure
  4235. *
  4236. * Return: QDF_STATUS
  4237. */
  4238. static QDF_STATUS
  4239. target_if_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
  4240. struct spectral_tgt_ops *tgt_ops)
  4241. {
  4242. if (!psoc) {
  4243. spectral_err("psoc is null");
  4244. return QDF_STATUS_E_INVAL;
  4245. }
  4246. ops_tgt = *tgt_ops;
  4247. return QDF_STATUS_SUCCESS;
  4248. }
  4249. /**
  4250. * target_if_register_netlink_cb() - Register Netlink callbacks
  4251. * @pdev: Pointer to pdev object
  4252. * @nl_cb: Netlink callbacks to register
  4253. *
  4254. * Return: void
  4255. */
  4256. static void
  4257. target_if_register_netlink_cb(
  4258. struct wlan_objmgr_pdev *pdev,
  4259. struct spectral_nl_cb *nl_cb)
  4260. {
  4261. struct target_if_spectral *spectral = NULL;
  4262. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4263. if (!spectral) {
  4264. spectral_err("SPECTRAL : Module doesn't exist");
  4265. return;
  4266. }
  4267. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  4268. if (spectral->use_nl_bcast)
  4269. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  4270. else
  4271. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  4272. }
  4273. /**
  4274. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  4275. * Netlink messages to the application layer
  4276. * @pdev: Pointer to pdev object
  4277. *
  4278. * Return: true for broadcast, false for unicast
  4279. */
  4280. static bool
  4281. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  4282. {
  4283. struct target_if_spectral *spectral = NULL;
  4284. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4285. if (!spectral) {
  4286. spectral_err("SPECTRAL : Module doesn't exist");
  4287. return false;
  4288. }
  4289. return spectral->use_nl_bcast;
  4290. }
  4291. /**
  4292. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  4293. * @pdev: Pointer to pdev object
  4294. *
  4295. * Return: void
  4296. */
  4297. static void
  4298. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  4299. {
  4300. struct target_if_spectral *spectral = NULL;
  4301. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4302. if (!spectral) {
  4303. spectral_err("SPECTRAL : Module doesn't exist");
  4304. return;
  4305. }
  4306. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  4307. }
  4308. static int
  4309. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  4310. void *payload)
  4311. {
  4312. struct target_if_spectral *spectral = NULL;
  4313. struct target_if_spectral_ops *p_sops = NULL;
  4314. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4315. if (!spectral) {
  4316. spectral_err("SPECTRAL : Module doesn't exist");
  4317. return -EPERM;
  4318. }
  4319. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4320. if (!p_sops) {
  4321. spectral_err("p_sops is null");
  4322. return -EPERM;
  4323. }
  4324. return p_sops->process_spectral_report(pdev, payload);
  4325. }
  4326. #ifdef DIRECT_BUF_RX_DEBUG
  4327. static inline void
  4328. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4329. {
  4330. if (!tx_ops) {
  4331. spectral_err("tx_ops is NULL");
  4332. return;
  4333. }
  4334. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  4335. target_if_spectral_set_dma_debug;
  4336. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  4337. target_if_spectral_check_and_do_dbr_ring_debug;
  4338. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  4339. target_if_spectral_check_and_do_dbr_buff_debug;
  4340. }
  4341. #else
  4342. static inline void
  4343. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4344. {
  4345. }
  4346. #endif
  4347. #if defined(WLAN_CONV_SPECTRAL_ENABLE) && defined(SPECTRAL_MODULIZED_ENABLE)
  4348. /**
  4349. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  4350. * register WMI event handler
  4351. * @psoc: Pointer to psoc object
  4352. * @event_id: Event id
  4353. * @handler_func: Handler function
  4354. * @rx_ctx: Context of WMI event processing
  4355. *
  4356. * Wrapper function to register WMI event handler
  4357. *
  4358. * Return: 0 for success else failure
  4359. */
  4360. static int
  4361. target_if_spectral_wmi_unified_register_event_handler(
  4362. struct wlan_objmgr_psoc *psoc,
  4363. wmi_conv_event_id event_id,
  4364. wmi_unified_event_handler handler_func,
  4365. uint8_t rx_ctx)
  4366. {
  4367. wmi_unified_t wmi_handle;
  4368. struct target_if_psoc_spectral *psoc_spectral;
  4369. if (!psoc) {
  4370. spectral_err("psoc is null");
  4371. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4372. }
  4373. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4374. if (!wmi_handle) {
  4375. spectral_err("WMI handle is null");
  4376. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4377. }
  4378. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4379. if (!psoc_spectral) {
  4380. spectral_err("spectral object is null");
  4381. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4382. }
  4383. return psoc_spectral->wmi_ops.wmi_unified_register_event_handler(
  4384. wmi_handle, event_id, handler_func, rx_ctx);
  4385. }
  4386. /**
  4387. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  4388. * to unregister WMI event handler
  4389. * @psoc: Pointer to psoc object
  4390. * @event_id: Event id
  4391. *
  4392. * Wrapper function to unregister WMI event handler
  4393. *
  4394. * Return: 0 for success else failure
  4395. */
  4396. static int
  4397. target_if_spectral_wmi_unified_unregister_event_handler(
  4398. struct wlan_objmgr_psoc *psoc,
  4399. wmi_conv_event_id event_id)
  4400. {
  4401. wmi_unified_t wmi_handle;
  4402. struct target_if_psoc_spectral *psoc_spectral;
  4403. if (!psoc) {
  4404. spectral_err("psoc is null");
  4405. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4406. }
  4407. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4408. if (!wmi_handle) {
  4409. spectral_err("WMI handle is null");
  4410. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4411. }
  4412. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4413. if (!psoc_spectral) {
  4414. spectral_err("spectral object is null");
  4415. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4416. }
  4417. return psoc_spectral->wmi_ops.wmi_unified_unregister_event_handler(
  4418. wmi_handle, event_id);
  4419. }
  4420. /**
  4421. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  4422. * function to extract fixed parameters from start scan response event
  4423. * @psoc: Pointer to psoc object
  4424. * @evt_buf: Event buffer
  4425. * @param: Start scan response parameters
  4426. *
  4427. * Wrapper function to extract fixed parameters from start scan response event
  4428. *
  4429. * Return: QDF_STATUS
  4430. */
  4431. static QDF_STATUS
  4432. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4433. struct wlan_objmgr_psoc *psoc,
  4434. uint8_t *evt_buf,
  4435. struct spectral_startscan_resp_params *param)
  4436. {
  4437. wmi_unified_t wmi_handle;
  4438. struct target_if_psoc_spectral *psoc_spectral;
  4439. if (!psoc) {
  4440. spectral_err("psoc is null");
  4441. return QDF_STATUS_E_INVAL;
  4442. }
  4443. if (!evt_buf) {
  4444. spectral_err("WMI event buffer is null");
  4445. return QDF_STATUS_E_INVAL;
  4446. }
  4447. if (!param) {
  4448. spectral_err("Spectral startscan response parameters is null");
  4449. return QDF_STATUS_E_INVAL;
  4450. }
  4451. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4452. if (!wmi_handle) {
  4453. spectral_err("WMI handle is null");
  4454. return QDF_STATUS_E_INVAL;
  4455. }
  4456. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4457. if (!psoc_spectral) {
  4458. spectral_err("spectral object is null");
  4459. return QDF_STATUS_E_FAILURE;
  4460. }
  4461. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4462. wmi_handle, evt_buf, param);
  4463. }
  4464. /**
  4465. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  4466. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  4467. * secondary 80 MHz FFT bins
  4468. * @psoc: Pointer to psoc object
  4469. * @evt_buf: Event buffer
  4470. * @param: FFT bin start and end indices
  4471. *
  4472. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  4473. * and secondary 80 MHz FFT bins
  4474. *
  4475. * Return: QDF_STATUS
  4476. */
  4477. static QDF_STATUS
  4478. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  4479. struct wlan_objmgr_psoc *psoc,
  4480. uint8_t *evt_buf,
  4481. struct spectral_fft_bin_markers_160_165mhz *param)
  4482. {
  4483. wmi_unified_t wmi_handle;
  4484. struct target_if_psoc_spectral *psoc_spectral;
  4485. if (!psoc) {
  4486. spectral_err("psoc is null");
  4487. return QDF_STATUS_E_INVAL;
  4488. }
  4489. if (!evt_buf) {
  4490. spectral_err("WMI event buffer is null");
  4491. return QDF_STATUS_E_INVAL;
  4492. }
  4493. if (!param) {
  4494. spectral_err("Spectral FFT bin markers is null");
  4495. return QDF_STATUS_E_INVAL;
  4496. }
  4497. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4498. if (!wmi_handle) {
  4499. spectral_err("WMI handle is null");
  4500. return QDF_STATUS_E_INVAL;
  4501. }
  4502. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4503. if (!psoc_spectral) {
  4504. spectral_err("spectral object is null");
  4505. return QDF_STATUS_E_FAILURE;
  4506. }
  4507. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fft_bin_index(
  4508. wmi_handle, evt_buf, param);
  4509. }
  4510. /**
  4511. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  4512. * object from scn handle
  4513. * @scn: scn handle
  4514. *
  4515. * Wrapper function to get psoc object from scn handle
  4516. *
  4517. * Return: Pointer to psoc object
  4518. */
  4519. static struct wlan_objmgr_psoc *
  4520. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  4521. {
  4522. if (!scn) {
  4523. spectral_err("scn is null");
  4524. return NULL;
  4525. }
  4526. return ops_tgt.tgt_get_psoc_from_scn_hdl(scn);
  4527. }
  4528. #else
  4529. /**
  4530. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  4531. * register WMI event handler
  4532. * @psoc: Pointer to psoc object
  4533. * @event_id: Event id
  4534. * @handler_func: Handler function
  4535. * @rx_ctx: Context of WMI event processing
  4536. *
  4537. * Wrapper function to register WMI event handler
  4538. *
  4539. * Return: 0 for success else failure
  4540. */
  4541. static int
  4542. target_if_spectral_wmi_unified_register_event_handler(
  4543. struct wlan_objmgr_psoc *psoc,
  4544. wmi_conv_event_id event_id,
  4545. wmi_unified_event_handler handler_func,
  4546. uint8_t rx_ctx)
  4547. {
  4548. wmi_unified_t wmi_handle;
  4549. if (!psoc) {
  4550. spectral_err("psoc is null");
  4551. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4552. }
  4553. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4554. if (!wmi_handle) {
  4555. spectral_err("WMI handle is null");
  4556. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4557. }
  4558. return wmi_unified_register_event_handler(wmi_handle, event_id,
  4559. handler_func, rx_ctx);
  4560. }
  4561. /**
  4562. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  4563. * to unregister WMI event handler
  4564. * @psoc: Pointer to psoc object
  4565. * @event_id: Event id
  4566. *
  4567. * Wrapper function to unregister WMI event handler
  4568. *
  4569. * Return: 0 for success else failure
  4570. */
  4571. static int
  4572. target_if_spectral_wmi_unified_unregister_event_handler(
  4573. struct wlan_objmgr_psoc *psoc,
  4574. wmi_conv_event_id event_id)
  4575. {
  4576. wmi_unified_t wmi_handle;
  4577. if (!psoc) {
  4578. spectral_err("psoc is null");
  4579. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4580. }
  4581. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4582. if (!wmi_handle) {
  4583. spectral_err("WMI handle is null");
  4584. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4585. }
  4586. return wmi_unified_unregister_event_handler(wmi_handle, event_id);
  4587. }
  4588. /**
  4589. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  4590. * function to extract fixed parameters from start scan response event
  4591. * @psoc: Pointer to psoc object
  4592. * @evt_buf: Event buffer
  4593. * @param: Start scan response parameters
  4594. *
  4595. * Wrapper function to extract fixed parameters from start scan response event
  4596. *
  4597. * Return: QDF_STATUS
  4598. */
  4599. static QDF_STATUS
  4600. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4601. struct wlan_objmgr_psoc *psoc,
  4602. uint8_t *evt_buf,
  4603. struct spectral_startscan_resp_params *param)
  4604. {
  4605. wmi_unified_t wmi_handle;
  4606. if (!psoc) {
  4607. spectral_err("psoc is null");
  4608. return QDF_STATUS_E_INVAL;
  4609. }
  4610. if (!evt_buf) {
  4611. spectral_err("WMI event buffer is null");
  4612. return QDF_STATUS_E_INVAL;
  4613. }
  4614. if (!param) {
  4615. spectral_err("Spectral startscan response parameters is null");
  4616. return QDF_STATUS_E_INVAL;
  4617. }
  4618. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4619. if (!wmi_handle) {
  4620. spectral_err("WMI handle is null");
  4621. return QDF_STATUS_E_INVAL;
  4622. }
  4623. return wmi_extract_pdev_sscan_fw_cmd_fixed_param(wmi_handle, evt_buf,
  4624. param);
  4625. }
  4626. /**
  4627. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  4628. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  4629. * secondary 80 MHz FFT bins
  4630. * @psoc: Pointer to psoc object
  4631. * @evt_buf: Event buffer
  4632. * @param: FFT bin start and end indices
  4633. *
  4634. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  4635. * and secondary 80 MHz FFT bins
  4636. *
  4637. * Return: QDF_STATUS
  4638. */
  4639. static QDF_STATUS
  4640. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  4641. struct wlan_objmgr_psoc *psoc,
  4642. uint8_t *evt_buf,
  4643. struct spectral_fft_bin_markers_160_165mhz *param)
  4644. {
  4645. wmi_unified_t wmi_handle;
  4646. if (!psoc) {
  4647. spectral_err("psoc is null");
  4648. return QDF_STATUS_E_INVAL;
  4649. }
  4650. if (!evt_buf) {
  4651. spectral_err("WMI event buffer is null");
  4652. return QDF_STATUS_E_INVAL;
  4653. }
  4654. if (!param) {
  4655. spectral_err("Spectral FFT bin markers is null");
  4656. return QDF_STATUS_E_INVAL;
  4657. }
  4658. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4659. if (!wmi_handle) {
  4660. spectral_err("WMI handle is null");
  4661. return QDF_STATUS_E_INVAL;
  4662. }
  4663. return wmi_extract_pdev_sscan_fft_bin_index(wmi_handle, evt_buf, param);
  4664. }
  4665. /**
  4666. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  4667. * object from scn handle
  4668. * @scn: scn handle
  4669. *
  4670. * Wrapper function to get psoc object from scn handle
  4671. *
  4672. * Return: Pointer to psoc object
  4673. */
  4674. static struct wlan_objmgr_psoc *
  4675. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  4676. {
  4677. if (!scn) {
  4678. spectral_err("scn is null");
  4679. return NULL;
  4680. }
  4681. return target_if_get_psoc_from_scn_hdl(scn);
  4682. }
  4683. #endif
  4684. /**
  4685. * target_if_spectral_fw_param_event_handler() - WMI event handler to
  4686. * process start scan response event
  4687. * @scn: Pointer to scn object
  4688. * @data_buf: Pointer to event buffer
  4689. * @data_len: Length of event buffer
  4690. *
  4691. * Return: 0 for success, else failure
  4692. */
  4693. static int
  4694. target_if_spectral_fw_param_event_handler(ol_scn_t scn, uint8_t *data_buf,
  4695. uint32_t data_len)
  4696. {
  4697. QDF_STATUS status;
  4698. struct wlan_objmgr_psoc *psoc;
  4699. struct wlan_objmgr_pdev *pdev;
  4700. struct wmi_unified *wmi_handle;
  4701. struct spectral_startscan_resp_params event_params = {0};
  4702. struct target_if_psoc_spectral *psoc_spectral;
  4703. struct target_if_spectral *spectral;
  4704. if (!scn) {
  4705. spectral_err("scn handle is null");
  4706. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4707. }
  4708. if (!data_buf) {
  4709. spectral_err("WMI event buffer null");
  4710. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4711. }
  4712. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  4713. if (!psoc) {
  4714. spectral_err("psoc is null");
  4715. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4716. }
  4717. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4718. if (!psoc_spectral) {
  4719. spectral_err("spectral object is null");
  4720. return QDF_STATUS_E_FAILURE;
  4721. }
  4722. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4723. if (!wmi_handle) {
  4724. spectral_err("WMI handle is null");
  4725. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4726. }
  4727. status = target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4728. psoc, data_buf, &event_params);
  4729. if (QDF_IS_STATUS_ERROR(status)) {
  4730. spectral_err("unable to extract sscan fw fixed params");
  4731. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4732. }
  4733. pdev = wlan_objmgr_get_pdev_by_id(psoc, event_params.pdev_id,
  4734. WLAN_SPECTRAL_ID);
  4735. if (!pdev) {
  4736. spectral_err("pdev is null");
  4737. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4738. }
  4739. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4740. if (!spectral) {
  4741. spectral_err("spectral object is null");
  4742. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  4743. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4744. }
  4745. if (event_params.num_fft_bin_index == 1) {
  4746. status =
  4747. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  4748. psoc, data_buf,
  4749. &spectral->rparams.marker[event_params.smode]);
  4750. if (QDF_IS_STATUS_ERROR(status)) {
  4751. spectral_err("unable to extract sscan fw fixed params");
  4752. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  4753. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4754. }
  4755. } else {
  4756. spectral->rparams.marker[event_params.smode].is_valid = false;
  4757. }
  4758. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  4759. return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
  4760. }
  4761. static QDF_STATUS
  4762. target_if_spectral_register_events(struct wlan_objmgr_psoc *psoc)
  4763. {
  4764. int ret;
  4765. if (!psoc) {
  4766. spectral_err("psoc is null");
  4767. return QDF_STATUS_E_INVAL;
  4768. }
  4769. ret = target_if_spectral_wmi_unified_register_event_handler(
  4770. psoc,
  4771. wmi_pdev_sscan_fw_param_eventid,
  4772. target_if_spectral_fw_param_event_handler,
  4773. WMI_RX_UMAC_CTX);
  4774. if (ret)
  4775. spectral_debug("event handler not supported, ret=%d", ret);
  4776. return QDF_STATUS_SUCCESS;
  4777. }
  4778. static QDF_STATUS
  4779. target_if_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
  4780. {
  4781. int ret;
  4782. if (!psoc) {
  4783. spectral_err("psoc is null");
  4784. return QDF_STATUS_E_INVAL;
  4785. }
  4786. ret = target_if_spectral_wmi_unified_unregister_event_handler(
  4787. psoc, wmi_pdev_sscan_fw_param_eventid);
  4788. if (ret)
  4789. spectral_debug("Unregister WMI event handler failed, ret = %d",
  4790. ret);
  4791. return QDF_STATUS_SUCCESS;
  4792. }
  4793. void
  4794. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4795. {
  4796. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  4797. target_if_pdev_spectral_init;
  4798. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  4799. target_if_pdev_spectral_deinit;
  4800. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init =
  4801. target_if_psoc_spectral_init;
  4802. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit =
  4803. target_if_psoc_spectral_deinit;
  4804. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  4805. target_if_set_spectral_config;
  4806. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  4807. target_if_get_spectral_config;
  4808. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  4809. target_if_start_spectral_scan;
  4810. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  4811. target_if_stop_spectral_scan;
  4812. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  4813. target_if_is_spectral_active;
  4814. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  4815. target_if_is_spectral_enabled;
  4816. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  4817. target_if_set_debug_level;
  4818. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  4819. target_if_get_debug_level;
  4820. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  4821. target_if_get_spectral_capinfo;
  4822. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  4823. target_if_get_spectral_diagstats;
  4824. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_wmi_ops =
  4825. target_if_register_spectral_wmi_ops;
  4826. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_tgt_ops =
  4827. target_if_register_spectral_tgt_ops;
  4828. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  4829. target_if_register_netlink_cb;
  4830. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  4831. target_if_use_nl_bcast;
  4832. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  4833. target_if_deregister_netlink_cb;
  4834. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  4835. target_if_process_spectral_report;
  4836. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  4837. target_if_spectral_direct_dma_support;
  4838. tx_ops->sptrl_tx_ops.sptrlto_register_events =
  4839. target_if_spectral_register_events;
  4840. tx_ops->sptrl_tx_ops.sptrlto_unregister_events =
  4841. target_if_spectral_unregister_events;
  4842. target_if_sptrl_debug_register_tx_ops(tx_ops);
  4843. }
  4844. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  4845. void
  4846. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  4847. uint16_t cw_int, uint32_t dcs_enabled)
  4848. {
  4849. struct spectral_samp_msg *msg = NULL;
  4850. struct target_if_spectral_ops *p_sops = NULL;
  4851. struct target_if_spectral *spectral = NULL;
  4852. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4853. if (!spectral) {
  4854. spectral_err("SPECTRAL : Module doesn't exist");
  4855. return;
  4856. }
  4857. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4858. if (!p_sops) {
  4859. spectral_err("p_sops is null");
  4860. return;
  4861. }
  4862. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  4863. spectral->pdev_obj,
  4864. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  4865. SPECTRAL_MSG_BUF_NEW);
  4866. if (msg) {
  4867. msg->int_type = cw_int ?
  4868. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  4869. msg->dcs_enabled = dcs_enabled;
  4870. msg->signature = SPECTRAL_SIGNATURE;
  4871. p_sops->get_mac_address(spectral, msg->macaddr);
  4872. if (spectral->send_phy_data
  4873. (pdev,
  4874. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  4875. spectral->spectral_sent_msg++;
  4876. }
  4877. }
  4878. qdf_export_symbol(target_if_spectral_send_intf_found_msg);