target_if_spectral.c 149 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489
  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. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  1877. else if (target_type == TARGET_TYPE_QCA8074 ||
  1878. target_type == TARGET_TYPE_QCA6018 ||
  1879. target_type == TARGET_TYPE_QCA6390)
  1880. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  1881. else
  1882. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  1883. if (target_type == TARGET_TYPE_QCA8074 ||
  1884. target_type == TARGET_TYPE_QCA8074V2 ||
  1885. target_type == TARGET_TYPE_QCA6018 ||
  1886. target_type == TARGET_TYPE_QCN9000) {
  1887. swar->inband_fftbin_size_adj = 1;
  1888. swar->null_fftbin_adj = 1;
  1889. } else {
  1890. swar->inband_fftbin_size_adj = 0;
  1891. swar->null_fftbin_adj = 0;
  1892. }
  1893. if (target_type == TARGET_TYPE_QCA8074V2)
  1894. swar->packmode_fftbin_size_adj = 1;
  1895. else
  1896. swar->packmode_fftbin_size_adj = 0;
  1897. }
  1898. /**
  1899. * target_if_spectral_report_params_init() - Initialize parameters which
  1900. * describes the structure of Spectral reports
  1901. *
  1902. * @rparams: Pointer to Spectral report parameter object
  1903. * @target_type: target type
  1904. *
  1905. * Function to Initialize parameters related to the structure of Spectral
  1906. * reports.
  1907. *
  1908. * Return: void
  1909. */
  1910. static void
  1911. target_if_spectral_report_params_init(
  1912. struct spectral_report_params *rparams,
  1913. uint32_t target_type)
  1914. {
  1915. enum spectral_scan_mode smode;
  1916. /* This entries are currently used by gen3 chipsets only. Hence
  1917. * initialization is done for gen3 alone. In future if other generations
  1918. * needs to use them they have to add proper initial values.
  1919. */
  1920. if (target_type == TARGET_TYPE_QCN9000) {
  1921. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_2;
  1922. rparams->num_spectral_detectors =
  1923. NUM_SPECTRAL_DETECTORS_GEN3_V2;
  1924. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1925. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1926. rparams->fragmentation_160[smode] = false;
  1927. rparams->max_agile_ch_width = CH_WIDTH_80P80MHZ;
  1928. } else {
  1929. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_1;
  1930. rparams->num_spectral_detectors =
  1931. NUM_SPECTRAL_DETECTORS_GEN3_V1;
  1932. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1933. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1934. rparams->fragmentation_160[smode] = true;
  1935. rparams->max_agile_ch_width = CH_WIDTH_80MHZ;
  1936. }
  1937. switch (rparams->version) {
  1938. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1939. rparams->ssumaary_padding_bytes =
  1940. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1;
  1941. rparams->fft_report_hdr_len =
  1942. FFT_REPORT_HEADER_LENGTH_GEN3_V1;
  1943. break;
  1944. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1945. rparams->ssumaary_padding_bytes =
  1946. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2;
  1947. rparams->fft_report_hdr_len =
  1948. FFT_REPORT_HEADER_LENGTH_GEN3_V2;
  1949. break;
  1950. default:
  1951. qdf_assert_always(0);
  1952. }
  1953. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_0] =
  1954. SPECTRAL_SCAN_MODE_NORMAL;
  1955. if (target_type == TARGET_TYPE_QCN9000) {
  1956. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  1957. SPECTRAL_SCAN_MODE_AGILE;
  1958. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  1959. SPECTRAL_SCAN_MODE_INVALID;
  1960. } else {
  1961. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_1] =
  1962. SPECTRAL_SCAN_MODE_NORMAL;
  1963. rparams->detid_mode_table[SPECTRAL_DETECTOR_ID_2] =
  1964. SPECTRAL_SCAN_MODE_AGILE;
  1965. }
  1966. }
  1967. /**
  1968. * target_if_spectral_timestamp_war_init() - Initialize Spectral timestamp WAR
  1969. * related info
  1970. * @twar: Pointer to Spectral timstamp WAR related info
  1971. *
  1972. * Function to Initialize parameters related to Spectral timestamp WAR
  1973. *
  1974. * Return: void
  1975. */
  1976. static void
  1977. target_if_spectral_timestamp_war_init(struct spectral_timestamp_war *twar)
  1978. {
  1979. enum spectral_scan_mode smode;
  1980. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1981. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1982. twar->last_fft_timestamp[smode] = 0;
  1983. twar->timestamp_war_offset[smode] = 0;
  1984. }
  1985. twar->target_reset_count = 0;
  1986. }
  1987. /**
  1988. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  1989. * functionality for the given pdev
  1990. * @pdev: Pointer to pdev object
  1991. *
  1992. * Function to initialize pointer to spectral target_if internal private data
  1993. *
  1994. * Return: On success, pointer to Spectral target_if internal private data, on
  1995. * failure, NULL
  1996. */
  1997. void *
  1998. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  1999. {
  2000. struct target_if_spectral_ops *p_sops = NULL;
  2001. struct target_if_spectral *spectral = NULL;
  2002. uint32_t target_type;
  2003. uint32_t target_revision;
  2004. struct wlan_objmgr_psoc *psoc;
  2005. struct wlan_lmac_if_target_tx_ops *tgt_tx_ops;
  2006. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  2007. QDF_STATUS status;
  2008. struct wlan_lmac_if_tx_ops *tx_ops;
  2009. if (!pdev) {
  2010. spectral_err("SPECTRAL: pdev is NULL!");
  2011. return NULL;
  2012. }
  2013. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  2014. sizeof(struct target_if_spectral));
  2015. if (!spectral)
  2016. return spectral;
  2017. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  2018. /* Store pdev in Spectral */
  2019. spectral->pdev_obj = pdev;
  2020. psoc = wlan_pdev_get_psoc(pdev);
  2021. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  2022. if (!tx_ops) {
  2023. spectral_err("tx_ops is NULL");
  2024. qdf_mem_free(spectral);
  2025. return NULL;
  2026. }
  2027. tgt_tx_ops = &tx_ops->target_tx_ops;
  2028. if (tgt_tx_ops->tgt_get_tgt_type) {
  2029. target_type = tgt_tx_ops->tgt_get_tgt_type(psoc);
  2030. } else {
  2031. qdf_mem_free(spectral);
  2032. return NULL;
  2033. }
  2034. if (tgt_tx_ops->tgt_get_tgt_revision) {
  2035. target_revision = tgt_tx_ops->tgt_get_tgt_revision(psoc);
  2036. } else {
  2037. qdf_mem_free(spectral);
  2038. return NULL;
  2039. }
  2040. /* init the function ptr table */
  2041. target_if_spectral_init_dummy_function_table(spectral);
  2042. /* get spectral function table */
  2043. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2044. /* TODO : Should this be called here of after ath_attach ? */
  2045. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  2046. spectral_info("HAL_CAP_PHYDIAG : Capable");
  2047. /* TODO: Need to fix the capablity check for RADAR */
  2048. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  2049. spectral_info("HAL_CAP_RADAR : Capable");
  2050. /* TODO : Need to fix the capablity check for SPECTRAL */
  2051. /* TODO : Should this be called here of after ath_attach ? */
  2052. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  2053. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  2054. qdf_spinlock_create(&spectral->spectral_lock);
  2055. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  2056. target_if_spectral_clear_stats(spectral);
  2057. if (target_type == TARGET_TYPE_QCA8074 ||
  2058. target_type == TARGET_TYPE_QCA8074V2 ||
  2059. target_type == TARGET_TYPE_QCA6018 ||
  2060. target_type == TARGET_TYPE_QCA6390 ||
  2061. target_type == TARGET_TYPE_QCN9000)
  2062. spectral->direct_dma_support = true;
  2063. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  2064. target_type);
  2065. target_if_spectral_report_params_init(&spectral->rparams, target_type);
  2066. if ((target_type == TARGET_TYPE_QCA8074) ||
  2067. (target_type == TARGET_TYPE_QCA8074V2) ||
  2068. (target_type == TARGET_TYPE_QCA6018) ||
  2069. (target_type == TARGET_TYPE_QCA5018) ||
  2070. (target_type == TARGET_TYPE_QCN9000) ||
  2071. (target_type == TARGET_TYPE_QCA6290) ||
  2072. (target_type == TARGET_TYPE_QCA6390)) {
  2073. spectral->spectral_gen = SPECTRAL_GEN3;
  2074. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  2075. spectral->tag_sscan_summary_exp =
  2076. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  2077. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  2078. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  2079. } else {
  2080. spectral->spectral_gen = SPECTRAL_GEN2;
  2081. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  2082. spectral->tag_sscan_summary_exp =
  2083. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  2084. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  2085. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  2086. }
  2087. status = target_if_init_spectral_param_min_max(
  2088. &spectral->param_min_max,
  2089. spectral->spectral_gen, target_type);
  2090. if (QDF_IS_STATUS_ERROR(status)) {
  2091. spectral_err("Failed to initialize parameter min max values");
  2092. goto fail;
  2093. }
  2094. target_if_init_spectral_param_properties(spectral);
  2095. /* Init spectral capability */
  2096. if (target_if_init_spectral_capability(spectral, target_type) !=
  2097. QDF_STATUS_SUCCESS) {
  2098. qdf_mem_free(spectral);
  2099. return NULL;
  2100. }
  2101. if (target_if_spectral_attach_simulation(spectral) < 0)
  2102. return NULL;
  2103. target_if_init_spectral_ops(spectral);
  2104. target_if_spectral_timestamp_war_init(&spectral->timestamp_war);
  2105. /* Spectral mode specific init */
  2106. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  2107. spectral->params_valid[smode] = false;
  2108. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  2109. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  2110. }
  2111. target_if_spectral_register_funcs(spectral, &spectral_ops);
  2112. if (target_if_spectral_check_hw_capability(spectral) == false) {
  2113. goto fail;
  2114. } else {
  2115. /*
  2116. * TODO: Once the driver architecture transitions to chipset
  2117. * versioning based checks, reflect this here.
  2118. */
  2119. spectral->is_160_format = false;
  2120. spectral->is_lb_edge_extrabins_format = false;
  2121. spectral->is_rb_edge_extrabins_format = false;
  2122. if (target_type == TARGET_TYPE_QCA9984 ||
  2123. target_type == TARGET_TYPE_QCA9888) {
  2124. spectral->is_160_format = true;
  2125. spectral->is_lb_edge_extrabins_format = true;
  2126. spectral->is_rb_edge_extrabins_format = true;
  2127. } else if ((target_type == TARGET_TYPE_AR900B) &&
  2128. (target_revision == AR900B_REV_2)) {
  2129. spectral->is_rb_edge_extrabins_format = true;
  2130. }
  2131. if (target_type == TARGET_TYPE_QCA9984 ||
  2132. target_type == TARGET_TYPE_QCA9888)
  2133. spectral->is_sec80_rssi_war_required = true;
  2134. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  2135. if (spectral->spectral_gen == SPECTRAL_GEN3)
  2136. init_160mhz_delivery_state_machine(spectral);
  2137. }
  2138. return spectral;
  2139. fail:
  2140. target_if_spectral_detach(spectral);
  2141. return NULL;
  2142. }
  2143. /**
  2144. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  2145. * functionality for the given pdev
  2146. * @pdev: Pointer to pdev object
  2147. *
  2148. * Function to de-initialize pointer to spectral target_if internal private data
  2149. *
  2150. * Return: None
  2151. */
  2152. void
  2153. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  2154. {
  2155. struct target_if_spectral *spectral = NULL;
  2156. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2157. if (!spectral) {
  2158. spectral_err("SPECTRAL : Module doesn't exist");
  2159. return;
  2160. }
  2161. target_if_spectral_detach(spectral);
  2162. return;
  2163. }
  2164. /**
  2165. * target_if_psoc_spectral_deinit() - De-initialize target_if Spectral
  2166. * functionality for the given psoc
  2167. * @psoc: Pointer to psoc object
  2168. *
  2169. * Function to de-initialize pointer to psoc spectral target_if internal
  2170. * private data
  2171. *
  2172. * Return: None
  2173. */
  2174. static void
  2175. target_if_psoc_spectral_deinit(struct wlan_objmgr_psoc *psoc)
  2176. {
  2177. struct target_if_psoc_spectral *psoc_spectral;
  2178. if (!psoc) {
  2179. spectral_err("psoc is null");
  2180. return;
  2181. }
  2182. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  2183. if (!psoc_spectral) {
  2184. spectral_err("Spectral target_if psoc object is null");
  2185. return;
  2186. }
  2187. qdf_mem_free(psoc_spectral);
  2188. }
  2189. /**
  2190. * target_if_psoc_spectral_init() - Initialize target_if Spectral
  2191. * functionality for the given psoc
  2192. * @psoc: Pointer to psoc object
  2193. *
  2194. * Function to initialize pointer to psoc spectral target_if internal
  2195. * private data
  2196. *
  2197. * Return: On success, pointer to Spectral psoc target_if internal
  2198. * private data, on failure, NULL
  2199. */
  2200. static void *
  2201. target_if_psoc_spectral_init(struct wlan_objmgr_psoc *psoc)
  2202. {
  2203. struct target_if_psoc_spectral *psoc_spectral = NULL;
  2204. if (!psoc) {
  2205. spectral_err("psoc is null");
  2206. goto fail;
  2207. }
  2208. psoc_spectral = (struct target_if_psoc_spectral *)qdf_mem_malloc(
  2209. sizeof(struct target_if_psoc_spectral));
  2210. if (!psoc_spectral) {
  2211. spectral_err("Spectral lmac psoc object allocation failed");
  2212. goto fail;
  2213. }
  2214. psoc_spectral->psoc_obj = psoc;
  2215. return psoc_spectral;
  2216. fail:
  2217. if (psoc_spectral)
  2218. target_if_psoc_spectral_deinit(psoc);
  2219. return psoc_spectral;
  2220. }
  2221. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  2222. * corresponding translation for Agile channel width.
  2223. * @spectral: pointer to Spectral object
  2224. * @chwidth: operating channel width
  2225. * @is_80_80_agile: Indicates an 80+80 agile Scan request
  2226. *
  2227. * Return: The translated channel width enum.
  2228. */
  2229. static enum phy_ch_width
  2230. target_if_spectral_find_agile_width(struct target_if_spectral *spectral,
  2231. enum phy_ch_width chwidth,
  2232. bool is_80_80_agile)
  2233. {
  2234. enum phy_ch_width agile_width;
  2235. struct wlan_objmgr_pdev *pdev;
  2236. struct wlan_objmgr_psoc *psoc;
  2237. if (!spectral) {
  2238. spectral_err("Spectral object is null");
  2239. return CH_WIDTH_INVALID;
  2240. }
  2241. pdev = spectral->pdev_obj;
  2242. if (!pdev) {
  2243. spectral_err("pdev is null");
  2244. return CH_WIDTH_INVALID;
  2245. }
  2246. psoc = wlan_pdev_get_psoc(pdev);
  2247. if (!psoc) {
  2248. spectral_err("psoc is null");
  2249. return CH_WIDTH_INVALID;
  2250. }
  2251. switch (chwidth) {
  2252. case CH_WIDTH_20MHZ:
  2253. agile_width = CH_WIDTH_20MHZ;
  2254. break;
  2255. case CH_WIDTH_40MHZ:
  2256. agile_width = CH_WIDTH_40MHZ;
  2257. break;
  2258. case CH_WIDTH_80MHZ:
  2259. agile_width = CH_WIDTH_80MHZ;
  2260. break;
  2261. case CH_WIDTH_80P80MHZ:
  2262. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  2263. WLAN_SOC_RESTRICTED_80P80_SUPPORT) && !is_80_80_agile)
  2264. agile_width = CH_WIDTH_160MHZ;
  2265. else
  2266. agile_width = CH_WIDTH_80P80MHZ;
  2267. if (agile_width > spectral->rparams.max_agile_ch_width)
  2268. agile_width = spectral->rparams.max_agile_ch_width;
  2269. break;
  2270. case CH_WIDTH_160MHZ:
  2271. if (wlan_psoc_nif_fw_ext_cap_get(psoc,
  2272. WLAN_SOC_RESTRICTED_80P80_SUPPORT) && is_80_80_agile)
  2273. agile_width = CH_WIDTH_80P80MHZ;
  2274. else
  2275. agile_width = CH_WIDTH_160MHZ;
  2276. if (agile_width > spectral->rparams.max_agile_ch_width)
  2277. agile_width = spectral->rparams.max_agile_ch_width;
  2278. break;
  2279. default:
  2280. spectral_err("Invalid channel width %d", chwidth);
  2281. agile_width = CH_WIDTH_INVALID;
  2282. break;
  2283. }
  2284. return agile_width;
  2285. }
  2286. /**
  2287. * target_if_calculate_center_freq() - Helper routine to
  2288. * check whether given frequency is center frequency of a
  2289. * WLAN channel
  2290. *
  2291. * @spectral: Pointer to Spectral object
  2292. * @chan_freq: Center frequency of a WLAN channel
  2293. * @is_valid: Indicates whether given frequency is valid
  2294. *
  2295. * Return: QDF_STATUS
  2296. */
  2297. static QDF_STATUS
  2298. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  2299. uint32_t chan_freq,
  2300. bool *is_valid)
  2301. {
  2302. struct regulatory_channel *cur_chan_list;
  2303. int i;
  2304. if (!pdev) {
  2305. spectral_err("pdev object is null");
  2306. return QDF_STATUS_E_FAILURE;
  2307. }
  2308. if (!is_valid) {
  2309. spectral_err("is valid argument is null");
  2310. return QDF_STATUS_E_FAILURE;
  2311. }
  2312. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  2313. if (!cur_chan_list)
  2314. return QDF_STATUS_E_FAILURE;
  2315. if (wlan_reg_get_current_chan_list(
  2316. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  2317. spectral_err("Failed to get cur_chan list");
  2318. qdf_mem_free(cur_chan_list);
  2319. return QDF_STATUS_E_FAILURE;
  2320. }
  2321. *is_valid = false;
  2322. for (i = 0; i < NUM_CHANNELS; i++) {
  2323. uint32_t flags;
  2324. uint32_t center_freq;
  2325. flags = cur_chan_list[i].chan_flags;
  2326. center_freq = cur_chan_list[i].center_freq;
  2327. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  2328. (center_freq == chan_freq)) {
  2329. *is_valid = true;
  2330. break;
  2331. }
  2332. }
  2333. qdf_mem_free(cur_chan_list);
  2334. return QDF_STATUS_SUCCESS;
  2335. }
  2336. /**
  2337. * target_if_calculate_center_freq() - Helper routine to
  2338. * find the center frequency of the agile span from a
  2339. * WLAN channel center frequency
  2340. *
  2341. * @spectral: Pointer to Spectral object
  2342. * @ch_width: Channel width array
  2343. * @chan_freq: Center frequency of a WLAN channel
  2344. * @center_freq: Pointer to center frequency
  2345. *
  2346. * Return: QDF_STATUS
  2347. */
  2348. static QDF_STATUS
  2349. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  2350. enum phy_ch_width *ch_width,
  2351. uint16_t chan_freq,
  2352. uint16_t *center_freq)
  2353. {
  2354. enum phy_ch_width agile_ch_width;
  2355. if (!spectral) {
  2356. spectral_err("spectral target if object is null");
  2357. return QDF_STATUS_E_FAILURE;
  2358. }
  2359. if (!ch_width) {
  2360. spectral_err("Channel width array is null");
  2361. return QDF_STATUS_E_INVAL;
  2362. }
  2363. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2364. if (!center_freq) {
  2365. spectral_err("center_freq argument is null");
  2366. return QDF_STATUS_E_FAILURE;
  2367. }
  2368. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2369. *center_freq = chan_freq;
  2370. } else {
  2371. uint16_t start_freq;
  2372. uint16_t end_freq;
  2373. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2374. enum channel_state state;
  2375. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2376. (spectral->pdev_obj, chan_freq, agile_ch_width,
  2377. &bonded_chan_ptr);
  2378. if (state == CHANNEL_STATE_DISABLE ||
  2379. state == CHANNEL_STATE_INVALID) {
  2380. spectral_err("Channel state is disable or invalid");
  2381. return QDF_STATUS_E_FAILURE;
  2382. }
  2383. if (!bonded_chan_ptr) {
  2384. spectral_err("Bonded channel is not found");
  2385. return QDF_STATUS_E_FAILURE;
  2386. }
  2387. start_freq = bonded_chan_ptr->start_freq;
  2388. end_freq = bonded_chan_ptr->end_freq;
  2389. *center_freq = (start_freq + end_freq) >> 1;
  2390. }
  2391. return QDF_STATUS_SUCCESS;
  2392. }
  2393. /**
  2394. * target_if_validate_center_freq() - Helper routine to
  2395. * validate user provided agile center frequency
  2396. *
  2397. * @spectral: Pointer to Spectral object
  2398. * @ch_width: Channel width array
  2399. * @center_freq: User provided agile span center frequency
  2400. * @is_valid: Indicates whether agile span center frequency is valid
  2401. *
  2402. * Return: QDF_STATUS
  2403. */
  2404. static QDF_STATUS
  2405. target_if_validate_center_freq(struct target_if_spectral *spectral,
  2406. enum phy_ch_width *ch_width,
  2407. uint16_t center_freq,
  2408. bool *is_valid)
  2409. {
  2410. enum phy_ch_width agile_ch_width;
  2411. struct wlan_objmgr_pdev *pdev;
  2412. QDF_STATUS status;
  2413. if (!spectral) {
  2414. spectral_err("spectral target if object is null");
  2415. return QDF_STATUS_E_FAILURE;
  2416. }
  2417. if (!ch_width) {
  2418. spectral_err("channel width array is null");
  2419. return QDF_STATUS_E_INVAL;
  2420. }
  2421. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2422. if (!is_valid) {
  2423. spectral_err("is_valid argument is null");
  2424. return QDF_STATUS_E_FAILURE;
  2425. }
  2426. pdev = spectral->pdev_obj;
  2427. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2428. status = target_if_is_center_freq_of_any_chan
  2429. (pdev, center_freq, is_valid);
  2430. if (QDF_IS_STATUS_ERROR(status))
  2431. return QDF_STATUS_E_FAILURE;
  2432. } else {
  2433. uint16_t start_freq;
  2434. uint16_t end_freq;
  2435. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2436. bool is_chan;
  2437. status = target_if_is_center_freq_of_any_chan
  2438. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2439. &is_chan);
  2440. if (QDF_IS_STATUS_ERROR(status))
  2441. return QDF_STATUS_E_FAILURE;
  2442. if (is_chan) {
  2443. uint32_t calulated_center_freq;
  2444. enum channel_state st;
  2445. st = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2446. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2447. agile_ch_width,
  2448. &bonded_chan_ptr);
  2449. if (st == CHANNEL_STATE_DISABLE ||
  2450. st == CHANNEL_STATE_INVALID) {
  2451. spectral_err("Channel state disable/invalid");
  2452. return QDF_STATUS_E_FAILURE;
  2453. }
  2454. if (!bonded_chan_ptr) {
  2455. spectral_err("Bonded channel is not found");
  2456. return QDF_STATUS_E_FAILURE;
  2457. }
  2458. start_freq = bonded_chan_ptr->start_freq;
  2459. end_freq = bonded_chan_ptr->end_freq;
  2460. calulated_center_freq = (start_freq + end_freq) >> 1;
  2461. *is_valid = (center_freq == calulated_center_freq);
  2462. } else {
  2463. *is_valid = false;
  2464. }
  2465. }
  2466. return QDF_STATUS_SUCCESS;
  2467. }
  2468. /**
  2469. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  2470. * check whether agile span overlaps with current operating band.
  2471. *
  2472. * @spectral: Pointer to Spectral object
  2473. * @ch_width: Channel width array
  2474. * @center_freq: Agile span center frequency
  2475. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  2476. *
  2477. * Helper routine to check whether agile span overlaps with current
  2478. * operating band.
  2479. *
  2480. * Return: QDF_STATUS
  2481. */
  2482. static QDF_STATUS
  2483. target_if_is_agile_span_overlap_with_operating_span
  2484. (struct target_if_spectral *spectral,
  2485. enum phy_ch_width *ch_width,
  2486. struct spectral_config_frequency *center_freq,
  2487. bool *is_overlapping)
  2488. {
  2489. enum phy_ch_width op_ch_width;
  2490. enum phy_ch_width agile_ch_width;
  2491. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2492. struct wlan_objmgr_vdev *vdev;
  2493. struct wlan_objmgr_pdev *pdev;
  2494. int16_t chan_freq;
  2495. uint32_t op_start_freq;
  2496. uint32_t op_end_freq;
  2497. uint32_t agile_start_freq;
  2498. uint32_t agile_end_freq;
  2499. uint32_t cfreq2;
  2500. if (!spectral) {
  2501. spectral_err("Spectral object is NULL");
  2502. return QDF_STATUS_E_FAILURE;
  2503. }
  2504. pdev = spectral->pdev_obj;
  2505. if (!pdev) {
  2506. spectral_err("pdev object is NULL");
  2507. return QDF_STATUS_E_FAILURE;
  2508. }
  2509. if (!ch_width) {
  2510. spectral_err("channel width array is null");
  2511. return QDF_STATUS_E_FAILURE;
  2512. }
  2513. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  2514. if (op_ch_width == CH_WIDTH_INVALID) {
  2515. spectral_err("Invalid channel width");
  2516. return QDF_STATUS_E_INVAL;
  2517. }
  2518. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  2519. if (agile_ch_width == CH_WIDTH_INVALID) {
  2520. spectral_err("Invalid channel width");
  2521. return QDF_STATUS_E_INVAL;
  2522. }
  2523. if (!is_overlapping) {
  2524. spectral_err("Argument(is_overlapping) is NULL");
  2525. return QDF_STATUS_E_FAILURE;
  2526. }
  2527. *is_overlapping = false;
  2528. vdev = target_if_spectral_get_vdev(spectral);
  2529. if (!vdev) {
  2530. spectral_err("vdev is NULL");
  2531. return QDF_STATUS_E_FAILURE;
  2532. }
  2533. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2534. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2535. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2536. if (cfreq2 < 0) {
  2537. spectral_err("cfreq2 is invalid");
  2538. return QDF_STATUS_E_FAILURE;
  2539. }
  2540. if (op_ch_width == CH_WIDTH_20MHZ) {
  2541. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  2542. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  2543. } else {
  2544. enum channel_state state;
  2545. state = wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2546. (pdev, chan_freq, op_ch_width, &bonded_chan_ptr);
  2547. if (state == CHANNEL_STATE_DISABLE ||
  2548. state == CHANNEL_STATE_INVALID) {
  2549. spectral_err("Channel state is disable or invalid");
  2550. return QDF_STATUS_E_FAILURE;
  2551. }
  2552. if (!bonded_chan_ptr) {
  2553. spectral_err("Bonded channel is not found");
  2554. return QDF_STATUS_E_FAILURE;
  2555. }
  2556. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  2557. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  2558. }
  2559. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  2560. agile_start_freq = center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  2561. agile_end_freq = center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  2562. if (agile_end_freq > op_start_freq &&
  2563. op_end_freq > agile_start_freq)
  2564. *is_overlapping = true;
  2565. agile_start_freq = center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  2566. agile_end_freq = center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  2567. if (agile_end_freq > op_start_freq &&
  2568. op_end_freq > agile_start_freq)
  2569. *is_overlapping = true;
  2570. } else {
  2571. agile_start_freq = center_freq->cfreq1 -
  2572. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2573. agile_end_freq = center_freq->cfreq1 +
  2574. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2575. if (agile_end_freq > op_start_freq &&
  2576. op_end_freq > agile_start_freq)
  2577. *is_overlapping = true;
  2578. }
  2579. if (op_ch_width == CH_WIDTH_80P80MHZ) {
  2580. uint32_t sec80_start_feq;
  2581. uint32_t sec80_end_freq;
  2582. sec80_start_feq = cfreq2 - FREQ_OFFSET_40MHZ;
  2583. sec80_end_freq = cfreq2 + FREQ_OFFSET_40MHZ;
  2584. if (agile_ch_width == CH_WIDTH_80P80MHZ) {
  2585. agile_start_freq =
  2586. center_freq->cfreq1 - FREQ_OFFSET_40MHZ;
  2587. agile_end_freq =
  2588. center_freq->cfreq1 + FREQ_OFFSET_40MHZ;
  2589. if (agile_end_freq > sec80_start_feq &&
  2590. sec80_end_freq > agile_start_freq)
  2591. *is_overlapping = true;
  2592. agile_start_freq =
  2593. center_freq->cfreq2 - FREQ_OFFSET_40MHZ;
  2594. agile_end_freq =
  2595. center_freq->cfreq2 + FREQ_OFFSET_40MHZ;
  2596. if (agile_end_freq > sec80_start_feq &&
  2597. sec80_end_freq > agile_start_freq)
  2598. *is_overlapping = true;
  2599. } else {
  2600. agile_start_freq = center_freq->cfreq1 -
  2601. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2602. agile_end_freq = center_freq->cfreq1 +
  2603. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2604. if (agile_end_freq > sec80_start_feq &&
  2605. sec80_end_freq > agile_start_freq)
  2606. *is_overlapping = true;
  2607. }
  2608. }
  2609. return QDF_STATUS_SUCCESS;
  2610. }
  2611. /**
  2612. * target_if_spectral_populate_chwidth() - Helper routine to
  2613. * populate channel width for different Spectral modes
  2614. *
  2615. * @spectral: Pointer to Spectral object
  2616. * @ch_width: Channel width array
  2617. * @is_80_80_agile: Indicates whether 80+80 agile scan is requested
  2618. *
  2619. * Helper routine to populate channel width for different Spectral modes
  2620. *
  2621. * Return: QDF_STATUS
  2622. */
  2623. static QDF_STATUS
  2624. target_if_spectral_populate_chwidth(struct target_if_spectral *spectral,
  2625. enum phy_ch_width *ch_width,
  2626. bool is_80_80_agile) {
  2627. struct wlan_objmgr_vdev *vdev;
  2628. enum spectral_scan_mode smode;
  2629. enum phy_ch_width vdev_ch_width;
  2630. smode = SPECTRAL_SCAN_MODE_NORMAL;
  2631. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2632. ch_width[smode] = CH_WIDTH_INVALID;
  2633. if (!spectral) {
  2634. spectral_err("Spectral object is null");
  2635. return QDF_STATUS_E_INVAL;
  2636. }
  2637. vdev = target_if_spectral_get_vdev(spectral);
  2638. if (!vdev) {
  2639. spectral_err("vdev is null");
  2640. return QDF_STATUS_E_FAILURE;
  2641. }
  2642. vdev_ch_width = target_if_vdev_get_ch_width(vdev);
  2643. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2644. if (vdev_ch_width == CH_WIDTH_INVALID) {
  2645. spectral_err("Invalid channel width %d", vdev_ch_width);
  2646. return QDF_STATUS_E_FAILURE;
  2647. }
  2648. ch_width[SPECTRAL_SCAN_MODE_NORMAL] = vdev_ch_width;
  2649. ch_width[SPECTRAL_SCAN_MODE_AGILE] =
  2650. target_if_spectral_find_agile_width(spectral, vdev_ch_width,
  2651. is_80_80_agile);
  2652. return QDF_STATUS_SUCCESS;
  2653. }
  2654. /**
  2655. * _target_if_set_spectral_config() - Set spectral config
  2656. * @spectral: Pointer to spectral object
  2657. * @param: Spectral parameter id and value
  2658. * @smode: Spectral scan mode
  2659. * @err: Spectral error code
  2660. *
  2661. * API to set spectral configurations
  2662. *
  2663. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2664. */
  2665. static QDF_STATUS
  2666. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  2667. const struct spectral_cp_param *param,
  2668. const enum spectral_scan_mode smode,
  2669. enum spectral_cp_error_code *err)
  2670. {
  2671. struct spectral_config params;
  2672. struct target_if_spectral_ops *p_sops;
  2673. struct spectral_config *sparams;
  2674. QDF_STATUS status;
  2675. bool is_overlapping;
  2676. uint16_t agile_cfreq;
  2677. bool is_valid_chan;
  2678. struct spectral_param_min_max *param_min_max;
  2679. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  2680. enum spectral_scan_mode m;
  2681. struct spectral_config_frequency center_freq = {0};
  2682. if (!err) {
  2683. spectral_err("Error code argument is null");
  2684. QDF_ASSERT(0);
  2685. return QDF_STATUS_E_FAILURE;
  2686. }
  2687. *err = SPECTRAL_SCAN_ERR_INVALID;
  2688. if (!param) {
  2689. spectral_err("Parameter object is null");
  2690. return QDF_STATUS_E_FAILURE;
  2691. }
  2692. if (!spectral) {
  2693. spectral_err("spectral object is NULL");
  2694. return QDF_STATUS_E_FAILURE;
  2695. }
  2696. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2697. param_min_max = &spectral->param_min_max;
  2698. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2699. spectral_err("Invalid Spectral mode %u", smode);
  2700. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2701. return QDF_STATUS_E_FAILURE;
  2702. }
  2703. sparams = &spectral->params[smode];
  2704. m = SPECTRAL_SCAN_MODE_NORMAL;
  2705. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  2706. ch_width[m] = CH_WIDTH_INVALID;
  2707. if (!spectral->params_valid[smode]) {
  2708. target_if_spectral_info_read(spectral,
  2709. smode,
  2710. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2711. &spectral->params[smode],
  2712. sizeof(spectral->params[smode]));
  2713. spectral->params_valid[smode] = true;
  2714. }
  2715. switch (param->id) {
  2716. case SPECTRAL_PARAM_FFT_PERIOD:
  2717. sparams->ss_fft_period = param->value;
  2718. break;
  2719. case SPECTRAL_PARAM_SCAN_PERIOD:
  2720. sparams->ss_period = param->value;
  2721. break;
  2722. case SPECTRAL_PARAM_SCAN_COUNT:
  2723. sparams->ss_count = param->value;
  2724. break;
  2725. case SPECTRAL_PARAM_SHORT_REPORT:
  2726. sparams->ss_short_report = (!!param->value) ? true : false;
  2727. break;
  2728. case SPECTRAL_PARAM_SPECT_PRI:
  2729. sparams->ss_spectral_pri = (!!param->value) ? true : false;
  2730. break;
  2731. case SPECTRAL_PARAM_FFT_SIZE:
  2732. status = target_if_spectral_populate_chwidth
  2733. (spectral, ch_width, spectral->params
  2734. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  2735. if (QDF_IS_STATUS_ERROR(status))
  2736. return QDF_STATUS_E_FAILURE;
  2737. if ((param->value < param_min_max->fft_size_min) ||
  2738. (param->value > param_min_max->fft_size_max
  2739. [ch_width[smode]])) {
  2740. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2741. return QDF_STATUS_E_FAILURE;
  2742. }
  2743. sparams->ss_fft_size = param->value;
  2744. break;
  2745. case SPECTRAL_PARAM_GC_ENA:
  2746. sparams->ss_gc_ena = !!param->value;
  2747. break;
  2748. case SPECTRAL_PARAM_RESTART_ENA:
  2749. sparams->ss_restart_ena = !!param->value;
  2750. break;
  2751. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  2752. sparams->ss_noise_floor_ref = param->value;
  2753. break;
  2754. case SPECTRAL_PARAM_INIT_DELAY:
  2755. sparams->ss_init_delay = param->value;
  2756. break;
  2757. case SPECTRAL_PARAM_NB_TONE_THR:
  2758. sparams->ss_nb_tone_thr = param->value;
  2759. break;
  2760. case SPECTRAL_PARAM_STR_BIN_THR:
  2761. sparams->ss_str_bin_thr = param->value;
  2762. break;
  2763. case SPECTRAL_PARAM_WB_RPT_MODE:
  2764. sparams->ss_wb_rpt_mode = !!param->value;
  2765. break;
  2766. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  2767. sparams->ss_rssi_rpt_mode = !!param->value;
  2768. break;
  2769. case SPECTRAL_PARAM_RSSI_THR:
  2770. sparams->ss_rssi_thr = param->value;
  2771. break;
  2772. case SPECTRAL_PARAM_PWR_FORMAT:
  2773. sparams->ss_pwr_format = !!param->value;
  2774. break;
  2775. case SPECTRAL_PARAM_RPT_MODE:
  2776. if ((param->value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  2777. (param->value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  2778. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2779. return QDF_STATUS_E_FAILURE;
  2780. }
  2781. sparams->ss_rpt_mode = param->value;
  2782. break;
  2783. case SPECTRAL_PARAM_BIN_SCALE:
  2784. sparams->ss_bin_scale = param->value;
  2785. break;
  2786. case SPECTRAL_PARAM_DBM_ADJ:
  2787. sparams->ss_dbm_adj = !!param->value;
  2788. break;
  2789. case SPECTRAL_PARAM_CHN_MASK:
  2790. sparams->ss_chn_mask = param->value;
  2791. break;
  2792. case SPECTRAL_PARAM_FREQUENCY:
  2793. status = target_if_spectral_populate_chwidth(
  2794. spectral, ch_width, param->freq.cfreq2 > 0);
  2795. if (QDF_IS_STATUS_ERROR(status)) {
  2796. spectral_err("Failed to populate channel width");
  2797. return QDF_STATUS_E_FAILURE;
  2798. }
  2799. if (ch_width[smode] != CH_WIDTH_80P80MHZ &&
  2800. param->freq.cfreq2) {
  2801. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2802. spectral_err("Non zero cfreq2 expected for 80p80 only");
  2803. return QDF_STATUS_E_INVAL;
  2804. }
  2805. if (ch_width[smode] == CH_WIDTH_80P80MHZ &&
  2806. !param->freq.cfreq2) {
  2807. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2808. spectral_err("Non zero cfreq2 expected for 80p80");
  2809. return QDF_STATUS_E_INVAL;
  2810. }
  2811. status = target_if_is_center_freq_of_any_chan
  2812. (spectral->pdev_obj, param->freq.cfreq1,
  2813. &is_valid_chan);
  2814. if (QDF_IS_STATUS_ERROR(status))
  2815. return QDF_STATUS_E_FAILURE;
  2816. if (is_valid_chan) {
  2817. status = target_if_calculate_center_freq(
  2818. spectral, ch_width,
  2819. param->freq.cfreq1,
  2820. &agile_cfreq);
  2821. if (QDF_IS_STATUS_ERROR(status)) {
  2822. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2823. return QDF_STATUS_E_FAILURE;
  2824. }
  2825. } else {
  2826. bool is_valid_agile_cfreq;
  2827. status = target_if_validate_center_freq
  2828. (spectral, ch_width, param->freq.cfreq1,
  2829. &is_valid_agile_cfreq);
  2830. if (QDF_IS_STATUS_ERROR(status))
  2831. return QDF_STATUS_E_FAILURE;
  2832. if (!is_valid_agile_cfreq) {
  2833. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2834. spectral_err("Invalid agile center frequency");
  2835. return QDF_STATUS_E_FAILURE;
  2836. }
  2837. agile_cfreq = param->freq.cfreq1;
  2838. }
  2839. center_freq.cfreq1 = agile_cfreq;
  2840. if (ch_width[smode] == CH_WIDTH_80P80MHZ) {
  2841. status = target_if_is_center_freq_of_any_chan
  2842. (spectral->pdev_obj, param->freq.cfreq2,
  2843. &is_valid_chan);
  2844. if (QDF_IS_STATUS_ERROR(status))
  2845. return QDF_STATUS_E_FAILURE;
  2846. if (is_valid_chan) {
  2847. status = target_if_calculate_center_freq(
  2848. spectral, ch_width,
  2849. param->freq.cfreq2,
  2850. &agile_cfreq);
  2851. if (QDF_IS_STATUS_ERROR(status)) {
  2852. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2853. return QDF_STATUS_E_FAILURE;
  2854. }
  2855. } else {
  2856. bool is_valid_agile_cfreq;
  2857. status = target_if_validate_center_freq
  2858. (spectral, ch_width, param->freq.cfreq2,
  2859. &is_valid_agile_cfreq);
  2860. if (QDF_IS_STATUS_ERROR(status))
  2861. return QDF_STATUS_E_FAILURE;
  2862. if (!is_valid_agile_cfreq) {
  2863. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2864. spectral_err("Invalid agile center frequency");
  2865. return QDF_STATUS_E_FAILURE;
  2866. }
  2867. agile_cfreq = param->freq.cfreq2;
  2868. }
  2869. center_freq.cfreq2 = agile_cfreq;
  2870. }
  2871. status = target_if_is_agile_span_overlap_with_operating_span
  2872. (spectral, ch_width,
  2873. &center_freq, &is_overlapping);
  2874. if (QDF_IS_STATUS_ERROR(status))
  2875. return QDF_STATUS_E_FAILURE;
  2876. if (is_overlapping) {
  2877. spectral_err("Agile freq %u, %u overlaps with operating span",
  2878. center_freq.cfreq1, center_freq.cfreq2);
  2879. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2880. return QDF_STATUS_E_FAILURE;
  2881. }
  2882. sparams->ss_frequency.cfreq1 = center_freq.cfreq1;
  2883. sparams->ss_frequency.cfreq2 = center_freq.cfreq2;
  2884. break;
  2885. }
  2886. p_sops->configure_spectral(spectral, sparams, smode);
  2887. /* only to validate the writes */
  2888. p_sops->get_spectral_config(spectral, &params, smode);
  2889. return QDF_STATUS_SUCCESS;
  2890. }
  2891. QDF_STATUS
  2892. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  2893. const struct spectral_cp_param *param,
  2894. const enum spectral_scan_mode smode,
  2895. enum spectral_cp_error_code *err)
  2896. {
  2897. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  2898. struct target_if_spectral *spectral;
  2899. QDF_STATUS status;
  2900. if (!err) {
  2901. spectral_err("Error code argument is null");
  2902. QDF_ASSERT(0);
  2903. return QDF_STATUS_E_FAILURE;
  2904. }
  2905. *err = SPECTRAL_SCAN_ERR_INVALID;
  2906. if (!pdev) {
  2907. spectral_err("pdev object is NULL");
  2908. return QDF_STATUS_E_FAILURE;
  2909. }
  2910. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2911. if (!spectral) {
  2912. spectral_err("spectral object is NULL");
  2913. return QDF_STATUS_E_FAILURE;
  2914. }
  2915. if (!param) {
  2916. spectral_err("parameter object is NULL");
  2917. return QDF_STATUS_E_FAILURE;
  2918. }
  2919. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2920. spectral_err("Invalid Spectral mode %u", smode);
  2921. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2922. return QDF_STATUS_E_FAILURE;
  2923. }
  2924. if (!spectral->properties[smode][param->id].supported) {
  2925. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  2926. param->id, smode);
  2927. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  2928. return QDF_STATUS_E_FAILURE;
  2929. }
  2930. if (spectral->properties[smode][param->id].common_all_modes) {
  2931. spectral_warn("Setting Spectral parameter %u for all modes",
  2932. param->id);
  2933. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  2934. status = _target_if_set_spectral_config
  2935. (spectral, param, mode, err);
  2936. if (QDF_IS_STATUS_ERROR(status))
  2937. return QDF_STATUS_E_FAILURE;
  2938. }
  2939. return QDF_STATUS_SUCCESS;
  2940. }
  2941. return _target_if_set_spectral_config(spectral, param, smode, err);
  2942. }
  2943. /**
  2944. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  2945. * @fft_len: FFT length
  2946. * @pdev: Pointer to pdev object
  2947. *
  2948. * API to get fft bin count for a given fft length
  2949. *
  2950. * Return: FFt bin count
  2951. */
  2952. static int
  2953. target_if_get_fft_bin_count(int fft_len)
  2954. {
  2955. int bin_count = 0;
  2956. switch (fft_len) {
  2957. case 5:
  2958. bin_count = 16;
  2959. break;
  2960. case 6:
  2961. bin_count = 32;
  2962. break;
  2963. case 7:
  2964. bin_count = 64;
  2965. break;
  2966. case 8:
  2967. bin_count = 128;
  2968. break;
  2969. case 9:
  2970. bin_count = 256;
  2971. break;
  2972. default:
  2973. break;
  2974. }
  2975. return bin_count;
  2976. }
  2977. /**
  2978. * target_if_init_upper_lower_flags() - Initializes control and extension
  2979. * segment flags
  2980. * @fft_len: FFT length
  2981. * @pdev: Pointer to pdev object
  2982. *
  2983. * API to initialize the control and extension flags with the lower/upper
  2984. * segment based on the HT mode
  2985. *
  2986. * Return: FFt bin count
  2987. */
  2988. static void
  2989. target_if_init_upper_lower_flags(struct target_if_spectral *spectral)
  2990. {
  2991. int current_channel = 0;
  2992. int ext_channel = 0;
  2993. struct target_if_spectral_ops *p_sops =
  2994. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2995. current_channel = p_sops->get_current_channel(spectral);
  2996. ext_channel = p_sops->get_extension_channel(spectral);
  2997. if ((current_channel == 0) || (ext_channel == 0))
  2998. return;
  2999. if (spectral->sc_spectral_20_40_mode) {
  3000. /* HT40 mode */
  3001. if (ext_channel < current_channel) {
  3002. spectral->lower_is_extension = 1;
  3003. spectral->upper_is_control = 1;
  3004. spectral->lower_is_control = 0;
  3005. spectral->upper_is_extension = 0;
  3006. } else {
  3007. spectral->lower_is_extension = 0;
  3008. spectral->upper_is_control = 0;
  3009. spectral->lower_is_control = 1;
  3010. spectral->upper_is_extension = 1;
  3011. }
  3012. } else {
  3013. /* HT20 mode, lower is always control */
  3014. spectral->lower_is_extension = 0;
  3015. spectral->upper_is_control = 0;
  3016. spectral->lower_is_control = 1;
  3017. spectral->upper_is_extension = 0;
  3018. }
  3019. }
  3020. /**
  3021. * target_if_get_spectral_config() - Get spectral configuration
  3022. * @pdev: Pointer to pdev object
  3023. * @param: Pointer to spectral_config structure in which the configuration
  3024. * should be returned
  3025. * @smode: Spectral scan mode
  3026. *
  3027. * API to get the current spectral configuration
  3028. *
  3029. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3030. */
  3031. QDF_STATUS
  3032. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  3033. struct spectral_config *param,
  3034. enum spectral_scan_mode smode)
  3035. {
  3036. struct target_if_spectral_ops *p_sops = NULL;
  3037. struct target_if_spectral *spectral = NULL;
  3038. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3039. if (!spectral) {
  3040. spectral_err("SPECTRAL : Module doesn't exist");
  3041. return QDF_STATUS_E_FAILURE;
  3042. }
  3043. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3044. if (!p_sops) {
  3045. spectral_err("p_sops is null");
  3046. return QDF_STATUS_E_FAILURE;
  3047. }
  3048. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3049. spectral_err("Invalid Spectral mode %u", smode);
  3050. return QDF_STATUS_E_FAILURE;
  3051. }
  3052. qdf_mem_zero(param, sizeof(struct spectral_config));
  3053. p_sops->get_spectral_config(spectral, param, smode);
  3054. return QDF_STATUS_SUCCESS;
  3055. }
  3056. /**
  3057. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  3058. * parameters
  3059. * @spectral: Pointer to Spectral target_if internal private data
  3060. * @spectral_params: Pointer to Spectral parameters
  3061. * @smode: Spectral scan mode
  3062. * @err: Spectral error code
  3063. *
  3064. * Enable use of desired Spectral parameters by configuring them into HW, and
  3065. * starting Spectral scan
  3066. *
  3067. * Return: 0 on success, 1 on failure
  3068. */
  3069. int
  3070. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  3071. struct spectral_config *spectral_params,
  3072. enum spectral_scan_mode smode,
  3073. enum spectral_cp_error_code *err)
  3074. {
  3075. int extension_channel = 0;
  3076. int current_channel = 0;
  3077. struct target_if_spectral_ops *p_sops = NULL;
  3078. QDF_STATUS status;
  3079. struct wlan_objmgr_pdev *pdev;
  3080. struct wlan_objmgr_psoc *psoc;
  3081. if (!spectral) {
  3082. spectral_err("Spectral LMAC object is NULL");
  3083. return 1;
  3084. }
  3085. pdev = spectral->pdev_obj;
  3086. if (!pdev) {
  3087. spectral_err("pdev is null");
  3088. return QDF_STATUS_E_INVAL;
  3089. }
  3090. psoc = wlan_pdev_get_psoc(pdev);
  3091. if (!psoc) {
  3092. spectral_err("psoc is null");
  3093. return QDF_STATUS_E_INVAL;
  3094. }
  3095. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3096. spectral_err("Invalid Spectral mode %u", smode);
  3097. return 1;
  3098. }
  3099. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3100. if (!p_sops) {
  3101. spectral_err("p_sops is NULL");
  3102. return 1;
  3103. }
  3104. spectral->sc_spectral_noise_pwr_cal =
  3105. spectral_params->ss_spectral_pri ? 1 : 0;
  3106. /* check if extension channel is present */
  3107. extension_channel = p_sops->get_extension_channel(spectral);
  3108. current_channel = p_sops->get_current_channel(spectral);
  3109. status = target_if_spectral_populate_chwidth(
  3110. spectral, spectral->ch_width,
  3111. spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  3112. ss_frequency.cfreq2 > 0);
  3113. if (QDF_IS_STATUS_ERROR(status)) {
  3114. spectral_err("Failed to get channel widths");
  3115. return 1;
  3116. }
  3117. if (spectral->capability.advncd_spectral_cap) {
  3118. spectral->lb_edge_extrabins = 0;
  3119. spectral->rb_edge_extrabins = 0;
  3120. if (spectral->is_lb_edge_extrabins_format &&
  3121. spectral->params[smode].ss_rpt_mode == 2) {
  3122. spectral->lb_edge_extrabins = 4;
  3123. }
  3124. if (spectral->is_rb_edge_extrabins_format &&
  3125. spectral->params[smode].ss_rpt_mode == 2) {
  3126. spectral->rb_edge_extrabins = 4;
  3127. }
  3128. if (spectral->ch_width[smode] == CH_WIDTH_20MHZ) {
  3129. spectral->sc_spectral_20_40_mode = 0;
  3130. spectral->spectral_numbins =
  3131. target_if_get_fft_bin_count(
  3132. spectral->params[smode].ss_fft_size);
  3133. spectral->spectral_fft_len =
  3134. target_if_get_fft_bin_count(
  3135. spectral->params[smode].ss_fft_size);
  3136. spectral->spectral_data_len =
  3137. target_if_get_fft_bin_count(
  3138. spectral->params[smode].ss_fft_size);
  3139. /*
  3140. * Initialize classifier params to be sent to user
  3141. * space classifier
  3142. */
  3143. spectral->classifier_params.lower_chan_in_mhz =
  3144. current_channel;
  3145. spectral->classifier_params.upper_chan_in_mhz = 0;
  3146. } else if (spectral->ch_width[smode] == CH_WIDTH_40MHZ) {
  3147. /* TODO : Remove this variable */
  3148. spectral->sc_spectral_20_40_mode = 1;
  3149. spectral->spectral_numbins =
  3150. target_if_get_fft_bin_count(
  3151. spectral->params[smode].ss_fft_size);
  3152. spectral->spectral_fft_len =
  3153. target_if_get_fft_bin_count(
  3154. spectral->params[smode].ss_fft_size);
  3155. spectral->spectral_data_len =
  3156. target_if_get_fft_bin_count(
  3157. spectral->params[smode].ss_fft_size);
  3158. /*
  3159. * Initialize classifier params to be sent to user
  3160. * space classifier
  3161. */
  3162. if (extension_channel < current_channel) {
  3163. spectral->classifier_params.lower_chan_in_mhz =
  3164. extension_channel;
  3165. spectral->classifier_params.upper_chan_in_mhz =
  3166. current_channel;
  3167. } else {
  3168. spectral->classifier_params.lower_chan_in_mhz =
  3169. current_channel;
  3170. spectral->classifier_params.upper_chan_in_mhz =
  3171. extension_channel;
  3172. }
  3173. } else if (spectral->ch_width[smode] == CH_WIDTH_80MHZ) {
  3174. /* Set the FFT Size */
  3175. /* TODO : Remove this variable */
  3176. spectral->sc_spectral_20_40_mode = 0;
  3177. spectral->spectral_numbins =
  3178. target_if_get_fft_bin_count(
  3179. spectral->params[smode].ss_fft_size);
  3180. spectral->spectral_fft_len =
  3181. target_if_get_fft_bin_count(
  3182. spectral->params[smode].ss_fft_size);
  3183. spectral->spectral_data_len =
  3184. target_if_get_fft_bin_count(
  3185. spectral->params[smode].ss_fft_size);
  3186. /*
  3187. * Initialize classifier params to be sent to user
  3188. * space classifier
  3189. */
  3190. spectral->classifier_params.lower_chan_in_mhz =
  3191. current_channel;
  3192. spectral->classifier_params.upper_chan_in_mhz = 0;
  3193. /*
  3194. * Initialize classifier params to be sent to user
  3195. * space classifier
  3196. */
  3197. if (extension_channel < current_channel) {
  3198. spectral->classifier_params.lower_chan_in_mhz =
  3199. extension_channel;
  3200. spectral->classifier_params.upper_chan_in_mhz =
  3201. current_channel;
  3202. } else {
  3203. spectral->classifier_params.lower_chan_in_mhz =
  3204. current_channel;
  3205. spectral->classifier_params.upper_chan_in_mhz =
  3206. extension_channel;
  3207. }
  3208. } else if (is_ch_width_160_or_80p80(
  3209. spectral->ch_width[smode])) {
  3210. /* Set the FFT Size */
  3211. /* The below applies to both 160 and 80+80 cases */
  3212. /* TODO : Remove this variable */
  3213. spectral->sc_spectral_20_40_mode = 0;
  3214. spectral->spectral_numbins =
  3215. target_if_get_fft_bin_count(
  3216. spectral->params[smode].ss_fft_size);
  3217. spectral->spectral_fft_len =
  3218. target_if_get_fft_bin_count(
  3219. spectral->params[smode].ss_fft_size);
  3220. spectral->spectral_data_len =
  3221. target_if_get_fft_bin_count(
  3222. spectral->params[smode].ss_fft_size);
  3223. /*
  3224. * Initialize classifier params to be sent to user
  3225. * space classifier
  3226. */
  3227. spectral->classifier_params.lower_chan_in_mhz =
  3228. current_channel;
  3229. spectral->classifier_params.upper_chan_in_mhz = 0;
  3230. /*
  3231. * Initialize classifier params to be sent to user
  3232. * space classifier
  3233. */
  3234. if (extension_channel < current_channel) {
  3235. spectral->classifier_params.lower_chan_in_mhz =
  3236. extension_channel;
  3237. spectral->classifier_params.upper_chan_in_mhz =
  3238. current_channel;
  3239. } else {
  3240. spectral->classifier_params.lower_chan_in_mhz =
  3241. current_channel;
  3242. spectral->classifier_params.upper_chan_in_mhz =
  3243. extension_channel;
  3244. }
  3245. }
  3246. if (spectral->spectral_numbins) {
  3247. spectral->spectral_numbins +=
  3248. spectral->lb_edge_extrabins;
  3249. spectral->spectral_numbins +=
  3250. spectral->rb_edge_extrabins;
  3251. }
  3252. if (spectral->spectral_fft_len) {
  3253. spectral->spectral_fft_len +=
  3254. spectral->lb_edge_extrabins;
  3255. spectral->spectral_fft_len +=
  3256. spectral->rb_edge_extrabins;
  3257. }
  3258. if (spectral->spectral_data_len) {
  3259. spectral->spectral_data_len +=
  3260. spectral->lb_edge_extrabins;
  3261. spectral->spectral_data_len +=
  3262. spectral->rb_edge_extrabins;
  3263. }
  3264. } else {
  3265. /*
  3266. * The decision to find 20/40 mode is found based on the
  3267. * presence of extension channel
  3268. * instead of channel width, as the channel width can
  3269. * dynamically change
  3270. */
  3271. if (extension_channel == 0) {
  3272. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  3273. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  3274. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  3275. spectral->spectral_data_len =
  3276. SPECTRAL_HT20_TOTAL_DATA_LEN;
  3277. /* only valid in 20-40 mode */
  3278. spectral->spectral_lower_max_index_offset = -1;
  3279. /* only valid in 20-40 mode */
  3280. spectral->spectral_upper_max_index_offset = -1;
  3281. spectral->spectral_max_index_offset =
  3282. spectral->spectral_fft_len + 2;
  3283. spectral->sc_spectral_20_40_mode = 0;
  3284. /*
  3285. * Initialize classifier params to be sent to user
  3286. * space classifier
  3287. */
  3288. spectral->classifier_params.lower_chan_in_mhz =
  3289. current_channel;
  3290. spectral->classifier_params.upper_chan_in_mhz = 0;
  3291. } else {
  3292. spectral->spectral_numbins =
  3293. SPECTRAL_HT40_TOTAL_NUM_BINS;
  3294. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  3295. spectral->spectral_data_len =
  3296. SPECTRAL_HT40_TOTAL_DATA_LEN;
  3297. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  3298. /* only valid in 20 mode */
  3299. spectral->spectral_max_index_offset = -1;
  3300. spectral->spectral_lower_max_index_offset =
  3301. spectral->spectral_fft_len + 2;
  3302. spectral->spectral_upper_max_index_offset =
  3303. spectral->spectral_fft_len + 5;
  3304. spectral->sc_spectral_20_40_mode = 1;
  3305. /*
  3306. * Initialize classifier params to be sent to user
  3307. * space classifier
  3308. */
  3309. if (extension_channel < current_channel) {
  3310. spectral->classifier_params.lower_chan_in_mhz =
  3311. extension_channel;
  3312. spectral->classifier_params.upper_chan_in_mhz =
  3313. current_channel;
  3314. } else {
  3315. spectral->classifier_params.lower_chan_in_mhz =
  3316. current_channel;
  3317. spectral->classifier_params.upper_chan_in_mhz =
  3318. extension_channel;
  3319. }
  3320. }
  3321. }
  3322. spectral->send_single_packet = 0;
  3323. spectral->classifier_params.spectral_20_40_mode =
  3324. spectral->sc_spectral_20_40_mode;
  3325. spectral->classifier_params.spectral_dc_index =
  3326. spectral->spectral_dc_index;
  3327. spectral->spectral_sent_msg = 0;
  3328. spectral->classify_scan = 0;
  3329. spectral->num_spectral_data = 0;
  3330. if (!p_sops->is_spectral_active(spectral, smode)) {
  3331. p_sops->configure_spectral(spectral, spectral_params, smode);
  3332. p_sops->start_spectral_scan(spectral, smode, err);
  3333. spectral->timestamp_war.timestamp_war_offset[smode] = 0;
  3334. spectral->timestamp_war.last_fft_timestamp[smode] = 0;
  3335. spectral->rparams.marker[smode].is_valid = false;
  3336. }
  3337. /* get current spectral configuration */
  3338. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  3339. target_if_init_upper_lower_flags(spectral);
  3340. return 0;
  3341. }
  3342. /**
  3343. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  3344. * Agile DFS
  3345. * @psoc: Pointer to psoc
  3346. * @object: Pointer to pdev
  3347. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  3348. *
  3349. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  3350. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  3351. *
  3352. * Return: void
  3353. */
  3354. static void
  3355. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  3356. void *object, void *arg)
  3357. {
  3358. bool *is_aspectral_prohibited = arg;
  3359. struct wlan_objmgr_pdev *cur_pdev = object;
  3360. bool is_agile_dfs_enabled_cur_pdev = false;
  3361. QDF_STATUS status;
  3362. qdf_assert_always(is_aspectral_prohibited);
  3363. if (*is_aspectral_prohibited)
  3364. return;
  3365. qdf_assert_always(psoc);
  3366. qdf_assert_always(cur_pdev);
  3367. status = ucfg_dfs_get_agile_precac_enable
  3368. (cur_pdev,
  3369. &is_agile_dfs_enabled_cur_pdev);
  3370. if (QDF_IS_STATUS_ERROR(status)) {
  3371. spectral_err("Get agile precac failed, prohibiting aSpectral");
  3372. *is_aspectral_prohibited = true;
  3373. return;
  3374. }
  3375. if (is_agile_dfs_enabled_cur_pdev) {
  3376. spectral_err("aDFS is in progress on one of the pdevs");
  3377. *is_aspectral_prohibited = true;
  3378. }
  3379. }
  3380. /**
  3381. * target_if_get_curr_band() - Get current operating band of pdev
  3382. *
  3383. * @spectral: pointer to spectral object
  3384. *
  3385. * API to get current operating band of a given pdev.
  3386. *
  3387. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  3388. */
  3389. static enum reg_wifi_band
  3390. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev)
  3391. {
  3392. struct wlan_objmgr_vdev *vdev;
  3393. int16_t chan_freq;
  3394. enum reg_wifi_band cur_band;
  3395. if (!pdev) {
  3396. spectral_err("pdev is NULL");
  3397. return REG_BAND_UNKNOWN;
  3398. }
  3399. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  3400. if (!vdev) {
  3401. spectral_debug("vdev is NULL");
  3402. return REG_BAND_UNKNOWN;
  3403. }
  3404. chan_freq = target_if_vdev_get_chan_freq(vdev);
  3405. cur_band = wlan_reg_freq_to_band(chan_freq);
  3406. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3407. return cur_band;
  3408. }
  3409. /**
  3410. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  3411. * any of the 5G pdevs
  3412. * @psoc: Pointer to psoc
  3413. * @object: Pointer to pdev
  3414. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  3415. * progress in any 5G pdevs
  3416. *
  3417. * Return: void
  3418. */
  3419. static void
  3420. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  3421. void *object, void *arg)
  3422. {
  3423. enum reg_wifi_band band;
  3424. bool *is_agile_scan_inprog_5g_pdev = arg;
  3425. struct target_if_spectral *spectral;
  3426. struct wlan_objmgr_pdev *cur_pdev = object;
  3427. struct target_if_spectral_ops *p_sops;
  3428. if (*is_agile_scan_inprog_5g_pdev)
  3429. return;
  3430. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  3431. if (!spectral) {
  3432. spectral_err("target if spectral handle is NULL");
  3433. return;
  3434. }
  3435. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3436. band = target_if_get_curr_band(cur_pdev);
  3437. if (band == REG_BAND_UNKNOWN) {
  3438. spectral_debug("Failed to get current band");
  3439. return;
  3440. }
  3441. if (band == REG_BAND_5G &&
  3442. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  3443. *is_agile_scan_inprog_5g_pdev = true;
  3444. }
  3445. /**
  3446. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  3447. * for current vdev rx chainmask.
  3448. *
  3449. * @spectral: Pointer to Spectral object
  3450. * @is_supported: Pointer to is_supported
  3451. *
  3452. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3453. */
  3454. static QDF_STATUS
  3455. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  3456. bool *is_supported)
  3457. {
  3458. struct wlan_objmgr_vdev *vdev;
  3459. uint8_t vdev_rxchainmask;
  3460. struct wlan_objmgr_psoc *psoc;
  3461. struct wlan_objmgr_pdev *pdev;
  3462. struct target_psoc_info *tgt_psoc_info;
  3463. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  3464. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  3465. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  3466. struct wlan_psoc_host_chainmask_table *table;
  3467. int j;
  3468. uint32_t table_id;
  3469. enum phy_ch_width ch_width;
  3470. uint8_t pdev_id;
  3471. if (!spectral) {
  3472. spectral_err("spectral target if object is null");
  3473. return QDF_STATUS_E_FAILURE;
  3474. }
  3475. if (!is_supported) {
  3476. spectral_err("is supported argument is null");
  3477. return QDF_STATUS_E_FAILURE;
  3478. }
  3479. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  3480. spectral_err("HW Agile mode is not supported up to gen 2");
  3481. return QDF_STATUS_E_FAILURE;
  3482. }
  3483. pdev = spectral->pdev_obj;
  3484. if (!pdev) {
  3485. spectral_err("pdev is null");
  3486. return QDF_STATUS_E_FAILURE;
  3487. }
  3488. psoc = wlan_pdev_get_psoc(pdev);
  3489. if (!psoc) {
  3490. spectral_err("psoc is null");
  3491. return QDF_STATUS_E_FAILURE;
  3492. }
  3493. vdev = target_if_spectral_get_vdev(spectral);
  3494. if (!vdev) {
  3495. spectral_err("First vdev is NULL");
  3496. return QDF_STATUS_E_FAILURE;
  3497. }
  3498. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  3499. if (!vdev_rxchainmask) {
  3500. spectral_err("vdev rx chainmask is zero");
  3501. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3502. return QDF_STATUS_E_FAILURE;
  3503. }
  3504. ch_width = target_if_vdev_get_ch_width(vdev);
  3505. if (ch_width == CH_WIDTH_INVALID) {
  3506. spectral_err("Invalid channel width");
  3507. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3508. return QDF_STATUS_E_FAILURE;
  3509. }
  3510. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3511. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  3512. if (!tgt_psoc_info) {
  3513. spectral_err("target_psoc_info is null");
  3514. return QDF_STATUS_E_FAILURE;
  3515. }
  3516. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  3517. if (!ext_svc_param) {
  3518. spectral_err("Extended service ready param null");
  3519. return QDF_STATUS_E_FAILURE;
  3520. }
  3521. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  3522. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  3523. if (!mac_phy_cap_arr) {
  3524. spectral_err("mac phy cap array is null");
  3525. return QDF_STATUS_E_FAILURE;
  3526. }
  3527. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  3528. if (!mac_phy_cap) {
  3529. spectral_err("mac phy cap is null");
  3530. return QDF_STATUS_E_FAILURE;
  3531. }
  3532. table_id = mac_phy_cap->chainmask_table_id;
  3533. table = &ext_svc_param->chainmask_table[table_id];
  3534. if (!table) {
  3535. spectral_err("chainmask table not found");
  3536. return QDF_STATUS_E_FAILURE;
  3537. }
  3538. for (j = 0; j < table->num_valid_chainmasks; j++) {
  3539. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  3540. if (ch_width <= CH_WIDTH_80MHZ)
  3541. *is_supported =
  3542. table->cap_list[j].supports_aSpectral;
  3543. else
  3544. *is_supported =
  3545. table->cap_list[j].supports_aSpectral_160;
  3546. break;
  3547. }
  3548. }
  3549. if (j == table->num_valid_chainmasks) {
  3550. spectral_err("vdev rx chainmask %u not found in table id = %u",
  3551. vdev_rxchainmask, table_id);
  3552. return QDF_STATUS_E_FAILURE;
  3553. }
  3554. return QDF_STATUS_SUCCESS;
  3555. }
  3556. QDF_STATUS
  3557. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3558. const enum spectral_scan_mode smode,
  3559. enum spectral_cp_error_code *err)
  3560. {
  3561. struct target_if_spectral_ops *p_sops;
  3562. struct target_if_spectral *spectral;
  3563. struct wlan_objmgr_psoc *psoc;
  3564. enum reg_wifi_band band;
  3565. if (!err) {
  3566. spectral_err("Error code argument is null");
  3567. QDF_ASSERT(0);
  3568. return QDF_STATUS_E_FAILURE;
  3569. }
  3570. *err = SPECTRAL_SCAN_ERR_INVALID;
  3571. if (!pdev) {
  3572. spectral_err("pdev object is NUll");
  3573. return QDF_STATUS_E_FAILURE;
  3574. }
  3575. psoc = wlan_pdev_get_psoc(pdev);
  3576. if (!psoc) {
  3577. spectral_err("psoc is null");
  3578. return QDF_STATUS_E_FAILURE;
  3579. }
  3580. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3581. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3582. spectral_err("Invalid Spectral mode %u", smode);
  3583. return QDF_STATUS_E_FAILURE;
  3584. }
  3585. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3586. if (!spectral) {
  3587. spectral_err("Spectral LMAC object is NUll");
  3588. return QDF_STATUS_E_FAILURE;
  3589. }
  3590. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3591. if (!p_sops) {
  3592. spectral_err("p_sops is null");
  3593. return QDF_STATUS_E_FAILURE;
  3594. }
  3595. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3596. QDF_STATUS status;
  3597. bool is_supported = false;
  3598. status = target_if_is_agile_supported_cur_chmask(spectral,
  3599. &is_supported);
  3600. if (QDF_IS_STATUS_ERROR(status)) {
  3601. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3602. return QDF_STATUS_E_FAILURE;
  3603. }
  3604. if (!is_supported) {
  3605. spectral_err("aSpectral unsupported for cur chainmask");
  3606. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3607. return QDF_STATUS_E_FAILURE;
  3608. }
  3609. }
  3610. band = target_if_get_curr_band(spectral->pdev_obj);
  3611. if (band == REG_BAND_UNKNOWN) {
  3612. spectral_err("Failed to get current band");
  3613. return QDF_STATUS_E_FAILURE;
  3614. }
  3615. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  3616. struct target_psoc_info *tgt_hdl;
  3617. enum wmi_host_hw_mode_config_type mode;
  3618. bool is_agile_scan_inprog_5g_pdev;
  3619. if (p_sops->is_spectral_active(spectral,
  3620. SPECTRAL_SCAN_MODE_AGILE)) {
  3621. spectral_err("Agile Scan in progress in current pdev");
  3622. return QDF_STATUS_E_FAILURE;
  3623. }
  3624. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  3625. if (!tgt_hdl) {
  3626. target_if_err("target_psoc_info is null");
  3627. return QDF_STATUS_E_FAILURE;
  3628. }
  3629. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  3630. switch (mode) {
  3631. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  3632. case WMI_HOST_HW_MODE_SBS:
  3633. case WMI_HOST_HW_MODE_DBS_SBS:
  3634. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  3635. is_agile_scan_inprog_5g_pdev = false;
  3636. wlan_objmgr_iterate_obj_list
  3637. (psoc, WLAN_PDEV_OP,
  3638. target_if_is_agile_scan_active_in_5g,
  3639. &is_agile_scan_inprog_5g_pdev, 0,
  3640. WLAN_SPECTRAL_ID);
  3641. break;
  3642. default:
  3643. is_agile_scan_inprog_5g_pdev = false;
  3644. break;
  3645. }
  3646. if (is_agile_scan_inprog_5g_pdev) {
  3647. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  3648. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3649. return QDF_STATUS_E_FAILURE;
  3650. }
  3651. }
  3652. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3653. bool is_aspectral_prohibited = false;
  3654. QDF_STATUS status;
  3655. status = wlan_objmgr_iterate_obj_list
  3656. (psoc, WLAN_PDEV_OP,
  3657. target_if_is_aspectral_prohibited_by_adfs,
  3658. &is_aspectral_prohibited, 0,
  3659. WLAN_SPECTRAL_ID);
  3660. if (QDF_IS_STATUS_ERROR(status)) {
  3661. spectral_err("Failed to iterate over pdevs");
  3662. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3663. return QDF_STATUS_E_FAILURE;
  3664. }
  3665. if (is_aspectral_prohibited) {
  3666. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3667. return QDF_STATUS_E_FAILURE;
  3668. }
  3669. }
  3670. if (!spectral->params_valid[smode]) {
  3671. target_if_spectral_info_read(spectral,
  3672. smode,
  3673. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3674. &spectral->params[smode],
  3675. sizeof(spectral->params[smode]));
  3676. spectral->params_valid[smode] = true;
  3677. }
  3678. qdf_spin_lock(&spectral->spectral_lock);
  3679. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3680. QDF_STATUS status;
  3681. bool is_overlapping;
  3682. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  3683. enum spectral_scan_mode m;
  3684. enum phy_ch_width op_ch_width;
  3685. enum phy_ch_width agile_ch_width;
  3686. m = SPECTRAL_SCAN_MODE_NORMAL;
  3687. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  3688. ch_width[m] = CH_WIDTH_INVALID;
  3689. status = target_if_spectral_populate_chwidth
  3690. (spectral, ch_width, spectral->params
  3691. [SPECTRAL_SCAN_MODE_AGILE].ss_frequency.cfreq2 > 0);
  3692. if (QDF_IS_STATUS_ERROR(status)) {
  3693. qdf_spin_unlock(&spectral->spectral_lock);
  3694. spectral_err("Failed to populate channel width");
  3695. return QDF_STATUS_E_FAILURE;
  3696. }
  3697. op_ch_width = ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  3698. agile_ch_width = ch_width[SPECTRAL_SCAN_MODE_AGILE];
  3699. if (!spectral->params[smode].ss_frequency.cfreq1 ||
  3700. (agile_ch_width == CH_WIDTH_80P80MHZ &&
  3701. !spectral->params[smode].ss_frequency.cfreq2)) {
  3702. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  3703. qdf_spin_unlock(&spectral->spectral_lock);
  3704. return QDF_STATUS_E_FAILURE;
  3705. }
  3706. status = target_if_is_agile_span_overlap_with_operating_span
  3707. (spectral, ch_width,
  3708. &spectral->params[smode].ss_frequency,
  3709. &is_overlapping);
  3710. if (QDF_IS_STATUS_ERROR(status)) {
  3711. qdf_spin_unlock(&spectral->spectral_lock);
  3712. return QDF_STATUS_E_FAILURE;
  3713. }
  3714. if (is_overlapping) {
  3715. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3716. qdf_spin_unlock(&spectral->spectral_lock);
  3717. return QDF_STATUS_E_FAILURE;
  3718. }
  3719. }
  3720. target_if_spectral_scan_enable_params(spectral,
  3721. &spectral->params[smode], smode,
  3722. err);
  3723. qdf_spin_unlock(&spectral->spectral_lock);
  3724. return QDF_STATUS_SUCCESS;
  3725. }
  3726. QDF_STATUS
  3727. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3728. const enum spectral_scan_mode smode,
  3729. enum spectral_cp_error_code *err)
  3730. {
  3731. struct target_if_spectral_ops *p_sops;
  3732. struct target_if_spectral *spectral;
  3733. if (!err) {
  3734. spectral_err("Error code argument is null");
  3735. QDF_ASSERT(0);
  3736. return QDF_STATUS_E_FAILURE;
  3737. }
  3738. *err = SPECTRAL_SCAN_ERR_INVALID;
  3739. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3740. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3741. spectral_err("Invalid Spectral mode %u", smode);
  3742. return QDF_STATUS_E_FAILURE;
  3743. }
  3744. if (!pdev) {
  3745. spectral_err("pdev object is NUll ");
  3746. return QDF_STATUS_E_FAILURE;
  3747. }
  3748. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3749. if (!spectral) {
  3750. spectral_err("Spectral LMAC object is NUll ");
  3751. return QDF_STATUS_E_FAILURE;
  3752. }
  3753. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3754. qdf_spin_lock(&spectral->spectral_lock);
  3755. p_sops->stop_spectral_scan(spectral, smode);
  3756. if (spectral->classify_scan) {
  3757. /* TODO : Check if this logic is necessary */
  3758. spectral->detects_control_channel = 0;
  3759. spectral->detects_extension_channel = 0;
  3760. spectral->detects_above_dc = 0;
  3761. spectral->detects_below_dc = 0;
  3762. spectral->classify_scan = 0;
  3763. }
  3764. spectral->send_single_packet = 0;
  3765. spectral->sc_spectral_scan = 0;
  3766. qdf_spin_unlock(&spectral->spectral_lock);
  3767. return QDF_STATUS_SUCCESS;
  3768. }
  3769. /**
  3770. * target_if_is_spectral_active() - Get whether Spectral is active
  3771. * @pdev: Pointer to pdev object
  3772. * @smode: Spectral scan mode
  3773. *
  3774. * API to get whether Spectral is active
  3775. *
  3776. * Return: True if Spectral is active, false if Spectral is not active
  3777. */
  3778. bool
  3779. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  3780. const enum spectral_scan_mode smode)
  3781. {
  3782. struct target_if_spectral *spectral = NULL;
  3783. struct target_if_spectral_ops *p_sops = NULL;
  3784. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3785. if (!spectral) {
  3786. spectral_err("SPECTRAL : Module doesn't exist");
  3787. return QDF_STATUS_E_FAILURE;
  3788. }
  3789. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3790. if (!p_sops) {
  3791. spectral_err("p_sops is null");
  3792. return QDF_STATUS_E_FAILURE;
  3793. }
  3794. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3795. spectral_err("Invalid Spectral mode %u", smode);
  3796. return QDF_STATUS_E_FAILURE;
  3797. }
  3798. return p_sops->is_spectral_active(spectral, smode);
  3799. }
  3800. /**
  3801. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  3802. * @pdev: Pointer to pdev object
  3803. * @smode: Spectral scan mode
  3804. *
  3805. * API to get whether Spectral is enabled
  3806. *
  3807. * Return: True if Spectral is enabled, false if Spectral is not enabled
  3808. */
  3809. bool
  3810. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  3811. enum spectral_scan_mode smode)
  3812. {
  3813. struct target_if_spectral *spectral = NULL;
  3814. struct target_if_spectral_ops *p_sops = NULL;
  3815. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3816. if (!spectral) {
  3817. spectral_err("SPECTRAL : Module doesn't exist");
  3818. return QDF_STATUS_E_FAILURE;
  3819. }
  3820. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3821. if (!p_sops) {
  3822. spectral_err("p_sops is null");
  3823. return QDF_STATUS_E_FAILURE;
  3824. }
  3825. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3826. spectral_err("Invalid Spectral mode %u", smode);
  3827. return QDF_STATUS_E_FAILURE;
  3828. }
  3829. return p_sops->is_spectral_enabled(spectral, smode);
  3830. }
  3831. #ifdef DIRECT_BUF_RX_DEBUG
  3832. /**
  3833. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  3834. * @pdev: Pointer to pdev object
  3835. * @enable: Enable/Disable Spectral DMA ring debug
  3836. *
  3837. * Start/stop Spectral DMA ring debug based on @enable.
  3838. * Also save the state for future use.
  3839. *
  3840. * Return: QDF_STATUS of operation
  3841. */
  3842. static QDF_STATUS
  3843. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3844. {
  3845. struct target_if_spectral *spectral;
  3846. struct wlan_lmac_if_tx_ops *tx_ops;
  3847. struct wlan_objmgr_psoc *psoc;
  3848. if (!pdev)
  3849. return QDF_STATUS_E_FAILURE;
  3850. psoc = wlan_pdev_get_psoc(pdev);
  3851. if (!psoc) {
  3852. spectral_err("psoc is null");
  3853. return QDF_STATUS_E_INVAL;
  3854. }
  3855. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  3856. if (!tx_ops) {
  3857. spectral_err("tx_ops is NULL");
  3858. return QDF_STATUS_E_INVAL;
  3859. }
  3860. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3861. if (!spectral) {
  3862. spectral_err("Spectal LMAC object is NULL");
  3863. return QDF_STATUS_E_INVAL;
  3864. }
  3865. /* Save the state */
  3866. spectral->dbr_ring_debug = enable;
  3867. if (enable)
  3868. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  3869. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  3870. else
  3871. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  3872. pdev, 0);
  3873. return QDF_STATUS_SUCCESS;
  3874. }
  3875. /**
  3876. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  3877. * @pdev: Pointer to pdev object
  3878. * @enable: Enable/Disable Spectral DMA buffer debug
  3879. *
  3880. * Start/stop Spectral DMA buffer debug based on @enable.
  3881. * Also save the state for future use.
  3882. *
  3883. * Return: QDF_STATUS of operation
  3884. */
  3885. static QDF_STATUS
  3886. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3887. {
  3888. struct target_if_spectral *spectral;
  3889. struct wlan_lmac_if_tx_ops *tx_ops;
  3890. struct wlan_objmgr_psoc *psoc;
  3891. if (!pdev)
  3892. return QDF_STATUS_E_FAILURE;
  3893. psoc = wlan_pdev_get_psoc(pdev);
  3894. if (!psoc) {
  3895. spectral_err("psoc is null");
  3896. return QDF_STATUS_E_INVAL;
  3897. }
  3898. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  3899. if (!tx_ops) {
  3900. spectral_err("tx_ops is NULL");
  3901. return QDF_STATUS_E_INVAL;
  3902. }
  3903. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3904. if (!spectral) {
  3905. spectral_err("Spectal LMAC object is NULL");
  3906. return QDF_STATUS_E_INVAL;
  3907. }
  3908. /* Save the state */
  3909. spectral->dbr_buff_debug = enable;
  3910. if (enable)
  3911. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  3912. pdev, 0, MEM_POISON_SIGNATURE);
  3913. else
  3914. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  3915. pdev, 0);
  3916. }
  3917. /**
  3918. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  3919. * debug based on the previous state
  3920. * @pdev: Pointer to pdev object
  3921. *
  3922. * Return: QDF_STATUS of operation
  3923. */
  3924. static QDF_STATUS
  3925. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  3926. {
  3927. struct target_if_spectral *spectral;
  3928. if (!pdev) {
  3929. spectral_err("pdev is NULL!");
  3930. return QDF_STATUS_E_FAILURE;
  3931. }
  3932. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3933. if (!spectral) {
  3934. spectral_err("Spectal LMAC object is NULL");
  3935. return QDF_STATUS_E_INVAL;
  3936. }
  3937. if (spectral->dbr_buff_debug)
  3938. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  3939. else
  3940. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  3941. }
  3942. /**
  3943. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  3944. * debug based on the previous state
  3945. * @pdev: Pointer to pdev object
  3946. *
  3947. * Return: QDF_STATUS of operation
  3948. */
  3949. static QDF_STATUS
  3950. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  3951. {
  3952. struct target_if_spectral *spectral;
  3953. if (!pdev) {
  3954. spectral_err("pdev is NULL!");
  3955. return QDF_STATUS_E_FAILURE;
  3956. }
  3957. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3958. if (!spectral) {
  3959. spectral_err("Spectal LMAC object is NULL");
  3960. return QDF_STATUS_E_INVAL;
  3961. }
  3962. if (spectral->dbr_ring_debug)
  3963. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  3964. else
  3965. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  3966. }
  3967. /**
  3968. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  3969. * @pdev: Pointer to pdev object
  3970. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  3971. * @debug_value: Value to be set for @dma_debug_type
  3972. *
  3973. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  3974. * based on @debug_value
  3975. *
  3976. * Return: QDF_STATUS of operation
  3977. */
  3978. static QDF_STATUS
  3979. target_if_spectral_set_dma_debug(
  3980. struct wlan_objmgr_pdev *pdev,
  3981. enum spectral_dma_debug dma_debug_type,
  3982. bool debug_value)
  3983. {
  3984. struct target_if_spectral_ops *p_sops;
  3985. struct wlan_objmgr_psoc *psoc;
  3986. struct wlan_lmac_if_tx_ops *tx_ops;
  3987. struct target_if_spectral *spectral;
  3988. if (!pdev)
  3989. return QDF_STATUS_E_FAILURE;
  3990. psoc = wlan_pdev_get_psoc(pdev);
  3991. if (!psoc) {
  3992. spectral_err("psoc is null");
  3993. return QDF_STATUS_E_INVAL;
  3994. }
  3995. tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
  3996. if (!tx_ops) {
  3997. spectral_err("tx_ops is NULL");
  3998. return QDF_STATUS_E_FAILURE;
  3999. }
  4000. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  4001. spectral_err("Unable to fetch target type");
  4002. return QDF_STATUS_E_FAILURE;
  4003. }
  4004. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4005. if (!spectral) {
  4006. spectral_err("Spectal LMAC object is NULL");
  4007. return QDF_STATUS_E_INVAL;
  4008. }
  4009. if (spectral->direct_dma_support) {
  4010. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4011. if (p_sops->is_spectral_active(spectral,
  4012. SPECTRAL_SCAN_MODE_NORMAL) ||
  4013. p_sops->is_spectral_active(spectral,
  4014. SPECTRAL_SCAN_MODE_AGILE)) {
  4015. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  4016. return QDF_STATUS_E_FAILURE;
  4017. }
  4018. switch (dma_debug_type) {
  4019. case SPECTRAL_DMA_RING_DEBUG:
  4020. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  4021. break;
  4022. case SPECTRAL_DMA_BUFFER_DEBUG:
  4023. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  4024. break;
  4025. default:
  4026. spectral_err("Unsupported DMA debug type : %d",
  4027. dma_debug_type);
  4028. return QDF_STATUS_E_FAILURE;
  4029. }
  4030. }
  4031. return QDF_STATUS_SUCCESS;
  4032. }
  4033. #endif /* DIRECT_BUF_RX_DEBUG */
  4034. /**
  4035. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  4036. * @pdev: Pointer to pdev object
  4037. *
  4038. * Return: Whether Direct-DMA is supported on this radio
  4039. */
  4040. static bool
  4041. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  4042. {
  4043. struct target_if_spectral *spectral;
  4044. if (!pdev) {
  4045. spectral_err("pdev is NULL!");
  4046. return false;
  4047. }
  4048. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4049. if (!spectral) {
  4050. spectral_err("Spectral LMAC object is NULL");
  4051. return false;
  4052. }
  4053. return spectral->direct_dma_support;
  4054. }
  4055. /**
  4056. * target_if_set_debug_level() - Set debug level for Spectral
  4057. * @pdev: Pointer to pdev object
  4058. * @debug_level: Debug level
  4059. *
  4060. * API to set the debug level for Spectral
  4061. *
  4062. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4063. */
  4064. QDF_STATUS
  4065. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  4066. {
  4067. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  4068. return QDF_STATUS_SUCCESS;
  4069. }
  4070. /**
  4071. * target_if_get_debug_level() - Get debug level for Spectral
  4072. * @pdev: Pointer to pdev object
  4073. *
  4074. * API to get the debug level for Spectral
  4075. *
  4076. * Return: Current debug level
  4077. */
  4078. uint32_t
  4079. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  4080. {
  4081. return spectral_debug_level;
  4082. }
  4083. /**
  4084. * target_if_get_spectral_capinfo() - Get Spectral capability information
  4085. * @pdev: Pointer to pdev object
  4086. * @scaps: Buffer into which data should be copied
  4087. *
  4088. * API to get the spectral capability information
  4089. *
  4090. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4091. */
  4092. QDF_STATUS
  4093. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  4094. struct spectral_caps *scaps)
  4095. {
  4096. struct target_if_spectral *spectral = NULL;
  4097. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4098. if (!spectral) {
  4099. spectral_err("SPECTRAL : Module doesn't exist");
  4100. return QDF_STATUS_E_FAILURE;
  4101. }
  4102. qdf_mem_copy(scaps, &spectral->capability,
  4103. sizeof(struct spectral_caps));
  4104. return QDF_STATUS_SUCCESS;
  4105. }
  4106. /**
  4107. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  4108. * @pdev: Pointer to pdev object
  4109. * @stats: Buffer into which data should be copied
  4110. *
  4111. * API to get the spectral diagnostic statistics
  4112. *
  4113. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  4114. */
  4115. QDF_STATUS
  4116. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  4117. struct spectral_diag_stats *stats)
  4118. {
  4119. struct target_if_spectral *spectral = NULL;
  4120. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4121. if (!spectral) {
  4122. spectral_err("SPECTRAL : Module doesn't exist");
  4123. return QDF_STATUS_E_FAILURE;
  4124. }
  4125. qdf_mem_copy(stats, &spectral->diag_stats,
  4126. sizeof(struct spectral_diag_stats));
  4127. return QDF_STATUS_SUCCESS;
  4128. }
  4129. /**
  4130. * target_if_register_spectral_wmi_ops() - Register Spectral WMI operations
  4131. * @psoc: Pointer to psoc object
  4132. * @wmi_ops: Pointer to the structure having Spectral WMI operations
  4133. *
  4134. * API for registering Spectral WMI operations in
  4135. * spectral internal data structure
  4136. *
  4137. * Return: QDF_STATUS
  4138. */
  4139. static QDF_STATUS
  4140. target_if_register_spectral_wmi_ops(struct wlan_objmgr_psoc *psoc,
  4141. struct spectral_wmi_ops *wmi_ops)
  4142. {
  4143. struct target_if_psoc_spectral *psoc_spectral;
  4144. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4145. if (!psoc_spectral) {
  4146. spectral_err("Spectral LMAC object is null");
  4147. return QDF_STATUS_E_INVAL;
  4148. }
  4149. psoc_spectral->wmi_ops = *wmi_ops;
  4150. return QDF_STATUS_SUCCESS;
  4151. }
  4152. /**
  4153. * target_if_register_spectral_tgt_ops() - Register Spectral target operations
  4154. * @psoc: Pointer to psoc object
  4155. * @tgt_ops: Pointer to the structure having Spectral target operations
  4156. *
  4157. * API for registering Spectral target operations in
  4158. * spectral internal data structure
  4159. *
  4160. * Return: QDF_STATUS
  4161. */
  4162. static QDF_STATUS
  4163. target_if_register_spectral_tgt_ops(struct wlan_objmgr_psoc *psoc,
  4164. struct spectral_tgt_ops *tgt_ops)
  4165. {
  4166. if (!psoc) {
  4167. spectral_err("psoc is null");
  4168. return QDF_STATUS_E_INVAL;
  4169. }
  4170. ops_tgt = *tgt_ops;
  4171. return QDF_STATUS_SUCCESS;
  4172. }
  4173. /**
  4174. * target_if_register_netlink_cb() - Register Netlink callbacks
  4175. * @pdev: Pointer to pdev object
  4176. * @nl_cb: Netlink callbacks to register
  4177. *
  4178. * Return: void
  4179. */
  4180. static void
  4181. target_if_register_netlink_cb(
  4182. struct wlan_objmgr_pdev *pdev,
  4183. struct spectral_nl_cb *nl_cb)
  4184. {
  4185. struct target_if_spectral *spectral = NULL;
  4186. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4187. if (!spectral) {
  4188. spectral_err("SPECTRAL : Module doesn't exist");
  4189. return;
  4190. }
  4191. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  4192. if (spectral->use_nl_bcast)
  4193. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  4194. else
  4195. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  4196. }
  4197. /**
  4198. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  4199. * Netlink messages to the application layer
  4200. * @pdev: Pointer to pdev object
  4201. *
  4202. * Return: true for broadcast, false for unicast
  4203. */
  4204. static bool
  4205. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  4206. {
  4207. struct target_if_spectral *spectral = NULL;
  4208. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4209. if (!spectral) {
  4210. spectral_err("SPECTRAL : Module doesn't exist");
  4211. return false;
  4212. }
  4213. return spectral->use_nl_bcast;
  4214. }
  4215. /**
  4216. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  4217. * @pdev: Pointer to pdev object
  4218. *
  4219. * Return: void
  4220. */
  4221. static void
  4222. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  4223. {
  4224. struct target_if_spectral *spectral = NULL;
  4225. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4226. if (!spectral) {
  4227. spectral_err("SPECTRAL : Module doesn't exist");
  4228. return;
  4229. }
  4230. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  4231. }
  4232. static int
  4233. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  4234. void *payload)
  4235. {
  4236. struct target_if_spectral *spectral = NULL;
  4237. struct target_if_spectral_ops *p_sops = NULL;
  4238. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4239. if (!spectral) {
  4240. spectral_err("SPECTRAL : Module doesn't exist");
  4241. return -EPERM;
  4242. }
  4243. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4244. if (!p_sops) {
  4245. spectral_err("p_sops is null");
  4246. return -EPERM;
  4247. }
  4248. return p_sops->process_spectral_report(pdev, payload);
  4249. }
  4250. #ifdef DIRECT_BUF_RX_DEBUG
  4251. static inline void
  4252. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4253. {
  4254. if (!tx_ops) {
  4255. spectral_err("tx_ops is NULL");
  4256. return;
  4257. }
  4258. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  4259. target_if_spectral_set_dma_debug;
  4260. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  4261. target_if_spectral_check_and_do_dbr_ring_debug;
  4262. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  4263. target_if_spectral_check_and_do_dbr_buff_debug;
  4264. }
  4265. #else
  4266. static inline void
  4267. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4268. {
  4269. }
  4270. #endif
  4271. #if defined(WLAN_CONV_SPECTRAL_ENABLE) && defined(SPECTRAL_MODULIZED_ENABLE)
  4272. /**
  4273. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  4274. * register WMI event handler
  4275. * @psoc: Pointer to psoc object
  4276. * @event_id: Event id
  4277. * @handler_func: Handler function
  4278. * @rx_ctx: Context of WMI event processing
  4279. *
  4280. * Wrapper function to register WMI event handler
  4281. *
  4282. * Return: 0 for success else failure
  4283. */
  4284. static int
  4285. target_if_spectral_wmi_unified_register_event_handler(
  4286. struct wlan_objmgr_psoc *psoc,
  4287. wmi_conv_event_id event_id,
  4288. wmi_unified_event_handler handler_func,
  4289. uint8_t rx_ctx)
  4290. {
  4291. wmi_unified_t wmi_handle;
  4292. struct target_if_psoc_spectral *psoc_spectral;
  4293. if (!psoc) {
  4294. spectral_err("psoc is null");
  4295. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4296. }
  4297. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4298. if (!wmi_handle) {
  4299. spectral_err("WMI handle is null");
  4300. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4301. }
  4302. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4303. if (!psoc_spectral) {
  4304. spectral_err("spectral object is null");
  4305. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4306. }
  4307. return psoc_spectral->wmi_ops.wmi_unified_register_event_handler(
  4308. wmi_handle, event_id, handler_func, rx_ctx);
  4309. }
  4310. /**
  4311. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  4312. * to unregister WMI event handler
  4313. * @psoc: Pointer to psoc object
  4314. * @event_id: Event id
  4315. *
  4316. * Wrapper function to unregister WMI event handler
  4317. *
  4318. * Return: 0 for success else failure
  4319. */
  4320. static int
  4321. target_if_spectral_wmi_unified_unregister_event_handler(
  4322. struct wlan_objmgr_psoc *psoc,
  4323. wmi_conv_event_id event_id)
  4324. {
  4325. wmi_unified_t wmi_handle;
  4326. struct target_if_psoc_spectral *psoc_spectral;
  4327. if (!psoc) {
  4328. spectral_err("psoc is null");
  4329. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4330. }
  4331. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4332. if (!wmi_handle) {
  4333. spectral_err("WMI handle is null");
  4334. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4335. }
  4336. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4337. if (!psoc_spectral) {
  4338. spectral_err("spectral object is null");
  4339. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4340. }
  4341. return psoc_spectral->wmi_ops.wmi_unified_unregister_event_handler(
  4342. wmi_handle, event_id);
  4343. }
  4344. /**
  4345. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  4346. * function to extract fixed parameters from start scan response event
  4347. * @psoc: Pointer to psoc object
  4348. * @evt_buf: Event buffer
  4349. * @param: Start scan response parameters
  4350. *
  4351. * Wrapper function to extract fixed parameters from start scan response event
  4352. *
  4353. * Return: QDF_STATUS
  4354. */
  4355. static QDF_STATUS
  4356. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4357. struct wlan_objmgr_psoc *psoc,
  4358. uint8_t *evt_buf,
  4359. struct spectral_startscan_resp_params *param)
  4360. {
  4361. wmi_unified_t wmi_handle;
  4362. struct target_if_psoc_spectral *psoc_spectral;
  4363. if (!psoc) {
  4364. spectral_err("psoc is null");
  4365. return QDF_STATUS_E_INVAL;
  4366. }
  4367. if (!evt_buf) {
  4368. spectral_err("WMI event buffer is null");
  4369. return QDF_STATUS_E_INVAL;
  4370. }
  4371. if (!param) {
  4372. spectral_err("Spectral startscan response parameters is null");
  4373. return QDF_STATUS_E_INVAL;
  4374. }
  4375. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4376. if (!wmi_handle) {
  4377. spectral_err("WMI handle is null");
  4378. return QDF_STATUS_E_INVAL;
  4379. }
  4380. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4381. if (!psoc_spectral) {
  4382. spectral_err("spectral object is null");
  4383. return QDF_STATUS_E_FAILURE;
  4384. }
  4385. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4386. wmi_handle, evt_buf, param);
  4387. }
  4388. /**
  4389. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  4390. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  4391. * secondary 80 MHz FFT bins
  4392. * @psoc: Pointer to psoc object
  4393. * @evt_buf: Event buffer
  4394. * @param: FFT bin start and end indices
  4395. *
  4396. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  4397. * and secondary 80 MHz FFT bins
  4398. *
  4399. * Return: QDF_STATUS
  4400. */
  4401. static QDF_STATUS
  4402. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  4403. struct wlan_objmgr_psoc *psoc,
  4404. uint8_t *evt_buf,
  4405. struct spectral_fft_bin_markers_160_165mhz *param)
  4406. {
  4407. wmi_unified_t wmi_handle;
  4408. struct target_if_psoc_spectral *psoc_spectral;
  4409. if (!psoc) {
  4410. spectral_err("psoc is null");
  4411. return QDF_STATUS_E_INVAL;
  4412. }
  4413. if (!evt_buf) {
  4414. spectral_err("WMI event buffer is null");
  4415. return QDF_STATUS_E_INVAL;
  4416. }
  4417. if (!param) {
  4418. spectral_err("Spectral FFT bin markers is null");
  4419. return QDF_STATUS_E_INVAL;
  4420. }
  4421. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4422. if (!wmi_handle) {
  4423. spectral_err("WMI handle is null");
  4424. return QDF_STATUS_E_INVAL;
  4425. }
  4426. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4427. if (!psoc_spectral) {
  4428. spectral_err("spectral object is null");
  4429. return QDF_STATUS_E_FAILURE;
  4430. }
  4431. return psoc_spectral->wmi_ops.wmi_extract_pdev_sscan_fft_bin_index(
  4432. wmi_handle, evt_buf, param);
  4433. }
  4434. /**
  4435. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  4436. * object from scn handle
  4437. * @scn: scn handle
  4438. *
  4439. * Wrapper function to get psoc object from scn handle
  4440. *
  4441. * Return: Pointer to psoc object
  4442. */
  4443. static struct wlan_objmgr_psoc *
  4444. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  4445. {
  4446. if (!scn) {
  4447. spectral_err("scn is null");
  4448. return NULL;
  4449. }
  4450. return ops_tgt.tgt_get_psoc_from_scn_hdl(scn);
  4451. }
  4452. #else
  4453. /**
  4454. * target_if_spectral_wmi_unified_register_event_handler() - Wrapper function to
  4455. * register WMI event handler
  4456. * @psoc: Pointer to psoc object
  4457. * @event_id: Event id
  4458. * @handler_func: Handler function
  4459. * @rx_ctx: Context of WMI event processing
  4460. *
  4461. * Wrapper function to register WMI event handler
  4462. *
  4463. * Return: 0 for success else failure
  4464. */
  4465. static int
  4466. target_if_spectral_wmi_unified_register_event_handler(
  4467. struct wlan_objmgr_psoc *psoc,
  4468. wmi_conv_event_id event_id,
  4469. wmi_unified_event_handler handler_func,
  4470. uint8_t rx_ctx)
  4471. {
  4472. wmi_unified_t wmi_handle;
  4473. if (!psoc) {
  4474. spectral_err("psoc is null");
  4475. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4476. }
  4477. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4478. if (!wmi_handle) {
  4479. spectral_err("WMI handle is null");
  4480. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4481. }
  4482. return wmi_unified_register_event_handler(wmi_handle, event_id,
  4483. handler_func, rx_ctx);
  4484. }
  4485. /**
  4486. * target_if_spectral_wmi_unified_unregister_event_handler() - Wrapper function
  4487. * to unregister WMI event handler
  4488. * @psoc: Pointer to psoc object
  4489. * @event_id: Event id
  4490. *
  4491. * Wrapper function to unregister WMI event handler
  4492. *
  4493. * Return: 0 for success else failure
  4494. */
  4495. static int
  4496. target_if_spectral_wmi_unified_unregister_event_handler(
  4497. struct wlan_objmgr_psoc *psoc,
  4498. wmi_conv_event_id event_id)
  4499. {
  4500. wmi_unified_t wmi_handle;
  4501. if (!psoc) {
  4502. spectral_err("psoc is null");
  4503. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4504. }
  4505. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4506. if (!wmi_handle) {
  4507. spectral_err("WMI handle is null");
  4508. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4509. }
  4510. return wmi_unified_unregister_event_handler(wmi_handle, event_id);
  4511. }
  4512. /**
  4513. * target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param() - Wrapper
  4514. * function to extract fixed parameters from start scan response event
  4515. * @psoc: Pointer to psoc object
  4516. * @evt_buf: Event buffer
  4517. * @param: Start scan response parameters
  4518. *
  4519. * Wrapper function to extract fixed parameters from start scan response event
  4520. *
  4521. * Return: QDF_STATUS
  4522. */
  4523. static QDF_STATUS
  4524. target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4525. struct wlan_objmgr_psoc *psoc,
  4526. uint8_t *evt_buf,
  4527. struct spectral_startscan_resp_params *param)
  4528. {
  4529. wmi_unified_t wmi_handle;
  4530. if (!psoc) {
  4531. spectral_err("psoc is null");
  4532. return QDF_STATUS_E_INVAL;
  4533. }
  4534. if (!evt_buf) {
  4535. spectral_err("WMI event buffer is null");
  4536. return QDF_STATUS_E_INVAL;
  4537. }
  4538. if (!param) {
  4539. spectral_err("Spectral startscan response parameters is null");
  4540. return QDF_STATUS_E_INVAL;
  4541. }
  4542. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4543. if (!wmi_handle) {
  4544. spectral_err("WMI handle is null");
  4545. return QDF_STATUS_E_INVAL;
  4546. }
  4547. return wmi_extract_pdev_sscan_fw_cmd_fixed_param(wmi_handle, evt_buf,
  4548. param);
  4549. }
  4550. /**
  4551. * target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index() - Wrapper
  4552. * function to extract start and end indices of primary 80 MHz, 5 MHz and
  4553. * secondary 80 MHz FFT bins
  4554. * @psoc: Pointer to psoc object
  4555. * @evt_buf: Event buffer
  4556. * @param: FFT bin start and end indices
  4557. *
  4558. * Wrapper function to extract start and end indices of primary 80 MHz, 5 MHz
  4559. * and secondary 80 MHz FFT bins
  4560. *
  4561. * Return: QDF_STATUS
  4562. */
  4563. static QDF_STATUS
  4564. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  4565. struct wlan_objmgr_psoc *psoc,
  4566. uint8_t *evt_buf,
  4567. struct spectral_fft_bin_markers_160_165mhz *param)
  4568. {
  4569. wmi_unified_t wmi_handle;
  4570. if (!psoc) {
  4571. spectral_err("psoc is null");
  4572. return QDF_STATUS_E_INVAL;
  4573. }
  4574. if (!evt_buf) {
  4575. spectral_err("WMI event buffer is null");
  4576. return QDF_STATUS_E_INVAL;
  4577. }
  4578. if (!param) {
  4579. spectral_err("Spectral FFT bin markers is null");
  4580. return QDF_STATUS_E_INVAL;
  4581. }
  4582. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4583. if (!wmi_handle) {
  4584. spectral_err("WMI handle is null");
  4585. return QDF_STATUS_E_INVAL;
  4586. }
  4587. return wmi_extract_pdev_sscan_fft_bin_index(wmi_handle, evt_buf, param);
  4588. }
  4589. /**
  4590. * target_if_spectral_get_psoc_from_scn_handle() - Wrapper function to get psoc
  4591. * object from scn handle
  4592. * @scn: scn handle
  4593. *
  4594. * Wrapper function to get psoc object from scn handle
  4595. *
  4596. * Return: Pointer to psoc object
  4597. */
  4598. static struct wlan_objmgr_psoc *
  4599. target_if_spectral_get_psoc_from_scn_handle(ol_scn_t scn)
  4600. {
  4601. if (!scn) {
  4602. spectral_err("scn is null");
  4603. return NULL;
  4604. }
  4605. return target_if_get_psoc_from_scn_hdl(scn);
  4606. }
  4607. #endif
  4608. /**
  4609. * target_if_spectral_fw_param_event_handler() - WMI event handler to
  4610. * process start scan response event
  4611. * @scn: Pointer to scn object
  4612. * @data_buf: Pointer to event buffer
  4613. * @data_len: Length of event buffer
  4614. *
  4615. * Return: 0 for success, else failure
  4616. */
  4617. static int
  4618. target_if_spectral_fw_param_event_handler(ol_scn_t scn, uint8_t *data_buf,
  4619. uint32_t data_len)
  4620. {
  4621. QDF_STATUS status;
  4622. struct wlan_objmgr_psoc *psoc;
  4623. struct wlan_objmgr_pdev *pdev;
  4624. struct wmi_unified *wmi_handle;
  4625. struct spectral_startscan_resp_params event_params = {0};
  4626. struct target_if_psoc_spectral *psoc_spectral;
  4627. struct target_if_spectral *spectral;
  4628. if (!scn) {
  4629. spectral_err("scn handle is null");
  4630. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4631. }
  4632. if (!data_buf) {
  4633. spectral_err("WMI event buffer null");
  4634. return qdf_status_to_os_return(QDF_STATUS_E_INVAL);
  4635. }
  4636. psoc = target_if_spectral_get_psoc_from_scn_handle(scn);
  4637. if (!psoc) {
  4638. spectral_err("psoc is null");
  4639. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4640. }
  4641. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  4642. if (!psoc_spectral) {
  4643. spectral_err("spectral object is null");
  4644. return QDF_STATUS_E_FAILURE;
  4645. }
  4646. wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
  4647. if (!wmi_handle) {
  4648. spectral_err("WMI handle is null");
  4649. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4650. }
  4651. status = target_if_spectral_wmi_extract_pdev_sscan_fw_cmd_fixed_param(
  4652. psoc, data_buf, &event_params);
  4653. if (QDF_IS_STATUS_ERROR(status)) {
  4654. spectral_err("unable to extract sscan fw fixed params");
  4655. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4656. }
  4657. pdev = wlan_objmgr_get_pdev_by_id(psoc, event_params.pdev_id,
  4658. WLAN_SPECTRAL_ID);
  4659. if (!pdev) {
  4660. spectral_err("pdev is null");
  4661. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4662. }
  4663. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4664. if (!spectral) {
  4665. spectral_err("spectral object is null");
  4666. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  4667. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4668. }
  4669. if (event_params.num_fft_bin_index == 1) {
  4670. status =
  4671. target_if_spectral_wmi_extract_pdev_sscan_fft_bin_index(
  4672. psoc, data_buf,
  4673. &spectral->rparams.marker[event_params.smode]);
  4674. if (QDF_IS_STATUS_ERROR(status)) {
  4675. spectral_err("unable to extract sscan fw fixed params");
  4676. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  4677. return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
  4678. }
  4679. } else {
  4680. spectral->rparams.marker[event_params.smode].is_valid = false;
  4681. }
  4682. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  4683. return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
  4684. }
  4685. static QDF_STATUS
  4686. target_if_spectral_register_events(struct wlan_objmgr_psoc *psoc)
  4687. {
  4688. int ret;
  4689. if (!psoc) {
  4690. spectral_err("psoc is null");
  4691. return QDF_STATUS_E_INVAL;
  4692. }
  4693. ret = target_if_spectral_wmi_unified_register_event_handler(
  4694. psoc,
  4695. wmi_pdev_sscan_fw_param_eventid,
  4696. target_if_spectral_fw_param_event_handler,
  4697. WMI_RX_UMAC_CTX);
  4698. if (ret)
  4699. spectral_debug("event handler not supported, ret=%d", ret);
  4700. return QDF_STATUS_SUCCESS;
  4701. }
  4702. static QDF_STATUS
  4703. target_if_spectral_unregister_events(struct wlan_objmgr_psoc *psoc)
  4704. {
  4705. int ret;
  4706. if (!psoc) {
  4707. spectral_err("psoc is null");
  4708. return QDF_STATUS_E_INVAL;
  4709. }
  4710. ret = target_if_spectral_wmi_unified_unregister_event_handler(
  4711. psoc, wmi_pdev_sscan_fw_param_eventid);
  4712. if (ret)
  4713. spectral_debug("Unregister WMI event handler failed, ret = %d",
  4714. ret);
  4715. return QDF_STATUS_SUCCESS;
  4716. }
  4717. void
  4718. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  4719. {
  4720. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  4721. target_if_pdev_spectral_init;
  4722. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  4723. target_if_pdev_spectral_deinit;
  4724. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_init =
  4725. target_if_psoc_spectral_init;
  4726. tx_ops->sptrl_tx_ops.sptrlto_psoc_spectral_deinit =
  4727. target_if_psoc_spectral_deinit;
  4728. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  4729. target_if_set_spectral_config;
  4730. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  4731. target_if_get_spectral_config;
  4732. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  4733. target_if_start_spectral_scan;
  4734. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  4735. target_if_stop_spectral_scan;
  4736. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  4737. target_if_is_spectral_active;
  4738. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  4739. target_if_is_spectral_enabled;
  4740. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  4741. target_if_set_debug_level;
  4742. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  4743. target_if_get_debug_level;
  4744. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  4745. target_if_get_spectral_capinfo;
  4746. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  4747. target_if_get_spectral_diagstats;
  4748. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_wmi_ops =
  4749. target_if_register_spectral_wmi_ops;
  4750. tx_ops->sptrl_tx_ops.sptrlto_register_spectral_tgt_ops =
  4751. target_if_register_spectral_tgt_ops;
  4752. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  4753. target_if_register_netlink_cb;
  4754. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  4755. target_if_use_nl_bcast;
  4756. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  4757. target_if_deregister_netlink_cb;
  4758. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  4759. target_if_process_spectral_report;
  4760. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  4761. target_if_spectral_direct_dma_support;
  4762. tx_ops->sptrl_tx_ops.sptrlto_register_events =
  4763. target_if_spectral_register_events;
  4764. tx_ops->sptrl_tx_ops.sptrlto_unregister_events =
  4765. target_if_spectral_unregister_events;
  4766. target_if_sptrl_debug_register_tx_ops(tx_ops);
  4767. }
  4768. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  4769. void
  4770. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  4771. uint16_t cw_int, uint32_t dcs_enabled)
  4772. {
  4773. struct spectral_samp_msg *msg = NULL;
  4774. struct target_if_spectral_ops *p_sops = NULL;
  4775. struct target_if_spectral *spectral = NULL;
  4776. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  4777. if (!spectral) {
  4778. spectral_err("SPECTRAL : Module doesn't exist");
  4779. return;
  4780. }
  4781. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  4782. if (!p_sops) {
  4783. spectral_err("p_sops is null");
  4784. return;
  4785. }
  4786. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  4787. spectral->pdev_obj,
  4788. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  4789. SPECTRAL_MSG_BUF_NEW);
  4790. if (msg) {
  4791. msg->int_type = cw_int ?
  4792. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  4793. msg->dcs_enabled = dcs_enabled;
  4794. msg->signature = SPECTRAL_SIGNATURE;
  4795. p_sops->get_mac_address(spectral, msg->macaddr);
  4796. if (spectral->send_phy_data
  4797. (pdev,
  4798. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  4799. spectral->spectral_sent_msg++;
  4800. }
  4801. }
  4802. qdf_export_symbol(target_if_spectral_send_intf_found_msg);