target_if_spectral.c 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310
  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. static void target_if_spectral_get_firstvdev_pdev(struct wlan_objmgr_pdev *pdev,
  43. void *obj, void *arg)
  44. {
  45. struct wlan_objmgr_vdev *vdev = obj;
  46. struct wlan_objmgr_vdev **first_vdev = arg;
  47. if (!(*first_vdev))
  48. *first_vdev = vdev;
  49. }
  50. struct wlan_objmgr_vdev *
  51. target_if_spectral_get_vdev(struct target_if_spectral *spectral)
  52. {
  53. struct wlan_objmgr_pdev *pdev = NULL;
  54. struct wlan_objmgr_vdev *first_vdev = NULL;
  55. qdf_assert_always(spectral);
  56. pdev = spectral->pdev_obj;
  57. qdf_assert_always(pdev);
  58. if (wlan_objmgr_pdev_try_get_ref(pdev, WLAN_SPECTRAL_ID) !=
  59. QDF_STATUS_SUCCESS) {
  60. spectral_err("Unable to get pdev reference.");
  61. return NULL;
  62. }
  63. wlan_objmgr_pdev_iterate_obj_list(pdev, WLAN_VDEV_OP,
  64. target_if_spectral_get_firstvdev_pdev,
  65. &first_vdev, 0, WLAN_SPECTRAL_ID);
  66. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  67. if (!first_vdev)
  68. return NULL;
  69. if (wlan_objmgr_vdev_try_get_ref(first_vdev, WLAN_SPECTRAL_ID) !=
  70. QDF_STATUS_SUCCESS)
  71. first_vdev = NULL;
  72. return first_vdev;
  73. }
  74. /**
  75. * target_if_send_vdev_spectral_configure_cmd() - Send WMI command to configure
  76. * spectral parameters
  77. * @spectral: Pointer to Spectral target_if internal private data
  78. * @smode: Spectral scan mode
  79. * @param: Pointer to spectral_config giving the Spectral configuration
  80. *
  81. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  82. */
  83. static int
  84. target_if_send_vdev_spectral_configure_cmd(struct target_if_spectral *spectral,
  85. enum spectral_scan_mode smode,
  86. struct spectral_config *param)
  87. {
  88. struct vdev_spectral_configure_params sparam;
  89. struct wlan_objmgr_pdev *pdev = NULL;
  90. struct wlan_objmgr_vdev *vdev = NULL;
  91. qdf_assert_always(spectral && param);
  92. pdev = spectral->pdev_obj;
  93. qdf_assert_always(pdev);
  94. vdev = target_if_spectral_get_vdev(spectral);
  95. if (!vdev)
  96. return QDF_STATUS_E_NOENT;
  97. qdf_mem_zero(&sparam, sizeof(sparam));
  98. sparam.vdev_id = wlan_vdev_get_id(vdev);
  99. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  100. sparam.count = param->ss_count;
  101. sparam.period = param->ss_period;
  102. sparam.spectral_pri = param->ss_spectral_pri;
  103. sparam.fft_size = param->ss_fft_size;
  104. sparam.gc_enable = param->ss_gc_ena;
  105. sparam.restart_enable = param->ss_restart_ena;
  106. sparam.noise_floor_ref = param->ss_noise_floor_ref;
  107. sparam.init_delay = param->ss_init_delay;
  108. sparam.nb_tone_thr = param->ss_nb_tone_thr;
  109. sparam.str_bin_thr = param->ss_str_bin_thr;
  110. sparam.wb_rpt_mode = param->ss_wb_rpt_mode;
  111. sparam.rssi_rpt_mode = param->ss_rssi_rpt_mode;
  112. sparam.rssi_thr = param->ss_rssi_thr;
  113. sparam.pwr_format = param->ss_pwr_format;
  114. sparam.rpt_mode = param->ss_rpt_mode;
  115. sparam.bin_scale = param->ss_bin_scale;
  116. sparam.dbm_adj = param->ss_dbm_adj;
  117. sparam.chn_mask = param->ss_chn_mask;
  118. sparam.mode = smode;
  119. sparam.center_freq = param->ss_frequency;
  120. return spectral->param_wmi_cmd_ops.wmi_spectral_configure_cmd_send(
  121. GET_WMI_HDL_FROM_PDEV(pdev), &sparam);
  122. }
  123. /**
  124. * target_if_send_vdev_spectral_enable_cmd() - Send WMI command to
  125. * enable/disable Spectral
  126. * @spectral: Pointer to Spectral target_if internal private data
  127. * @smode: Spectral scan mode
  128. * @is_spectral_active_valid: Flag to indicate if spectral activate (trigger) is
  129. * valid
  130. * @is_spectral_active: Value of spectral activate
  131. * @is_spectral_enabled_valid: Flag to indicate if spectral enable is valid
  132. * @is_spectral_enabled: Value of spectral enable
  133. *
  134. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  135. */
  136. static int
  137. target_if_send_vdev_spectral_enable_cmd(struct target_if_spectral *spectral,
  138. enum spectral_scan_mode smode,
  139. uint8_t is_spectral_active_valid,
  140. uint8_t is_spectral_active,
  141. uint8_t is_spectral_enabled_valid,
  142. uint8_t is_spectral_enabled)
  143. {
  144. struct vdev_spectral_enable_params param;
  145. struct wlan_objmgr_pdev *pdev = NULL;
  146. struct wlan_objmgr_vdev *vdev = NULL;
  147. qdf_assert_always(spectral);
  148. pdev = spectral->pdev_obj;
  149. qdf_assert_always(pdev);
  150. vdev = target_if_spectral_get_vdev(spectral);
  151. if (!vdev)
  152. return QDF_STATUS_E_NOENT;
  153. qdf_mem_zero(&param, sizeof(param));
  154. param.vdev_id = wlan_vdev_get_id(vdev);
  155. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  156. param.active_valid = is_spectral_active_valid;
  157. param.enabled_valid = is_spectral_enabled_valid;
  158. param.active = is_spectral_active;
  159. param.enabled = is_spectral_enabled;
  160. param.mode = smode;
  161. return spectral->param_wmi_cmd_ops.wmi_spectral_enable_cmd_send(
  162. GET_WMI_HDL_FROM_PDEV(pdev), &param);
  163. }
  164. /**
  165. * target_if_spectral_info_init_defaults() - Helper function to load defaults
  166. * for Spectral information (parameters and state) into cache.
  167. * @spectral: Pointer to Spectral target_if internal private data
  168. * @smode: Spectral scan mode
  169. *
  170. * It is assumed that the caller has obtained the requisite lock if applicable.
  171. * Note that this is currently treated as a temporary function. Ideally, we
  172. * would like to get defaults from the firmware.
  173. *
  174. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  175. */
  176. static QDF_STATUS
  177. target_if_spectral_info_init_defaults(struct target_if_spectral *spectral,
  178. enum spectral_scan_mode smode)
  179. {
  180. struct target_if_spectral_param_state_info *info;
  181. struct wlan_objmgr_vdev *vdev = NULL;
  182. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  183. spectral_err("Invalid Spectral mode %u", smode);
  184. return QDF_STATUS_E_FAILURE;
  185. }
  186. info = &spectral->param_info[smode];
  187. /* State */
  188. info->osps_cache.osc_spectral_active = SPECTRAL_SCAN_ACTIVE_DEFAULT;
  189. info->osps_cache.osc_spectral_enabled = SPECTRAL_SCAN_ENABLE_DEFAULT;
  190. /* Parameters */
  191. info->osps_cache.osc_params.ss_count = SPECTRAL_SCAN_COUNT_DEFAULT;
  192. if (spectral->spectral_gen == SPECTRAL_GEN3)
  193. info->osps_cache.osc_params.ss_period =
  194. SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT;
  195. else
  196. info->osps_cache.osc_params.ss_period =
  197. SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT;
  198. info->osps_cache.osc_params.ss_spectral_pri =
  199. SPECTRAL_SCAN_PRIORITY_DEFAULT;
  200. info->osps_cache.osc_params.ss_fft_size =
  201. SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  202. info->osps_cache.osc_params.ss_gc_ena = SPECTRAL_SCAN_GC_ENA_DEFAULT;
  203. info->osps_cache.osc_params.ss_restart_ena =
  204. SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  205. info->osps_cache.osc_params.ss_noise_floor_ref =
  206. SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  207. info->osps_cache.osc_params.ss_init_delay =
  208. SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  209. info->osps_cache.osc_params.ss_nb_tone_thr =
  210. SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  211. info->osps_cache.osc_params.ss_str_bin_thr =
  212. SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  213. info->osps_cache.osc_params.ss_wb_rpt_mode =
  214. SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  215. info->osps_cache.osc_params.ss_rssi_rpt_mode =
  216. SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  217. info->osps_cache.osc_params.ss_rssi_thr =
  218. SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  219. info->osps_cache.osc_params.ss_pwr_format =
  220. SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  221. info->osps_cache.osc_params.ss_rpt_mode =
  222. SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  223. info->osps_cache.osc_params.ss_bin_scale =
  224. SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  225. info->osps_cache.osc_params.ss_dbm_adj = SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  226. vdev = target_if_spectral_get_vdev(spectral);
  227. if (!vdev)
  228. return QDF_STATUS_E_NOENT;
  229. info->osps_cache.osc_params.ss_chn_mask =
  230. wlan_vdev_mlme_get_rxchainmask(vdev);
  231. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  232. info->osps_cache.osc_params.ss_short_report =
  233. SPECTRAL_SCAN_SHORT_REPORT_DEFAULT;
  234. info->osps_cache.osc_params.ss_fft_period =
  235. SPECTRAL_SCAN_FFT_PERIOD_DEFAULT;
  236. info->osps_cache.osc_params.ss_frequency =
  237. SPECTRAL_SCAN_FREQUENCY_DEFAULT;
  238. /* The cache is now valid */
  239. info->osps_cache.osc_is_valid = 1;
  240. return QDF_STATUS_SUCCESS;
  241. }
  242. /**
  243. * target_if_log_read_spectral_active() - Helper function to log whether
  244. * spectral is active after reading cache
  245. * @function_name: Function name
  246. * @output: whether spectral is active or not
  247. *
  248. * Helper function to log whether spectral is active after reading cache
  249. *
  250. * Return: none
  251. */
  252. static void
  253. target_if_log_read_spectral_active(
  254. const char *function_name,
  255. unsigned char output)
  256. {
  257. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE. Returning val=%u",
  258. function_name, output);
  259. }
  260. /**
  261. * target_if_log_read_spectral_enabled() - Helper function to log whether
  262. * spectral is enabled after reading cache
  263. * @function_name: Function name
  264. * @output: whether spectral is enabled or not
  265. *
  266. * Helper function to log whether spectral is enabled after reading cache
  267. *
  268. * Return: none
  269. */
  270. static void
  271. target_if_log_read_spectral_enabled(
  272. const char *function_name,
  273. unsigned char output)
  274. {
  275. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED. Returning val=%u",
  276. function_name, output);
  277. }
  278. /**
  279. * target_if_log_read_spectral_enabled() - Helper function to log spectral
  280. * parameters after reading cache
  281. * @function_name: Function name
  282. * @pparam: Spectral parameters
  283. *
  284. * Helper function to log spectral parameters after reading cache
  285. *
  286. * Return: none
  287. */
  288. static void
  289. target_if_log_read_spectral_params(
  290. const char *function_name,
  291. struct spectral_config *pparam)
  292. {
  293. 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_frequency=%u\n",
  294. function_name,
  295. pparam->ss_count,
  296. pparam->ss_period,
  297. pparam->ss_spectral_pri,
  298. pparam->ss_fft_size,
  299. pparam->ss_gc_ena,
  300. pparam->ss_restart_ena,
  301. (int8_t)pparam->ss_noise_floor_ref,
  302. pparam->ss_init_delay,
  303. pparam->ss_nb_tone_thr,
  304. pparam->ss_str_bin_thr,
  305. pparam->ss_wb_rpt_mode,
  306. pparam->ss_rssi_rpt_mode,
  307. (int8_t)pparam->ss_rssi_thr,
  308. pparam->ss_pwr_format,
  309. pparam->ss_rpt_mode,
  310. pparam->ss_bin_scale,
  311. pparam->ss_dbm_adj,
  312. pparam->ss_chn_mask,
  313. pparam->ss_frequency);
  314. }
  315. /**
  316. * target_if_log_read_spectral_active_catch_validate() - Helper function to
  317. * log whether spectral is active after intializing the cache
  318. * @function_name: Function name
  319. * @output: whether spectral is active or not
  320. *
  321. * Helper function to log whether spectral is active after intializing cache
  322. *
  323. * Return: none
  324. */
  325. static void
  326. target_if_log_read_spectral_active_catch_validate(
  327. const char *function_name,
  328. unsigned char output)
  329. {
  330. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE on initial cache validation\nReturning val=%u",
  331. function_name, output);
  332. }
  333. /**
  334. * target_if_log_read_spectral_enabled_catch_validate() - Helper function to
  335. * log whether spectral is enabled after intializing the cache
  336. * @function_name: Function name
  337. * @output: whether spectral is enabled or not
  338. *
  339. * Helper function to log whether spectral is enabled after intializing cache
  340. *
  341. * Return: none
  342. */
  343. static void
  344. target_if_log_read_spectral_enabled_catch_validate(
  345. const char *function_name,
  346. unsigned char output)
  347. {
  348. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED on initial cache validation\nReturning val=%u\n",
  349. function_name, output);
  350. }
  351. /**
  352. * target_if_log_read_spectral_params_catch_validate() - Helper function to
  353. * log spectral parameters after intializing the cache
  354. * @function_name: Function name
  355. * @pparam: Spectral parameters
  356. *
  357. * Helper function to log spectral parameters after intializing the cache
  358. *
  359. * Return: none
  360. */
  361. static void
  362. target_if_log_read_spectral_params_catch_validate(
  363. const char *function_name,
  364. struct spectral_config *pparam)
  365. {
  366. 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",
  367. function_name,
  368. pparam->ss_count,
  369. pparam->ss_period,
  370. pparam->ss_spectral_pri,
  371. pparam->ss_fft_size,
  372. pparam->ss_gc_ena,
  373. pparam->ss_restart_ena,
  374. (int8_t)pparam->ss_noise_floor_ref,
  375. pparam->ss_init_delay,
  376. pparam->ss_nb_tone_thr,
  377. pparam->ss_str_bin_thr,
  378. pparam->ss_wb_rpt_mode,
  379. pparam->ss_rssi_rpt_mode,
  380. (int8_t)pparam->ss_rssi_thr,
  381. pparam->ss_pwr_format,
  382. pparam->ss_rpt_mode,
  383. pparam->ss_bin_scale,
  384. pparam->ss_dbm_adj, pparam->ss_chn_mask);
  385. }
  386. /**
  387. * target_if_spectral_info_read() - Read spectral information from the cache.
  388. * @spectral: Pointer to Spectral target_if internal private data
  389. * @smode: Spectral scan mode
  390. * @specifier: target_if_spectral_info enumeration specifying which
  391. * information is required
  392. * @output: Void output pointer into which the information will be read
  393. * @output_len: size of object pointed to by output pointer
  394. *
  395. * Read spectral parameters or the desired state information from the cache.
  396. *
  397. * Return: 0 on success, negative error code on failure
  398. */
  399. static int
  400. target_if_spectral_info_read(
  401. struct target_if_spectral *spectral,
  402. enum spectral_scan_mode smode,
  403. enum target_if_spectral_info specifier,
  404. void *output, int output_len)
  405. {
  406. /*
  407. * Note: This function is designed to be able to accommodate
  408. * WMI reads for defaults, non-cacheable information, etc
  409. * if required.
  410. */
  411. struct target_if_spectral_param_state_info *info;
  412. int is_cacheable = 0;
  413. int init_def_retval = 0;
  414. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  415. spectral_err("Invalid Spectral mode %u", smode);
  416. return -EINVAL;
  417. }
  418. info = &spectral->param_info[smode];
  419. if (!output)
  420. return -EINVAL;
  421. switch (specifier) {
  422. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  423. if (output_len != sizeof(info->osps_cache.osc_spectral_active))
  424. return -EINVAL;
  425. is_cacheable = 1;
  426. break;
  427. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  428. if (output_len != sizeof(info->osps_cache.osc_spectral_enabled))
  429. return -EINVAL;
  430. is_cacheable = 1;
  431. break;
  432. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  433. if (output_len != sizeof(info->osps_cache.osc_params))
  434. return -EINVAL;
  435. is_cacheable = 1;
  436. break;
  437. default:
  438. spectral_err("Unknown target_if_spectral_info specifier");
  439. return -EINVAL;
  440. }
  441. qdf_spin_lock(&info->osps_lock);
  442. if (is_cacheable) {
  443. if (info->osps_cache.osc_is_valid) {
  444. switch (specifier) {
  445. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  446. qdf_mem_copy(
  447. output,
  448. &info->osps_cache.osc_spectral_active,
  449. sizeof(info->osps_cache.osc_spectral_active));
  450. target_if_log_read_spectral_active(
  451. __func__,
  452. *((unsigned char *)output));
  453. break;
  454. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  455. qdf_mem_copy(
  456. output,
  457. &info->osps_cache.osc_spectral_enabled,
  458. sizeof(
  459. info->osps_cache.osc_spectral_enabled));
  460. target_if_log_read_spectral_enabled(
  461. __func__,
  462. *((unsigned char *)output));
  463. break;
  464. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  465. qdf_mem_copy(
  466. output,
  467. &info->osps_cache.osc_params,
  468. sizeof(info->osps_cache.osc_params));
  469. target_if_log_read_spectral_params(
  470. __func__,
  471. (struct spectral_config *)output);
  472. break;
  473. default:
  474. /* We can't reach this point */
  475. break;
  476. }
  477. qdf_spin_unlock(&info->osps_lock);
  478. return 0;
  479. }
  480. }
  481. /* Cache is invalid */
  482. /*
  483. * If WMI Reads are implemented to fetch defaults/non-cacheable info,
  484. * then the below implementation will change
  485. */
  486. init_def_retval =
  487. target_if_spectral_info_init_defaults(spectral, smode);
  488. if (init_def_retval != QDF_STATUS_SUCCESS) {
  489. qdf_spin_unlock(&info->osps_lock);
  490. if (init_def_retval == QDF_STATUS_E_NOENT)
  491. return -ENOENT;
  492. else
  493. return -EINVAL;
  494. }
  495. /* target_if_spectral_info_init_defaults() has set cache to valid */
  496. switch (specifier) {
  497. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  498. qdf_mem_copy(output,
  499. &info->osps_cache.osc_spectral_active,
  500. sizeof(info->osps_cache.osc_spectral_active));
  501. target_if_log_read_spectral_active_catch_validate(
  502. __func__,
  503. *((unsigned char *)output));
  504. break;
  505. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  506. qdf_mem_copy(output,
  507. &info->osps_cache.osc_spectral_enabled,
  508. sizeof(info->osps_cache.osc_spectral_enabled));
  509. target_if_log_read_spectral_enabled_catch_validate(
  510. __func__,
  511. *((unsigned char *)output));
  512. break;
  513. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  514. qdf_mem_copy(output,
  515. &info->osps_cache.osc_params,
  516. sizeof(info->osps_cache.osc_params));
  517. target_if_log_read_spectral_params_catch_validate(
  518. __func__,
  519. (struct spectral_config *)output);
  520. break;
  521. default:
  522. /* We can't reach this point */
  523. break;
  524. }
  525. qdf_spin_unlock(&info->osps_lock);
  526. return 0;
  527. }
  528. /**
  529. * target_if_log_write_spectral_active() - Helper function to log inputs and
  530. * return value of call to configure the Spectral 'active' configuration,
  531. * TARGET_IF_SPECTRAL_INFO_ACTIVE into firmware
  532. * @function_name: Function name in which this is called
  533. * @pval: whether spectral is active or not
  534. * @ret: return value of the firmware write function
  535. *
  536. * Return: none
  537. */
  538. static void
  539. target_if_log_write_spectral_active(
  540. const char *function_name,
  541. uint8_t pval,
  542. int ret)
  543. {
  544. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE with val=%u status=%d",
  545. function_name, pval, ret);
  546. }
  547. /**
  548. * target_if_log_write_spectral_enabled() - Helper function to log inputs and
  549. * return value of call to configure the Spectral 'enabled' configuration,
  550. * TARGET_IF_SPECTRAL_INFO_ENABLED into firmware
  551. * @function_name: Function name in which this is called
  552. * @pval: whether spectral is enabled or not
  553. * @ret: return value of the firmware write function
  554. *
  555. * Return: none
  556. */
  557. static void
  558. target_if_log_write_spectral_enabled(
  559. const char *function_name,
  560. uint8_t pval,
  561. int ret)
  562. {
  563. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED with val=%u status=%d",
  564. function_name, pval, ret);
  565. }
  566. /**
  567. * target_if_log_write_spectral_params() - Helper function to log inputs and
  568. * return value of call to configure Spectral parameters,
  569. * TARGET_IF_SPECTRAL_INFO_PARAMS into firmware
  570. * @param: Spectral parameters
  571. * @function_name: Function name in which this is called
  572. * @ret: return value of the firmware write function
  573. *
  574. * Return: none
  575. */
  576. static void
  577. target_if_log_write_spectral_params(
  578. struct spectral_config *param,
  579. const char *function_name,
  580. int ret)
  581. {
  582. 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_frequency=%u\nstatus = %d",
  583. function_name,
  584. param->ss_count,
  585. param->ss_period,
  586. param->ss_spectral_pri,
  587. param->ss_fft_size,
  588. param->ss_gc_ena,
  589. param->ss_restart_ena,
  590. (int8_t)param->ss_noise_floor_ref,
  591. param->ss_init_delay,
  592. param->ss_nb_tone_thr,
  593. param->ss_str_bin_thr,
  594. param->ss_wb_rpt_mode,
  595. param->ss_rssi_rpt_mode,
  596. (int8_t)param->ss_rssi_thr,
  597. param->ss_pwr_format,
  598. param->ss_rpt_mode,
  599. param->ss_bin_scale,
  600. param->ss_dbm_adj,
  601. param->ss_chn_mask,
  602. param->ss_frequency,
  603. ret);
  604. }
  605. /**
  606. * target_if_spectral_info_write() - Write Spectral information to the
  607. * firmware, and update cache
  608. * @spectral: Pointer to Spectral target_if internal private data
  609. * @smode: Spectral scan mode
  610. * @specifier: target_if_spectral_info enumeration specifying which
  611. * information is involved
  612. * @input: void input pointer containing the information to be written
  613. * @input_len: size of object pointed to by input pointer
  614. *
  615. * Write Spectral parameters or the desired state information to
  616. * the firmware, and update cache
  617. *
  618. * Return: 0 on success, negative error code on failure
  619. */
  620. static int
  621. target_if_spectral_info_write(
  622. struct target_if_spectral *spectral,
  623. enum spectral_scan_mode smode,
  624. enum target_if_spectral_info specifier,
  625. void *input, int input_len)
  626. {
  627. struct target_if_spectral_param_state_info *info;
  628. int ret;
  629. uint8_t *pval = NULL;
  630. struct spectral_config *param = NULL;
  631. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  632. spectral_err("Invalid Spectral mode %u", smode);
  633. return -EINVAL;
  634. }
  635. info = &spectral->param_info[smode];
  636. if (!input)
  637. return -EINVAL;
  638. switch (specifier) {
  639. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  640. if (input_len != sizeof(info->osps_cache.osc_spectral_active))
  641. return -EINVAL;
  642. pval = (uint8_t *)input;
  643. qdf_spin_lock(&info->osps_lock);
  644. ret = target_if_send_vdev_spectral_enable_cmd(spectral, smode,
  645. 1, *pval, 0, 0);
  646. target_if_log_write_spectral_active(
  647. __func__,
  648. *pval,
  649. ret);
  650. if (ret < 0) {
  651. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  652. ret);
  653. qdf_spin_unlock(&info->osps_lock);
  654. return ret;
  655. }
  656. info->osps_cache.osc_spectral_active = *pval;
  657. /* The cache is now valid */
  658. info->osps_cache.osc_is_valid = 1;
  659. qdf_spin_unlock(&info->osps_lock);
  660. break;
  661. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  662. if (input_len != sizeof(info->osps_cache.osc_spectral_enabled))
  663. return -EINVAL;
  664. pval = (uint8_t *)input;
  665. qdf_spin_lock(&info->osps_lock);
  666. ret = target_if_send_vdev_spectral_enable_cmd(spectral, smode,
  667. 0, 0, 1, *pval);
  668. target_if_log_write_spectral_enabled(
  669. __func__,
  670. *pval,
  671. ret);
  672. if (ret < 0) {
  673. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  674. ret);
  675. qdf_spin_unlock(&info->osps_lock);
  676. return ret;
  677. }
  678. info->osps_cache.osc_spectral_enabled = *pval;
  679. /* The cache is now valid */
  680. info->osps_cache.osc_is_valid = 1;
  681. qdf_spin_unlock(&info->osps_lock);
  682. break;
  683. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  684. if (input_len != sizeof(info->osps_cache.osc_params))
  685. return -EINVAL;
  686. param = (struct spectral_config *)input;
  687. qdf_spin_lock(&info->osps_lock);
  688. ret = target_if_send_vdev_spectral_configure_cmd(spectral,
  689. smode, param);
  690. target_if_log_write_spectral_params(
  691. param,
  692. __func__,
  693. ret);
  694. if (ret < 0) {
  695. spectral_err("target_if_send_vdev_spectral_configure_cmd failed with error=%d",
  696. ret);
  697. qdf_spin_unlock(&info->osps_lock);
  698. return ret;
  699. }
  700. qdf_mem_copy(&info->osps_cache.osc_params,
  701. param, sizeof(info->osps_cache.osc_params));
  702. /* The cache is now valid */
  703. info->osps_cache.osc_is_valid = 1;
  704. qdf_spin_unlock(&info->osps_lock);
  705. break;
  706. default:
  707. spectral_err("Unknown target_if_spectral_info specifier");
  708. return -EINVAL;
  709. }
  710. return 0;
  711. }
  712. /**
  713. * target_if_spectral_get_tsf64() - Function to get the TSF value
  714. * @arg: Pointer to handle for Spectral target_if internal private data
  715. *
  716. * Get the last TSF received in WMI buffer
  717. *
  718. * Return: TSF value
  719. */
  720. static uint64_t
  721. target_if_spectral_get_tsf64(void *arg)
  722. {
  723. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  724. return spectral->tsf64;
  725. }
  726. /**
  727. * target_if_spectral_get_capability() - Function to get whether a
  728. * given Spectral hardware capability is available
  729. * @arg: Pointer to handle for Spectral target_if internal private data
  730. * @type: Spectral hardware capability type
  731. *
  732. * Get whether a given Spectral hardware capability is available
  733. *
  734. * Return: True if the capability is available, false if the capability is not
  735. * available
  736. */
  737. uint32_t
  738. target_if_spectral_get_capability(void *arg, enum spectral_capability_type type)
  739. {
  740. int status = STATUS_FAIL;
  741. switch (type) {
  742. case SPECTRAL_CAP_PHYDIAG:
  743. case SPECTRAL_CAP_RADAR:
  744. case SPECTRAL_CAP_SPECTRAL_SCAN:
  745. case SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN:
  746. status = STATUS_PASS;
  747. break;
  748. default:
  749. status = STATUS_FAIL;
  750. }
  751. return status;
  752. }
  753. /**
  754. * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
  755. * @arg: Pointer to handle for Spectral target_if internal private data
  756. * @rxfilter: Rx filter to be used
  757. *
  758. * Note: This is only a placeholder function. It is not currently required since
  759. * FW should be taking care of setting the required filters.
  760. *
  761. * Return: 0
  762. */
  763. uint32_t
  764. target_if_spectral_set_rxfilter(void *arg, int rxfilter)
  765. {
  766. /*
  767. * Will not be required since enabling of spectral in firmware
  768. * will take care of this
  769. */
  770. return 0;
  771. }
  772. /**
  773. * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
  774. * @arg: Pointer to handle for Spectral target_if internal private data
  775. *
  776. * Note: This is only a placeholder function. It is not currently required since
  777. * FW should be taking care of setting the required filters.
  778. *
  779. * Return: 0
  780. */
  781. uint32_t
  782. target_if_spectral_get_rxfilter(void *arg)
  783. {
  784. /*
  785. * Will not be required since enabling of spectral in firmware
  786. * will take care of this
  787. */
  788. return 0;
  789. }
  790. /**
  791. * target_if_sops_is_spectral_active() - Get whether Spectral is active
  792. * @arg: Pointer to handle for Spectral target_if internal private data
  793. * @smode: Spectral scan mode
  794. *
  795. * Function to check whether Spectral is active
  796. *
  797. * Return: True if Spectral is active, false if Spectral is not active
  798. */
  799. uint32_t
  800. target_if_sops_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  801. {
  802. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  803. uint8_t val = 0;
  804. int ret;
  805. ret = target_if_spectral_info_read(
  806. spectral,
  807. smode,
  808. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  809. &val, sizeof(val));
  810. if (ret != 0) {
  811. /*
  812. * Could not determine if Spectral is active.
  813. * Return false as a safe value.
  814. * XXX: Consider changing the function prototype
  815. * to be able to indicate failure to fetch value.
  816. */
  817. return 0;
  818. }
  819. return val;
  820. }
  821. /**
  822. * target_if_sops_is_spectral_enabled() - Get whether Spectral is enabled
  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 enabled
  827. *
  828. * Return: True if Spectral is enabled, false if Spectral is not enabled
  829. */
  830. uint32_t
  831. target_if_sops_is_spectral_enabled(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_ENABLED,
  840. &val, sizeof(val));
  841. if (ret != 0) {
  842. /*
  843. * Could not determine if Spectral is enabled.
  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_start_spectral_scan() - Start Spectral scan
  854. * @arg: Pointer to handle for Spectral target_if internal private data
  855. * @smode: Spectral scan mode
  856. * @err: Spectral error code
  857. *
  858. * Function to start spectral scan
  859. *
  860. * Return: 0 on success else failure
  861. */
  862. uint32_t
  863. target_if_sops_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  864. enum spectral_cp_error_code *err)
  865. {
  866. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  867. uint8_t val = 1;
  868. uint8_t enabled = 0;
  869. int ret;
  870. ret = target_if_spectral_info_read(
  871. spectral,
  872. smode,
  873. TARGET_IF_SPECTRAL_INFO_ENABLED,
  874. &enabled, sizeof(enabled));
  875. if (ret != 0) {
  876. /*
  877. * Could not determine if Spectral is enabled. Assume we need
  878. * to enable it
  879. */
  880. enabled = 0;
  881. }
  882. if (!enabled) {
  883. ret = target_if_spectral_info_write(
  884. spectral,
  885. smode,
  886. TARGET_IF_SPECTRAL_INFO_ENABLED,
  887. &val, sizeof(val));
  888. if (ret != 0)
  889. return ret;
  890. }
  891. ret = target_if_spectral_info_write(
  892. spectral,
  893. smode,
  894. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  895. &val, sizeof(val));
  896. if (ret != 0)
  897. return ret;
  898. return 0;
  899. }
  900. /**
  901. * target_if_sops_stop_spectral_scan() - Stop Spectral scan
  902. * @arg: Pointer to handle for Spectral target_if internal private data
  903. * @smode: Spectral scan mode
  904. *
  905. * Function to stop spectral scan
  906. *
  907. * Return: 0 on success else failure
  908. */
  909. uint32_t
  910. target_if_sops_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  911. {
  912. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  913. uint8_t val = 0;
  914. int tempret, ret = 0;
  915. uint8_t enabled = 0;
  916. tempret = target_if_spectral_info_read(
  917. spectral,
  918. smode,
  919. TARGET_IF_SPECTRAL_INFO_ENABLED,
  920. &enabled, sizeof(enabled));
  921. if (tempret)
  922. /*
  923. * Could not determine if Spectral is enabled. Assume scan is
  924. * not in progress
  925. */
  926. enabled = 0;
  927. /* if scan is not enabled, no need to send stop to FW */
  928. if (!enabled)
  929. return -EPERM;
  930. tempret = target_if_spectral_info_write(
  931. spectral,
  932. smode,
  933. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  934. &val, sizeof(val));
  935. if (tempret != 0)
  936. ret = tempret;
  937. tempret = target_if_spectral_info_write(
  938. spectral,
  939. smode,
  940. TARGET_IF_SPECTRAL_INFO_ENABLED,
  941. &val, sizeof(val));
  942. if (tempret != 0)
  943. ret = tempret;
  944. return ret;
  945. }
  946. /**
  947. * target_if_spectral_get_extension_channel() - Get the Extension channel
  948. * @arg: Pointer to handle for Spectral target_if internal private data
  949. *
  950. * Function to get the current Extension channel (in MHz)
  951. *
  952. * Return: Current Extension channel (in MHz) on success, 0 on failure or if
  953. * extension channel is not present.
  954. */
  955. uint32_t
  956. target_if_spectral_get_extension_channel(void *arg)
  957. {
  958. /*
  959. * XXX: Once we expand to use cases where Spectral could be activated
  960. * without a channel being set to VDEV, we need to consider returning a
  961. * negative value in case of failure and having all callers handle this.
  962. */
  963. struct target_if_spectral *spectral = NULL;
  964. struct wlan_objmgr_vdev *vdev = NULL;
  965. uint16_t sec20chan_freq = 0;
  966. qdf_assert_always(arg);
  967. spectral = (struct target_if_spectral *)arg;
  968. vdev = target_if_spectral_get_vdev(spectral);
  969. if (!vdev)
  970. return 0;
  971. if (target_if_vdev_get_sec20chan_freq_mhz(vdev, &sec20chan_freq) < 0) {
  972. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  973. return 0;
  974. }
  975. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  976. return sec20chan_freq;
  977. }
  978. /**
  979. * target_if_spectral_get_current_channel() - Get the current channel
  980. * @arg: Pointer to handle for Spectral target_if internal private data
  981. *
  982. * Function to get the current channel (in MHz)
  983. *
  984. * Return: Current channel (in MHz) on success, 0 on failure
  985. */
  986. uint32_t
  987. target_if_spectral_get_current_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. int16_t chan_freq = 0;
  996. struct wlan_objmgr_vdev *vdev = NULL;
  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. chan_freq = target_if_vdev_get_chan_freq(vdev);
  1003. if (chan_freq < 0) {
  1004. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1005. return 0;
  1006. }
  1007. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1008. return chan_freq;
  1009. }
  1010. /**
  1011. * target_if_spectral_reset_hw() - Reset the hardware
  1012. * @arg: Pointer to handle for Spectral target_if internal private data
  1013. *
  1014. * This is only a placeholder since it is not currently required in the offload
  1015. * case.
  1016. *
  1017. * Return: 0
  1018. */
  1019. uint32_t
  1020. target_if_spectral_reset_hw(void *arg)
  1021. {
  1022. not_yet_implemented();
  1023. return 0;
  1024. }
  1025. /**
  1026. * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
  1027. * Noisefloor history buffer
  1028. * @arg: Pointer to handle for Spectral target_if internal private data
  1029. * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
  1030. *
  1031. * This is only a placeholder since it is not currently required in the offload
  1032. * case.
  1033. *
  1034. * Return: 0
  1035. */
  1036. uint32_t
  1037. target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1038. {
  1039. not_yet_implemented();
  1040. return 0;
  1041. }
  1042. /**
  1043. * target_if_spectral_get_ext_noisefloor() - Get the extension channel
  1044. * noisefloor
  1045. * @arg: Pointer to handle for Spectral target_if internal private data
  1046. *
  1047. * This is only a placeholder since it is not currently required in the offload
  1048. * case.
  1049. *
  1050. * Return: 0
  1051. */
  1052. int8_t
  1053. target_if_spectral_get_ext_noisefloor(void *arg)
  1054. {
  1055. not_yet_implemented();
  1056. return 0;
  1057. }
  1058. /**
  1059. * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
  1060. * @arg: Pointer to handle for Spectral target_if internal private data
  1061. *
  1062. * This is only a placeholder since it is not currently required in the offload
  1063. * case.
  1064. *
  1065. * Return: 0
  1066. */
  1067. int8_t
  1068. target_if_spectral_get_ctl_noisefloor(void *arg)
  1069. {
  1070. not_yet_implemented();
  1071. return 0;
  1072. }
  1073. /**
  1074. * target_if_spectral_sops_configure_params() - Configure user supplied Spectral
  1075. * parameters
  1076. * @arg: Pointer to handle for Spectral target_if internal private data
  1077. * @params: Spectral parameters
  1078. * @smode: Spectral scan mode
  1079. *
  1080. * Function to configure spectral parameters
  1081. *
  1082. * Return: 0 on success else failure
  1083. */
  1084. uint32_t
  1085. target_if_spectral_sops_configure_params(
  1086. void *arg, struct spectral_config *params,
  1087. enum spectral_scan_mode smode)
  1088. {
  1089. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1090. return target_if_spectral_info_write(
  1091. spectral,
  1092. smode,
  1093. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1094. params, sizeof(*params));
  1095. }
  1096. /**
  1097. * target_if_spectral_sops_get_params() - Get user configured Spectral
  1098. * parameters
  1099. * @arg: Pointer to handle for Spectral target_if internal private data
  1100. * @params: Pointer to buffer into which Spectral parameters should be copied
  1101. * @smode: Spectral scan mode
  1102. *
  1103. * Function to get the configured spectral parameters
  1104. *
  1105. * Return: 0 on success else failure
  1106. */
  1107. uint32_t
  1108. target_if_spectral_sops_get_params(void *arg, struct spectral_config *params,
  1109. enum spectral_scan_mode smode)
  1110. {
  1111. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1112. return target_if_spectral_info_read(
  1113. spectral,
  1114. smode,
  1115. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1116. params, sizeof(*params));
  1117. }
  1118. /**
  1119. * target_if_spectral_get_ent_mask() - Get enterprise mask
  1120. * @arg: Pointer to handle for Spectral target_if internal private data
  1121. *
  1122. * This is only a placeholder since it is not currently required in the offload
  1123. * case.
  1124. *
  1125. * Return: 0
  1126. */
  1127. static uint32_t
  1128. target_if_spectral_get_ent_mask(void *arg)
  1129. {
  1130. not_yet_implemented();
  1131. return 0;
  1132. }
  1133. /**
  1134. * target_if_spectral_get_macaddr() - Get radio MAC address
  1135. * @arg: Pointer to handle for Spectral target_if internal private data
  1136. * @addr: Pointer to buffer into which MAC address should be copied
  1137. *
  1138. * Function to get the MAC address of the pdev
  1139. *
  1140. * Return: 0 on success, -1 on failure
  1141. */
  1142. static uint32_t
  1143. target_if_spectral_get_macaddr(void *arg, char *addr)
  1144. {
  1145. uint8_t *myaddr = NULL;
  1146. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1147. struct wlan_objmgr_pdev *pdev = NULL;
  1148. pdev = spectral->pdev_obj;
  1149. wlan_pdev_obj_lock(pdev);
  1150. myaddr = wlan_pdev_get_hw_macaddr(pdev);
  1151. wlan_pdev_obj_unlock(pdev);
  1152. qdf_mem_copy(addr, myaddr, QDF_MAC_ADDR_SIZE);
  1153. return 0;
  1154. }
  1155. /**
  1156. * target_if_init_spectral_param_properties() - Initialize Spectral parameter
  1157. * properties
  1158. * @spectral: Pointer to Spectral target_if internal private data
  1159. *
  1160. * Initialize Spectral parameter properties
  1161. *
  1162. * Return: QDF_STATUS
  1163. */
  1164. static QDF_STATUS
  1165. target_if_init_spectral_param_properties(struct target_if_spectral *spectral)
  1166. {
  1167. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1168. int param;
  1169. /* Initialize default values for properties.
  1170. * Default values are supported for all the parameters for all modes
  1171. * and allows different values for each mode for all the parameters .
  1172. */
  1173. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1174. for (param = 0; param < SPECTRAL_PARAM_MAX; param++) {
  1175. spectral->properties[smode][param].supported = true;
  1176. spectral->properties[smode][param].common_all_modes =
  1177. false;
  1178. }
  1179. }
  1180. /* Once FW advertisement is in place remove this hard coding */
  1181. smode = SPECTRAL_SCAN_MODE_NORMAL;
  1182. spectral->properties[SPECTRAL_SCAN_MODE_NORMAL]
  1183. [SPECTRAL_PARAM_FREQUENCY].supported = false;
  1184. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1185. spectral->properties[smode]
  1186. [SPECTRAL_PARAM_SPECT_PRI].common_all_modes = true;
  1187. spectral->properties[smode]
  1188. [SPECTRAL_PARAM_SCAN_PERIOD].common_all_modes = true;
  1189. spectral->properties[smode]
  1190. [SPECTRAL_PARAM_INIT_DELAY].common_all_modes = true;
  1191. }
  1192. return QDF_STATUS_SUCCESS;
  1193. }
  1194. /**
  1195. * target_if_init_spectral_capability() - Initialize Spectral capability
  1196. * @spectral: Pointer to Spectral target_if internal private data
  1197. *
  1198. * This is a workaround.
  1199. *
  1200. * Return: QDF_STATUS
  1201. */
  1202. QDF_STATUS
  1203. target_if_init_spectral_capability(struct target_if_spectral *spectral)
  1204. {
  1205. struct wlan_objmgr_psoc *psoc;
  1206. struct wlan_objmgr_pdev *pdev;
  1207. struct wlan_psoc_host_spectral_scaling_params *scaling_params;
  1208. uint8_t num_bin_scaling_params, param_idx, pdev_id;
  1209. struct target_psoc_info *tgt_psoc_info;
  1210. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  1211. struct spectral_caps *pcap = &spectral->capability;
  1212. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  1213. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  1214. struct wlan_psoc_host_chainmask_table *table;
  1215. int j;
  1216. uint32_t table_id;
  1217. pdev = spectral->pdev_obj;
  1218. psoc = wlan_pdev_get_psoc(pdev);
  1219. if (!psoc) {
  1220. spectral_err("psoc is null");
  1221. return QDF_STATUS_E_FAILURE;
  1222. }
  1223. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  1224. if (!tgt_psoc_info) {
  1225. spectral_err("target_psoc_info is null");
  1226. return QDF_STATUS_E_FAILURE;
  1227. }
  1228. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  1229. num_bin_scaling_params = ext_svc_param->num_bin_scaling_params;
  1230. scaling_params = target_psoc_get_spectral_scaling_params(tgt_psoc_info);
  1231. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  1232. /* XXX : Workaround: Set Spectral capability */
  1233. pcap = &spectral->capability;
  1234. pcap->phydiag_cap = 1;
  1235. pcap->radar_cap = 1;
  1236. pcap->spectral_cap = 1;
  1237. pcap->advncd_spectral_cap = 1;
  1238. pcap->hw_gen = spectral->spectral_gen;
  1239. if (spectral->spectral_gen >= SPECTRAL_GEN3) {
  1240. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  1241. if (!mac_phy_cap_arr) {
  1242. spectral_err("mac phy cap array is null");
  1243. return QDF_STATUS_E_FAILURE;
  1244. }
  1245. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  1246. if (!mac_phy_cap) {
  1247. spectral_err("mac phy cap is null");
  1248. return QDF_STATUS_E_FAILURE;
  1249. }
  1250. table_id = mac_phy_cap->chainmask_table_id;
  1251. table = &ext_svc_param->chainmask_table[table_id];
  1252. if (!table) {
  1253. spectral_err("chainmask table not found");
  1254. return QDF_STATUS_E_FAILURE;
  1255. }
  1256. for (j = 0; j < table->num_valid_chainmasks; j++) {
  1257. pcap->agile_spectral_cap |=
  1258. table->cap_list[j].supports_aSpectral;
  1259. pcap->agile_spectral_cap_160 |=
  1260. table->cap_list[j].supports_aSpectral_160;
  1261. }
  1262. pcap->agile_spectral_cap_80p80 = pcap->agile_spectral_cap_160;
  1263. } else {
  1264. pcap->agile_spectral_cap = false;
  1265. pcap->agile_spectral_cap_160 = false;
  1266. pcap->agile_spectral_cap_80p80 = false;
  1267. }
  1268. for (param_idx = 0; param_idx < num_bin_scaling_params; param_idx++) {
  1269. if (scaling_params[param_idx].pdev_id == pdev_id) {
  1270. pcap->is_scaling_params_populated = true;
  1271. pcap->formula_id = scaling_params[param_idx].formula_id;
  1272. pcap->low_level_offset =
  1273. scaling_params[param_idx].low_level_offset;
  1274. pcap->high_level_offset =
  1275. scaling_params[param_idx].high_level_offset;
  1276. pcap->rssi_thr = scaling_params[param_idx].rssi_thr;
  1277. pcap->default_agc_max_gain =
  1278. scaling_params[param_idx].default_agc_max_gain;
  1279. break;
  1280. }
  1281. }
  1282. return QDF_STATUS_SUCCESS;
  1283. }
  1284. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1285. /**
  1286. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1287. * internal operations with functions related to spectral simulation
  1288. * @p_sops: spectral low level ops table
  1289. *
  1290. * Initialize spectral target_if internal operations with functions
  1291. * related to spectral simulation
  1292. *
  1293. * Return: None
  1294. */
  1295. static void
  1296. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1297. {
  1298. /*
  1299. * Spectral simulation is currently intended for platform transitions
  1300. * where underlying HW support may not be available for some time.
  1301. * Hence, we do not currently provide a runtime switch to turn the
  1302. * simulation on or off.
  1303. * In case of future requirements where runtime switches are required,
  1304. * this can be added. But it is suggested to use application layer
  1305. * simulation as far as possible in such cases, since the main
  1306. * use of record and replay of samples would concern higher
  1307. * level sample processing rather than lower level delivery.
  1308. */
  1309. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  1310. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  1311. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  1312. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  1313. p_sops->configure_spectral =
  1314. target_if_spectral_sops_sim_configure_params;
  1315. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  1316. }
  1317. #else
  1318. /**
  1319. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1320. * internal operations
  1321. * @p_sops: spectral low level ops table
  1322. *
  1323. * Return: None
  1324. */
  1325. static void
  1326. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1327. {
  1328. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  1329. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  1330. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  1331. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  1332. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  1333. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  1334. }
  1335. #endif
  1336. /**
  1337. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  1338. * operations common to all Spectral chipset generations
  1339. *
  1340. * Initializes target_if_spectral_ops common to all chipset generations
  1341. *
  1342. * Return: None
  1343. */
  1344. static void
  1345. target_if_init_spectral_ops_common(void)
  1346. {
  1347. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1348. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  1349. p_sops->get_capability = target_if_spectral_get_capability;
  1350. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  1351. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  1352. target_if_init_spectral_simulation_ops(p_sops);
  1353. p_sops->get_extension_channel =
  1354. target_if_spectral_get_extension_channel;
  1355. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  1356. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  1357. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  1358. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  1359. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  1360. p_sops->reset_hw = target_if_spectral_reset_hw;
  1361. p_sops->get_chain_noise_floor =
  1362. target_if_spectral_get_chain_noise_floor;
  1363. }
  1364. /**
  1365. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  1366. * operations specific to Spectral chipset generation 2.
  1367. *
  1368. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  1369. *
  1370. * Return: None
  1371. */
  1372. static void
  1373. target_if_init_spectral_ops_gen2(void)
  1374. {
  1375. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1376. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  1377. }
  1378. /**
  1379. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  1380. * operations specific to Spectral chipset generation 3.
  1381. *
  1382. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  1383. *
  1384. * Return: None
  1385. */
  1386. static void
  1387. target_if_init_spectral_ops_gen3(void)
  1388. {
  1389. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1390. p_sops->process_spectral_report =
  1391. target_if_spectral_process_report_gen3;
  1392. return;
  1393. }
  1394. /**
  1395. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  1396. * operations.
  1397. * @spectral: Pointer to Spectral target_if internal private data
  1398. *
  1399. * Initializes all function pointers in target_if_spectral_ops for
  1400. * all generations
  1401. *
  1402. * Return: None
  1403. */
  1404. static void
  1405. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  1406. {
  1407. target_if_init_spectral_ops_common();
  1408. if (spectral->spectral_gen == SPECTRAL_GEN2)
  1409. target_if_init_spectral_ops_gen2();
  1410. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  1411. target_if_init_spectral_ops_gen3();
  1412. else
  1413. spectral_err("Invalid Spectral generation");
  1414. }
  1415. /*
  1416. * Dummy Functions:
  1417. * These functions are initially registered to avoid any crashes due to
  1418. * invocation of spectral functions before they are registered.
  1419. */
  1420. static uint64_t
  1421. null_get_tsf64(void *arg)
  1422. {
  1423. spectral_ops_not_registered("get_tsf64");
  1424. return 0;
  1425. }
  1426. static uint32_t
  1427. null_get_capability(void *arg, enum spectral_capability_type type)
  1428. {
  1429. /*
  1430. * TODO : We should have conditional compilation to get the capability
  1431. * : We have not yet attahced ATH layer here, so there is no
  1432. * : way to check the HAL capbalities
  1433. */
  1434. spectral_ops_not_registered("get_capability");
  1435. /* TODO : For the time being, we are returning TRUE */
  1436. return true;
  1437. }
  1438. static uint32_t
  1439. null_set_rxfilter(void *arg, int rxfilter)
  1440. {
  1441. spectral_ops_not_registered("set_rxfilter");
  1442. return 1;
  1443. }
  1444. static uint32_t
  1445. null_get_rxfilter(void *arg)
  1446. {
  1447. spectral_ops_not_registered("get_rxfilter");
  1448. return 0;
  1449. }
  1450. static uint32_t
  1451. null_is_spectral_active(void *arg, enum spectral_scan_mode smode)
  1452. {
  1453. spectral_ops_not_registered("is_spectral_active");
  1454. return 1;
  1455. }
  1456. static uint32_t
  1457. null_is_spectral_enabled(void *arg, enum spectral_scan_mode smode)
  1458. {
  1459. spectral_ops_not_registered("is_spectral_enabled");
  1460. return 1;
  1461. }
  1462. static uint32_t
  1463. null_start_spectral_scan(void *arg, enum spectral_scan_mode smode,
  1464. enum spectral_cp_error_code *err)
  1465. {
  1466. spectral_ops_not_registered("start_spectral_scan");
  1467. return 1;
  1468. }
  1469. static uint32_t
  1470. null_stop_spectral_scan(void *arg, enum spectral_scan_mode smode)
  1471. {
  1472. spectral_ops_not_registered("stop_spectral_scan");
  1473. return 1;
  1474. }
  1475. static uint32_t
  1476. null_get_extension_channel(void *arg)
  1477. {
  1478. spectral_ops_not_registered("get_extension_channel");
  1479. return 1;
  1480. }
  1481. static int8_t
  1482. null_get_ctl_noisefloor(void *arg)
  1483. {
  1484. spectral_ops_not_registered("get_ctl_noisefloor");
  1485. return 1;
  1486. }
  1487. static int8_t
  1488. null_get_ext_noisefloor(void *arg)
  1489. {
  1490. spectral_ops_not_registered("get_ext_noisefloor");
  1491. return 0;
  1492. }
  1493. static uint32_t
  1494. null_configure_spectral(void *arg, struct spectral_config *params,
  1495. enum spectral_scan_mode smode)
  1496. {
  1497. spectral_ops_not_registered("configure_spectral");
  1498. return 0;
  1499. }
  1500. static uint32_t
  1501. null_get_spectral_config(void *arg, struct spectral_config *params,
  1502. enum spectral_scan_mode smode)
  1503. {
  1504. spectral_ops_not_registered("get_spectral_config");
  1505. return 0;
  1506. }
  1507. static uint32_t
  1508. null_get_ent_spectral_mask(void *arg)
  1509. {
  1510. spectral_ops_not_registered("get_ent_spectral_mask");
  1511. return 0;
  1512. }
  1513. static uint32_t
  1514. null_get_mac_address(void *arg, char *addr)
  1515. {
  1516. spectral_ops_not_registered("get_mac_address");
  1517. return 0;
  1518. }
  1519. static uint32_t
  1520. null_get_current_channel(void *arg)
  1521. {
  1522. spectral_ops_not_registered("get_current_channel");
  1523. return 0;
  1524. }
  1525. static uint32_t
  1526. null_reset_hw(void *arg)
  1527. {
  1528. spectral_ops_not_registered("get_current_channel");
  1529. return 0;
  1530. }
  1531. static uint32_t
  1532. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1533. {
  1534. spectral_ops_not_registered("get_chain_noise_floor");
  1535. return 0;
  1536. }
  1537. static int
  1538. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  1539. uint8_t *data,
  1540. uint32_t datalen,
  1541. struct target_if_spectral_rfqual_info *p_rfqual,
  1542. struct target_if_spectral_chan_info *p_chaninfo,
  1543. uint64_t tsf64,
  1544. struct target_if_spectral_acs_stats *acs_stats)
  1545. {
  1546. spectral_ops_not_registered("spectral_process_phyerr");
  1547. return 0;
  1548. }
  1549. static int
  1550. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  1551. void *payload)
  1552. {
  1553. spectral_ops_not_registered("process_spectral_report");
  1554. return 0;
  1555. }
  1556. /**
  1557. * target_if_spectral_init_dummy_function_table() -
  1558. * Initialize target_if internal
  1559. * Spectral operations to dummy functions
  1560. * @ps: Pointer to Spectral target_if internal private data
  1561. *
  1562. * Initialize all the function pointers in target_if_spectral_ops with
  1563. * dummy functions.
  1564. *
  1565. * Return: None
  1566. */
  1567. static void
  1568. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  1569. {
  1570. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  1571. p_sops->get_tsf64 = null_get_tsf64;
  1572. p_sops->get_capability = null_get_capability;
  1573. p_sops->set_rxfilter = null_set_rxfilter;
  1574. p_sops->get_rxfilter = null_get_rxfilter;
  1575. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  1576. p_sops->is_spectral_active = null_is_spectral_active;
  1577. p_sops->start_spectral_scan = null_start_spectral_scan;
  1578. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  1579. p_sops->get_extension_channel = null_get_extension_channel;
  1580. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  1581. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  1582. p_sops->configure_spectral = null_configure_spectral;
  1583. p_sops->get_spectral_config = null_get_spectral_config;
  1584. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  1585. p_sops->get_mac_address = null_get_mac_address;
  1586. p_sops->get_current_channel = null_get_current_channel;
  1587. p_sops->reset_hw = null_reset_hw;
  1588. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  1589. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  1590. p_sops->process_spectral_report = null_process_spectral_report;
  1591. }
  1592. /**
  1593. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  1594. * operations
  1595. * @spectral: Pointer to Spectral target_if internal private data
  1596. * @p: Pointer to Spectral function table
  1597. *
  1598. * Return: None
  1599. */
  1600. static void
  1601. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  1602. struct target_if_spectral_ops *p)
  1603. {
  1604. struct target_if_spectral_ops *p_sops =
  1605. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1606. p_sops->get_tsf64 = p->get_tsf64;
  1607. p_sops->get_capability = p->get_capability;
  1608. p_sops->set_rxfilter = p->set_rxfilter;
  1609. p_sops->get_rxfilter = p->get_rxfilter;
  1610. p_sops->is_spectral_enabled = p->is_spectral_enabled;
  1611. p_sops->is_spectral_active = p->is_spectral_active;
  1612. p_sops->start_spectral_scan = p->start_spectral_scan;
  1613. p_sops->stop_spectral_scan = p->stop_spectral_scan;
  1614. p_sops->get_extension_channel = p->get_extension_channel;
  1615. p_sops->get_ctl_noisefloor = p->get_ctl_noisefloor;
  1616. p_sops->get_ext_noisefloor = p->get_ext_noisefloor;
  1617. p_sops->configure_spectral = p->configure_spectral;
  1618. p_sops->get_spectral_config = p->get_spectral_config;
  1619. p_sops->get_ent_spectral_mask = p->get_ent_spectral_mask;
  1620. p_sops->get_mac_address = p->get_mac_address;
  1621. p_sops->get_current_channel = p->get_current_channel;
  1622. p_sops->reset_hw = p->reset_hw;
  1623. p_sops->get_chain_noise_floor = p->get_chain_noise_floor;
  1624. p_sops->spectral_process_phyerr = p->spectral_process_phyerr;
  1625. p_sops->process_spectral_report = p->process_spectral_report;
  1626. }
  1627. /**
  1628. * target_if_spectral_clear_stats() - Clear Spectral stats
  1629. * @spectral: Pointer to Spectral target_if internal private data
  1630. *
  1631. * Function to clear spectral stats
  1632. *
  1633. * Return: None
  1634. */
  1635. static void
  1636. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  1637. {
  1638. struct target_if_spectral_ops *p_sops =
  1639. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1640. qdf_mem_zero(&spectral->spectral_stats,
  1641. sizeof(struct target_if_spectral_stats));
  1642. spectral->spectral_stats.last_reset_tstamp =
  1643. p_sops->get_tsf64(spectral);
  1644. }
  1645. /**
  1646. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  1647. * @spectral: Pointer to Spectral target_if internal private data
  1648. *
  1649. * Function to check whether hardware supports spectral
  1650. *
  1651. * Return: True if HW supports Spectral, false if HW does not support Spectral
  1652. */
  1653. static int
  1654. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  1655. {
  1656. struct target_if_spectral_ops *p_sops = NULL;
  1657. struct spectral_caps *pcap = NULL;
  1658. int is_spectral_supported = true;
  1659. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1660. pcap = &spectral->capability;
  1661. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  1662. is_spectral_supported = false;
  1663. spectral_info("SPECTRAL : No PHYDIAG support");
  1664. return is_spectral_supported;
  1665. }
  1666. pcap->phydiag_cap = 1;
  1667. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  1668. is_spectral_supported = false;
  1669. spectral_info("SPECTRAL : No RADAR support");
  1670. return is_spectral_supported;
  1671. }
  1672. pcap->radar_cap = 1;
  1673. if (p_sops->get_capability(spectral,
  1674. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  1675. is_spectral_supported = false;
  1676. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  1677. return is_spectral_supported;
  1678. }
  1679. pcap->spectral_cap = 1;
  1680. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  1681. == false) {
  1682. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  1683. } else {
  1684. pcap->advncd_spectral_cap = 1;
  1685. }
  1686. return is_spectral_supported;
  1687. }
  1688. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1689. /**
  1690. * target_if_spectral_detach_simulation() - De-initialize Spectral
  1691. * Simulation functionality
  1692. * @spectral: Pointer to Spectral target_if internal private data
  1693. *
  1694. * Function to de-initialize Spectral Simulation functionality
  1695. *
  1696. * Return: None
  1697. */
  1698. static void
  1699. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1700. {
  1701. target_if_spectral_sim_detach(spectral);
  1702. }
  1703. #else
  1704. static void
  1705. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1706. {
  1707. }
  1708. #endif
  1709. /**
  1710. * target_if_spectral_detach() - De-initialize target_if Spectral
  1711. * @pdev: Pointer to pdev object
  1712. *
  1713. * Function to detach target_if spectral
  1714. *
  1715. * Return: None
  1716. */
  1717. static void
  1718. target_if_spectral_detach(struct target_if_spectral *spectral)
  1719. {
  1720. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1721. spectral_info("spectral detach");
  1722. if (spectral) {
  1723. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1724. qdf_spinlock_destroy
  1725. (&spectral->param_info[smode].osps_lock);
  1726. target_if_spectral_detach_simulation(spectral);
  1727. qdf_spinlock_destroy(&spectral->spectral_lock);
  1728. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  1729. qdf_mem_free(spectral);
  1730. spectral = NULL;
  1731. }
  1732. }
  1733. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1734. /**
  1735. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  1736. * functionality
  1737. * @spectral: Pointer to Spectral target_if internal private data
  1738. *
  1739. * Function to initialize spectral simulation functionality
  1740. *
  1741. * Return: 0 on success, negative error code on failure
  1742. */
  1743. static int
  1744. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1745. {
  1746. if (target_if_spectral_sim_attach(spectral)) {
  1747. qdf_mem_free(spectral);
  1748. return -EPERM;
  1749. }
  1750. return 0;
  1751. }
  1752. #else
  1753. static int
  1754. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1755. {
  1756. return 0;
  1757. }
  1758. #endif
  1759. /**
  1760. * target_if_spectral_len_adj_swar_init() - Initialize FFT bin length adjustment
  1761. * related info
  1762. * @swar: Pointer to Spectral FFT bin length adjustment SWAR params
  1763. * @target_type: Target type
  1764. *
  1765. * Function to Initialize parameters related to Spectral FFT bin
  1766. * length adjustment SWARs.
  1767. *
  1768. * Return: void
  1769. */
  1770. static void
  1771. target_if_spectral_len_adj_swar_init(struct spectral_fft_bin_len_adj_swar *swar,
  1772. uint32_t target_type)
  1773. {
  1774. if (target_type == TARGET_TYPE_QCA8074V2 ||
  1775. target_type == TARGET_TYPE_QCN9000)
  1776. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  1777. else if (target_type == TARGET_TYPE_QCA8074 ||
  1778. target_type == TARGET_TYPE_QCA6018 ||
  1779. target_type == TARGET_TYPE_QCA6390)
  1780. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  1781. else
  1782. swar->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  1783. if (target_type == TARGET_TYPE_QCA8074 ||
  1784. target_type == TARGET_TYPE_QCA8074V2 ||
  1785. target_type == TARGET_TYPE_QCA6018 ||
  1786. target_type == TARGET_TYPE_QCN9000) {
  1787. swar->inband_fftbin_size_adj = 1;
  1788. swar->null_fftbin_adj = 1;
  1789. } else {
  1790. swar->inband_fftbin_size_adj = 0;
  1791. swar->null_fftbin_adj = 0;
  1792. }
  1793. if (target_type == TARGET_TYPE_QCA8074V2)
  1794. swar->packmode_fftbin_size_adj = 1;
  1795. else
  1796. swar->packmode_fftbin_size_adj = 0;
  1797. }
  1798. /**
  1799. * target_if_spectral_report_params_init() - Initialize parameters which
  1800. * describes the structure of Spectral reports
  1801. *
  1802. * @rparams: Pointer to Spectral report parameter object
  1803. * @target_type: target type
  1804. *
  1805. * Function to Initialize parameters related to the structure of Spectral
  1806. * reports.
  1807. *
  1808. * Return: void
  1809. */
  1810. static void
  1811. target_if_spectral_report_params_init(
  1812. struct spectral_report_params *rparams,
  1813. uint32_t target_type)
  1814. {
  1815. /* This entries are currently used by gen3 chipsets only. Hence
  1816. * initialization is done for gen3 alone. In future if other generations
  1817. * needs to use them they have to add proper initial values.
  1818. */
  1819. if (target_type == TARGET_TYPE_QCN9000)
  1820. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_2;
  1821. else
  1822. rparams->version = SPECTRAL_REPORT_FORMAT_VERSION_1;
  1823. switch (rparams->version) {
  1824. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1825. rparams->ssumaary_padding_bytes =
  1826. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1;
  1827. rparams->fft_report_hdr_len =
  1828. FFT_REPORT_HEADER_LENGTH_GEN3_V1;
  1829. break;
  1830. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1831. rparams->ssumaary_padding_bytes =
  1832. NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2;
  1833. rparams->fft_report_hdr_len =
  1834. FFT_REPORT_HEADER_LENGTH_GEN3_V2;
  1835. break;
  1836. default:
  1837. qdf_assert_always(0);
  1838. }
  1839. }
  1840. /**
  1841. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  1842. * functionality for the given pdev
  1843. * @pdev: Pointer to pdev object
  1844. *
  1845. * Function to initialize pointer to spectral target_if internal private data
  1846. *
  1847. * Return: On success, pointer to Spectral target_if internal private data, on
  1848. * failure, NULL
  1849. */
  1850. void *
  1851. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  1852. {
  1853. struct target_if_spectral_ops *p_sops = NULL;
  1854. struct target_if_spectral *spectral = NULL;
  1855. uint32_t target_type;
  1856. uint32_t target_revision;
  1857. struct wlan_objmgr_psoc *psoc;
  1858. struct wlan_lmac_if_target_tx_ops *tx_ops;
  1859. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1860. if (!pdev) {
  1861. spectral_err("SPECTRAL: pdev is NULL!");
  1862. return NULL;
  1863. }
  1864. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  1865. sizeof(struct target_if_spectral));
  1866. if (!spectral)
  1867. return spectral;
  1868. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  1869. /* Store pdev in Spectral */
  1870. spectral->pdev_obj = pdev;
  1871. psoc = wlan_pdev_get_psoc(pdev);
  1872. tx_ops = &psoc->soc_cb.tx_ops.target_tx_ops;
  1873. if (tx_ops->tgt_get_tgt_type) {
  1874. target_type = tx_ops->tgt_get_tgt_type(psoc);
  1875. } else {
  1876. qdf_mem_free(spectral);
  1877. return NULL;
  1878. }
  1879. if (tx_ops->tgt_get_tgt_revision) {
  1880. target_revision = tx_ops->tgt_get_tgt_revision(psoc);
  1881. } else {
  1882. qdf_mem_free(spectral);
  1883. return NULL;
  1884. }
  1885. /* init the function ptr table */
  1886. target_if_spectral_init_dummy_function_table(spectral);
  1887. /* get spectral function table */
  1888. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1889. /* TODO : Should this be called here of after ath_attach ? */
  1890. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  1891. spectral_info("HAL_CAP_PHYDIAG : Capable");
  1892. /* TODO: Need to fix the capablity check for RADAR */
  1893. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  1894. spectral_info("HAL_CAP_RADAR : Capable");
  1895. /* TODO : Need to fix the capablity check for SPECTRAL */
  1896. /* TODO : Should this be called here of after ath_attach ? */
  1897. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  1898. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  1899. qdf_spinlock_create(&spectral->spectral_lock);
  1900. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  1901. target_if_spectral_clear_stats(spectral);
  1902. if (target_type == TARGET_TYPE_QCA8074 ||
  1903. target_type == TARGET_TYPE_QCA8074V2 ||
  1904. target_type == TARGET_TYPE_QCA6018 ||
  1905. target_type == TARGET_TYPE_QCA6390 ||
  1906. target_type == TARGET_TYPE_QCN9000)
  1907. spectral->direct_dma_support = true;
  1908. target_if_spectral_len_adj_swar_init(&spectral->len_adj_swar,
  1909. target_type);
  1910. target_if_spectral_report_params_init(&spectral->rparams, target_type);
  1911. if ((target_type == TARGET_TYPE_QCA8074) ||
  1912. (target_type == TARGET_TYPE_QCA8074V2) ||
  1913. (target_type == TARGET_TYPE_QCA6018) ||
  1914. (target_type == TARGET_TYPE_QCN9000) ||
  1915. (target_type == TARGET_TYPE_QCA6290) ||
  1916. (target_type == TARGET_TYPE_QCA6390)) {
  1917. spectral->spectral_gen = SPECTRAL_GEN3;
  1918. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  1919. spectral->tag_sscan_summary_exp =
  1920. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  1921. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  1922. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  1923. spectral->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3;
  1924. spectral->fft_size_max =
  1925. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT;
  1926. if (target_type == TARGET_TYPE_QCN9000)
  1927. spectral->fft_size_max =
  1928. SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000;
  1929. } else {
  1930. spectral->spectral_gen = SPECTRAL_GEN2;
  1931. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  1932. spectral->tag_sscan_summary_exp =
  1933. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  1934. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  1935. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  1936. spectral->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1937. spectral->fft_size_max = SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1938. }
  1939. target_if_init_spectral_param_properties(spectral);
  1940. /* Init spectral capability */
  1941. if (target_if_init_spectral_capability(spectral) !=
  1942. QDF_STATUS_SUCCESS) {
  1943. qdf_mem_free(spectral);
  1944. return NULL;
  1945. }
  1946. if (target_if_spectral_attach_simulation(spectral) < 0)
  1947. return NULL;
  1948. target_if_init_spectral_ops(spectral);
  1949. /* Spectral mode specific init */
  1950. spectral->target_reset_count = 0;
  1951. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1952. spectral->last_fft_timestamp[smode] = 0;
  1953. spectral->timestamp_war_offset[smode] = 0;
  1954. spectral->params_valid[smode] = false;
  1955. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  1956. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  1957. }
  1958. target_if_spectral_register_funcs(spectral, &spectral_ops);
  1959. if (target_if_spectral_check_hw_capability(spectral) == false) {
  1960. target_if_spectral_detach(spectral);
  1961. spectral = NULL;
  1962. } else {
  1963. /*
  1964. * TODO: Once the driver architecture transitions to chipset
  1965. * versioning based checks, reflect this here.
  1966. */
  1967. spectral->is_160_format = false;
  1968. spectral->is_lb_edge_extrabins_format = false;
  1969. spectral->is_rb_edge_extrabins_format = false;
  1970. if (target_type == TARGET_TYPE_QCA9984 ||
  1971. target_type == TARGET_TYPE_QCA9888) {
  1972. spectral->is_160_format = true;
  1973. spectral->is_lb_edge_extrabins_format = true;
  1974. spectral->is_rb_edge_extrabins_format = true;
  1975. } else if ((target_type == TARGET_TYPE_AR900B) &&
  1976. (target_revision == AR900B_REV_2)) {
  1977. spectral->is_rb_edge_extrabins_format = true;
  1978. }
  1979. if (target_type == TARGET_TYPE_QCA9984 ||
  1980. target_type == TARGET_TYPE_QCA9888)
  1981. spectral->is_sec80_rssi_war_required = true;
  1982. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  1983. if (spectral->spectral_gen == SPECTRAL_GEN3)
  1984. init_160mhz_delivery_state_machine(spectral);
  1985. }
  1986. return spectral;
  1987. }
  1988. /**
  1989. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  1990. * functionality for the given pdev
  1991. * @pdev: Pointer to pdev object
  1992. *
  1993. * Function to de-initialize pointer to spectral target_if internal private data
  1994. *
  1995. * Return: None
  1996. */
  1997. void
  1998. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  1999. {
  2000. struct target_if_spectral *spectral = NULL;
  2001. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2002. if (!spectral) {
  2003. spectral_err("SPECTRAL : Module doesn't exist");
  2004. return;
  2005. }
  2006. target_if_spectral_detach(spectral);
  2007. return;
  2008. }
  2009. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  2010. * corresponding translation for Agile channel width.
  2011. * Translation schema of different operating modes:
  2012. * 20 -> 20, 40 -> 40, (80 & 160 & 80_80) -> 80.
  2013. * @chwidth: Channel width enum.
  2014. *
  2015. * Return: The translated channel width enum.
  2016. */
  2017. static enum phy_ch_width
  2018. target_if_spectral_find_agile_width(enum phy_ch_width chwidth)
  2019. {
  2020. switch (chwidth) {
  2021. case CH_WIDTH_20MHZ:
  2022. return CH_WIDTH_20MHZ;
  2023. case CH_WIDTH_40MHZ:
  2024. return CH_WIDTH_40MHZ;
  2025. case CH_WIDTH_80MHZ:
  2026. case CH_WIDTH_80P80MHZ:
  2027. case CH_WIDTH_160MHZ:
  2028. return CH_WIDTH_80MHZ;
  2029. default:
  2030. spectral_err("Invalid chwidth enum %d", chwidth);
  2031. return CH_WIDTH_INVALID;
  2032. }
  2033. }
  2034. /**
  2035. * target_if_calculate_center_freq() - Helper routine to
  2036. * check whether given frequency is center frequency of a
  2037. * WLAN channel
  2038. *
  2039. * @spectral: Pointer to Spectral object
  2040. * @chan_freq: Center frequency of a WLAN channel
  2041. * @is_valid: Indicates whether given frequency is valid
  2042. *
  2043. * Return: QDF_STATUS
  2044. */
  2045. static QDF_STATUS
  2046. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  2047. uint32_t chan_freq,
  2048. bool *is_valid)
  2049. {
  2050. struct regulatory_channel *cur_chan_list;
  2051. int i;
  2052. if (!pdev) {
  2053. spectral_err("pdev object is null");
  2054. return QDF_STATUS_E_FAILURE;
  2055. }
  2056. if (!is_valid) {
  2057. spectral_err("is valid argument is null");
  2058. return QDF_STATUS_E_FAILURE;
  2059. }
  2060. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  2061. if (!cur_chan_list)
  2062. return QDF_STATUS_E_FAILURE;
  2063. if (wlan_reg_get_current_chan_list(
  2064. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  2065. spectral_err("Failed to get cur_chan list");
  2066. qdf_mem_free(cur_chan_list);
  2067. return QDF_STATUS_E_FAILURE;
  2068. }
  2069. *is_valid = false;
  2070. for (i = 0; i < NUM_CHANNELS; i++) {
  2071. uint32_t flags;
  2072. uint32_t center_freq;
  2073. flags = cur_chan_list[i].chan_flags;
  2074. center_freq = cur_chan_list[i].center_freq;
  2075. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  2076. (center_freq == chan_freq)) {
  2077. *is_valid = true;
  2078. break;
  2079. }
  2080. }
  2081. qdf_mem_free(cur_chan_list);
  2082. return QDF_STATUS_SUCCESS;
  2083. }
  2084. /**
  2085. * target_if_calculate_center_freq() - Helper routine to
  2086. * find the center frequency of the agile span from a
  2087. * WLAN channel center frequency
  2088. *
  2089. * @spectral: Pointer to Spectral object
  2090. * @chan_freq: Center frequency of a WLAN channel
  2091. * @center_freq: Pointer to center frequency
  2092. *
  2093. * Return: QDF_STATUS
  2094. */
  2095. static QDF_STATUS
  2096. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  2097. uint16_t chan_freq,
  2098. uint16_t *center_freq)
  2099. {
  2100. struct wlan_objmgr_vdev *vdev;
  2101. enum phy_ch_width ch_width;
  2102. enum phy_ch_width agile_ch_width;
  2103. if (!spectral) {
  2104. spectral_err("spectral target if object is null");
  2105. return QDF_STATUS_E_FAILURE;
  2106. }
  2107. if (!center_freq) {
  2108. spectral_err("center_freq argument is null");
  2109. return QDF_STATUS_E_FAILURE;
  2110. }
  2111. vdev = target_if_spectral_get_vdev(spectral);
  2112. if (!vdev) {
  2113. spectral_err("vdev is NULL");
  2114. return QDF_STATUS_E_FAILURE;
  2115. }
  2116. ch_width = target_if_vdev_get_ch_width(vdev);
  2117. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2118. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2119. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2120. *center_freq = chan_freq;
  2121. } else {
  2122. uint16_t start_freq;
  2123. uint16_t end_freq;
  2124. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2125. wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2126. (spectral->pdev_obj, chan_freq, agile_ch_width,
  2127. &bonded_chan_ptr);
  2128. if (!bonded_chan_ptr) {
  2129. spectral_err("Bonded channel is not found");
  2130. return QDF_STATUS_E_FAILURE;
  2131. }
  2132. start_freq = bonded_chan_ptr->start_freq;
  2133. end_freq = bonded_chan_ptr->end_freq;
  2134. *center_freq = (start_freq + end_freq) >> 1;
  2135. }
  2136. return QDF_STATUS_SUCCESS;
  2137. }
  2138. /**
  2139. * target_if_validate_center_freq() - Helper routine to
  2140. * validate user provided agile center frequency
  2141. *
  2142. * @spectral: Pointer to Spectral object
  2143. * @center_freq: User provided agile span center frequency
  2144. * @is_valid: Indicates whether agile span center frequency is valid
  2145. *
  2146. * Return: QDF_STATUS
  2147. */
  2148. static QDF_STATUS
  2149. target_if_validate_center_freq(struct target_if_spectral *spectral,
  2150. uint16_t center_freq,
  2151. bool *is_valid)
  2152. {
  2153. struct wlan_objmgr_vdev *vdev;
  2154. enum phy_ch_width ch_width;
  2155. enum phy_ch_width agile_ch_width;
  2156. struct wlan_objmgr_pdev *pdev;
  2157. QDF_STATUS status;
  2158. if (!spectral) {
  2159. spectral_err("spectral target if object is null");
  2160. return QDF_STATUS_E_FAILURE;
  2161. }
  2162. if (!is_valid) {
  2163. spectral_err("is_valid argument is null");
  2164. return QDF_STATUS_E_FAILURE;
  2165. }
  2166. pdev = spectral->pdev_obj;
  2167. vdev = target_if_spectral_get_vdev(spectral);
  2168. if (!vdev) {
  2169. spectral_err("vdev is NULL");
  2170. return QDF_STATUS_E_FAILURE;
  2171. }
  2172. ch_width = target_if_vdev_get_ch_width(vdev);
  2173. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2174. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2175. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2176. status = target_if_is_center_freq_of_any_chan
  2177. (pdev, center_freq, is_valid);
  2178. if (QDF_IS_STATUS_ERROR(status))
  2179. return QDF_STATUS_E_FAILURE;
  2180. } else {
  2181. uint16_t start_freq;
  2182. uint16_t end_freq;
  2183. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2184. bool is_chan;
  2185. status = target_if_is_center_freq_of_any_chan
  2186. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2187. &is_chan);
  2188. if (QDF_IS_STATUS_ERROR(status))
  2189. return QDF_STATUS_E_FAILURE;
  2190. if (is_chan) {
  2191. uint32_t calulated_center_freq;
  2192. wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2193. (pdev, center_freq + FREQ_OFFSET_10MHZ,
  2194. agile_ch_width,
  2195. &bonded_chan_ptr);
  2196. if (!bonded_chan_ptr) {
  2197. spectral_err("Bonded channel is not found");
  2198. return QDF_STATUS_E_FAILURE;
  2199. }
  2200. start_freq = bonded_chan_ptr->start_freq;
  2201. end_freq = bonded_chan_ptr->end_freq;
  2202. calulated_center_freq = (start_freq + end_freq) >> 1;
  2203. *is_valid = (center_freq == calulated_center_freq);
  2204. } else {
  2205. *is_valid = false;
  2206. }
  2207. }
  2208. return QDF_STATUS_SUCCESS;
  2209. }
  2210. /**
  2211. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  2212. * check whether agile span overlaps with current operating band.
  2213. *
  2214. * @spectral: Pointer to Spectral object
  2215. * @ss_frequency: Agile span center frequency
  2216. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  2217. *
  2218. * Helper routine to check whether agile span overlaps with current
  2219. * operating band.
  2220. *
  2221. * Return: QDF_STATUS
  2222. */
  2223. static QDF_STATUS
  2224. target_if_is_agile_span_overlap_with_operating_span
  2225. (struct target_if_spectral *spectral,
  2226. uint32_t ss_frequency,
  2227. bool *is_overlapping)
  2228. {
  2229. enum phy_ch_width ch_width;
  2230. enum phy_ch_width agile_ch_width;
  2231. const struct bonded_channel_freq *bonded_chan_ptr = NULL;
  2232. struct wlan_objmgr_vdev *vdev;
  2233. struct wlan_objmgr_pdev *pdev;
  2234. int16_t chan_freq;
  2235. uint32_t op_start_freq;
  2236. uint32_t op_end_freq;
  2237. uint32_t agile_start_freq;
  2238. uint32_t agile_end_freq;
  2239. uint32_t cfreq2;
  2240. if (!spectral) {
  2241. spectral_err("Spectral object is NULL");
  2242. return QDF_STATUS_E_FAILURE;
  2243. }
  2244. pdev = spectral->pdev_obj;
  2245. if (!pdev) {
  2246. spectral_err("pdev object is NULL");
  2247. return QDF_STATUS_E_FAILURE;
  2248. }
  2249. if (!is_overlapping) {
  2250. spectral_err("Argument(is_overlapping) is NULL");
  2251. return QDF_STATUS_E_FAILURE;
  2252. }
  2253. vdev = target_if_spectral_get_vdev(spectral);
  2254. if (!vdev) {
  2255. spectral_err("vdev is NULL");
  2256. return QDF_STATUS_E_FAILURE;
  2257. }
  2258. ch_width = target_if_vdev_get_ch_width(vdev);
  2259. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2260. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2261. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2262. if (cfreq2 < 0)
  2263. return QDF_STATUS_E_FAILURE;
  2264. if (ch_width == CH_WIDTH_20MHZ) {
  2265. op_start_freq = chan_freq - FREQ_OFFSET_10MHZ;
  2266. op_end_freq = chan_freq + FREQ_OFFSET_10MHZ;
  2267. } else {
  2268. wlan_reg_get_5g_bonded_channel_and_state_for_freq
  2269. (pdev, chan_freq, ch_width, &bonded_chan_ptr);
  2270. if (!bonded_chan_ptr) {
  2271. spectral_err("Bonded channel is not found");
  2272. return QDF_STATUS_E_FAILURE;
  2273. }
  2274. op_start_freq = bonded_chan_ptr->start_freq - FREQ_OFFSET_10MHZ;
  2275. op_end_freq = bonded_chan_ptr->end_freq - FREQ_OFFSET_10MHZ;
  2276. }
  2277. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2278. if (agile_ch_width == CH_WIDTH_INVALID)
  2279. return QDF_STATUS_E_FAILURE;
  2280. agile_start_freq = ss_frequency -
  2281. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2282. agile_end_freq = ss_frequency +
  2283. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2284. if (agile_end_freq <= op_start_freq || op_end_freq <= agile_start_freq)
  2285. *is_overlapping = false;
  2286. else
  2287. *is_overlapping = true;
  2288. /* Use non zero cfreq2 to identify 80p80 */
  2289. if (cfreq2) {
  2290. uint32_t sec80_start_feq;
  2291. uint32_t sec80_end_freq;
  2292. sec80_start_feq = cfreq2 - 40;
  2293. sec80_end_freq = cfreq2 + 40;
  2294. if ((agile_end_freq > sec80_start_feq) &&
  2295. (sec80_end_freq > agile_start_freq))
  2296. *is_overlapping = true;
  2297. }
  2298. return QDF_STATUS_SUCCESS;
  2299. }
  2300. /**
  2301. * _target_if_set_spectral_config() - Set spectral config
  2302. * @spectral: Pointer to spectral object
  2303. * @threshtype: config type
  2304. * @value: config value
  2305. * @smode: Spectral scan mode
  2306. * @err: Spectral error code
  2307. *
  2308. * API to set spectral configurations
  2309. *
  2310. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2311. */
  2312. static QDF_STATUS
  2313. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  2314. const uint32_t threshtype, const uint32_t value,
  2315. const enum spectral_scan_mode smode,
  2316. enum spectral_cp_error_code *err)
  2317. {
  2318. struct spectral_config params;
  2319. struct target_if_spectral_ops *p_sops;
  2320. struct spectral_config *sparams;
  2321. QDF_STATUS status;
  2322. bool is_overlapping;
  2323. uint16_t agile_cfreq;
  2324. bool is_valid_chan;
  2325. if (!err) {
  2326. spectral_err("Error code argument is null");
  2327. QDF_ASSERT(0);
  2328. }
  2329. *err = SPECTRAL_SCAN_ERR_INVALID;
  2330. if (!spectral) {
  2331. spectral_err("spectral object is NULL");
  2332. return QDF_STATUS_E_FAILURE;
  2333. }
  2334. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2335. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2336. spectral_err("Invalid Spectral mode %u", smode);
  2337. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2338. return QDF_STATUS_E_FAILURE;
  2339. }
  2340. sparams = &spectral->params[smode];
  2341. if (!spectral->params_valid[smode]) {
  2342. target_if_spectral_info_read(spectral,
  2343. smode,
  2344. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2345. &spectral->params[smode],
  2346. sizeof(spectral->params[smode]));
  2347. spectral->params_valid[smode] = true;
  2348. }
  2349. switch (threshtype) {
  2350. case SPECTRAL_PARAM_FFT_PERIOD:
  2351. sparams->ss_fft_period = value;
  2352. break;
  2353. case SPECTRAL_PARAM_SCAN_PERIOD:
  2354. sparams->ss_period = value;
  2355. break;
  2356. case SPECTRAL_PARAM_SCAN_COUNT:
  2357. sparams->ss_count = value;
  2358. break;
  2359. case SPECTRAL_PARAM_SHORT_REPORT:
  2360. sparams->ss_short_report = (!!value) ? true : false;
  2361. break;
  2362. case SPECTRAL_PARAM_SPECT_PRI:
  2363. sparams->ss_spectral_pri = (!!value) ? true : false;
  2364. break;
  2365. case SPECTRAL_PARAM_FFT_SIZE:
  2366. if ((value < spectral->fft_size_min) ||
  2367. (value > spectral->fft_size_max)) {
  2368. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2369. return QDF_STATUS_E_FAILURE;
  2370. }
  2371. sparams->ss_fft_size = value;
  2372. break;
  2373. case SPECTRAL_PARAM_GC_ENA:
  2374. sparams->ss_gc_ena = !!value;
  2375. break;
  2376. case SPECTRAL_PARAM_RESTART_ENA:
  2377. sparams->ss_restart_ena = !!value;
  2378. break;
  2379. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  2380. sparams->ss_noise_floor_ref = value;
  2381. break;
  2382. case SPECTRAL_PARAM_INIT_DELAY:
  2383. sparams->ss_init_delay = value;
  2384. break;
  2385. case SPECTRAL_PARAM_NB_TONE_THR:
  2386. sparams->ss_nb_tone_thr = value;
  2387. break;
  2388. case SPECTRAL_PARAM_STR_BIN_THR:
  2389. sparams->ss_str_bin_thr = value;
  2390. break;
  2391. case SPECTRAL_PARAM_WB_RPT_MODE:
  2392. sparams->ss_wb_rpt_mode = !!value;
  2393. break;
  2394. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  2395. sparams->ss_rssi_rpt_mode = !!value;
  2396. break;
  2397. case SPECTRAL_PARAM_RSSI_THR:
  2398. sparams->ss_rssi_thr = value;
  2399. break;
  2400. case SPECTRAL_PARAM_PWR_FORMAT:
  2401. sparams->ss_pwr_format = !!value;
  2402. break;
  2403. case SPECTRAL_PARAM_RPT_MODE:
  2404. if ((value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  2405. (value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  2406. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2407. return QDF_STATUS_E_FAILURE;
  2408. }
  2409. sparams->ss_rpt_mode = value;
  2410. break;
  2411. case SPECTRAL_PARAM_BIN_SCALE:
  2412. sparams->ss_bin_scale = value;
  2413. break;
  2414. case SPECTRAL_PARAM_DBM_ADJ:
  2415. sparams->ss_dbm_adj = !!value;
  2416. break;
  2417. case SPECTRAL_PARAM_CHN_MASK:
  2418. sparams->ss_chn_mask = value;
  2419. break;
  2420. case SPECTRAL_PARAM_FREQUENCY:
  2421. status = target_if_is_center_freq_of_any_chan
  2422. (spectral->pdev_obj, value, &is_valid_chan);
  2423. if (QDF_IS_STATUS_ERROR(status))
  2424. return QDF_STATUS_E_FAILURE;
  2425. if (is_valid_chan) {
  2426. status = target_if_calculate_center_freq(spectral,
  2427. value,
  2428. &agile_cfreq);
  2429. if (QDF_IS_STATUS_ERROR(status)) {
  2430. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2431. return QDF_STATUS_E_FAILURE;
  2432. }
  2433. } else {
  2434. bool is_valid_agile_cfreq;
  2435. status = target_if_validate_center_freq
  2436. (spectral, value, &is_valid_agile_cfreq);
  2437. if (QDF_IS_STATUS_ERROR(status))
  2438. return QDF_STATUS_E_FAILURE;
  2439. if (!is_valid_agile_cfreq) {
  2440. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2441. spectral_err("Invalid agile center frequency");
  2442. return QDF_STATUS_E_FAILURE;
  2443. }
  2444. agile_cfreq = value;
  2445. }
  2446. status = target_if_is_agile_span_overlap_with_operating_span
  2447. (spectral, agile_cfreq, &is_overlapping);
  2448. if (QDF_IS_STATUS_ERROR(status))
  2449. return QDF_STATUS_E_FAILURE;
  2450. if (is_overlapping) {
  2451. spectral_err("Agile span overlapping with current BW");
  2452. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2453. return QDF_STATUS_E_FAILURE;
  2454. }
  2455. sparams->ss_frequency = agile_cfreq;
  2456. break;
  2457. }
  2458. p_sops->configure_spectral(spectral, sparams, smode);
  2459. /* only to validate the writes */
  2460. p_sops->get_spectral_config(spectral, &params, smode);
  2461. return QDF_STATUS_SUCCESS;
  2462. }
  2463. QDF_STATUS
  2464. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  2465. const uint32_t threshtype, const uint32_t value,
  2466. const enum spectral_scan_mode smode,
  2467. enum spectral_cp_error_code *err)
  2468. {
  2469. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  2470. struct target_if_spectral *spectral;
  2471. QDF_STATUS status;
  2472. if (!err) {
  2473. spectral_err("Error code argument is null");
  2474. QDF_ASSERT(0);
  2475. }
  2476. *err = SPECTRAL_SCAN_ERR_INVALID;
  2477. if (!pdev) {
  2478. spectral_err("pdev object is NULL");
  2479. return QDF_STATUS_E_FAILURE;
  2480. }
  2481. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2482. if (!spectral) {
  2483. spectral_err("spectral object is NULL");
  2484. return QDF_STATUS_E_FAILURE;
  2485. }
  2486. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2487. spectral_err("Invalid Spectral mode %u", smode);
  2488. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2489. return QDF_STATUS_E_FAILURE;
  2490. }
  2491. if (!spectral->properties[smode][threshtype].supported) {
  2492. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  2493. threshtype, smode);
  2494. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  2495. return QDF_STATUS_E_FAILURE;
  2496. }
  2497. if (spectral->properties[smode][threshtype].common_all_modes) {
  2498. spectral_warn("Setting Spectral parameter %u for all modes",
  2499. threshtype);
  2500. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  2501. status = _target_if_set_spectral_config
  2502. (spectral, threshtype, value,
  2503. mode, err);
  2504. if (QDF_IS_STATUS_ERROR(status))
  2505. return QDF_STATUS_E_FAILURE;
  2506. }
  2507. return QDF_STATUS_SUCCESS;
  2508. }
  2509. return _target_if_set_spectral_config(spectral, threshtype,
  2510. value, smode, err);
  2511. }
  2512. /**
  2513. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  2514. * @fft_len: FFT length
  2515. * @pdev: Pointer to pdev object
  2516. *
  2517. * API to get fft bin count for a given fft length
  2518. *
  2519. * Return: FFt bin count
  2520. */
  2521. static int
  2522. target_if_get_fft_bin_count(int fft_len)
  2523. {
  2524. int bin_count = 0;
  2525. switch (fft_len) {
  2526. case 5:
  2527. bin_count = 16;
  2528. break;
  2529. case 6:
  2530. bin_count = 32;
  2531. break;
  2532. case 7:
  2533. bin_count = 64;
  2534. break;
  2535. case 8:
  2536. bin_count = 128;
  2537. break;
  2538. case 9:
  2539. bin_count = 256;
  2540. break;
  2541. default:
  2542. break;
  2543. }
  2544. return bin_count;
  2545. }
  2546. /**
  2547. * target_if_init_upper_lower_flags() - Initializes control and extension
  2548. * segment flags
  2549. * @fft_len: FFT length
  2550. * @pdev: Pointer to pdev object
  2551. *
  2552. * API to initialize the control and extension flags with the lower/upper
  2553. * segment based on the HT mode
  2554. *
  2555. * Return: FFt bin count
  2556. */
  2557. static void
  2558. target_if_init_upper_lower_flags(struct target_if_spectral *spectral)
  2559. {
  2560. int current_channel = 0;
  2561. int ext_channel = 0;
  2562. struct target_if_spectral_ops *p_sops =
  2563. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2564. current_channel = p_sops->get_current_channel(spectral);
  2565. ext_channel = p_sops->get_extension_channel(spectral);
  2566. if ((current_channel == 0) || (ext_channel == 0))
  2567. return;
  2568. if (spectral->sc_spectral_20_40_mode) {
  2569. /* HT40 mode */
  2570. if (ext_channel < current_channel) {
  2571. spectral->lower_is_extension = 1;
  2572. spectral->upper_is_control = 1;
  2573. spectral->lower_is_control = 0;
  2574. spectral->upper_is_extension = 0;
  2575. } else {
  2576. spectral->lower_is_extension = 0;
  2577. spectral->upper_is_control = 0;
  2578. spectral->lower_is_control = 1;
  2579. spectral->upper_is_extension = 1;
  2580. }
  2581. } else {
  2582. /* HT20 mode, lower is always control */
  2583. spectral->lower_is_extension = 0;
  2584. spectral->upper_is_control = 0;
  2585. spectral->lower_is_control = 1;
  2586. spectral->upper_is_extension = 0;
  2587. }
  2588. }
  2589. /**
  2590. * target_if_get_spectral_config() - Get spectral configuration
  2591. * @pdev: Pointer to pdev object
  2592. * @param: Pointer to spectral_config structure in which the configuration
  2593. * should be returned
  2594. * @smode: Spectral scan mode
  2595. *
  2596. * API to get the current spectral configuration
  2597. *
  2598. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2599. */
  2600. QDF_STATUS
  2601. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  2602. struct spectral_config *param,
  2603. enum spectral_scan_mode smode)
  2604. {
  2605. struct target_if_spectral_ops *p_sops = NULL;
  2606. struct target_if_spectral *spectral = NULL;
  2607. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2608. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2609. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2610. spectral_err("Invalid Spectral mode %u", smode);
  2611. return QDF_STATUS_E_FAILURE;
  2612. }
  2613. qdf_mem_zero(param, sizeof(struct spectral_config));
  2614. p_sops->get_spectral_config(spectral, param, smode);
  2615. return QDF_STATUS_SUCCESS;
  2616. }
  2617. /**
  2618. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  2619. * parameters
  2620. * @spectral: Pointer to Spectral target_if internal private data
  2621. * @spectral_params: Pointer to Spectral parameters
  2622. * @smode: Spectral scan mode
  2623. * @err: Spectral error code
  2624. *
  2625. * Enable use of desired Spectral parameters by configuring them into HW, and
  2626. * starting Spectral scan
  2627. *
  2628. * Return: 0 on success, 1 on failure
  2629. */
  2630. int
  2631. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  2632. struct spectral_config *spectral_params,
  2633. enum spectral_scan_mode smode,
  2634. enum spectral_cp_error_code *err)
  2635. {
  2636. int extension_channel = 0;
  2637. int current_channel = 0;
  2638. struct target_if_spectral_ops *p_sops = NULL;
  2639. struct wlan_objmgr_vdev *vdev = NULL;
  2640. if (!spectral) {
  2641. spectral_err("Spectral LMAC object is NULL");
  2642. return 1;
  2643. }
  2644. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2645. spectral_err("Invalid Spectral mode %u", smode);
  2646. return 1;
  2647. }
  2648. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2649. if (!p_sops) {
  2650. spectral_err("p_sops is NULL");
  2651. return 1;
  2652. }
  2653. spectral->sc_spectral_noise_pwr_cal =
  2654. spectral_params->ss_spectral_pri ? 1 : 0;
  2655. /* check if extension channel is present */
  2656. extension_channel = p_sops->get_extension_channel(spectral);
  2657. current_channel = p_sops->get_current_channel(spectral);
  2658. vdev = target_if_spectral_get_vdev(spectral);
  2659. if (!vdev)
  2660. return 1;
  2661. spectral->ch_width = target_if_vdev_get_ch_width(vdev);
  2662. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2663. if (spectral->ch_width == CH_WIDTH_INVALID)
  2664. return 1;
  2665. spectral->agile_ch_width =
  2666. target_if_spectral_find_agile_width(spectral->ch_width);
  2667. if (spectral->capability.advncd_spectral_cap) {
  2668. spectral->lb_edge_extrabins = 0;
  2669. spectral->rb_edge_extrabins = 0;
  2670. if (spectral->is_lb_edge_extrabins_format &&
  2671. spectral->params[smode].ss_rpt_mode == 2) {
  2672. spectral->lb_edge_extrabins = 4;
  2673. }
  2674. if (spectral->is_rb_edge_extrabins_format &&
  2675. spectral->params[smode].ss_rpt_mode == 2) {
  2676. spectral->rb_edge_extrabins = 4;
  2677. }
  2678. if (spectral->ch_width == CH_WIDTH_20MHZ) {
  2679. spectral->sc_spectral_20_40_mode = 0;
  2680. spectral->spectral_numbins =
  2681. target_if_get_fft_bin_count(
  2682. spectral->params[smode].ss_fft_size);
  2683. spectral->spectral_fft_len =
  2684. target_if_get_fft_bin_count(
  2685. spectral->params[smode].ss_fft_size);
  2686. spectral->spectral_data_len =
  2687. target_if_get_fft_bin_count(
  2688. spectral->params[smode].ss_fft_size);
  2689. /*
  2690. * Initialize classifier params to be sent to user
  2691. * space classifier
  2692. */
  2693. spectral->classifier_params.lower_chan_in_mhz =
  2694. current_channel;
  2695. spectral->classifier_params.upper_chan_in_mhz = 0;
  2696. } else if (spectral->ch_width == CH_WIDTH_40MHZ) {
  2697. /* TODO : Remove this variable */
  2698. spectral->sc_spectral_20_40_mode = 1;
  2699. spectral->spectral_numbins =
  2700. target_if_get_fft_bin_count(
  2701. spectral->params[smode].ss_fft_size);
  2702. spectral->spectral_fft_len =
  2703. target_if_get_fft_bin_count(
  2704. spectral->params[smode].ss_fft_size);
  2705. spectral->spectral_data_len =
  2706. target_if_get_fft_bin_count(
  2707. spectral->params[smode].ss_fft_size);
  2708. /*
  2709. * Initialize classifier params to be sent to user
  2710. * space classifier
  2711. */
  2712. if (extension_channel < current_channel) {
  2713. spectral->classifier_params.lower_chan_in_mhz =
  2714. extension_channel;
  2715. spectral->classifier_params.upper_chan_in_mhz =
  2716. current_channel;
  2717. } else {
  2718. spectral->classifier_params.lower_chan_in_mhz =
  2719. current_channel;
  2720. spectral->classifier_params.upper_chan_in_mhz =
  2721. extension_channel;
  2722. }
  2723. } else if (spectral->ch_width == CH_WIDTH_80MHZ) {
  2724. /* Set the FFT Size */
  2725. /* TODO : Remove this variable */
  2726. spectral->sc_spectral_20_40_mode = 0;
  2727. spectral->spectral_numbins =
  2728. target_if_get_fft_bin_count(
  2729. spectral->params[smode].ss_fft_size);
  2730. spectral->spectral_fft_len =
  2731. target_if_get_fft_bin_count(
  2732. spectral->params[smode].ss_fft_size);
  2733. spectral->spectral_data_len =
  2734. target_if_get_fft_bin_count(
  2735. spectral->params[smode].ss_fft_size);
  2736. /*
  2737. * Initialize classifier params to be sent to user
  2738. * space classifier
  2739. */
  2740. spectral->classifier_params.lower_chan_in_mhz =
  2741. current_channel;
  2742. spectral->classifier_params.upper_chan_in_mhz = 0;
  2743. /*
  2744. * Initialize classifier params to be sent to user
  2745. * space classifier
  2746. */
  2747. if (extension_channel < current_channel) {
  2748. spectral->classifier_params.lower_chan_in_mhz =
  2749. extension_channel;
  2750. spectral->classifier_params.upper_chan_in_mhz =
  2751. current_channel;
  2752. } else {
  2753. spectral->classifier_params.lower_chan_in_mhz =
  2754. current_channel;
  2755. spectral->classifier_params.upper_chan_in_mhz =
  2756. extension_channel;
  2757. }
  2758. } else if (spectral->ch_width == CH_WIDTH_160MHZ) {
  2759. /* Set the FFT Size */
  2760. /* The below applies to both 160 and 80+80 cases */
  2761. /* TODO : Remove this variable */
  2762. spectral->sc_spectral_20_40_mode = 0;
  2763. spectral->spectral_numbins =
  2764. target_if_get_fft_bin_count(
  2765. spectral->params[smode].ss_fft_size);
  2766. spectral->spectral_fft_len =
  2767. target_if_get_fft_bin_count(
  2768. spectral->params[smode].ss_fft_size);
  2769. spectral->spectral_data_len =
  2770. target_if_get_fft_bin_count(
  2771. spectral->params[smode].ss_fft_size);
  2772. /*
  2773. * Initialize classifier params to be sent to user
  2774. * space classifier
  2775. */
  2776. spectral->classifier_params.lower_chan_in_mhz =
  2777. current_channel;
  2778. spectral->classifier_params.upper_chan_in_mhz = 0;
  2779. /*
  2780. * Initialize classifier params to be sent to user
  2781. * space classifier
  2782. */
  2783. if (extension_channel < current_channel) {
  2784. spectral->classifier_params.lower_chan_in_mhz =
  2785. extension_channel;
  2786. spectral->classifier_params.upper_chan_in_mhz =
  2787. current_channel;
  2788. } else {
  2789. spectral->classifier_params.lower_chan_in_mhz =
  2790. current_channel;
  2791. spectral->classifier_params.upper_chan_in_mhz =
  2792. extension_channel;
  2793. }
  2794. }
  2795. if (spectral->spectral_numbins) {
  2796. spectral->spectral_numbins +=
  2797. spectral->lb_edge_extrabins;
  2798. spectral->spectral_numbins +=
  2799. spectral->rb_edge_extrabins;
  2800. }
  2801. if (spectral->spectral_fft_len) {
  2802. spectral->spectral_fft_len +=
  2803. spectral->lb_edge_extrabins;
  2804. spectral->spectral_fft_len +=
  2805. spectral->rb_edge_extrabins;
  2806. }
  2807. if (spectral->spectral_data_len) {
  2808. spectral->spectral_data_len +=
  2809. spectral->lb_edge_extrabins;
  2810. spectral->spectral_data_len +=
  2811. spectral->rb_edge_extrabins;
  2812. }
  2813. } else {
  2814. /*
  2815. * The decision to find 20/40 mode is found based on the
  2816. * presence of extension channel
  2817. * instead of channel width, as the channel width can
  2818. * dynamically change
  2819. */
  2820. if (extension_channel == 0) {
  2821. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  2822. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  2823. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  2824. spectral->spectral_data_len =
  2825. SPECTRAL_HT20_TOTAL_DATA_LEN;
  2826. /* only valid in 20-40 mode */
  2827. spectral->spectral_lower_max_index_offset = -1;
  2828. /* only valid in 20-40 mode */
  2829. spectral->spectral_upper_max_index_offset = -1;
  2830. spectral->spectral_max_index_offset =
  2831. spectral->spectral_fft_len + 2;
  2832. spectral->sc_spectral_20_40_mode = 0;
  2833. /*
  2834. * Initialize classifier params to be sent to user
  2835. * space classifier
  2836. */
  2837. spectral->classifier_params.lower_chan_in_mhz =
  2838. current_channel;
  2839. spectral->classifier_params.upper_chan_in_mhz = 0;
  2840. } else {
  2841. spectral->spectral_numbins =
  2842. SPECTRAL_HT40_TOTAL_NUM_BINS;
  2843. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  2844. spectral->spectral_data_len =
  2845. SPECTRAL_HT40_TOTAL_DATA_LEN;
  2846. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  2847. /* only valid in 20 mode */
  2848. spectral->spectral_max_index_offset = -1;
  2849. spectral->spectral_lower_max_index_offset =
  2850. spectral->spectral_fft_len + 2;
  2851. spectral->spectral_upper_max_index_offset =
  2852. spectral->spectral_fft_len + 5;
  2853. spectral->sc_spectral_20_40_mode = 1;
  2854. /*
  2855. * Initialize classifier params to be sent to user
  2856. * space classifier
  2857. */
  2858. if (extension_channel < current_channel) {
  2859. spectral->classifier_params.lower_chan_in_mhz =
  2860. extension_channel;
  2861. spectral->classifier_params.upper_chan_in_mhz =
  2862. current_channel;
  2863. } else {
  2864. spectral->classifier_params.lower_chan_in_mhz =
  2865. current_channel;
  2866. spectral->classifier_params.upper_chan_in_mhz =
  2867. extension_channel;
  2868. }
  2869. }
  2870. }
  2871. spectral->send_single_packet = 0;
  2872. spectral->classifier_params.spectral_20_40_mode =
  2873. spectral->sc_spectral_20_40_mode;
  2874. spectral->classifier_params.spectral_dc_index =
  2875. spectral->spectral_dc_index;
  2876. spectral->spectral_sent_msg = 0;
  2877. spectral->classify_scan = 0;
  2878. spectral->num_spectral_data = 0;
  2879. if (!p_sops->is_spectral_active(spectral, smode)) {
  2880. p_sops->configure_spectral(spectral, spectral_params, smode);
  2881. p_sops->start_spectral_scan(spectral, smode, err);
  2882. spectral->timestamp_war_offset[smode] = 0;
  2883. spectral->last_fft_timestamp[smode] = 0;
  2884. }
  2885. /* get current spectral configuration */
  2886. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  2887. target_if_init_upper_lower_flags(spectral);
  2888. return 0;
  2889. }
  2890. /**
  2891. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  2892. * Agile DFS
  2893. * @psoc: Pointer to psoc
  2894. * @object: Pointer to pdev
  2895. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  2896. *
  2897. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  2898. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  2899. *
  2900. * Return: void
  2901. */
  2902. static void
  2903. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  2904. void *object, void *arg)
  2905. {
  2906. bool *is_aspectral_prohibited = arg;
  2907. struct wlan_objmgr_pdev *cur_pdev = object;
  2908. bool is_agile_dfs_enabled_cur_pdev = false;
  2909. QDF_STATUS status;
  2910. qdf_assert_always(is_aspectral_prohibited);
  2911. if (*is_aspectral_prohibited)
  2912. return;
  2913. qdf_assert_always(psoc);
  2914. qdf_assert_always(cur_pdev);
  2915. status = ucfg_dfs_get_agile_precac_enable
  2916. (cur_pdev,
  2917. &is_agile_dfs_enabled_cur_pdev);
  2918. if (QDF_IS_STATUS_ERROR(status)) {
  2919. spectral_err("Get agile precac failed, prohibiting aSpectral");
  2920. *is_aspectral_prohibited = true;
  2921. return;
  2922. }
  2923. if (is_agile_dfs_enabled_cur_pdev) {
  2924. spectral_err("aDFS is in progress on one of the pdevs");
  2925. *is_aspectral_prohibited = true;
  2926. }
  2927. }
  2928. /**
  2929. * target_if_get_curr_band() - Get current operating band of pdev
  2930. *
  2931. * @spectral: pointer to spectral object
  2932. *
  2933. * API to get current operating band of a given pdev.
  2934. *
  2935. * Return: if success enum reg_wifi_band, REG_BAND_UNKNOWN in case of failure
  2936. */
  2937. static enum reg_wifi_band
  2938. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev)
  2939. {
  2940. struct wlan_objmgr_vdev *vdev;
  2941. int16_t chan_freq;
  2942. enum reg_wifi_band cur_band;
  2943. if (!pdev) {
  2944. spectral_err("pdev is NULL");
  2945. return REG_BAND_UNKNOWN;
  2946. }
  2947. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  2948. if (!vdev) {
  2949. spectral_debug("vdev is NULL");
  2950. return REG_BAND_UNKNOWN;
  2951. }
  2952. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2953. cur_band = wlan_reg_freq_to_band(chan_freq);
  2954. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2955. return cur_band;
  2956. }
  2957. /**
  2958. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  2959. * any of the 5G pdevs
  2960. * @psoc: Pointer to psoc
  2961. * @object: Pointer to pdev
  2962. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  2963. * progress in any 5G pdevs
  2964. *
  2965. * Return: void
  2966. */
  2967. static void
  2968. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  2969. void *object, void *arg)
  2970. {
  2971. enum reg_wifi_band band;
  2972. bool *is_agile_scan_inprog_5g_pdev = arg;
  2973. struct target_if_spectral *spectral;
  2974. struct wlan_objmgr_pdev *cur_pdev = object;
  2975. struct target_if_spectral_ops *p_sops;
  2976. if (*is_agile_scan_inprog_5g_pdev)
  2977. return;
  2978. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  2979. if (!spectral) {
  2980. spectral_err("target if spectral handle is NULL");
  2981. return;
  2982. }
  2983. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2984. band = target_if_get_curr_band(cur_pdev);
  2985. if (band == REG_BAND_UNKNOWN) {
  2986. spectral_debug("Failed to get current band");
  2987. return;
  2988. }
  2989. if (band == REG_BAND_5G &&
  2990. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  2991. *is_agile_scan_inprog_5g_pdev = true;
  2992. }
  2993. /**
  2994. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  2995. * for current vdev rx chainmask.
  2996. *
  2997. * @spectral: Pointer to Spectral object
  2998. * @is_supported: Pointer to is_supported
  2999. *
  3000. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3001. */
  3002. static QDF_STATUS
  3003. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  3004. bool *is_supported)
  3005. {
  3006. struct wlan_objmgr_vdev *vdev;
  3007. uint8_t vdev_rxchainmask;
  3008. struct wlan_objmgr_psoc *psoc;
  3009. struct wlan_objmgr_pdev *pdev;
  3010. struct target_psoc_info *tgt_psoc_info;
  3011. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  3012. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  3013. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  3014. struct wlan_psoc_host_chainmask_table *table;
  3015. int j;
  3016. uint32_t table_id;
  3017. enum phy_ch_width ch_width;
  3018. uint8_t pdev_id;
  3019. if (!spectral) {
  3020. spectral_err("spectral target if object is null");
  3021. return QDF_STATUS_E_FAILURE;
  3022. }
  3023. if (!is_supported) {
  3024. spectral_err("is supported argument is null");
  3025. return QDF_STATUS_E_FAILURE;
  3026. }
  3027. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  3028. spectral_err("HW Agile mode is not supported up to gen 2");
  3029. return QDF_STATUS_E_FAILURE;
  3030. }
  3031. pdev = spectral->pdev_obj;
  3032. if (!pdev) {
  3033. spectral_err("pdev is null");
  3034. return QDF_STATUS_E_FAILURE;
  3035. }
  3036. psoc = wlan_pdev_get_psoc(pdev);
  3037. if (!psoc) {
  3038. spectral_err("psoc is null");
  3039. return QDF_STATUS_E_FAILURE;
  3040. }
  3041. vdev = target_if_spectral_get_vdev(spectral);
  3042. if (!vdev) {
  3043. spectral_err("First vdev is NULL");
  3044. return QDF_STATUS_E_FAILURE;
  3045. }
  3046. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  3047. if (!vdev_rxchainmask) {
  3048. spectral_err("vdev rx chainmask is zero");
  3049. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3050. return QDF_STATUS_E_FAILURE;
  3051. }
  3052. ch_width = target_if_vdev_get_ch_width(vdev);
  3053. if (ch_width == CH_WIDTH_INVALID) {
  3054. spectral_err("Invalid channel width");
  3055. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3056. return QDF_STATUS_E_FAILURE;
  3057. }
  3058. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3059. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  3060. if (!tgt_psoc_info) {
  3061. spectral_err("target_psoc_info is null");
  3062. return QDF_STATUS_E_FAILURE;
  3063. }
  3064. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  3065. if (!ext_svc_param) {
  3066. spectral_err("Extended service ready param null");
  3067. return QDF_STATUS_E_FAILURE;
  3068. }
  3069. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  3070. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  3071. if (!mac_phy_cap_arr) {
  3072. spectral_err("mac phy cap array is null");
  3073. return QDF_STATUS_E_FAILURE;
  3074. }
  3075. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  3076. if (!mac_phy_cap) {
  3077. spectral_err("mac phy cap is null");
  3078. return QDF_STATUS_E_FAILURE;
  3079. }
  3080. table_id = mac_phy_cap->chainmask_table_id;
  3081. table = &ext_svc_param->chainmask_table[table_id];
  3082. if (!table) {
  3083. spectral_err("chainmask table not found");
  3084. return QDF_STATUS_E_FAILURE;
  3085. }
  3086. for (j = 0; j < table->num_valid_chainmasks; j++) {
  3087. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  3088. if (ch_width <= CH_WIDTH_80MHZ)
  3089. *is_supported =
  3090. table->cap_list[j].supports_aSpectral;
  3091. else
  3092. *is_supported =
  3093. table->cap_list[j].supports_aSpectral_160;
  3094. break;
  3095. }
  3096. }
  3097. if (j == table->num_valid_chainmasks) {
  3098. spectral_err("vdev rx chainmask %u not found in table id = %u",
  3099. vdev_rxchainmask, table_id);
  3100. return QDF_STATUS_E_FAILURE;
  3101. }
  3102. return QDF_STATUS_SUCCESS;
  3103. }
  3104. QDF_STATUS
  3105. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3106. const enum spectral_scan_mode smode,
  3107. enum spectral_cp_error_code *err)
  3108. {
  3109. struct target_if_spectral_ops *p_sops;
  3110. struct target_if_spectral *spectral;
  3111. struct wlan_objmgr_psoc *psoc;
  3112. enum reg_wifi_band band;
  3113. if (!err) {
  3114. spectral_err("Error code argument is null");
  3115. QDF_ASSERT(0);
  3116. }
  3117. *err = SPECTRAL_SCAN_ERR_INVALID;
  3118. psoc = wlan_pdev_get_psoc(pdev);
  3119. if (!psoc) {
  3120. spectral_err("psoc is null");
  3121. return QDF_STATUS_E_FAILURE;
  3122. }
  3123. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3124. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3125. spectral_err("Invalid Spectral mode %u", smode);
  3126. return QDF_STATUS_E_FAILURE;
  3127. }
  3128. if (!pdev) {
  3129. spectral_err("pdev object is NUll");
  3130. return QDF_STATUS_E_FAILURE;
  3131. }
  3132. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3133. if (!spectral) {
  3134. spectral_err("Spectral LMAC object is NUll");
  3135. return QDF_STATUS_E_FAILURE;
  3136. }
  3137. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3138. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3139. QDF_STATUS status;
  3140. bool is_supported = false;
  3141. status = target_if_is_agile_supported_cur_chmask(spectral,
  3142. &is_supported);
  3143. if (QDF_IS_STATUS_ERROR(status)) {
  3144. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3145. return QDF_STATUS_E_FAILURE;
  3146. }
  3147. if (!is_supported) {
  3148. spectral_err("aSpectral unsupported for cur chainmask");
  3149. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3150. return QDF_STATUS_E_FAILURE;
  3151. }
  3152. }
  3153. band = target_if_get_curr_band(spectral->pdev_obj);
  3154. if (band == REG_BAND_UNKNOWN) {
  3155. spectral_err("Failed to get current band");
  3156. return QDF_STATUS_E_FAILURE;
  3157. }
  3158. if ((band == REG_BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  3159. struct target_psoc_info *tgt_hdl;
  3160. enum wmi_host_hw_mode_config_type mode;
  3161. bool is_agile_scan_inprog_5g_pdev;
  3162. if (p_sops->is_spectral_active(spectral,
  3163. SPECTRAL_SCAN_MODE_AGILE)) {
  3164. spectral_err("Agile Scan in progress in current pdev");
  3165. return QDF_STATUS_E_FAILURE;
  3166. }
  3167. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  3168. if (!tgt_hdl) {
  3169. target_if_err("target_psoc_info is null");
  3170. return QDF_STATUS_E_FAILURE;
  3171. }
  3172. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  3173. switch (mode) {
  3174. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  3175. case WMI_HOST_HW_MODE_SBS:
  3176. case WMI_HOST_HW_MODE_DBS_SBS:
  3177. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  3178. is_agile_scan_inprog_5g_pdev = false;
  3179. wlan_objmgr_iterate_obj_list
  3180. (psoc, WLAN_PDEV_OP,
  3181. target_if_is_agile_scan_active_in_5g,
  3182. &is_agile_scan_inprog_5g_pdev, 0,
  3183. WLAN_SPECTRAL_ID);
  3184. break;
  3185. default:
  3186. is_agile_scan_inprog_5g_pdev = false;
  3187. break;
  3188. }
  3189. if (is_agile_scan_inprog_5g_pdev) {
  3190. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  3191. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3192. return QDF_STATUS_E_FAILURE;
  3193. }
  3194. }
  3195. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3196. bool is_aspectral_prohibited = false;
  3197. QDF_STATUS status;
  3198. status = wlan_objmgr_iterate_obj_list
  3199. (psoc, WLAN_PDEV_OP,
  3200. target_if_is_aspectral_prohibited_by_adfs,
  3201. &is_aspectral_prohibited, 0,
  3202. WLAN_SPECTRAL_ID);
  3203. if (QDF_IS_STATUS_ERROR(status)) {
  3204. spectral_err("Failed to iterate over pdevs");
  3205. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3206. return QDF_STATUS_E_FAILURE;
  3207. }
  3208. if (is_aspectral_prohibited) {
  3209. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3210. return QDF_STATUS_E_FAILURE;
  3211. }
  3212. }
  3213. if (!spectral->params_valid[smode]) {
  3214. target_if_spectral_info_read(spectral,
  3215. smode,
  3216. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3217. &spectral->params[smode],
  3218. sizeof(spectral->params[smode]));
  3219. spectral->params_valid[smode] = true;
  3220. }
  3221. qdf_spin_lock(&spectral->spectral_lock);
  3222. if (smode == SPECTRAL_SCAN_MODE_AGILE &&
  3223. !spectral->params[smode].ss_frequency) {
  3224. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  3225. qdf_spin_unlock(&spectral->spectral_lock);
  3226. return QDF_STATUS_E_FAILURE;
  3227. }
  3228. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3229. QDF_STATUS status;
  3230. bool is_overlapping;
  3231. status = target_if_is_agile_span_overlap_with_operating_span
  3232. (spectral,
  3233. spectral->params[smode].ss_frequency,
  3234. &is_overlapping);
  3235. if (QDF_IS_STATUS_ERROR(status)) {
  3236. qdf_spin_unlock(&spectral->spectral_lock);
  3237. return QDF_STATUS_E_FAILURE;
  3238. }
  3239. if (is_overlapping) {
  3240. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3241. qdf_spin_unlock(&spectral->spectral_lock);
  3242. return QDF_STATUS_E_FAILURE;
  3243. }
  3244. }
  3245. target_if_spectral_scan_enable_params(spectral,
  3246. &spectral->params[smode], smode,
  3247. err);
  3248. qdf_spin_unlock(&spectral->spectral_lock);
  3249. return QDF_STATUS_SUCCESS;
  3250. }
  3251. QDF_STATUS
  3252. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3253. const enum spectral_scan_mode smode,
  3254. enum spectral_cp_error_code *err)
  3255. {
  3256. struct target_if_spectral_ops *p_sops;
  3257. struct target_if_spectral *spectral;
  3258. if (!err) {
  3259. spectral_err("Error code argument is null");
  3260. QDF_ASSERT(0);
  3261. }
  3262. *err = SPECTRAL_SCAN_ERR_INVALID;
  3263. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3264. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3265. spectral_err("Invalid Spectral mode %u", smode);
  3266. return QDF_STATUS_E_FAILURE;
  3267. }
  3268. if (!pdev) {
  3269. spectral_err("pdev object is NUll ");
  3270. return QDF_STATUS_E_FAILURE;
  3271. }
  3272. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3273. if (!spectral) {
  3274. spectral_err("Spectral LMAC object is NUll ");
  3275. return QDF_STATUS_E_FAILURE;
  3276. }
  3277. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3278. qdf_spin_lock(&spectral->spectral_lock);
  3279. p_sops->stop_spectral_scan(spectral, smode);
  3280. if (spectral->classify_scan) {
  3281. /* TODO : Check if this logic is necessary */
  3282. spectral->detects_control_channel = 0;
  3283. spectral->detects_extension_channel = 0;
  3284. spectral->detects_above_dc = 0;
  3285. spectral->detects_below_dc = 0;
  3286. spectral->classify_scan = 0;
  3287. }
  3288. spectral->send_single_packet = 0;
  3289. spectral->sc_spectral_scan = 0;
  3290. qdf_spin_unlock(&spectral->spectral_lock);
  3291. return QDF_STATUS_SUCCESS;
  3292. }
  3293. /**
  3294. * target_if_is_spectral_active() - Get whether Spectral is active
  3295. * @pdev: Pointer to pdev object
  3296. * @smode: Spectral scan mode
  3297. *
  3298. * API to get whether Spectral is active
  3299. *
  3300. * Return: True if Spectral is active, false if Spectral is not active
  3301. */
  3302. bool
  3303. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  3304. const enum spectral_scan_mode smode)
  3305. {
  3306. struct target_if_spectral *spectral = NULL;
  3307. struct target_if_spectral_ops *p_sops = NULL;
  3308. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3309. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3310. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3311. spectral_err("Invalid Spectral mode %u", smode);
  3312. return QDF_STATUS_E_FAILURE;
  3313. }
  3314. return p_sops->is_spectral_active(spectral, smode);
  3315. }
  3316. /**
  3317. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  3318. * @pdev: Pointer to pdev object
  3319. * @smode: Spectral scan mode
  3320. *
  3321. * API to get whether Spectral is enabled
  3322. *
  3323. * Return: True if Spectral is enabled, false if Spectral is not enabled
  3324. */
  3325. bool
  3326. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  3327. enum spectral_scan_mode smode)
  3328. {
  3329. struct target_if_spectral *spectral = NULL;
  3330. struct target_if_spectral_ops *p_sops = NULL;
  3331. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3332. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3333. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3334. spectral_err("Invalid Spectral mode %u", smode);
  3335. return QDF_STATUS_E_FAILURE;
  3336. }
  3337. return p_sops->is_spectral_enabled(spectral, smode);
  3338. }
  3339. #ifdef DIRECT_BUF_RX_DEBUG
  3340. /**
  3341. * target_if_spectral_do_dbr_ring_debug() - Start/Stop Spectral DMA ring debug
  3342. * @pdev: Pointer to pdev object
  3343. * @enable: Enable/Disable Spectral DMA ring debug
  3344. *
  3345. * Start/stop Spectral DMA ring debug based on @enable.
  3346. * Also save the state for future use.
  3347. *
  3348. * Return: QDF_STATUS of operation
  3349. */
  3350. static QDF_STATUS
  3351. target_if_spectral_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3352. {
  3353. struct target_if_spectral *spectral;
  3354. struct wlan_lmac_if_tx_ops *tx_ops;
  3355. struct wlan_objmgr_psoc *psoc;
  3356. if (!pdev)
  3357. return QDF_STATUS_E_FAILURE;
  3358. psoc = wlan_pdev_get_psoc(pdev);
  3359. if (!psoc) {
  3360. spectral_err("psoc is null");
  3361. return QDF_STATUS_E_INVAL;
  3362. }
  3363. tx_ops = &psoc->soc_cb.tx_ops;
  3364. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3365. if (!spectral) {
  3366. spectral_err("Spectal LMAC object is NULL");
  3367. return QDF_STATUS_E_INVAL;
  3368. }
  3369. /* Save the state */
  3370. spectral->dbr_ring_debug = enable;
  3371. if (enable)
  3372. return tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug(
  3373. pdev, 0, SPECTRAL_DBR_RING_DEBUG_SIZE);
  3374. else
  3375. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug(
  3376. pdev, 0);
  3377. return QDF_STATUS_SUCCESS;
  3378. }
  3379. /**
  3380. * target_if_spectral_do_dbr_buff_debug() - Start/Stop Spectral DMA buffer debug
  3381. * @pdev: Pointer to pdev object
  3382. * @enable: Enable/Disable Spectral DMA buffer debug
  3383. *
  3384. * Start/stop Spectral DMA buffer debug based on @enable.
  3385. * Also save the state for future use.
  3386. *
  3387. * Return: QDF_STATUS of operation
  3388. */
  3389. static QDF_STATUS
  3390. target_if_spectral_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev, bool enable)
  3391. {
  3392. struct target_if_spectral *spectral;
  3393. struct wlan_lmac_if_tx_ops *tx_ops;
  3394. struct wlan_objmgr_psoc *psoc;
  3395. if (!pdev)
  3396. return QDF_STATUS_E_FAILURE;
  3397. psoc = wlan_pdev_get_psoc(pdev);
  3398. if (!psoc) {
  3399. spectral_err("psoc is null");
  3400. return QDF_STATUS_E_INVAL;
  3401. }
  3402. tx_ops = &psoc->soc_cb.tx_ops;
  3403. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3404. if (!spectral) {
  3405. spectral_err("Spectal LMAC object is NULL");
  3406. return QDF_STATUS_E_INVAL;
  3407. }
  3408. /* Save the state */
  3409. spectral->dbr_buff_debug = enable;
  3410. if (enable)
  3411. return tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning(
  3412. pdev, 0, MEM_POISON_SIGNATURE);
  3413. else
  3414. return tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning(
  3415. pdev, 0);
  3416. }
  3417. /**
  3418. * target_if_spectral_check_and_do_dbr_buff_debug() - Start/Stop Spectral buffer
  3419. * debug based on the previous state
  3420. * @pdev: Pointer to pdev object
  3421. *
  3422. * Return: QDF_STATUS of operation
  3423. */
  3424. static QDF_STATUS
  3425. target_if_spectral_check_and_do_dbr_buff_debug(struct wlan_objmgr_pdev *pdev)
  3426. {
  3427. struct target_if_spectral *spectral;
  3428. if (!pdev) {
  3429. spectral_err("pdev is NULL!");
  3430. return QDF_STATUS_E_FAILURE;
  3431. }
  3432. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3433. if (!spectral) {
  3434. spectral_err("Spectal LMAC object is NULL");
  3435. return QDF_STATUS_E_INVAL;
  3436. }
  3437. if (spectral->dbr_buff_debug)
  3438. return target_if_spectral_do_dbr_buff_debug(pdev, true);
  3439. else
  3440. return target_if_spectral_do_dbr_buff_debug(pdev, false);
  3441. }
  3442. /**
  3443. * target_if_spectral_check_and_do_dbr_ring_debug() - Start/Stop Spectral ring
  3444. * debug based on the previous state
  3445. * @pdev: Pointer to pdev object
  3446. *
  3447. * Return: QDF_STATUS of operation
  3448. */
  3449. static QDF_STATUS
  3450. target_if_spectral_check_and_do_dbr_ring_debug(struct wlan_objmgr_pdev *pdev)
  3451. {
  3452. struct target_if_spectral *spectral;
  3453. if (!pdev) {
  3454. spectral_err("pdev is NULL!");
  3455. return QDF_STATUS_E_FAILURE;
  3456. }
  3457. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3458. if (!spectral) {
  3459. spectral_err("Spectal LMAC object is NULL");
  3460. return QDF_STATUS_E_INVAL;
  3461. }
  3462. if (spectral->dbr_ring_debug)
  3463. return target_if_spectral_do_dbr_ring_debug(pdev, true);
  3464. else
  3465. return target_if_spectral_do_dbr_ring_debug(pdev, false);
  3466. }
  3467. /**
  3468. * target_if_spectral_set_dma_debug() - Set DMA debug for Spectral
  3469. * @pdev: Pointer to pdev object
  3470. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  3471. * @debug_value: Value to be set for @dma_debug_type
  3472. *
  3473. * Set DMA debug for Spectral and start/stop Spectral DMA debug function
  3474. * based on @debug_value
  3475. *
  3476. * Return: QDF_STATUS of operation
  3477. */
  3478. static QDF_STATUS
  3479. target_if_spectral_set_dma_debug(
  3480. struct wlan_objmgr_pdev *pdev,
  3481. enum spectral_dma_debug dma_debug_type,
  3482. bool debug_value)
  3483. {
  3484. struct target_if_spectral_ops *p_sops;
  3485. struct wlan_objmgr_psoc *psoc;
  3486. struct wlan_lmac_if_tx_ops *tx_ops;
  3487. struct target_if_spectral *spectral;
  3488. if (!pdev)
  3489. return QDF_STATUS_E_FAILURE;
  3490. psoc = wlan_pdev_get_psoc(pdev);
  3491. if (!psoc) {
  3492. spectral_err("psoc is null");
  3493. return QDF_STATUS_E_INVAL;
  3494. }
  3495. tx_ops = &psoc->soc_cb.tx_ops;
  3496. if (!tx_ops->target_tx_ops.tgt_get_tgt_type) {
  3497. spectral_err("Unable to fetch target type");
  3498. return QDF_STATUS_E_FAILURE;
  3499. }
  3500. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3501. if (!spectral) {
  3502. spectral_err("Spectal LMAC object is NULL");
  3503. return QDF_STATUS_E_INVAL;
  3504. }
  3505. if (spectral->direct_dma_support) {
  3506. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3507. if (p_sops->is_spectral_active(spectral,
  3508. SPECTRAL_SCAN_MODE_NORMAL) ||
  3509. p_sops->is_spectral_active(spectral,
  3510. SPECTRAL_SCAN_MODE_AGILE)) {
  3511. spectral_err("Altering DBR debug config isn't allowed during an ongoing scan");
  3512. return QDF_STATUS_E_FAILURE;
  3513. }
  3514. switch (dma_debug_type) {
  3515. case SPECTRAL_DMA_RING_DEBUG:
  3516. target_if_spectral_do_dbr_ring_debug(pdev, debug_value);
  3517. break;
  3518. case SPECTRAL_DMA_BUFFER_DEBUG:
  3519. target_if_spectral_do_dbr_buff_debug(pdev, debug_value);
  3520. break;
  3521. default:
  3522. spectral_err("Unsupported DMA debug type : %d",
  3523. dma_debug_type);
  3524. return QDF_STATUS_E_FAILURE;
  3525. }
  3526. }
  3527. return QDF_STATUS_SUCCESS;
  3528. }
  3529. #endif /* DIRECT_BUF_RX_DEBUG */
  3530. /**
  3531. * target_if_spectral_direct_dma_support() - Get Direct-DMA support
  3532. * @pdev: Pointer to pdev object
  3533. *
  3534. * Return: Whether Direct-DMA is supported on this radio
  3535. */
  3536. static bool
  3537. target_if_spectral_direct_dma_support(struct wlan_objmgr_pdev *pdev)
  3538. {
  3539. struct target_if_spectral *spectral;
  3540. if (!pdev) {
  3541. spectral_err("pdev is NULL!");
  3542. return false;
  3543. }
  3544. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3545. if (!spectral) {
  3546. spectral_err("Spectral LMAC object is NULL");
  3547. return false;
  3548. }
  3549. return spectral->direct_dma_support;
  3550. }
  3551. /**
  3552. * target_if_set_debug_level() - Set debug level for Spectral
  3553. * @pdev: Pointer to pdev object
  3554. * @debug_level: Debug level
  3555. *
  3556. * API to set the debug level for Spectral
  3557. *
  3558. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3559. */
  3560. QDF_STATUS
  3561. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  3562. {
  3563. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  3564. return QDF_STATUS_SUCCESS;
  3565. }
  3566. /**
  3567. * target_if_get_debug_level() - Get debug level for Spectral
  3568. * @pdev: Pointer to pdev object
  3569. *
  3570. * API to get the debug level for Spectral
  3571. *
  3572. * Return: Current debug level
  3573. */
  3574. uint32_t
  3575. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  3576. {
  3577. return spectral_debug_level;
  3578. }
  3579. /**
  3580. * target_if_get_spectral_capinfo() - Get Spectral capability information
  3581. * @pdev: Pointer to pdev object
  3582. * @scaps: Buffer into which data should be copied
  3583. *
  3584. * API to get the spectral capability information
  3585. *
  3586. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3587. */
  3588. QDF_STATUS
  3589. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  3590. struct spectral_caps *scaps)
  3591. {
  3592. struct target_if_spectral *spectral = NULL;
  3593. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3594. qdf_mem_copy(scaps, &spectral->capability,
  3595. sizeof(struct spectral_caps));
  3596. return QDF_STATUS_SUCCESS;
  3597. }
  3598. /**
  3599. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  3600. * @pdev: Pointer to pdev object
  3601. * @stats: Buffer into which data should be copied
  3602. *
  3603. * API to get the spectral diagnostic statistics
  3604. *
  3605. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3606. */
  3607. QDF_STATUS
  3608. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  3609. struct spectral_diag_stats *stats)
  3610. {
  3611. struct target_if_spectral *spectral = NULL;
  3612. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3613. qdf_mem_copy(stats, &spectral->diag_stats,
  3614. sizeof(struct spectral_diag_stats));
  3615. return QDF_STATUS_SUCCESS;
  3616. }
  3617. /**
  3618. * target_if_register_wmi_spectral_cmd_ops() - Register wmi_spectral_cmd_ops
  3619. * @cmd_ops: Pointer to the structure having wmi_spectral_cmd function pointers
  3620. * @pdev: Pointer to pdev object
  3621. *
  3622. * API for register wmi_spectral_cmd_ops in spectral internal data structure
  3623. *
  3624. * Return: void
  3625. */
  3626. void
  3627. target_if_register_wmi_spectral_cmd_ops(struct wlan_objmgr_pdev *pdev,
  3628. struct wmi_spectral_cmd_ops *cmd_ops)
  3629. {
  3630. struct target_if_spectral *spectral =
  3631. get_target_if_spectral_handle_from_pdev(pdev);
  3632. if (!spectral) {
  3633. spectral_err("Spectral LMAC object is null");
  3634. return;
  3635. }
  3636. spectral->param_wmi_cmd_ops = *cmd_ops;
  3637. }
  3638. /**
  3639. * target_if_register_netlink_cb() - Register Netlink callbacks
  3640. * @pdev: Pointer to pdev object
  3641. * @nl_cb: Netlink callbacks to register
  3642. *
  3643. * Return: void
  3644. */
  3645. static void
  3646. target_if_register_netlink_cb(
  3647. struct wlan_objmgr_pdev *pdev,
  3648. struct spectral_nl_cb *nl_cb)
  3649. {
  3650. struct target_if_spectral *spectral = NULL;
  3651. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3652. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  3653. if (spectral->use_nl_bcast)
  3654. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  3655. else
  3656. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  3657. }
  3658. /**
  3659. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  3660. * Netlink messages to the application layer
  3661. * @pdev: Pointer to pdev object
  3662. *
  3663. * Return: true for broadcast, false for unicast
  3664. */
  3665. static bool
  3666. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  3667. {
  3668. struct target_if_spectral *spectral = NULL;
  3669. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3670. return spectral->use_nl_bcast;
  3671. }
  3672. /**
  3673. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  3674. * @pdev: Pointer to pdev object
  3675. *
  3676. * Return: void
  3677. */
  3678. static void
  3679. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  3680. {
  3681. struct target_if_spectral *spectral = NULL;
  3682. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3683. if (!spectral) {
  3684. spectral_err("SPECTRAL : Module doesn't exist");
  3685. return;
  3686. }
  3687. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  3688. }
  3689. static int
  3690. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  3691. void *payload)
  3692. {
  3693. struct target_if_spectral *spectral = NULL;
  3694. struct target_if_spectral_ops *p_sops = NULL;
  3695. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3696. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3697. return p_sops->process_spectral_report(pdev, payload);
  3698. }
  3699. #ifdef DIRECT_BUF_RX_DEBUG
  3700. static inline void
  3701. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3702. {
  3703. if (!tx_ops)
  3704. return;
  3705. tx_ops->sptrl_tx_ops.sptrlto_set_dma_debug =
  3706. target_if_spectral_set_dma_debug;
  3707. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_ring_debug =
  3708. target_if_spectral_check_and_do_dbr_ring_debug;
  3709. tx_ops->sptrl_tx_ops.sptrlto_check_and_do_dbr_buff_debug =
  3710. target_if_spectral_check_and_do_dbr_buff_debug;
  3711. }
  3712. #else
  3713. static inline void
  3714. target_if_sptrl_debug_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3715. {
  3716. }
  3717. #endif
  3718. void
  3719. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3720. {
  3721. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  3722. target_if_pdev_spectral_init;
  3723. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  3724. target_if_pdev_spectral_deinit;
  3725. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  3726. target_if_set_spectral_config;
  3727. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  3728. target_if_get_spectral_config;
  3729. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  3730. target_if_start_spectral_scan;
  3731. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  3732. target_if_stop_spectral_scan;
  3733. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  3734. target_if_is_spectral_active;
  3735. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  3736. target_if_is_spectral_enabled;
  3737. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  3738. target_if_set_debug_level;
  3739. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  3740. target_if_get_debug_level;
  3741. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  3742. target_if_get_spectral_capinfo;
  3743. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  3744. target_if_get_spectral_diagstats;
  3745. tx_ops->sptrl_tx_ops.sptrlto_register_wmi_spectral_cmd_ops =
  3746. target_if_register_wmi_spectral_cmd_ops;
  3747. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  3748. target_if_register_netlink_cb;
  3749. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  3750. target_if_use_nl_bcast;
  3751. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  3752. target_if_deregister_netlink_cb;
  3753. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  3754. target_if_process_spectral_report;
  3755. tx_ops->sptrl_tx_ops.sptrlto_direct_dma_support =
  3756. target_if_spectral_direct_dma_support;
  3757. target_if_sptrl_debug_register_tx_ops(tx_ops);
  3758. }
  3759. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  3760. void
  3761. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  3762. uint16_t cw_int, uint32_t dcs_enabled)
  3763. {
  3764. struct spectral_samp_msg *msg = NULL;
  3765. struct target_if_spectral_ops *p_sops = NULL;
  3766. struct target_if_spectral *spectral = NULL;
  3767. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3768. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  3769. spectral->pdev_obj,
  3770. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  3771. SPECTRAL_MSG_BUF_NEW);
  3772. if (msg) {
  3773. msg->int_type = cw_int ?
  3774. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  3775. msg->dcs_enabled = dcs_enabled;
  3776. msg->signature = SPECTRAL_SIGNATURE;
  3777. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3778. p_sops->get_mac_address(spectral, msg->macaddr);
  3779. if (spectral->send_phy_data
  3780. (pdev,
  3781. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  3782. spectral->spectral_sent_msg++;
  3783. }
  3784. }
  3785. qdf_export_symbol(target_if_spectral_send_intf_found_msg);