target_if_spectral.c 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974
  1. /*
  2. * Copyright (c) 2011,2017-2019 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_pdev_spectral_init() - Initialize target_if Spectral
  1761. * functionality for the given pdev
  1762. * @pdev: Pointer to pdev object
  1763. *
  1764. * Function to initialize pointer to spectral target_if internal private data
  1765. *
  1766. * Return: On success, pointer to Spectral target_if internal private data, on
  1767. * failure, NULL
  1768. */
  1769. void *
  1770. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  1771. {
  1772. struct target_if_spectral_ops *p_sops = NULL;
  1773. struct target_if_spectral *spectral = NULL;
  1774. uint32_t target_type;
  1775. uint32_t target_revision;
  1776. struct wlan_objmgr_psoc *psoc;
  1777. struct wlan_lmac_if_target_tx_ops *tx_ops;
  1778. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1779. if (!pdev) {
  1780. spectral_err("SPECTRAL: pdev is NULL!");
  1781. return NULL;
  1782. }
  1783. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  1784. sizeof(struct target_if_spectral));
  1785. if (!spectral)
  1786. return spectral;
  1787. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  1788. /* Store pdev in Spectral */
  1789. spectral->pdev_obj = pdev;
  1790. psoc = wlan_pdev_get_psoc(pdev);
  1791. tx_ops = &psoc->soc_cb.tx_ops.target_tx_ops;
  1792. if (tx_ops->tgt_get_tgt_type) {
  1793. target_type = tx_ops->tgt_get_tgt_type(psoc);
  1794. } else {
  1795. qdf_mem_free(spectral);
  1796. return NULL;
  1797. }
  1798. if (tx_ops->tgt_get_tgt_revision) {
  1799. target_revision = tx_ops->tgt_get_tgt_revision(psoc);
  1800. } else {
  1801. qdf_mem_free(spectral);
  1802. return NULL;
  1803. }
  1804. /* init the function ptr table */
  1805. target_if_spectral_init_dummy_function_table(spectral);
  1806. /* get spectral function table */
  1807. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1808. /* TODO : Should this be called here of after ath_attach ? */
  1809. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  1810. spectral_info("HAL_CAP_PHYDIAG : Capable");
  1811. /* TODO: Need to fix the capablity check for RADAR */
  1812. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  1813. spectral_info("HAL_CAP_RADAR : Capable");
  1814. /* TODO : Need to fix the capablity check for SPECTRAL */
  1815. /* TODO : Should this be called here of after ath_attach ? */
  1816. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  1817. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  1818. qdf_spinlock_create(&spectral->spectral_lock);
  1819. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  1820. target_if_spectral_clear_stats(spectral);
  1821. if (target_type == TARGET_TYPE_QCA8074V2)
  1822. spectral->fftbin_size_war =
  1823. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE;
  1824. else if (target_type == TARGET_TYPE_QCA8074 ||
  1825. target_type == TARGET_TYPE_QCA6018 ||
  1826. target_type == TARGET_TYPE_QCA6390)
  1827. spectral->fftbin_size_war =
  1828. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE;
  1829. else
  1830. spectral->fftbin_size_war = SPECTRAL_FFTBIN_SIZE_NO_WAR;
  1831. if (target_type == TARGET_TYPE_QCA8074 ||
  1832. target_type == TARGET_TYPE_QCA8074V2 ||
  1833. target_type == TARGET_TYPE_QCA6018) {
  1834. spectral->inband_fftbin_size_adj = 1;
  1835. spectral->null_fftbin_adj = 1;
  1836. } else {
  1837. spectral->inband_fftbin_size_adj = 0;
  1838. spectral->null_fftbin_adj = 0;
  1839. }
  1840. if ((target_type == TARGET_TYPE_QCA8074) ||
  1841. (target_type == TARGET_TYPE_QCA8074V2) ||
  1842. (target_type == TARGET_TYPE_QCA6018) ||
  1843. (target_type == TARGET_TYPE_QCN9000) ||
  1844. (target_type == TARGET_TYPE_QCA6290) ||
  1845. (target_type == TARGET_TYPE_QCA6390)) {
  1846. spectral->spectral_gen = SPECTRAL_GEN3;
  1847. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  1848. spectral->tag_sscan_summary_exp =
  1849. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  1850. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  1851. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  1852. spectral->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3;
  1853. spectral->fft_size_max = SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3;
  1854. } else {
  1855. spectral->spectral_gen = SPECTRAL_GEN2;
  1856. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  1857. spectral->tag_sscan_summary_exp =
  1858. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  1859. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  1860. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  1861. spectral->fft_size_min = SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2;
  1862. spectral->fft_size_max = SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2;
  1863. }
  1864. target_if_init_spectral_param_properties(spectral);
  1865. /* Init spectral capability */
  1866. if (target_if_init_spectral_capability(spectral) !=
  1867. QDF_STATUS_SUCCESS) {
  1868. qdf_mem_free(spectral);
  1869. return NULL;
  1870. }
  1871. if (target_if_spectral_attach_simulation(spectral) < 0)
  1872. return NULL;
  1873. target_if_init_spectral_ops(spectral);
  1874. /* Spectral mode specific init */
  1875. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++) {
  1876. spectral->last_fft_timestamp[smode] = 0;
  1877. spectral->timestamp_war_offset[smode] = 0;
  1878. spectral->params_valid[smode] = false;
  1879. qdf_spinlock_create(&spectral->param_info[smode].osps_lock);
  1880. spectral->param_info[smode].osps_cache.osc_is_valid = 0;
  1881. }
  1882. target_if_spectral_register_funcs(spectral, &spectral_ops);
  1883. if (target_if_spectral_check_hw_capability(spectral) == false) {
  1884. target_if_spectral_detach(spectral);
  1885. spectral = NULL;
  1886. } else {
  1887. /*
  1888. * TODO: Once the driver architecture transitions to chipset
  1889. * versioning based checks, reflect this here.
  1890. */
  1891. spectral->is_160_format = false;
  1892. spectral->is_lb_edge_extrabins_format = false;
  1893. spectral->is_rb_edge_extrabins_format = false;
  1894. if (target_type == TARGET_TYPE_QCA9984 ||
  1895. target_type == TARGET_TYPE_QCA9888) {
  1896. spectral->is_160_format = true;
  1897. spectral->is_lb_edge_extrabins_format = true;
  1898. spectral->is_rb_edge_extrabins_format = true;
  1899. } else if ((target_type == TARGET_TYPE_AR900B) &&
  1900. (target_revision == AR900B_REV_2)) {
  1901. spectral->is_rb_edge_extrabins_format = true;
  1902. }
  1903. if (target_type == TARGET_TYPE_QCA9984 ||
  1904. target_type == TARGET_TYPE_QCA9888)
  1905. spectral->is_sec80_rssi_war_required = true;
  1906. spectral->use_nl_bcast = SPECTRAL_USE_NL_BCAST;
  1907. if (spectral->spectral_gen == SPECTRAL_GEN3)
  1908. init_160mhz_delivery_state_machine(spectral);
  1909. }
  1910. return spectral;
  1911. }
  1912. /**
  1913. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  1914. * functionality for the given pdev
  1915. * @pdev: Pointer to pdev object
  1916. *
  1917. * Function to de-initialize pointer to spectral target_if internal private data
  1918. *
  1919. * Return: None
  1920. */
  1921. void
  1922. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  1923. {
  1924. struct target_if_spectral *spectral = NULL;
  1925. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1926. if (!spectral) {
  1927. spectral_err("SPECTRAL : Module doesn't exist");
  1928. return;
  1929. }
  1930. target_if_spectral_detach(spectral);
  1931. return;
  1932. }
  1933. /* target_if_spectral_find_agile_width() - Given a channel width enum, find the
  1934. * corresponding translation for Agile channel width.
  1935. * Translation schema of different operating modes:
  1936. * 20 -> 20, 40 -> 40, (80 & 160 & 80_80) -> 80.
  1937. * @chwidth: Channel width enum.
  1938. *
  1939. * Return: The translated channel width enum.
  1940. */
  1941. static enum phy_ch_width
  1942. target_if_spectral_find_agile_width(enum phy_ch_width chwidth)
  1943. {
  1944. switch (chwidth) {
  1945. case CH_WIDTH_20MHZ:
  1946. return CH_WIDTH_20MHZ;
  1947. case CH_WIDTH_40MHZ:
  1948. return CH_WIDTH_40MHZ;
  1949. case CH_WIDTH_80MHZ:
  1950. case CH_WIDTH_80P80MHZ:
  1951. case CH_WIDTH_160MHZ:
  1952. return CH_WIDTH_80MHZ;
  1953. default:
  1954. spectral_err("Invalid chwidth enum %d", chwidth);
  1955. return CH_WIDTH_INVALID;
  1956. }
  1957. }
  1958. /**
  1959. * target_if_calculate_center_freq() - Helper routine to
  1960. * check whether given frequency is center frequency of a
  1961. * WLAN channel
  1962. *
  1963. * @spectral: Pointer to Spectral object
  1964. * @chan_freq: Center frequency of a WLAN channel
  1965. * @is_valid: Indicates whether given frequency is valid
  1966. *
  1967. * Return: QDF_STATUS
  1968. */
  1969. static QDF_STATUS
  1970. target_if_is_center_freq_of_any_chan(struct wlan_objmgr_pdev *pdev,
  1971. uint32_t chan_freq,
  1972. bool *is_valid)
  1973. {
  1974. struct regulatory_channel *cur_chan_list;
  1975. int i;
  1976. if (!pdev) {
  1977. spectral_err("pdev object is null");
  1978. return QDF_STATUS_E_FAILURE;
  1979. }
  1980. if (!is_valid) {
  1981. spectral_err("is valid argument is null");
  1982. return QDF_STATUS_E_FAILURE;
  1983. }
  1984. cur_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*cur_chan_list));
  1985. if (!cur_chan_list)
  1986. return QDF_STATUS_E_FAILURE;
  1987. if (wlan_reg_get_current_chan_list(
  1988. pdev, cur_chan_list) != QDF_STATUS_SUCCESS) {
  1989. spectral_err("Failed to get cur_chan list");
  1990. qdf_mem_free(cur_chan_list);
  1991. return QDF_STATUS_E_FAILURE;
  1992. }
  1993. *is_valid = false;
  1994. for (i = 0; i < NUM_CHANNELS; i++) {
  1995. uint32_t flags;
  1996. uint32_t center_freq;
  1997. flags = cur_chan_list[i].chan_flags;
  1998. center_freq = cur_chan_list[i].center_freq;
  1999. if (!(flags & REGULATORY_CHAN_DISABLED) &&
  2000. (center_freq == chan_freq)) {
  2001. *is_valid = true;
  2002. break;
  2003. }
  2004. }
  2005. qdf_mem_free(cur_chan_list);
  2006. return QDF_STATUS_SUCCESS;
  2007. }
  2008. /**
  2009. * target_if_calculate_center_freq() - Helper routine to
  2010. * find the center frequency of the agile span from a
  2011. * WLAN channel center frequency
  2012. *
  2013. * @spectral: Pointer to Spectral object
  2014. * @chan_freq: Center frequency of a WLAN channel
  2015. * @center_freq: Pointer to center frequency
  2016. *
  2017. * Return: QDF_STATUS
  2018. */
  2019. static QDF_STATUS
  2020. target_if_calculate_center_freq(struct target_if_spectral *spectral,
  2021. uint16_t chan_freq,
  2022. uint16_t *center_freq)
  2023. {
  2024. struct wlan_objmgr_vdev *vdev;
  2025. enum phy_ch_width ch_width;
  2026. enum phy_ch_width agile_ch_width;
  2027. uint16_t chan_num;
  2028. if (!spectral) {
  2029. spectral_err("spectral target if object is null");
  2030. return QDF_STATUS_E_FAILURE;
  2031. }
  2032. if (!center_freq) {
  2033. spectral_err("center_freq argument is null");
  2034. return QDF_STATUS_E_FAILURE;
  2035. }
  2036. chan_num = wlan_reg_freq_to_chan(spectral->pdev_obj, chan_freq);
  2037. vdev = target_if_spectral_get_vdev(spectral);
  2038. if (!vdev) {
  2039. spectral_err("vdev is NULL");
  2040. return QDF_STATUS_E_FAILURE;
  2041. }
  2042. ch_width = target_if_vdev_get_ch_width(vdev);
  2043. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2044. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2045. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2046. *center_freq = chan_freq;
  2047. } else {
  2048. uint16_t start_freq;
  2049. uint16_t end_freq;
  2050. const struct bonded_channel *bonded_chan_ptr = NULL;
  2051. wlan_reg_get_5g_bonded_channel_and_state
  2052. (spectral->pdev_obj, chan_num, agile_ch_width,
  2053. &bonded_chan_ptr);
  2054. if (!bonded_chan_ptr) {
  2055. spectral_err("Bonded channel is not found");
  2056. return QDF_STATUS_E_FAILURE;
  2057. }
  2058. start_freq = wlan_reg_chan_to_freq(spectral->pdev_obj,
  2059. bonded_chan_ptr->start_ch);
  2060. end_freq = wlan_reg_chan_to_freq(spectral->pdev_obj,
  2061. bonded_chan_ptr->end_ch);
  2062. *center_freq = (start_freq + end_freq) >> 1;
  2063. }
  2064. return QDF_STATUS_SUCCESS;
  2065. }
  2066. /**
  2067. * target_if_validate_center_freq() - Helper routine to
  2068. * validate user provided agile center frequency
  2069. *
  2070. * @spectral: Pointer to Spectral object
  2071. * @center_freq: User provided agile span center frequency
  2072. * @is_valid: Indicates whether agile span center frequency is valid
  2073. *
  2074. * Return: QDF_STATUS
  2075. */
  2076. static QDF_STATUS
  2077. target_if_validate_center_freq(struct target_if_spectral *spectral,
  2078. uint16_t center_freq,
  2079. bool *is_valid)
  2080. {
  2081. struct wlan_objmgr_vdev *vdev;
  2082. enum phy_ch_width ch_width;
  2083. enum phy_ch_width agile_ch_width;
  2084. uint16_t chan_num;
  2085. struct wlan_objmgr_pdev *pdev;
  2086. QDF_STATUS status;
  2087. if (!spectral) {
  2088. spectral_err("spectral target if object is null");
  2089. return QDF_STATUS_E_FAILURE;
  2090. }
  2091. if (!is_valid) {
  2092. spectral_err("is_valid argument is null");
  2093. return QDF_STATUS_E_FAILURE;
  2094. }
  2095. pdev = spectral->pdev_obj;
  2096. vdev = target_if_spectral_get_vdev(spectral);
  2097. if (!vdev) {
  2098. spectral_err("vdev is NULL");
  2099. return QDF_STATUS_E_FAILURE;
  2100. }
  2101. ch_width = target_if_vdev_get_ch_width(vdev);
  2102. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2103. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2104. if (agile_ch_width == CH_WIDTH_20MHZ) {
  2105. status = target_if_is_center_freq_of_any_chan
  2106. (pdev, center_freq, is_valid);
  2107. if (QDF_IS_STATUS_ERROR(status))
  2108. return QDF_STATUS_E_FAILURE;
  2109. } else {
  2110. uint16_t start_freq;
  2111. uint16_t end_freq;
  2112. const struct bonded_channel *bonded_chan_ptr = NULL;
  2113. bool is_chan;
  2114. status = target_if_is_center_freq_of_any_chan
  2115. (pdev, center_freq + 10, &is_chan);
  2116. if (QDF_IS_STATUS_ERROR(status))
  2117. return QDF_STATUS_E_FAILURE;
  2118. if (is_chan) {
  2119. uint32_t calulated_center_freq;
  2120. chan_num = wlan_reg_freq_to_chan(pdev,
  2121. center_freq + 10);
  2122. wlan_reg_get_5g_bonded_channel_and_state
  2123. (pdev, chan_num, agile_ch_width,
  2124. &bonded_chan_ptr);
  2125. if (!bonded_chan_ptr) {
  2126. spectral_err("Bonded channel is not found");
  2127. return QDF_STATUS_E_FAILURE;
  2128. }
  2129. start_freq = wlan_reg_chan_to_freq
  2130. (pdev, bonded_chan_ptr->start_ch);
  2131. end_freq = wlan_reg_chan_to_freq
  2132. (pdev, bonded_chan_ptr->end_ch);
  2133. calulated_center_freq = (start_freq + end_freq) >> 1;
  2134. *is_valid = (center_freq == calulated_center_freq);
  2135. } else {
  2136. *is_valid = false;
  2137. }
  2138. }
  2139. return QDF_STATUS_SUCCESS;
  2140. }
  2141. /**
  2142. * target_if_is_agile_span_overlap_with_operating_span() - Helper routine to
  2143. * check whether agile span overlaps with current operating band.
  2144. *
  2145. * @spectral: Pointer to Spectral object
  2146. * @ss_frequency: Agile span center frequency
  2147. * @is_overlapping: Indicates whether Agile span overlaps with operating span
  2148. *
  2149. * Helper routine to check whether agile span overlaps with current
  2150. * operating band.
  2151. *
  2152. * Return: QDF_STATUS
  2153. */
  2154. static QDF_STATUS
  2155. target_if_is_agile_span_overlap_with_operating_span
  2156. (struct target_if_spectral *spectral,
  2157. uint32_t ss_frequency,
  2158. bool *is_overlapping)
  2159. {
  2160. uint32_t chan_num;
  2161. enum phy_ch_width ch_width;
  2162. enum phy_ch_width agile_ch_width;
  2163. const struct bonded_channel *bonded_chan_ptr = NULL;
  2164. struct wlan_objmgr_vdev *vdev;
  2165. struct wlan_objmgr_pdev *pdev;
  2166. int16_t chan_freq;
  2167. uint32_t op_start_freq;
  2168. uint32_t op_end_freq;
  2169. uint32_t agile_start_freq;
  2170. uint32_t agile_end_freq;
  2171. uint32_t cfreq2;
  2172. if (!spectral) {
  2173. spectral_err("Spectral object is NULL");
  2174. return QDF_STATUS_E_FAILURE;
  2175. }
  2176. pdev = spectral->pdev_obj;
  2177. if (!pdev) {
  2178. spectral_err("pdev object is NULL");
  2179. return QDF_STATUS_E_FAILURE;
  2180. }
  2181. if (!is_overlapping) {
  2182. spectral_err("Argument(is_overlapping) is NULL");
  2183. return QDF_STATUS_E_FAILURE;
  2184. }
  2185. vdev = target_if_spectral_get_vdev(spectral);
  2186. if (!vdev) {
  2187. spectral_err("vdev is NULL");
  2188. return QDF_STATUS_E_FAILURE;
  2189. }
  2190. ch_width = target_if_vdev_get_ch_width(vdev);
  2191. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2192. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  2193. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2194. if (cfreq2 < 0)
  2195. return QDF_STATUS_E_FAILURE;
  2196. chan_num = wlan_reg_freq_to_chan(pdev, chan_freq);
  2197. if (ch_width == CH_WIDTH_20MHZ) {
  2198. op_start_freq = chan_freq - 10;
  2199. op_end_freq = chan_freq + 10;
  2200. } else {
  2201. wlan_reg_get_5g_bonded_channel_and_state
  2202. (pdev, chan_num, ch_width, &bonded_chan_ptr);
  2203. if (!bonded_chan_ptr) {
  2204. spectral_err("Bonded channel is not found");
  2205. return QDF_STATUS_E_FAILURE;
  2206. }
  2207. op_start_freq =
  2208. wlan_reg_chan_to_freq(pdev,
  2209. bonded_chan_ptr->start_ch) - 10;
  2210. op_end_freq =
  2211. wlan_reg_chan_to_freq(pdev,
  2212. bonded_chan_ptr->end_ch) + 10;
  2213. }
  2214. agile_ch_width = target_if_spectral_find_agile_width(ch_width);
  2215. if (agile_ch_width == CH_WIDTH_INVALID)
  2216. return QDF_STATUS_E_FAILURE;
  2217. agile_start_freq = ss_frequency -
  2218. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2219. agile_end_freq = ss_frequency +
  2220. (wlan_reg_get_bw_value(agile_ch_width) >> 1);
  2221. if (agile_end_freq <= op_start_freq || op_end_freq <= agile_start_freq)
  2222. *is_overlapping = false;
  2223. else
  2224. *is_overlapping = true;
  2225. /* Use non zero cfreq2 to identify 80p80 */
  2226. if (cfreq2) {
  2227. uint32_t sec80_start_feq;
  2228. uint32_t sec80_end_freq;
  2229. sec80_start_feq = cfreq2 - 40;
  2230. sec80_end_freq = cfreq2 + 40;
  2231. if ((agile_end_freq > sec80_start_feq) &&
  2232. (sec80_end_freq > agile_start_freq))
  2233. *is_overlapping = true;
  2234. }
  2235. return QDF_STATUS_SUCCESS;
  2236. }
  2237. /**
  2238. * _target_if_set_spectral_config() - Set spectral config
  2239. * @spectral: Pointer to spectral object
  2240. * @threshtype: config type
  2241. * @value: config value
  2242. * @smode: Spectral scan mode
  2243. * @err: Spectral error code
  2244. *
  2245. * API to set spectral configurations
  2246. *
  2247. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2248. */
  2249. static QDF_STATUS
  2250. _target_if_set_spectral_config(struct target_if_spectral *spectral,
  2251. const uint32_t threshtype, const uint32_t value,
  2252. const enum spectral_scan_mode smode,
  2253. enum spectral_cp_error_code *err)
  2254. {
  2255. struct spectral_config params;
  2256. struct target_if_spectral_ops *p_sops;
  2257. struct spectral_config *sparams;
  2258. QDF_STATUS status;
  2259. bool is_overlapping;
  2260. uint16_t agile_cfreq;
  2261. bool is_valid_chan;
  2262. if (!err) {
  2263. spectral_err("Error code argument is null");
  2264. QDF_ASSERT(0);
  2265. }
  2266. *err = SPECTRAL_SCAN_ERR_INVALID;
  2267. if (!spectral) {
  2268. spectral_err("spectral object is NULL");
  2269. return QDF_STATUS_E_FAILURE;
  2270. }
  2271. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2272. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2273. spectral_err("Invalid Spectral mode %u", smode);
  2274. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2275. return QDF_STATUS_E_FAILURE;
  2276. }
  2277. sparams = &spectral->params[smode];
  2278. if (!spectral->params_valid[smode]) {
  2279. target_if_spectral_info_read(spectral,
  2280. smode,
  2281. TARGET_IF_SPECTRAL_INFO_PARAMS,
  2282. &spectral->params[smode],
  2283. sizeof(spectral->params[smode]));
  2284. spectral->params_valid[smode] = true;
  2285. }
  2286. switch (threshtype) {
  2287. case SPECTRAL_PARAM_FFT_PERIOD:
  2288. sparams->ss_fft_period = value;
  2289. break;
  2290. case SPECTRAL_PARAM_SCAN_PERIOD:
  2291. sparams->ss_period = value;
  2292. break;
  2293. case SPECTRAL_PARAM_SCAN_COUNT:
  2294. sparams->ss_count = value;
  2295. break;
  2296. case SPECTRAL_PARAM_SHORT_REPORT:
  2297. sparams->ss_short_report = (!!value) ? true : false;
  2298. break;
  2299. case SPECTRAL_PARAM_SPECT_PRI:
  2300. sparams->ss_spectral_pri = (!!value) ? true : false;
  2301. break;
  2302. case SPECTRAL_PARAM_FFT_SIZE:
  2303. if ((value < spectral->fft_size_min) ||
  2304. (value > spectral->fft_size_max)) {
  2305. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2306. return QDF_STATUS_E_FAILURE;
  2307. }
  2308. sparams->ss_fft_size = value;
  2309. break;
  2310. case SPECTRAL_PARAM_GC_ENA:
  2311. sparams->ss_gc_ena = !!value;
  2312. break;
  2313. case SPECTRAL_PARAM_RESTART_ENA:
  2314. sparams->ss_restart_ena = !!value;
  2315. break;
  2316. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  2317. sparams->ss_noise_floor_ref = value;
  2318. break;
  2319. case SPECTRAL_PARAM_INIT_DELAY:
  2320. sparams->ss_init_delay = value;
  2321. break;
  2322. case SPECTRAL_PARAM_NB_TONE_THR:
  2323. sparams->ss_nb_tone_thr = value;
  2324. break;
  2325. case SPECTRAL_PARAM_STR_BIN_THR:
  2326. sparams->ss_str_bin_thr = value;
  2327. break;
  2328. case SPECTRAL_PARAM_WB_RPT_MODE:
  2329. sparams->ss_wb_rpt_mode = !!value;
  2330. break;
  2331. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  2332. sparams->ss_rssi_rpt_mode = !!value;
  2333. break;
  2334. case SPECTRAL_PARAM_RSSI_THR:
  2335. sparams->ss_rssi_thr = value;
  2336. break;
  2337. case SPECTRAL_PARAM_PWR_FORMAT:
  2338. sparams->ss_pwr_format = !!value;
  2339. break;
  2340. case SPECTRAL_PARAM_RPT_MODE:
  2341. if ((value < SPECTRAL_PARAM_RPT_MODE_MIN) ||
  2342. (value > SPECTRAL_PARAM_RPT_MODE_MAX)) {
  2343. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2344. return QDF_STATUS_E_FAILURE;
  2345. }
  2346. sparams->ss_rpt_mode = value;
  2347. break;
  2348. case SPECTRAL_PARAM_BIN_SCALE:
  2349. sparams->ss_bin_scale = value;
  2350. break;
  2351. case SPECTRAL_PARAM_DBM_ADJ:
  2352. sparams->ss_dbm_adj = !!value;
  2353. break;
  2354. case SPECTRAL_PARAM_CHN_MASK:
  2355. sparams->ss_chn_mask = value;
  2356. break;
  2357. case SPECTRAL_PARAM_FREQUENCY:
  2358. status = target_if_is_center_freq_of_any_chan
  2359. (spectral->pdev_obj, value, &is_valid_chan);
  2360. if (QDF_IS_STATUS_ERROR(status))
  2361. return QDF_STATUS_E_FAILURE;
  2362. if (is_valid_chan) {
  2363. status = target_if_calculate_center_freq(spectral,
  2364. value,
  2365. &agile_cfreq);
  2366. if (QDF_IS_STATUS_ERROR(status)) {
  2367. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2368. return QDF_STATUS_E_FAILURE;
  2369. }
  2370. } else {
  2371. bool is_valid_agile_cfreq;
  2372. status = target_if_validate_center_freq
  2373. (spectral, value, &is_valid_agile_cfreq);
  2374. if (QDF_IS_STATUS_ERROR(status))
  2375. return QDF_STATUS_E_FAILURE;
  2376. if (!is_valid_agile_cfreq) {
  2377. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2378. spectral_err("Invalid agile center frequency");
  2379. return QDF_STATUS_E_FAILURE;
  2380. }
  2381. agile_cfreq = value;
  2382. }
  2383. status = target_if_is_agile_span_overlap_with_operating_span
  2384. (spectral, agile_cfreq, &is_overlapping);
  2385. if (QDF_IS_STATUS_ERROR(status))
  2386. return QDF_STATUS_E_FAILURE;
  2387. if (is_overlapping) {
  2388. spectral_err("Agile span overlapping with current BW");
  2389. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  2390. return QDF_STATUS_E_FAILURE;
  2391. }
  2392. sparams->ss_frequency = agile_cfreq;
  2393. break;
  2394. }
  2395. p_sops->configure_spectral(spectral, sparams, smode);
  2396. /* only to validate the writes */
  2397. p_sops->get_spectral_config(spectral, &params, smode);
  2398. return QDF_STATUS_SUCCESS;
  2399. }
  2400. QDF_STATUS
  2401. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  2402. const uint32_t threshtype, const uint32_t value,
  2403. const enum spectral_scan_mode smode,
  2404. enum spectral_cp_error_code *err)
  2405. {
  2406. enum spectral_scan_mode mode = SPECTRAL_SCAN_MODE_NORMAL;
  2407. struct target_if_spectral *spectral;
  2408. QDF_STATUS status;
  2409. if (!err) {
  2410. spectral_err("Error code argument is null");
  2411. QDF_ASSERT(0);
  2412. }
  2413. *err = SPECTRAL_SCAN_ERR_INVALID;
  2414. if (!pdev) {
  2415. spectral_err("pdev object is NULL");
  2416. return QDF_STATUS_E_FAILURE;
  2417. }
  2418. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2419. if (!spectral) {
  2420. spectral_err("spectral object is NULL");
  2421. return QDF_STATUS_E_FAILURE;
  2422. }
  2423. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2424. spectral_err("Invalid Spectral mode %u", smode);
  2425. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  2426. return QDF_STATUS_E_FAILURE;
  2427. }
  2428. if (!spectral->properties[smode][threshtype].supported) {
  2429. spectral_err("Spectral parameter(%u) unsupported for mode %u",
  2430. threshtype, smode);
  2431. *err = SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED;
  2432. return QDF_STATUS_E_FAILURE;
  2433. }
  2434. if (spectral->properties[smode][threshtype].common_all_modes) {
  2435. spectral_warn("Setting Spectral parameter %u for all modes",
  2436. threshtype);
  2437. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++) {
  2438. status = _target_if_set_spectral_config
  2439. (spectral, threshtype, value,
  2440. mode, err);
  2441. if (QDF_IS_STATUS_ERROR(status))
  2442. return QDF_STATUS_E_FAILURE;
  2443. }
  2444. return QDF_STATUS_SUCCESS;
  2445. }
  2446. return _target_if_set_spectral_config(spectral, threshtype,
  2447. value, smode, err);
  2448. }
  2449. /**
  2450. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  2451. * @fft_len: FFT length
  2452. * @pdev: Pointer to pdev object
  2453. *
  2454. * API to get fft bin count for a given fft length
  2455. *
  2456. * Return: FFt bin count
  2457. */
  2458. static int
  2459. target_if_get_fft_bin_count(int fft_len)
  2460. {
  2461. int bin_count = 0;
  2462. switch (fft_len) {
  2463. case 5:
  2464. bin_count = 16;
  2465. break;
  2466. case 6:
  2467. bin_count = 32;
  2468. break;
  2469. case 7:
  2470. bin_count = 64;
  2471. break;
  2472. case 8:
  2473. bin_count = 128;
  2474. break;
  2475. case 9:
  2476. bin_count = 256;
  2477. break;
  2478. default:
  2479. break;
  2480. }
  2481. return bin_count;
  2482. }
  2483. /**
  2484. * target_if_init_upper_lower_flags() - Initializes control and extension
  2485. * segment flags
  2486. * @fft_len: FFT length
  2487. * @pdev: Pointer to pdev object
  2488. *
  2489. * API to initialize the control and extension flags with the lower/upper
  2490. * segment based on the HT mode
  2491. *
  2492. * Return: FFt bin count
  2493. */
  2494. static void
  2495. target_if_init_upper_lower_flags(struct target_if_spectral *spectral)
  2496. {
  2497. int current_channel = 0;
  2498. int ext_channel = 0;
  2499. struct target_if_spectral_ops *p_sops =
  2500. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2501. current_channel = p_sops->get_current_channel(spectral);
  2502. ext_channel = p_sops->get_extension_channel(spectral);
  2503. if ((current_channel == 0) || (ext_channel == 0))
  2504. return;
  2505. if (spectral->sc_spectral_20_40_mode) {
  2506. /* HT40 mode */
  2507. if (ext_channel < current_channel) {
  2508. spectral->lower_is_extension = 1;
  2509. spectral->upper_is_control = 1;
  2510. spectral->lower_is_control = 0;
  2511. spectral->upper_is_extension = 0;
  2512. } else {
  2513. spectral->lower_is_extension = 0;
  2514. spectral->upper_is_control = 0;
  2515. spectral->lower_is_control = 1;
  2516. spectral->upper_is_extension = 1;
  2517. }
  2518. } else {
  2519. /* HT20 mode, lower is always control */
  2520. spectral->lower_is_extension = 0;
  2521. spectral->upper_is_control = 0;
  2522. spectral->lower_is_control = 1;
  2523. spectral->upper_is_extension = 0;
  2524. }
  2525. }
  2526. /**
  2527. * target_if_get_spectral_config() - Get spectral configuration
  2528. * @pdev: Pointer to pdev object
  2529. * @param: Pointer to spectral_config structure in which the configuration
  2530. * should be returned
  2531. * @smode: Spectral scan mode
  2532. *
  2533. * API to get the current spectral configuration
  2534. *
  2535. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2536. */
  2537. QDF_STATUS
  2538. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  2539. struct spectral_config *param,
  2540. enum spectral_scan_mode smode)
  2541. {
  2542. struct target_if_spectral_ops *p_sops = NULL;
  2543. struct target_if_spectral *spectral = NULL;
  2544. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2545. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2546. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2547. spectral_err("Invalid Spectral mode %u", smode);
  2548. return QDF_STATUS_E_FAILURE;
  2549. }
  2550. qdf_mem_zero(param, sizeof(struct spectral_config));
  2551. p_sops->get_spectral_config(spectral, param, smode);
  2552. return QDF_STATUS_SUCCESS;
  2553. }
  2554. /**
  2555. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  2556. * parameters
  2557. * @spectral: Pointer to Spectral target_if internal private data
  2558. * @spectral_params: Pointer to Spectral parameters
  2559. * @smode: Spectral scan mode
  2560. * @err: Spectral error code
  2561. *
  2562. * Enable use of desired Spectral parameters by configuring them into HW, and
  2563. * starting Spectral scan
  2564. *
  2565. * Return: 0 on success, 1 on failure
  2566. */
  2567. int
  2568. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  2569. struct spectral_config *spectral_params,
  2570. enum spectral_scan_mode smode,
  2571. enum spectral_cp_error_code *err)
  2572. {
  2573. int extension_channel = 0;
  2574. int current_channel = 0;
  2575. struct target_if_spectral_ops *p_sops = NULL;
  2576. struct wlan_objmgr_vdev *vdev = NULL;
  2577. if (!spectral) {
  2578. spectral_err("Spectral LMAC object is NULL");
  2579. return 1;
  2580. }
  2581. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2582. spectral_err("Invalid Spectral mode %u", smode);
  2583. return 1;
  2584. }
  2585. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2586. if (!p_sops) {
  2587. spectral_err("p_sops is NULL");
  2588. return 1;
  2589. }
  2590. spectral->sc_spectral_noise_pwr_cal =
  2591. spectral_params->ss_spectral_pri ? 1 : 0;
  2592. /* check if extension channel is present */
  2593. extension_channel = p_sops->get_extension_channel(spectral);
  2594. current_channel = p_sops->get_current_channel(spectral);
  2595. vdev = target_if_spectral_get_vdev(spectral);
  2596. if (!vdev)
  2597. return 1;
  2598. spectral->ch_width = target_if_vdev_get_ch_width(vdev);
  2599. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2600. if (spectral->ch_width == CH_WIDTH_INVALID)
  2601. return 1;
  2602. if (spectral->capability.advncd_spectral_cap) {
  2603. spectral->lb_edge_extrabins = 0;
  2604. spectral->rb_edge_extrabins = 0;
  2605. if (spectral->is_lb_edge_extrabins_format &&
  2606. spectral->params[smode].ss_rpt_mode == 2) {
  2607. spectral->lb_edge_extrabins = 4;
  2608. }
  2609. if (spectral->is_rb_edge_extrabins_format &&
  2610. spectral->params[smode].ss_rpt_mode == 2) {
  2611. spectral->rb_edge_extrabins = 4;
  2612. }
  2613. if (spectral->ch_width == CH_WIDTH_20MHZ) {
  2614. spectral->sc_spectral_20_40_mode = 0;
  2615. spectral->spectral_numbins =
  2616. target_if_get_fft_bin_count(
  2617. spectral->params[smode].ss_fft_size);
  2618. spectral->spectral_fft_len =
  2619. target_if_get_fft_bin_count(
  2620. spectral->params[smode].ss_fft_size);
  2621. spectral->spectral_data_len =
  2622. target_if_get_fft_bin_count(
  2623. spectral->params[smode].ss_fft_size);
  2624. /*
  2625. * Initialize classifier params to be sent to user
  2626. * space classifier
  2627. */
  2628. spectral->classifier_params.lower_chan_in_mhz =
  2629. current_channel;
  2630. spectral->classifier_params.upper_chan_in_mhz = 0;
  2631. } else if (spectral->ch_width == CH_WIDTH_40MHZ) {
  2632. /* TODO : Remove this variable */
  2633. spectral->sc_spectral_20_40_mode = 1;
  2634. spectral->spectral_numbins =
  2635. target_if_get_fft_bin_count(
  2636. spectral->params[smode].ss_fft_size);
  2637. spectral->spectral_fft_len =
  2638. target_if_get_fft_bin_count(
  2639. spectral->params[smode].ss_fft_size);
  2640. spectral->spectral_data_len =
  2641. target_if_get_fft_bin_count(
  2642. spectral->params[smode].ss_fft_size);
  2643. /*
  2644. * Initialize classifier params to be sent to user
  2645. * space classifier
  2646. */
  2647. if (extension_channel < current_channel) {
  2648. spectral->classifier_params.lower_chan_in_mhz =
  2649. extension_channel;
  2650. spectral->classifier_params.upper_chan_in_mhz =
  2651. current_channel;
  2652. } else {
  2653. spectral->classifier_params.lower_chan_in_mhz =
  2654. current_channel;
  2655. spectral->classifier_params.upper_chan_in_mhz =
  2656. extension_channel;
  2657. }
  2658. } else if (spectral->ch_width == CH_WIDTH_80MHZ) {
  2659. /* Set the FFT Size */
  2660. /* TODO : Remove this variable */
  2661. spectral->sc_spectral_20_40_mode = 0;
  2662. spectral->spectral_numbins =
  2663. target_if_get_fft_bin_count(
  2664. spectral->params[smode].ss_fft_size);
  2665. spectral->spectral_fft_len =
  2666. target_if_get_fft_bin_count(
  2667. spectral->params[smode].ss_fft_size);
  2668. spectral->spectral_data_len =
  2669. target_if_get_fft_bin_count(
  2670. spectral->params[smode].ss_fft_size);
  2671. /*
  2672. * Initialize classifier params to be sent to user
  2673. * space classifier
  2674. */
  2675. spectral->classifier_params.lower_chan_in_mhz =
  2676. current_channel;
  2677. spectral->classifier_params.upper_chan_in_mhz = 0;
  2678. /*
  2679. * Initialize classifier params to be sent to user
  2680. * space classifier
  2681. */
  2682. if (extension_channel < current_channel) {
  2683. spectral->classifier_params.lower_chan_in_mhz =
  2684. extension_channel;
  2685. spectral->classifier_params.upper_chan_in_mhz =
  2686. current_channel;
  2687. } else {
  2688. spectral->classifier_params.lower_chan_in_mhz =
  2689. current_channel;
  2690. spectral->classifier_params.upper_chan_in_mhz =
  2691. extension_channel;
  2692. }
  2693. } else if (spectral->ch_width == CH_WIDTH_160MHZ) {
  2694. /* Set the FFT Size */
  2695. /* The below applies to both 160 and 80+80 cases */
  2696. /* TODO : Remove this variable */
  2697. spectral->sc_spectral_20_40_mode = 0;
  2698. spectral->spectral_numbins =
  2699. target_if_get_fft_bin_count(
  2700. spectral->params[smode].ss_fft_size);
  2701. spectral->spectral_fft_len =
  2702. target_if_get_fft_bin_count(
  2703. spectral->params[smode].ss_fft_size);
  2704. spectral->spectral_data_len =
  2705. target_if_get_fft_bin_count(
  2706. spectral->params[smode].ss_fft_size);
  2707. /*
  2708. * Initialize classifier params to be sent to user
  2709. * space classifier
  2710. */
  2711. spectral->classifier_params.lower_chan_in_mhz =
  2712. current_channel;
  2713. spectral->classifier_params.upper_chan_in_mhz = 0;
  2714. /*
  2715. * Initialize classifier params to be sent to user
  2716. * space classifier
  2717. */
  2718. if (extension_channel < current_channel) {
  2719. spectral->classifier_params.lower_chan_in_mhz =
  2720. extension_channel;
  2721. spectral->classifier_params.upper_chan_in_mhz =
  2722. current_channel;
  2723. } else {
  2724. spectral->classifier_params.lower_chan_in_mhz =
  2725. current_channel;
  2726. spectral->classifier_params.upper_chan_in_mhz =
  2727. extension_channel;
  2728. }
  2729. }
  2730. if (spectral->spectral_numbins) {
  2731. spectral->spectral_numbins +=
  2732. spectral->lb_edge_extrabins;
  2733. spectral->spectral_numbins +=
  2734. spectral->rb_edge_extrabins;
  2735. }
  2736. if (spectral->spectral_fft_len) {
  2737. spectral->spectral_fft_len +=
  2738. spectral->lb_edge_extrabins;
  2739. spectral->spectral_fft_len +=
  2740. spectral->rb_edge_extrabins;
  2741. }
  2742. if (spectral->spectral_data_len) {
  2743. spectral->spectral_data_len +=
  2744. spectral->lb_edge_extrabins;
  2745. spectral->spectral_data_len +=
  2746. spectral->rb_edge_extrabins;
  2747. }
  2748. } else {
  2749. /*
  2750. * The decision to find 20/40 mode is found based on the
  2751. * presence of extension channel
  2752. * instead of channel width, as the channel width can
  2753. * dynamically change
  2754. */
  2755. if (extension_channel == 0) {
  2756. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  2757. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  2758. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  2759. spectral->spectral_data_len =
  2760. SPECTRAL_HT20_TOTAL_DATA_LEN;
  2761. /* only valid in 20-40 mode */
  2762. spectral->spectral_lower_max_index_offset = -1;
  2763. /* only valid in 20-40 mode */
  2764. spectral->spectral_upper_max_index_offset = -1;
  2765. spectral->spectral_max_index_offset =
  2766. spectral->spectral_fft_len + 2;
  2767. spectral->sc_spectral_20_40_mode = 0;
  2768. /*
  2769. * Initialize classifier params to be sent to user
  2770. * space classifier
  2771. */
  2772. spectral->classifier_params.lower_chan_in_mhz =
  2773. current_channel;
  2774. spectral->classifier_params.upper_chan_in_mhz = 0;
  2775. } else {
  2776. spectral->spectral_numbins =
  2777. SPECTRAL_HT40_TOTAL_NUM_BINS;
  2778. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  2779. spectral->spectral_data_len =
  2780. SPECTRAL_HT40_TOTAL_DATA_LEN;
  2781. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  2782. /* only valid in 20 mode */
  2783. spectral->spectral_max_index_offset = -1;
  2784. spectral->spectral_lower_max_index_offset =
  2785. spectral->spectral_fft_len + 2;
  2786. spectral->spectral_upper_max_index_offset =
  2787. spectral->spectral_fft_len + 5;
  2788. spectral->sc_spectral_20_40_mode = 1;
  2789. /*
  2790. * Initialize classifier params to be sent to user
  2791. * space classifier
  2792. */
  2793. if (extension_channel < current_channel) {
  2794. spectral->classifier_params.lower_chan_in_mhz =
  2795. extension_channel;
  2796. spectral->classifier_params.upper_chan_in_mhz =
  2797. current_channel;
  2798. } else {
  2799. spectral->classifier_params.lower_chan_in_mhz =
  2800. current_channel;
  2801. spectral->classifier_params.upper_chan_in_mhz =
  2802. extension_channel;
  2803. }
  2804. }
  2805. }
  2806. spectral->send_single_packet = 0;
  2807. spectral->classifier_params.spectral_20_40_mode =
  2808. spectral->sc_spectral_20_40_mode;
  2809. spectral->classifier_params.spectral_dc_index =
  2810. spectral->spectral_dc_index;
  2811. spectral->spectral_sent_msg = 0;
  2812. spectral->classify_scan = 0;
  2813. spectral->num_spectral_data = 0;
  2814. if (!p_sops->is_spectral_active(spectral, smode)) {
  2815. p_sops->configure_spectral(spectral, spectral_params, smode);
  2816. p_sops->start_spectral_scan(spectral, smode, err);
  2817. spectral->timestamp_war_offset[smode] = 0;
  2818. spectral->last_fft_timestamp[smode] = 0;
  2819. }
  2820. /* get current spectral configuration */
  2821. p_sops->get_spectral_config(spectral, &spectral->params[smode], smode);
  2822. target_if_init_upper_lower_flags(spectral);
  2823. return 0;
  2824. }
  2825. /**
  2826. * target_if_is_aspectral_prohibited_by_adfs() - Is Agile Spectral prohibited by
  2827. * Agile DFS
  2828. * @psoc: Pointer to psoc
  2829. * @object: Pointer to pdev
  2830. * @arg: Pointer to flag which indicates whether Agile Spectral is prohibited
  2831. *
  2832. * This API checks whether Agile DFS is running on any of the pdevs. If so, it
  2833. * indicates that Agile Spectral scan is prohibited by Agile DFS.
  2834. *
  2835. * Return: void
  2836. */
  2837. static void
  2838. target_if_is_aspectral_prohibited_by_adfs(struct wlan_objmgr_psoc *psoc,
  2839. void *object, void *arg)
  2840. {
  2841. bool *is_aspectral_prohibited = arg;
  2842. struct wlan_objmgr_pdev *cur_pdev = object;
  2843. bool is_agile_dfs_enabled_cur_pdev = false;
  2844. QDF_STATUS status;
  2845. qdf_assert_always(is_aspectral_prohibited);
  2846. if (*is_aspectral_prohibited)
  2847. return;
  2848. qdf_assert_always(psoc);
  2849. qdf_assert_always(cur_pdev);
  2850. status = ucfg_dfs_get_agile_precac_enable
  2851. (cur_pdev,
  2852. &is_agile_dfs_enabled_cur_pdev);
  2853. if (QDF_IS_STATUS_ERROR(status)) {
  2854. spectral_err("Get agile precac failed, prohibiting aSpectral");
  2855. *is_aspectral_prohibited = true;
  2856. return;
  2857. }
  2858. if (is_agile_dfs_enabled_cur_pdev) {
  2859. spectral_err("aDFS is in progress on one of the pdevs");
  2860. *is_aspectral_prohibited = true;
  2861. }
  2862. }
  2863. /**
  2864. * target_if_get_curr_band() - Get current operating band of pdev
  2865. *
  2866. * @spectral: pointer to spectral object
  2867. *
  2868. * API to get current operating band of a given pdev.
  2869. *
  2870. * Return: if success enum band_info, BAND_UNKNOWN in case of failure
  2871. */
  2872. static enum band_info
  2873. target_if_get_curr_band(struct wlan_objmgr_pdev *pdev)
  2874. {
  2875. struct wlan_objmgr_vdev *vdev;
  2876. int16_t chan_freq;
  2877. enum band_info cur_band;
  2878. uint32_t chan_num;
  2879. if (!pdev) {
  2880. spectral_err("pdev is NULL");
  2881. return BAND_UNKNOWN;
  2882. }
  2883. vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_SPECTRAL_ID);
  2884. if (!vdev) {
  2885. spectral_debug("vdev is NULL");
  2886. return BAND_UNKNOWN;
  2887. }
  2888. chan_freq = target_if_vdev_get_chan_freq(vdev);
  2889. chan_num = wlan_reg_freq_to_chan(pdev, chan_freq);
  2890. cur_band = wlan_reg_chan_to_band(chan_num);
  2891. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2892. return cur_band;
  2893. }
  2894. /**
  2895. * target_if_is_agile_scan_active_in_5g() - Is Agile Spectral scan active on
  2896. * any of the 5G pdevs
  2897. * @psoc: Pointer to psoc
  2898. * @object: Pointer to pdev
  2899. * @arg: Pointer to flag which indicates whether Agile Spectral scan is in
  2900. * progress in any 5G pdevs
  2901. *
  2902. * Return: void
  2903. */
  2904. static void
  2905. target_if_is_agile_scan_active_in_5g(struct wlan_objmgr_psoc *psoc,
  2906. void *object, void *arg)
  2907. {
  2908. enum band_info band;
  2909. bool *is_agile_scan_inprog_5g_pdev = arg;
  2910. struct target_if_spectral *spectral;
  2911. struct wlan_objmgr_pdev *cur_pdev = object;
  2912. struct target_if_spectral_ops *p_sops;
  2913. if (*is_agile_scan_inprog_5g_pdev)
  2914. return;
  2915. spectral = get_target_if_spectral_handle_from_pdev(cur_pdev);
  2916. if (!spectral) {
  2917. spectral_err("target if spectral handle is NULL");
  2918. return;
  2919. }
  2920. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2921. band = target_if_get_curr_band(cur_pdev);
  2922. if (band == BAND_UNKNOWN) {
  2923. spectral_debug("Failed to get current band");
  2924. return;
  2925. }
  2926. if (band == BAND_5G &&
  2927. p_sops->is_spectral_active(spectral, SPECTRAL_SCAN_MODE_AGILE))
  2928. *is_agile_scan_inprog_5g_pdev = true;
  2929. }
  2930. /**
  2931. * target_if_is_agile_supported_cur_chmask() - Is Agile Spectral scan supported
  2932. * for current vdev rx chainmask.
  2933. *
  2934. * @spectral: Pointer to Spectral object
  2935. * @is_supported: Pointer to is_supported
  2936. *
  2937. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  2938. */
  2939. static QDF_STATUS
  2940. target_if_is_agile_supported_cur_chmask(struct target_if_spectral *spectral,
  2941. bool *is_supported)
  2942. {
  2943. struct wlan_objmgr_vdev *vdev;
  2944. uint8_t vdev_rxchainmask;
  2945. struct wlan_objmgr_psoc *psoc;
  2946. struct wlan_objmgr_pdev *pdev;
  2947. struct target_psoc_info *tgt_psoc_info;
  2948. struct wlan_psoc_host_service_ext_param *ext_svc_param;
  2949. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap_arr = NULL;
  2950. struct wlan_psoc_host_mac_phy_caps *mac_phy_cap = NULL;
  2951. struct wlan_psoc_host_chainmask_table *table;
  2952. int j;
  2953. uint32_t table_id;
  2954. enum phy_ch_width ch_width;
  2955. uint8_t pdev_id;
  2956. if (!spectral) {
  2957. spectral_err("spectral target if object is null");
  2958. return QDF_STATUS_E_FAILURE;
  2959. }
  2960. if (!is_supported) {
  2961. spectral_err("is supported argument is null");
  2962. return QDF_STATUS_E_FAILURE;
  2963. }
  2964. if (spectral->spectral_gen <= SPECTRAL_GEN2) {
  2965. spectral_err("HW Agile mode is not supported up to gen 2");
  2966. return QDF_STATUS_E_FAILURE;
  2967. }
  2968. pdev = spectral->pdev_obj;
  2969. if (!pdev) {
  2970. spectral_err("pdev is null");
  2971. return QDF_STATUS_E_FAILURE;
  2972. }
  2973. psoc = wlan_pdev_get_psoc(pdev);
  2974. if (!psoc) {
  2975. spectral_err("psoc is null");
  2976. return QDF_STATUS_E_FAILURE;
  2977. }
  2978. vdev = target_if_spectral_get_vdev(spectral);
  2979. if (!vdev) {
  2980. spectral_err("First vdev is NULL");
  2981. return QDF_STATUS_E_FAILURE;
  2982. }
  2983. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  2984. if (!vdev_rxchainmask) {
  2985. spectral_err("vdev rx chainmask is zero");
  2986. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2987. return QDF_STATUS_E_FAILURE;
  2988. }
  2989. ch_width = target_if_vdev_get_ch_width(vdev);
  2990. if (ch_width == CH_WIDTH_INVALID) {
  2991. spectral_err("Invalid channel width");
  2992. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2993. return QDF_STATUS_E_FAILURE;
  2994. }
  2995. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2996. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  2997. if (!tgt_psoc_info) {
  2998. spectral_err("target_psoc_info is null");
  2999. return QDF_STATUS_E_FAILURE;
  3000. }
  3001. ext_svc_param = target_psoc_get_service_ext_param(tgt_psoc_info);
  3002. if (!ext_svc_param) {
  3003. spectral_err("Extended service ready param null");
  3004. return QDF_STATUS_E_FAILURE;
  3005. }
  3006. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  3007. mac_phy_cap_arr = target_psoc_get_mac_phy_cap(tgt_psoc_info);
  3008. if (!mac_phy_cap_arr) {
  3009. spectral_err("mac phy cap array is null");
  3010. return QDF_STATUS_E_FAILURE;
  3011. }
  3012. mac_phy_cap = &mac_phy_cap_arr[pdev_id];
  3013. if (!mac_phy_cap) {
  3014. spectral_err("mac phy cap is null");
  3015. return QDF_STATUS_E_FAILURE;
  3016. }
  3017. table_id = mac_phy_cap->chainmask_table_id;
  3018. table = &ext_svc_param->chainmask_table[table_id];
  3019. if (!table) {
  3020. spectral_err("chainmask table not found");
  3021. return QDF_STATUS_E_FAILURE;
  3022. }
  3023. for (j = 0; j < table->num_valid_chainmasks; j++) {
  3024. if (table->cap_list[j].chainmask == vdev_rxchainmask) {
  3025. if (ch_width <= CH_WIDTH_80MHZ)
  3026. *is_supported =
  3027. table->cap_list[j].supports_aSpectral;
  3028. else
  3029. *is_supported =
  3030. table->cap_list[j].supports_aSpectral_160;
  3031. break;
  3032. }
  3033. }
  3034. if (j == table->num_valid_chainmasks) {
  3035. spectral_err("vdev rx chainmask %u not found in table id = %u",
  3036. vdev_rxchainmask, table_id);
  3037. return QDF_STATUS_E_FAILURE;
  3038. }
  3039. return QDF_STATUS_SUCCESS;
  3040. }
  3041. QDF_STATUS
  3042. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3043. const enum spectral_scan_mode smode,
  3044. enum spectral_cp_error_code *err)
  3045. {
  3046. struct target_if_spectral_ops *p_sops;
  3047. struct target_if_spectral *spectral;
  3048. struct wlan_objmgr_psoc *psoc;
  3049. enum band_info band;
  3050. if (!err) {
  3051. spectral_err("Error code argument is null");
  3052. QDF_ASSERT(0);
  3053. }
  3054. *err = SPECTRAL_SCAN_ERR_INVALID;
  3055. psoc = wlan_pdev_get_psoc(pdev);
  3056. if (!psoc) {
  3057. spectral_err("psoc is null");
  3058. return QDF_STATUS_E_FAILURE;
  3059. }
  3060. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3061. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3062. spectral_err("Invalid Spectral mode %u", smode);
  3063. return QDF_STATUS_E_FAILURE;
  3064. }
  3065. if (!pdev) {
  3066. spectral_err("pdev object is NUll");
  3067. return QDF_STATUS_E_FAILURE;
  3068. }
  3069. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3070. if (!spectral) {
  3071. spectral_err("Spectral LMAC object is NUll");
  3072. return QDF_STATUS_E_FAILURE;
  3073. }
  3074. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3075. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3076. QDF_STATUS status;
  3077. bool is_supported = false;
  3078. status = target_if_is_agile_supported_cur_chmask(spectral,
  3079. &is_supported);
  3080. if (QDF_IS_STATUS_ERROR(status)) {
  3081. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3082. return QDF_STATUS_E_FAILURE;
  3083. }
  3084. if (!is_supported) {
  3085. spectral_err("aSpectral unsupported for cur chainmask");
  3086. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3087. return QDF_STATUS_E_FAILURE;
  3088. }
  3089. }
  3090. band = target_if_get_curr_band(spectral->pdev_obj);
  3091. if (band == BAND_UNKNOWN) {
  3092. spectral_err("Failed to get current band");
  3093. return QDF_STATUS_E_FAILURE;
  3094. }
  3095. if ((band == BAND_5G) && (smode == SPECTRAL_SCAN_MODE_AGILE)) {
  3096. struct target_psoc_info *tgt_hdl;
  3097. enum wmi_host_hw_mode_config_type mode;
  3098. bool is_agile_scan_inprog_5g_pdev;
  3099. if (p_sops->is_spectral_active(spectral,
  3100. SPECTRAL_SCAN_MODE_AGILE)) {
  3101. spectral_err("Agile Scan in progress in current pdev");
  3102. return QDF_STATUS_E_FAILURE;
  3103. }
  3104. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  3105. if (!tgt_hdl) {
  3106. target_if_err("target_psoc_info is null");
  3107. return QDF_STATUS_E_FAILURE;
  3108. }
  3109. mode = target_psoc_get_preferred_hw_mode(tgt_hdl);
  3110. switch (mode) {
  3111. case WMI_HOST_HW_MODE_SBS_PASSIVE:
  3112. case WMI_HOST_HW_MODE_SBS:
  3113. case WMI_HOST_HW_MODE_DBS_SBS:
  3114. case WMI_HOST_HW_MODE_DBS_OR_SBS:
  3115. is_agile_scan_inprog_5g_pdev = false;
  3116. wlan_objmgr_iterate_obj_list
  3117. (psoc, WLAN_PDEV_OP,
  3118. target_if_is_agile_scan_active_in_5g,
  3119. &is_agile_scan_inprog_5g_pdev, 0,
  3120. WLAN_SPECTRAL_ID);
  3121. break;
  3122. default:
  3123. is_agile_scan_inprog_5g_pdev = false;
  3124. break;
  3125. }
  3126. if (is_agile_scan_inprog_5g_pdev) {
  3127. spectral_err("Agile Scan in progress in one of the SBS 5G pdev");
  3128. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3129. return QDF_STATUS_E_FAILURE;
  3130. }
  3131. }
  3132. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3133. bool is_aspectral_prohibited = false;
  3134. QDF_STATUS status;
  3135. status = wlan_objmgr_iterate_obj_list
  3136. (psoc, WLAN_PDEV_OP,
  3137. target_if_is_aspectral_prohibited_by_adfs,
  3138. &is_aspectral_prohibited, 0,
  3139. WLAN_SPECTRAL_ID);
  3140. if (QDF_IS_STATUS_ERROR(status)) {
  3141. spectral_err("Failed to iterate over pdevs");
  3142. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3143. return QDF_STATUS_E_FAILURE;
  3144. }
  3145. if (is_aspectral_prohibited) {
  3146. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3147. return QDF_STATUS_E_FAILURE;
  3148. }
  3149. }
  3150. if (!spectral->params_valid[smode]) {
  3151. target_if_spectral_info_read(spectral,
  3152. smode,
  3153. TARGET_IF_SPECTRAL_INFO_PARAMS,
  3154. &spectral->params[smode],
  3155. sizeof(spectral->params[smode]));
  3156. spectral->params_valid[smode] = true;
  3157. }
  3158. qdf_spin_lock(&spectral->spectral_lock);
  3159. if (smode == SPECTRAL_SCAN_MODE_AGILE &&
  3160. !spectral->params[smode].ss_frequency) {
  3161. *err = SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED;
  3162. qdf_spin_unlock(&spectral->spectral_lock);
  3163. return QDF_STATUS_E_FAILURE;
  3164. }
  3165. if (smode == SPECTRAL_SCAN_MODE_AGILE) {
  3166. QDF_STATUS status;
  3167. bool is_overlapping;
  3168. status = target_if_is_agile_span_overlap_with_operating_span
  3169. (spectral,
  3170. spectral->params[smode].ss_frequency,
  3171. &is_overlapping);
  3172. if (QDF_IS_STATUS_ERROR(status)) {
  3173. qdf_spin_unlock(&spectral->spectral_lock);
  3174. return QDF_STATUS_E_FAILURE;
  3175. }
  3176. if (is_overlapping) {
  3177. *err = SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE;
  3178. qdf_spin_unlock(&spectral->spectral_lock);
  3179. return QDF_STATUS_E_FAILURE;
  3180. }
  3181. }
  3182. target_if_spectral_scan_enable_params(spectral,
  3183. &spectral->params[smode], smode,
  3184. err);
  3185. qdf_spin_unlock(&spectral->spectral_lock);
  3186. return QDF_STATUS_SUCCESS;
  3187. }
  3188. QDF_STATUS
  3189. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  3190. const enum spectral_scan_mode smode,
  3191. enum spectral_cp_error_code *err)
  3192. {
  3193. struct target_if_spectral_ops *p_sops;
  3194. struct target_if_spectral *spectral;
  3195. if (!err) {
  3196. spectral_err("Error code argument is null");
  3197. QDF_ASSERT(0);
  3198. }
  3199. *err = SPECTRAL_SCAN_ERR_INVALID;
  3200. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3201. *err = SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED;
  3202. spectral_err("Invalid Spectral mode %u", smode);
  3203. return QDF_STATUS_E_FAILURE;
  3204. }
  3205. if (!pdev) {
  3206. spectral_err("pdev object is NUll ");
  3207. return QDF_STATUS_E_FAILURE;
  3208. }
  3209. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3210. if (!spectral) {
  3211. spectral_err("Spectral LMAC object is NUll ");
  3212. return QDF_STATUS_E_FAILURE;
  3213. }
  3214. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3215. qdf_spin_lock(&spectral->spectral_lock);
  3216. p_sops->stop_spectral_scan(spectral, smode);
  3217. if (spectral->classify_scan) {
  3218. /* TODO : Check if this logic is necessary */
  3219. spectral->detects_control_channel = 0;
  3220. spectral->detects_extension_channel = 0;
  3221. spectral->detects_above_dc = 0;
  3222. spectral->detects_below_dc = 0;
  3223. spectral->classify_scan = 0;
  3224. }
  3225. spectral->send_single_packet = 0;
  3226. spectral->sc_spectral_scan = 0;
  3227. qdf_spin_unlock(&spectral->spectral_lock);
  3228. return QDF_STATUS_SUCCESS;
  3229. }
  3230. /**
  3231. * target_if_is_spectral_active() - Get whether Spectral is active
  3232. * @pdev: Pointer to pdev object
  3233. * @smode: Spectral scan mode
  3234. *
  3235. * API to get whether Spectral is active
  3236. *
  3237. * Return: True if Spectral is active, false if Spectral is not active
  3238. */
  3239. bool
  3240. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  3241. const enum spectral_scan_mode smode)
  3242. {
  3243. struct target_if_spectral *spectral = NULL;
  3244. struct target_if_spectral_ops *p_sops = NULL;
  3245. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3246. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3247. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3248. spectral_err("Invalid Spectral mode %u", smode);
  3249. return QDF_STATUS_E_FAILURE;
  3250. }
  3251. return p_sops->is_spectral_active(spectral, smode);
  3252. }
  3253. /**
  3254. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  3255. * @pdev: Pointer to pdev object
  3256. * @smode: Spectral scan mode
  3257. *
  3258. * API to get whether Spectral is enabled
  3259. *
  3260. * Return: True if Spectral is enabled, false if Spectral is not enabled
  3261. */
  3262. bool
  3263. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  3264. enum spectral_scan_mode smode)
  3265. {
  3266. struct target_if_spectral *spectral = NULL;
  3267. struct target_if_spectral_ops *p_sops = NULL;
  3268. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3269. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3270. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  3271. spectral_err("Invalid Spectral mode %u", smode);
  3272. return QDF_STATUS_E_FAILURE;
  3273. }
  3274. return p_sops->is_spectral_enabled(spectral, smode);
  3275. }
  3276. /**
  3277. * target_if_set_debug_level() - Set debug level for Spectral
  3278. * @pdev: Pointer to pdev object
  3279. * @debug_level: Debug level
  3280. *
  3281. * API to set the debug level for Spectral
  3282. *
  3283. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3284. */
  3285. QDF_STATUS
  3286. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  3287. {
  3288. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  3289. return QDF_STATUS_SUCCESS;
  3290. }
  3291. /**
  3292. * target_if_get_debug_level() - Get debug level for Spectral
  3293. * @pdev: Pointer to pdev object
  3294. *
  3295. * API to get the debug level for Spectral
  3296. *
  3297. * Return: Current debug level
  3298. */
  3299. uint32_t
  3300. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  3301. {
  3302. return spectral_debug_level;
  3303. }
  3304. /**
  3305. * target_if_get_spectral_capinfo() - Get Spectral capability information
  3306. * @pdev: Pointer to pdev object
  3307. * @scaps: Buffer into which data should be copied
  3308. *
  3309. * API to get the spectral capability information
  3310. *
  3311. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3312. */
  3313. QDF_STATUS
  3314. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  3315. struct spectral_caps *scaps)
  3316. {
  3317. struct target_if_spectral *spectral = NULL;
  3318. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3319. qdf_mem_copy(scaps, &spectral->capability,
  3320. sizeof(struct spectral_caps));
  3321. return QDF_STATUS_SUCCESS;
  3322. }
  3323. /**
  3324. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  3325. * @pdev: Pointer to pdev object
  3326. * @stats: Buffer into which data should be copied
  3327. *
  3328. * API to get the spectral diagnostic statistics
  3329. *
  3330. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE on failure
  3331. */
  3332. QDF_STATUS
  3333. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  3334. struct spectral_diag_stats *stats)
  3335. {
  3336. struct target_if_spectral *spectral = NULL;
  3337. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3338. qdf_mem_copy(stats, &spectral->diag_stats,
  3339. sizeof(struct spectral_diag_stats));
  3340. return QDF_STATUS_SUCCESS;
  3341. }
  3342. /**
  3343. * target_if_register_wmi_spectral_cmd_ops() - Register wmi_spectral_cmd_ops
  3344. * @cmd_ops: Pointer to the structure having wmi_spectral_cmd function pointers
  3345. * @pdev: Pointer to pdev object
  3346. *
  3347. * API for register wmi_spectral_cmd_ops in spectral internal data structure
  3348. *
  3349. * Return: void
  3350. */
  3351. void
  3352. target_if_register_wmi_spectral_cmd_ops(struct wlan_objmgr_pdev *pdev,
  3353. struct wmi_spectral_cmd_ops *cmd_ops)
  3354. {
  3355. struct target_if_spectral *spectral =
  3356. get_target_if_spectral_handle_from_pdev(pdev);
  3357. if (!spectral) {
  3358. spectral_err("Spectral LMAC object is null");
  3359. return;
  3360. }
  3361. spectral->param_wmi_cmd_ops = *cmd_ops;
  3362. }
  3363. /**
  3364. * target_if_register_netlink_cb() - Register Netlink callbacks
  3365. * @pdev: Pointer to pdev object
  3366. * @nl_cb: Netlink callbacks to register
  3367. *
  3368. * Return: void
  3369. */
  3370. static void
  3371. target_if_register_netlink_cb(
  3372. struct wlan_objmgr_pdev *pdev,
  3373. struct spectral_nl_cb *nl_cb)
  3374. {
  3375. struct target_if_spectral *spectral = NULL;
  3376. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3377. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  3378. if (spectral->use_nl_bcast)
  3379. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  3380. else
  3381. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  3382. }
  3383. /**
  3384. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  3385. * Netlink messages to the application layer
  3386. * @pdev: Pointer to pdev object
  3387. *
  3388. * Return: true for broadcast, false for unicast
  3389. */
  3390. static bool
  3391. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  3392. {
  3393. struct target_if_spectral *spectral = NULL;
  3394. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3395. return spectral->use_nl_bcast;
  3396. }
  3397. /**
  3398. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  3399. * @pdev: Pointer to pdev object
  3400. *
  3401. * Return: void
  3402. */
  3403. static void
  3404. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  3405. {
  3406. struct target_if_spectral *spectral = NULL;
  3407. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3408. if (!spectral) {
  3409. spectral_err("SPECTRAL : Module doesn't exist");
  3410. return;
  3411. }
  3412. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  3413. }
  3414. static int
  3415. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  3416. void *payload)
  3417. {
  3418. struct target_if_spectral *spectral = NULL;
  3419. struct target_if_spectral_ops *p_sops = NULL;
  3420. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3421. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3422. return p_sops->process_spectral_report(pdev, payload);
  3423. }
  3424. void
  3425. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  3426. {
  3427. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  3428. target_if_pdev_spectral_init;
  3429. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  3430. target_if_pdev_spectral_deinit;
  3431. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  3432. target_if_set_spectral_config;
  3433. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  3434. target_if_get_spectral_config;
  3435. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  3436. target_if_start_spectral_scan;
  3437. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  3438. target_if_stop_spectral_scan;
  3439. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  3440. target_if_is_spectral_active;
  3441. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  3442. target_if_is_spectral_enabled;
  3443. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  3444. target_if_set_debug_level;
  3445. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  3446. target_if_get_debug_level;
  3447. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  3448. target_if_get_spectral_capinfo;
  3449. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  3450. target_if_get_spectral_diagstats;
  3451. tx_ops->sptrl_tx_ops.sptrlto_register_wmi_spectral_cmd_ops =
  3452. target_if_register_wmi_spectral_cmd_ops;
  3453. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  3454. target_if_register_netlink_cb;
  3455. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  3456. target_if_use_nl_bcast;
  3457. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  3458. target_if_deregister_netlink_cb;
  3459. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  3460. target_if_process_spectral_report;
  3461. }
  3462. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  3463. void
  3464. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  3465. uint16_t cw_int, uint32_t dcs_enabled)
  3466. {
  3467. struct spectral_samp_msg *msg = NULL;
  3468. struct target_if_spectral_ops *p_sops = NULL;
  3469. struct target_if_spectral *spectral = NULL;
  3470. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3471. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_sbuff(
  3472. spectral->pdev_obj,
  3473. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  3474. SPECTRAL_MSG_BUF_NEW);
  3475. if (msg) {
  3476. msg->int_type = cw_int ?
  3477. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  3478. msg->dcs_enabled = dcs_enabled;
  3479. msg->signature = SPECTRAL_SIGNATURE;
  3480. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3481. p_sops->get_mac_address(spectral, msg->macaddr);
  3482. if (spectral->send_phy_data
  3483. (pdev,
  3484. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION) == 0)
  3485. spectral->spectral_sent_msg++;
  3486. }
  3487. }
  3488. qdf_export_symbol(target_if_spectral_send_intf_found_msg);