target_if_spectral.c 100 KB

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