target_if_spectral.c 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924
  1. /*
  2. * Copyright (c) 2011,2017-2018 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. #ifdef CONFIG_WIN
  30. #include <wlan_mlme_dispatcher.h>
  31. #endif /*CONFIG_WIN*/
  32. #include <reg_services_public_struct.h>
  33. #include <target_if_spectral_sim.h>
  34. #include <target_if.h>
  35. #include <qdf_module.h>
  36. /**
  37. * @spectral_ops - Spectral function table, holds the Spectral functions that
  38. * depend on whether the architecture is Direct Attach or Offload. This is used
  39. * to populate the actual Spectral function table present in the Spectral
  40. * module.
  41. */
  42. struct target_if_spectral_ops spectral_ops;
  43. int spectral_debug_level = DEBUG_SPECTRAL;
  44. static void target_if_spectral_get_firstvdev_pdev(struct wlan_objmgr_pdev *pdev,
  45. void *obj, void *arg)
  46. {
  47. struct wlan_objmgr_vdev *vdev = obj;
  48. struct wlan_objmgr_vdev **first_vdev = arg;
  49. if (!(*first_vdev))
  50. *first_vdev = vdev;
  51. }
  52. struct wlan_objmgr_vdev *
  53. target_if_spectral_get_vdev(struct target_if_spectral *spectral)
  54. {
  55. struct wlan_objmgr_pdev *pdev = NULL;
  56. struct wlan_objmgr_vdev *first_vdev = NULL;
  57. qdf_assert_always(spectral);
  58. pdev = spectral->pdev_obj;
  59. qdf_assert_always(pdev);
  60. if (wlan_objmgr_pdev_try_get_ref(pdev, WLAN_SPECTRAL_ID) !=
  61. QDF_STATUS_SUCCESS) {
  62. spectral_err("Unable to get pdev reference.");
  63. return NULL;
  64. }
  65. wlan_objmgr_pdev_iterate_obj_list(pdev, WLAN_VDEV_OP,
  66. target_if_spectral_get_firstvdev_pdev,
  67. &first_vdev, 0, WLAN_SPECTRAL_ID);
  68. wlan_objmgr_pdev_release_ref(pdev, WLAN_SPECTRAL_ID);
  69. if (wlan_objmgr_vdev_try_get_ref(first_vdev, WLAN_SPECTRAL_ID) !=
  70. QDF_STATUS_SUCCESS)
  71. first_vdev = NULL;
  72. if (!first_vdev) {
  73. spectral_warn("Unable to get first vdev of pdev.");
  74. return NULL;
  75. }
  76. return first_vdev;
  77. }
  78. /**
  79. * target_if_send_vdev_spectral_configure_cmd() - Send WMI command to configure
  80. * spectral parameters
  81. * @spectral: Pointer to Spectral target_if internal private data
  82. * @param: Pointer to spectral_config giving the Spectral configuration
  83. *
  84. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  85. */
  86. static int
  87. target_if_send_vdev_spectral_configure_cmd(struct target_if_spectral *spectral,
  88. struct spectral_config *param)
  89. {
  90. struct vdev_spectral_configure_params sparam;
  91. struct wlan_objmgr_pdev *pdev = NULL;
  92. struct wlan_objmgr_vdev *vdev = NULL;
  93. qdf_assert_always(spectral && param);
  94. pdev = spectral->pdev_obj;
  95. qdf_assert_always(pdev);
  96. vdev = target_if_spectral_get_vdev(spectral);
  97. if (!vdev)
  98. return QDF_STATUS_E_NOENT;
  99. qdf_mem_set(&sparam, sizeof(sparam), 0);
  100. sparam.vdev_id = wlan_vdev_get_id(vdev);
  101. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  102. sparam.count = param->ss_count;
  103. sparam.period = param->ss_period;
  104. sparam.spectral_pri = param->ss_spectral_pri;
  105. sparam.fft_size = param->ss_fft_size;
  106. sparam.gc_enable = param->ss_gc_ena;
  107. sparam.restart_enable = param->ss_restart_ena;
  108. sparam.noise_floor_ref = param->ss_noise_floor_ref;
  109. sparam.init_delay = param->ss_init_delay;
  110. sparam.nb_tone_thr = param->ss_nb_tone_thr;
  111. sparam.str_bin_thr = param->ss_str_bin_thr;
  112. sparam.wb_rpt_mode = param->ss_wb_rpt_mode;
  113. sparam.rssi_rpt_mode = param->ss_rssi_rpt_mode;
  114. sparam.rssi_thr = param->ss_rssi_thr;
  115. sparam.pwr_format = param->ss_pwr_format;
  116. sparam.rpt_mode = param->ss_rpt_mode;
  117. sparam.bin_scale = param->ss_bin_scale;
  118. sparam.dbm_adj = param->ss_dbm_adj;
  119. sparam.chn_mask = param->ss_chn_mask;
  120. return spectral->param_wmi_cmd_ops.wmi_spectral_configure_cmd_send(
  121. GET_WMI_HDL_FROM_PDEV(pdev), &sparam);
  122. }
  123. /**
  124. * target_if_send_vdev_spectral_enable_cmd() - Send WMI command to
  125. * enable/disable Spectral
  126. * @spectral: Pointer to Spectral target_if internal private data
  127. * @is_spectral_active_valid: Flag to indicate if spectral activate (trigger) is
  128. * valid
  129. * @is_spectral_active: Value of spectral activate
  130. * @is_spectral_enabled_valid: Flag to indicate if spectral enable is valid
  131. * @is_spectral_enabled: Value of spectral enable
  132. *
  133. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  134. */
  135. static int
  136. target_if_send_vdev_spectral_enable_cmd(struct target_if_spectral *spectral,
  137. uint8_t is_spectral_active_valid,
  138. uint8_t is_spectral_active,
  139. uint8_t is_spectral_enabled_valid,
  140. uint8_t is_spectral_enabled)
  141. {
  142. struct vdev_spectral_enable_params param;
  143. struct wlan_objmgr_pdev *pdev = NULL;
  144. struct wlan_objmgr_vdev *vdev = NULL;
  145. qdf_assert_always(spectral);
  146. pdev = spectral->pdev_obj;
  147. qdf_assert_always(pdev);
  148. vdev = target_if_spectral_get_vdev(spectral);
  149. if (!vdev)
  150. return QDF_STATUS_E_NOENT;
  151. qdf_mem_set(&param, sizeof(param), 0);
  152. param.vdev_id = wlan_vdev_get_id(vdev);
  153. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  154. param.active_valid = is_spectral_active_valid;
  155. param.enabled_valid = is_spectral_enabled_valid;
  156. param.active = is_spectral_active;
  157. param.enabled = is_spectral_enabled;
  158. return spectral->param_wmi_cmd_ops.wmi_spectral_enable_cmd_send(
  159. GET_WMI_HDL_FROM_PDEV(pdev), &param);
  160. }
  161. /**
  162. * target_if_spectral_info_init_defaults() - Helper function to load defaults
  163. * for Spectral information (parameters and state) into cache.
  164. * @spectral: Pointer to Spectral target_if internal private data
  165. *
  166. * It is assumed that the caller has obtained the requisite lock if applicable.
  167. * Note that this is currently treated as a temporary function. Ideally, we
  168. * would like to get defaults from the firmware.
  169. *
  170. * Return: QDF_STATUS_SUCCESS on success, negative error code on failure
  171. */
  172. static int
  173. target_if_spectral_info_init_defaults(struct target_if_spectral *spectral)
  174. {
  175. struct target_if_spectral_param_state_info *info =
  176. &spectral->param_info;
  177. struct wlan_objmgr_vdev *vdev = NULL;
  178. /* State */
  179. info->osps_cache.osc_spectral_active = SPECTRAL_SCAN_ACTIVE_DEFAULT;
  180. info->osps_cache.osc_spectral_enabled = SPECTRAL_SCAN_ENABLE_DEFAULT;
  181. /* Parameters */
  182. info->osps_cache.osc_params.ss_count = SPECTRAL_SCAN_COUNT_DEFAULT;
  183. if (spectral->spectral_gen == SPECTRAL_GEN3)
  184. info->osps_cache.osc_params.ss_period =
  185. SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT;
  186. else
  187. info->osps_cache.osc_params.ss_period =
  188. SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT;
  189. info->osps_cache.osc_params.ss_spectral_pri =
  190. SPECTRAL_SCAN_PRIORITY_DEFAULT;
  191. info->osps_cache.osc_params.ss_fft_size =
  192. SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  193. info->osps_cache.osc_params.ss_gc_ena = SPECTRAL_SCAN_GC_ENA_DEFAULT;
  194. info->osps_cache.osc_params.ss_restart_ena =
  195. SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  196. info->osps_cache.osc_params.ss_noise_floor_ref =
  197. SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  198. info->osps_cache.osc_params.ss_init_delay =
  199. SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  200. info->osps_cache.osc_params.ss_nb_tone_thr =
  201. SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  202. info->osps_cache.osc_params.ss_str_bin_thr =
  203. SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  204. info->osps_cache.osc_params.ss_wb_rpt_mode =
  205. SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  206. info->osps_cache.osc_params.ss_rssi_rpt_mode =
  207. SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  208. info->osps_cache.osc_params.ss_rssi_thr =
  209. SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  210. info->osps_cache.osc_params.ss_pwr_format =
  211. SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  212. info->osps_cache.osc_params.ss_rpt_mode =
  213. SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  214. info->osps_cache.osc_params.ss_bin_scale =
  215. SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  216. info->osps_cache.osc_params.ss_dbm_adj = SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  217. vdev = target_if_spectral_get_vdev(spectral);
  218. if (!vdev)
  219. return QDF_STATUS_E_NOENT;
  220. info->osps_cache.osc_params.ss_chn_mask =
  221. wlan_vdev_mlme_get_rxchainmask(vdev);
  222. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  223. /* The cache is now valid */
  224. info->osps_cache.osc_is_valid = 1;
  225. return QDF_STATUS_SUCCESS;
  226. }
  227. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  228. /**
  229. * target_if_log_read_spectral_active() - Helper function to log whether
  230. * spectral is active after reading cache
  231. * @function_name: Function name
  232. * @output: whether spectral is active or not
  233. *
  234. * Helper function to log whether spectral is active after reading cache
  235. *
  236. * Return: none
  237. */
  238. static void
  239. target_if_log_read_spectral_active(
  240. const char *function_name,
  241. unsigned char output)
  242. {
  243. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE. Returning val=%u",
  244. function_name, output);
  245. }
  246. /**
  247. * target_if_log_read_spectral_enabled() - Helper function to log whether
  248. * spectral is enabled after reading cache
  249. * @function_name: Function name
  250. * @output: whether spectral is enabled or not
  251. *
  252. * Helper function to log whether spectral is enabled after reading cache
  253. *
  254. * Return: none
  255. */
  256. static void
  257. target_if_log_read_spectral_enabled(
  258. const char *function_name,
  259. unsigned char output)
  260. {
  261. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED. Returning val=%u",
  262. function_name, output);
  263. }
  264. /**
  265. * target_if_log_read_spectral_enabled() - Helper function to log spectral
  266. * parameters after reading cache
  267. * @function_name: Function name
  268. * @pparam: Spectral parameters
  269. *
  270. * Helper function to log spectral parameters after reading cache
  271. *
  272. * Return: none
  273. */
  274. static void
  275. target_if_log_read_spectral_params(
  276. const char *function_name,
  277. struct spectral_config *pparam)
  278. {
  279. 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\n",
  280. function_name,
  281. pparam->ss_count,
  282. pparam->ss_period,
  283. pparam->ss_spectral_pri,
  284. pparam->ss_fft_size,
  285. pparam->ss_gc_ena,
  286. pparam->ss_restart_ena,
  287. (int8_t)pparam->ss_noise_floor_ref,
  288. pparam->ss_init_delay,
  289. pparam->ss_nb_tone_thr,
  290. pparam->ss_str_bin_thr,
  291. pparam->ss_wb_rpt_mode,
  292. pparam->ss_rssi_rpt_mode,
  293. (int8_t)pparam->ss_rssi_thr,
  294. pparam->ss_pwr_format,
  295. pparam->ss_rpt_mode,
  296. pparam->ss_bin_scale,
  297. pparam->ss_dbm_adj,
  298. pparam->ss_chn_mask);
  299. }
  300. /**
  301. * target_if_log_read_spectral_active_catch_validate() - Helper function to
  302. * log whether spectral is active after intializing the cache
  303. * @function_name: Function name
  304. * @output: whether spectral is active or not
  305. *
  306. * Helper function to log whether spectral is active after intializing cache
  307. *
  308. * Return: none
  309. */
  310. static void
  311. target_if_log_read_spectral_active_catch_validate(
  312. const char *function_name,
  313. unsigned char output)
  314. {
  315. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE on initial cache validation\nReturning val=%u",
  316. function_name, output);
  317. }
  318. /**
  319. * target_if_log_read_spectral_enabled_catch_validate() - Helper function to
  320. * log whether spectral is enabled after intializing the cache
  321. * @function_name: Function name
  322. * @output: whether spectral is enabled or not
  323. *
  324. * Helper function to log whether spectral is enabled after intializing cache
  325. *
  326. * Return: none
  327. */
  328. static void
  329. target_if_log_read_spectral_enabled_catch_validate(
  330. const char *function_name,
  331. unsigned char output)
  332. {
  333. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED on initial cache validation\nReturning val=%u\n",
  334. function_name, output);
  335. }
  336. /**
  337. * target_if_log_read_spectral_params_catch_validate() - Helper function to
  338. * log spectral parameters after intializing the cache
  339. * @function_name: Function name
  340. * @pparam: Spectral parameters
  341. *
  342. * Helper function to log spectral parameters after intializing the cache
  343. *
  344. * Return: none
  345. */
  346. static void
  347. target_if_log_read_spectral_params_catch_validate(
  348. const char *function_name,
  349. struct spectral_config *pparam)
  350. {
  351. 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",
  352. function_name,
  353. pparam->ss_count,
  354. pparam->ss_period,
  355. pparam->ss_spectral_pri,
  356. pparam->ss_fft_size,
  357. pparam->ss_gc_ena,
  358. pparam->ss_restart_ena,
  359. (int8_t)pparam->ss_noise_floor_ref,
  360. pparam->ss_init_delay,
  361. pparam->ss_nb_tone_thr,
  362. pparam->ss_str_bin_thr,
  363. pparam->ss_wb_rpt_mode,
  364. pparam->ss_rssi_rpt_mode,
  365. (int8_t)pparam->ss_rssi_thr,
  366. pparam->ss_pwr_format,
  367. pparam->ss_rpt_mode,
  368. pparam->ss_bin_scale,
  369. pparam->ss_dbm_adj, pparam->ss_chn_mask);
  370. }
  371. #else
  372. static void
  373. target_if_log_read_spectral_active(
  374. const char *function_name,
  375. unsigned char output)
  376. {
  377. }
  378. static void
  379. target_if_log_read_spectral_enabled(
  380. const char *function_name,
  381. unsigned char output)
  382. {
  383. }
  384. static void
  385. target_if_log_read_spectral_params(
  386. const char *function_name,
  387. struct spectral_config *pparam)
  388. {
  389. }
  390. static void
  391. target_if_log_read_spectral_active_catch_validate(
  392. const char *function_name,
  393. unsigned char output)
  394. {
  395. }
  396. static void
  397. target_if_log_read_spectral_enabled_catch_validate(
  398. const char *function_name,
  399. unsigned char output)
  400. {
  401. }
  402. static void
  403. target_if_log_read_spectral_params_catch_validate(
  404. const char *function_name,
  405. struct spectral_config *pparam)
  406. {
  407. }
  408. #endif
  409. /**
  410. * target_if_spectral_info_read() - Read spectral information from the cache.
  411. * @spectral: Pointer to Spectral target_if internal private data
  412. * @specifier: target_if_spectral_info enumeration specifying which
  413. * information is required
  414. * @output: Void output pointer into which the information will be read
  415. * @output_len: size of object pointed to by output pointer
  416. *
  417. * Read spectral parameters or the desired state information from the cache.
  418. *
  419. * Return: 0 on success, negative error code on failure
  420. */
  421. static int
  422. target_if_spectral_info_read(
  423. struct target_if_spectral *spectral,
  424. enum target_if_spectral_info specifier,
  425. void *output, int output_len)
  426. {
  427. /*
  428. * Note: This function is designed to be able to accommodate
  429. * WMI reads for defaults, non-cacheable information, etc
  430. * if required.
  431. */
  432. struct target_if_spectral_param_state_info *info =
  433. &spectral->param_info;
  434. int is_cacheable = 0;
  435. int init_def_retval = 0;
  436. if (!output)
  437. return -EINVAL;
  438. switch (specifier) {
  439. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  440. if (output_len != sizeof(info->osps_cache.osc_spectral_active))
  441. return -EINVAL;
  442. is_cacheable = 1;
  443. break;
  444. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  445. if (output_len != sizeof(info->osps_cache.osc_spectral_enabled))
  446. return -EINVAL;
  447. is_cacheable = 1;
  448. break;
  449. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  450. if (output_len != sizeof(info->osps_cache.osc_params))
  451. return -EINVAL;
  452. is_cacheable = 1;
  453. break;
  454. default:
  455. spectral_err("Unknown target_if_spectral_info specifier");
  456. return -EINVAL;
  457. }
  458. qdf_spin_lock(&info->osps_lock);
  459. if (is_cacheable) {
  460. if (info->osps_cache.osc_is_valid) {
  461. switch (specifier) {
  462. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  463. qdf_mem_copy(
  464. output,
  465. &info->osps_cache.osc_spectral_active,
  466. sizeof(info->osps_cache.osc_spectral_active));
  467. target_if_log_read_spectral_active(
  468. __func__,
  469. *((unsigned char *)output));
  470. break;
  471. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  472. qdf_mem_copy(
  473. output,
  474. &info->osps_cache.osc_spectral_enabled,
  475. sizeof(
  476. info->osps_cache.osc_spectral_enabled));
  477. target_if_log_read_spectral_enabled(
  478. __func__,
  479. *((unsigned char *)output));
  480. break;
  481. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  482. qdf_mem_copy(
  483. output,
  484. &info->osps_cache.osc_params,
  485. sizeof(info->osps_cache.osc_params));
  486. target_if_log_read_spectral_params(
  487. __func__,
  488. (struct spectral_config *)output);
  489. break;
  490. default:
  491. /* We can't reach this point */
  492. break;
  493. }
  494. qdf_spin_unlock(&info->osps_lock);
  495. return 0;
  496. }
  497. }
  498. /* Cache is invalid */
  499. /*
  500. * If WMI Reads are implemented to fetch defaults/non-cacheable info,
  501. * then the below implementation will change
  502. */
  503. init_def_retval = target_if_spectral_info_init_defaults(spectral);
  504. if (init_def_retval != QDF_STATUS_SUCCESS) {
  505. qdf_spin_unlock(&info->osps_lock);
  506. if (init_def_retval == QDF_STATUS_E_NOENT)
  507. return -ENOENT;
  508. else
  509. return -EINVAL;
  510. }
  511. /* target_if_spectral_info_init_defaults() has set cache to valid */
  512. switch (specifier) {
  513. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  514. qdf_mem_copy(output,
  515. &info->osps_cache.osc_spectral_active,
  516. sizeof(info->osps_cache.osc_spectral_active));
  517. target_if_log_read_spectral_active_catch_validate(
  518. __func__,
  519. *((unsigned char *)output));
  520. break;
  521. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  522. qdf_mem_copy(output,
  523. &info->osps_cache.osc_spectral_enabled,
  524. sizeof(info->osps_cache.osc_spectral_enabled));
  525. target_if_log_read_spectral_enabled_catch_validate(
  526. __func__,
  527. *((unsigned char *)output));
  528. break;
  529. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  530. qdf_mem_copy(output,
  531. &info->osps_cache.osc_params,
  532. sizeof(info->osps_cache.osc_params));
  533. target_if_log_read_spectral_params_catch_validate(
  534. __func__,
  535. (struct spectral_config *)output);
  536. break;
  537. default:
  538. /* We can't reach this point */
  539. break;
  540. }
  541. qdf_spin_unlock(&info->osps_lock);
  542. return 0;
  543. }
  544. #ifdef OL_SPECTRAL_DEBUG_CONFIG_INTERACTIONS
  545. /**
  546. * target_if_log_write_spectral_active() - Helper function to log inputs and
  547. * return value of call to configure the Spectral 'active' configuration,
  548. * TARGET_IF_SPECTRAL_INFO_ACTIVE into firmware
  549. * @function_name: Function name in which this is called
  550. * @pval: whether spectral is active or not
  551. * @ret: return value of the firmware write function
  552. *
  553. * Return: none
  554. */
  555. static void
  556. target_if_log_write_spectral_active(
  557. const char *function_name,
  558. uint8_t pval,
  559. int ret)
  560. {
  561. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ACTIVE with val=%u status=%d",
  562. function_name, pval, ret);
  563. }
  564. /**
  565. * target_if_log_write_spectral_enabled() - Helper function to log inputs and
  566. * return value of call to configure the Spectral 'enabled' configuration,
  567. * TARGET_IF_SPECTRAL_INFO_ENABLED into firmware
  568. * @function_name: Function name in which this is called
  569. * @pval: whether spectral is enabled or not
  570. * @ret: return value of the firmware write function
  571. *
  572. * Return: none
  573. */
  574. static void
  575. target_if_log_write_spectral_enabled(
  576. const char *function_name,
  577. uint8_t pval,
  578. int ret)
  579. {
  580. spectral_debug("%s: TARGET_IF_SPECTRAL_INFO_ENABLED with val=%u status=%d",
  581. function_name, pval, ret);
  582. }
  583. /**
  584. * target_if_log_write_spectral_params() - Helper function to log inputs and
  585. * return value of call to configure Spectral parameters,
  586. * TARGET_IF_SPECTRAL_INFO_PARAMS into firmware
  587. * @param: Spectral parameters
  588. * @function_name: Function name in which this is called
  589. * @ret: return value of the firmware write function
  590. *
  591. * Return: none
  592. */
  593. static void
  594. target_if_log_write_spectral_params(
  595. struct spectral_config *param,
  596. const char *function_name,
  597. int ret)
  598. {
  599. 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\nstatus = %d",
  600. function_name,
  601. param->ss_count,
  602. param->ss_period,
  603. param->ss_spectral_pri,
  604. param->ss_fft_size,
  605. param->ss_gc_ena,
  606. param->ss_restart_ena,
  607. (int8_t)param->ss_noise_floor_ref,
  608. param->ss_init_delay,
  609. param->ss_nb_tone_thr,
  610. param->ss_str_bin_thr,
  611. param->ss_wb_rpt_mode,
  612. param->ss_rssi_rpt_mode,
  613. (int8_t)param->ss_rssi_thr,
  614. param->ss_pwr_format,
  615. param->ss_rpt_mode,
  616. param->ss_bin_scale,
  617. param->ss_dbm_adj, param->ss_chn_mask, ret);
  618. }
  619. #else
  620. static void
  621. target_if_log_write_spectral_active(
  622. const char *function_name,
  623. uint8_t pval,
  624. int ret)
  625. {
  626. }
  627. static void
  628. target_if_log_write_spectral_enabled(
  629. const char *function_name,
  630. uint8_t pval,
  631. int ret)
  632. {
  633. }
  634. static void
  635. target_if_log_write_spectral_params(
  636. struct spectral_config *param,
  637. const char *function_name,
  638. int ret)
  639. {
  640. }
  641. #endif
  642. /**
  643. * target_if_spectral_info_write() - Write Spectral information to the
  644. * firmware, and update cache
  645. * @spectral: Pointer to Spectral target_if internal private data
  646. * @specifier: target_if_spectral_info enumeration specifying which
  647. * information is involved
  648. * @input: void input pointer containing the information to be written
  649. * @input_len: size of object pointed to by input pointer
  650. *
  651. * Write Spectral parameters or the desired state information to
  652. * the firmware, and update cache
  653. *
  654. * Return: 0 on success, negative error code on failure
  655. */
  656. static int
  657. target_if_spectral_info_write(
  658. struct target_if_spectral *spectral,
  659. enum target_if_spectral_info specifier,
  660. void *input, int input_len)
  661. {
  662. struct target_if_spectral_param_state_info *info =
  663. &spectral->param_info;
  664. int ret;
  665. uint8_t *pval = NULL;
  666. struct spectral_config *param = NULL;
  667. if (!input)
  668. return -EINVAL;
  669. switch (specifier) {
  670. case TARGET_IF_SPECTRAL_INFO_ACTIVE:
  671. if (input_len != sizeof(info->osps_cache.osc_spectral_active))
  672. return -EINVAL;
  673. pval = (uint8_t *)input;
  674. qdf_spin_lock(&info->osps_lock);
  675. ret = target_if_send_vdev_spectral_enable_cmd(spectral,
  676. 1, *pval, 0, 0);
  677. target_if_log_write_spectral_active(
  678. __func__,
  679. *pval,
  680. ret);
  681. if (ret < 0) {
  682. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  683. ret);
  684. qdf_spin_unlock(&info->osps_lock);
  685. return ret;
  686. }
  687. info->osps_cache.osc_spectral_active = *pval;
  688. qdf_spin_unlock(&info->osps_lock);
  689. break;
  690. case TARGET_IF_SPECTRAL_INFO_ENABLED:
  691. if (input_len != sizeof(info->osps_cache.osc_spectral_enabled))
  692. return -EINVAL;
  693. pval = (uint8_t *)input;
  694. qdf_spin_lock(&info->osps_lock);
  695. ret = target_if_send_vdev_spectral_enable_cmd(spectral,
  696. 0, 0, 1, *pval);
  697. target_if_log_write_spectral_enabled(
  698. __func__,
  699. *pval,
  700. ret);
  701. if (ret < 0) {
  702. spectral_err("target_if_send_vdev_spectral_enable_cmd failed with error=%d",
  703. ret);
  704. qdf_spin_unlock(&info->osps_lock);
  705. return ret;
  706. }
  707. info->osps_cache.osc_spectral_enabled = *pval;
  708. qdf_spin_unlock(&info->osps_lock);
  709. break;
  710. case TARGET_IF_SPECTRAL_INFO_PARAMS:
  711. if (input_len != sizeof(info->osps_cache.osc_params))
  712. return -EINVAL;
  713. param = (struct spectral_config *)input;
  714. qdf_spin_lock(&info->osps_lock);
  715. ret = target_if_send_vdev_spectral_configure_cmd(spectral,
  716. param);
  717. target_if_log_write_spectral_params(
  718. param,
  719. __func__,
  720. ret);
  721. if (ret < 0) {
  722. spectral_err("target_if_send_vdev_spectral_configure_cmd failed with error=%d",
  723. ret);
  724. qdf_spin_unlock(&info->osps_lock);
  725. return ret;
  726. }
  727. qdf_mem_copy(&info->osps_cache.osc_params,
  728. param, sizeof(info->osps_cache.osc_params));
  729. qdf_spin_unlock(&info->osps_lock);
  730. break;
  731. default:
  732. spectral_err("Unknown target_if_spectral_info specifier");
  733. return -EINVAL;
  734. }
  735. return 0;
  736. }
  737. /**
  738. * target_if_spectral_get_tsf64() - Function to get the TSF value
  739. * @arg: Pointer to handle for Spectral target_if internal private data
  740. *
  741. * Get the last TSF received in WMI buffer
  742. *
  743. * Return: TSF value
  744. */
  745. static uint64_t
  746. target_if_spectral_get_tsf64(void *arg)
  747. {
  748. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  749. return spectral->tsf64;
  750. }
  751. /**
  752. * target_if_spectral_get_capability() - Function to get whether a
  753. * given Spectral hardware capability is available
  754. * @arg: Pointer to handle for Spectral target_if internal private data
  755. * @type: Spectral hardware capability type
  756. *
  757. * Get whether a given Spectral hardware capability is available
  758. *
  759. * Return: True if the capability is available, false if the capability is not
  760. * available
  761. */
  762. uint32_t
  763. target_if_spectral_get_capability(void *arg, enum spectral_capability_type type)
  764. {
  765. int status = STATUS_FAIL;
  766. switch (type) {
  767. case SPECTRAL_CAP_PHYDIAG:
  768. case SPECTRAL_CAP_RADAR:
  769. case SPECTRAL_CAP_SPECTRAL_SCAN:
  770. case SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN:
  771. status = STATUS_PASS;
  772. break;
  773. default:
  774. status = STATUS_FAIL;
  775. }
  776. return status;
  777. }
  778. /**
  779. * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
  780. * @arg: Pointer to handle for Spectral target_if internal private data
  781. * @rxfilter: Rx filter to be used
  782. *
  783. * Note: This is only a placeholder function. It is not currently required since
  784. * FW should be taking care of setting the required filters.
  785. *
  786. * Return: 0
  787. */
  788. uint32_t
  789. target_if_spectral_set_rxfilter(void *arg, int rxfilter)
  790. {
  791. /*
  792. * Will not be required since enabling of spectral in firmware
  793. * will take care of this
  794. */
  795. return 0;
  796. }
  797. /**
  798. * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
  799. * @arg: Pointer to handle for Spectral target_if internal private data
  800. *
  801. * Note: This is only a placeholder function. It is not currently required since
  802. * FW should be taking care of setting the required filters.
  803. *
  804. * Return: 0
  805. */
  806. uint32_t
  807. target_if_spectral_get_rxfilter(void *arg)
  808. {
  809. /*
  810. * Will not be required since enabling of spectral in firmware
  811. * will take care of this
  812. */
  813. return 0;
  814. }
  815. /**
  816. * target_if_sops_is_spectral_active() - Get whether Spectral is active
  817. * @arg: Pointer to handle for Spectral target_if internal private data
  818. *
  819. * Function to check whether Spectral is active
  820. *
  821. * Return: True if Spectral is active, false if Spectral is not active
  822. */
  823. uint32_t
  824. target_if_sops_is_spectral_active(void *arg)
  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. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  832. &val, sizeof(val));
  833. if (ret != 0) {
  834. /*
  835. * Could not determine if Spectral is active.
  836. * Return false as a safe value.
  837. * XXX: Consider changing the function prototype
  838. * to be able to indicate failure to fetch value.
  839. */
  840. return 0;
  841. }
  842. return val;
  843. }
  844. /**
  845. * target_if_sops_is_spectral_enabled() - Get whether Spectral is enabled
  846. * @arg: Pointer to handle for Spectral target_if internal private data
  847. *
  848. * Function to check whether Spectral is enabled
  849. *
  850. * Return: True if Spectral is enabled, false if Spectral is not enabled
  851. */
  852. uint32_t
  853. target_if_sops_is_spectral_enabled(void *arg)
  854. {
  855. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  856. uint8_t val = 0;
  857. int ret;
  858. ret = target_if_spectral_info_read(
  859. spectral,
  860. TARGET_IF_SPECTRAL_INFO_ENABLED,
  861. &val, sizeof(val));
  862. if (ret != 0) {
  863. /*
  864. * Could not determine if Spectral is enabled.
  865. * Return false as a safe value.
  866. * XXX: Consider changing the function prototype
  867. * to be able to indicate failure to fetch value.
  868. */
  869. return 0;
  870. }
  871. return val;
  872. }
  873. /**
  874. * target_if_sops_start_spectral_scan() - Start Spectral scan
  875. * @arg: Pointer to handle for Spectral target_if internal private data
  876. *
  877. * Function to start spectral scan
  878. *
  879. * Return: 0 on success else failure
  880. */
  881. uint32_t
  882. target_if_sops_start_spectral_scan(void *arg)
  883. {
  884. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  885. uint8_t val = 1;
  886. uint8_t enabled = 0;
  887. int ret;
  888. ret = target_if_spectral_info_read(
  889. spectral,
  890. TARGET_IF_SPECTRAL_INFO_ENABLED,
  891. &enabled, sizeof(enabled));
  892. if (ret != 0) {
  893. /*
  894. * Could not determine if Spectral is enabled. Assume we need
  895. * to enable it
  896. */
  897. enabled = 0;
  898. }
  899. if (!enabled) {
  900. ret = target_if_spectral_info_write(
  901. spectral,
  902. TARGET_IF_SPECTRAL_INFO_ENABLED,
  903. &val, sizeof(val));
  904. if (ret != 0)
  905. return ret;
  906. }
  907. ret = target_if_spectral_info_write(
  908. spectral,
  909. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  910. &val, sizeof(val));
  911. if (ret != 0)
  912. return ret;
  913. return 0;
  914. }
  915. /**
  916. * target_if_sops_stop_spectral_scan() - Stop Spectral scan
  917. * @arg: Pointer to handle for Spectral target_if internal private data
  918. *
  919. * Function to stop spectral scan
  920. *
  921. * Return: 0 on success else failure
  922. */
  923. uint32_t
  924. target_if_sops_stop_spectral_scan(void *arg)
  925. {
  926. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  927. uint8_t val = 0;
  928. int tempret, ret = 0;
  929. tempret = target_if_spectral_info_write(
  930. spectral,
  931. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  932. &val, sizeof(val));
  933. if (tempret != 0)
  934. ret = tempret;
  935. tempret = target_if_spectral_info_write(
  936. spectral,
  937. TARGET_IF_SPECTRAL_INFO_ENABLED,
  938. &val, sizeof(val));
  939. if (tempret != 0)
  940. ret = tempret;
  941. return ret;
  942. }
  943. /**
  944. * target_if_spectral_get_extension_channel() - Get the Extension channel
  945. * @arg: Pointer to handle for Spectral target_if internal private data
  946. *
  947. * Function to get the current Extension channel (in MHz)
  948. *
  949. * Return: Current Extension channel (in MHz) on success, 0 on failure or if
  950. * extension channel is not present.
  951. */
  952. uint32_t
  953. target_if_spectral_get_extension_channel(void *arg)
  954. {
  955. /*
  956. * XXX: Once we expand to use cases where Spectral could be activated
  957. * without a channel being set to VDEV, we need to consider returning a
  958. * negative value in case of failure and having all callers handle this.
  959. */
  960. struct target_if_spectral *spectral = NULL;
  961. struct wlan_objmgr_vdev *vdev = NULL;
  962. uint16_t sec20chan_freq = 0;
  963. qdf_assert_always(arg);
  964. spectral = (struct target_if_spectral *)arg;
  965. vdev = target_if_spectral_get_vdev(spectral);
  966. if (!vdev)
  967. return 0;
  968. if (target_if_vdev_get_sec20chan_freq_mhz(vdev, &sec20chan_freq) < 0) {
  969. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  970. return 0;
  971. }
  972. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  973. return sec20chan_freq;
  974. }
  975. /**
  976. * target_if_spectral_get_current_channel() - Get the current channel
  977. * @arg: Pointer to handle for Spectral target_if internal private data
  978. *
  979. * Function to get the current channel (in MHz)
  980. *
  981. * Return: Current channel (in MHz) on success, 0 on failure
  982. */
  983. uint32_t
  984. target_if_spectral_get_current_channel(void *arg)
  985. {
  986. /*
  987. * XXX: Once we expand to use cases where Spectral could be activated
  988. * without a channel being set to VDEV, we need to consider returning a
  989. * negative value in case of failure and having all callers handle this.
  990. */
  991. struct target_if_spectral *spectral = NULL;
  992. int16_t chan_freq = 0;
  993. struct wlan_objmgr_vdev *vdev = NULL;
  994. qdf_assert_always(arg);
  995. spectral = (struct target_if_spectral *)arg;
  996. vdev = target_if_spectral_get_vdev(spectral);
  997. if (!vdev)
  998. return 0;
  999. chan_freq = target_if_vdev_get_chan_freq(vdev);
  1000. if (chan_freq < 0) {
  1001. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1002. return 0;
  1003. }
  1004. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1005. return chan_freq;
  1006. }
  1007. /**
  1008. * target_if_spectral_reset_hw() - Reset the hardware
  1009. * @arg: Pointer to handle for Spectral target_if internal private data
  1010. *
  1011. * This is only a placeholder since it is not currently required in the offload
  1012. * case.
  1013. *
  1014. * Return: 0
  1015. */
  1016. uint32_t
  1017. target_if_spectral_reset_hw(void *arg)
  1018. {
  1019. not_yet_implemented();
  1020. return 0;
  1021. }
  1022. /**
  1023. * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
  1024. * Noisefloor history buffer
  1025. * @arg: Pointer to handle for Spectral target_if internal private data
  1026. * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
  1027. *
  1028. * This is only a placeholder since it is not currently required in the offload
  1029. * case.
  1030. *
  1031. * Return: 0
  1032. */
  1033. uint32_t
  1034. target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1035. {
  1036. not_yet_implemented();
  1037. return 0;
  1038. }
  1039. /**
  1040. * target_if_spectral_get_ext_noisefloor() - Get the extension channel
  1041. * noisefloor
  1042. * @arg: Pointer to handle for Spectral target_if internal private data
  1043. *
  1044. * This is only a placeholder since it is not currently required in the offload
  1045. * case.
  1046. *
  1047. * Return: 0
  1048. */
  1049. int8_t
  1050. target_if_spectral_get_ext_noisefloor(void *arg)
  1051. {
  1052. not_yet_implemented();
  1053. return 0;
  1054. }
  1055. /**
  1056. * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
  1057. * @arg: Pointer to handle for Spectral target_if internal private data
  1058. *
  1059. * This is only a placeholder since it is not currently required in the offload
  1060. * case.
  1061. *
  1062. * Return: 0
  1063. */
  1064. int8_t
  1065. target_if_spectral_get_ctl_noisefloor(void *arg)
  1066. {
  1067. not_yet_implemented();
  1068. return 0;
  1069. }
  1070. /**
  1071. * target_if_spectral_sops_configure_params() - Configure user supplied Spectral
  1072. * parameters
  1073. * @arg: Pointer to handle for Spectral target_if internal private data
  1074. * @params: Spectral parameters
  1075. *
  1076. * Function to configure spectral parameters
  1077. *
  1078. * Return: 0 on success else failure
  1079. */
  1080. uint32_t
  1081. target_if_spectral_sops_configure_params(
  1082. void *arg, struct spectral_config *params)
  1083. {
  1084. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1085. return target_if_spectral_info_write(
  1086. spectral,
  1087. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1088. params, sizeof(*params));
  1089. }
  1090. /**
  1091. * target_if_spectral_sops_get_params() - Get user configured Spectral
  1092. * parameters
  1093. * @arg: Pointer to handle for Spectral target_if internal private data
  1094. * @params: Pointer to buffer into which Spectral parameters should be copied
  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. {
  1103. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1104. return target_if_spectral_info_read(
  1105. spectral,
  1106. TARGET_IF_SPECTRAL_INFO_PARAMS,
  1107. params, sizeof(*params));
  1108. }
  1109. /**
  1110. * target_if_spectral_get_ent_mask() - Get enterprise mask
  1111. * @arg: Pointer to handle for Spectral target_if internal private data
  1112. *
  1113. * This is only a placeholder since it is not currently required in the offload
  1114. * case.
  1115. *
  1116. * Return: 0
  1117. */
  1118. static uint32_t
  1119. target_if_spectral_get_ent_mask(void *arg)
  1120. {
  1121. not_yet_implemented();
  1122. return 0;
  1123. }
  1124. /**
  1125. * target_if_spectral_get_macaddr() - Get radio MAC address
  1126. * @arg: Pointer to handle for Spectral target_if internal private data
  1127. * @addr: Pointer to buffer into which MAC address should be copied
  1128. *
  1129. * Function to get the MAC address of the pdev
  1130. *
  1131. * Return: 0 on success, -1 on failure
  1132. */
  1133. static uint32_t
  1134. target_if_spectral_get_macaddr(void *arg, char *addr)
  1135. {
  1136. uint8_t *myaddr = NULL;
  1137. struct target_if_spectral *spectral = (struct target_if_spectral *)arg;
  1138. struct wlan_objmgr_pdev *pdev = NULL;
  1139. pdev = spectral->pdev_obj;
  1140. wlan_pdev_obj_lock(pdev);
  1141. myaddr = wlan_pdev_get_hw_macaddr(pdev);
  1142. wlan_pdev_obj_unlock(pdev);
  1143. qdf_mem_copy(addr, myaddr, IEEE80211_ADDR_LEN);
  1144. return 0;
  1145. }
  1146. /**
  1147. * target_if_init_spectral_capability() - Initialize Spectral capability
  1148. * @spectral: Pointer to Spectral target_if internal private data
  1149. *
  1150. * This is a workaround.
  1151. *
  1152. * Return: None
  1153. */
  1154. void
  1155. target_if_init_spectral_capability(struct target_if_spectral *spectral)
  1156. {
  1157. struct spectral_caps *pcap = &spectral->capability;
  1158. /* XXX : Workaround: Set Spectral capability */
  1159. pcap = &spectral->capability;
  1160. pcap->phydiag_cap = 1;
  1161. pcap->radar_cap = 1;
  1162. pcap->spectral_cap = 1;
  1163. pcap->advncd_spectral_cap = 1;
  1164. pcap->hw_gen = spectral->spectral_gen;
  1165. }
  1166. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1167. /**
  1168. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1169. * internal operations with functions related to spectral simulation
  1170. * @p_sops: spectral low level ops table
  1171. *
  1172. * Initialize spectral target_if internal operations with functions
  1173. * related to spectral simulation
  1174. *
  1175. * Return: None
  1176. */
  1177. static void
  1178. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1179. {
  1180. /*
  1181. * Spectral simulation is currently intended for platform transitions
  1182. * where underlying HW support may not be available for some time.
  1183. * Hence, we do not currently provide a runtime switch to turn the
  1184. * simulation on or off.
  1185. * In case of future requirements where runtime switches are required,
  1186. * this can be added. But it is suggested to use application layer
  1187. * simulation as far as possible in such cases, since the main
  1188. * use of record and replay of samples would concern higher
  1189. * level sample processing rather than lower level delivery.
  1190. */
  1191. p_sops->is_spectral_enabled = target_if_spectral_sops_sim_is_enabled;
  1192. p_sops->is_spectral_active = target_if_spectral_sops_sim_is_active;
  1193. p_sops->start_spectral_scan = target_if_spectral_sops_sim_start_scan;
  1194. p_sops->stop_spectral_scan = target_if_spectral_sops_sim_stop_scan;
  1195. p_sops->configure_spectral =
  1196. target_if_spectral_sops_sim_configure_params;
  1197. p_sops->get_spectral_config = target_if_spectral_sops_sim_get_params;
  1198. }
  1199. #else
  1200. /**
  1201. * target_if_init_spectral_simulation_ops() - Initialize spectral target_if
  1202. * internal operations
  1203. * @p_sops: spectral low level ops table
  1204. *
  1205. * Return: None
  1206. */
  1207. static void
  1208. target_if_init_spectral_simulation_ops(struct target_if_spectral_ops *p_sops)
  1209. {
  1210. p_sops->is_spectral_enabled = target_if_sops_is_spectral_enabled;
  1211. p_sops->is_spectral_active = target_if_sops_is_spectral_active;
  1212. p_sops->start_spectral_scan = target_if_sops_start_spectral_scan;
  1213. p_sops->stop_spectral_scan = target_if_sops_stop_spectral_scan;
  1214. p_sops->configure_spectral = target_if_spectral_sops_configure_params;
  1215. p_sops->get_spectral_config = target_if_spectral_sops_get_params;
  1216. }
  1217. #endif
  1218. /**
  1219. * target_if_init_spectral_ops_common() - Initialize Spectral target_if internal
  1220. * operations common to all Spectral chipset generations
  1221. *
  1222. * Initializes target_if_spectral_ops common to all chipset generations
  1223. *
  1224. * Return: None
  1225. */
  1226. static void
  1227. target_if_init_spectral_ops_common(void)
  1228. {
  1229. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1230. p_sops->get_tsf64 = target_if_spectral_get_tsf64;
  1231. p_sops->get_capability = target_if_spectral_get_capability;
  1232. p_sops->set_rxfilter = target_if_spectral_set_rxfilter;
  1233. p_sops->get_rxfilter = target_if_spectral_get_rxfilter;
  1234. target_if_init_spectral_simulation_ops(p_sops);
  1235. p_sops->get_extension_channel =
  1236. target_if_spectral_get_extension_channel;
  1237. p_sops->get_ctl_noisefloor = target_if_spectral_get_ctl_noisefloor;
  1238. p_sops->get_ext_noisefloor = target_if_spectral_get_ext_noisefloor;
  1239. p_sops->get_ent_spectral_mask = target_if_spectral_get_ent_mask;
  1240. p_sops->get_mac_address = target_if_spectral_get_macaddr;
  1241. p_sops->get_current_channel = target_if_spectral_get_current_channel;
  1242. p_sops->reset_hw = target_if_spectral_reset_hw;
  1243. p_sops->get_chain_noise_floor =
  1244. target_if_spectral_get_chain_noise_floor;
  1245. }
  1246. /**
  1247. * target_if_init_spectral_ops_gen2() - Initialize Spectral target_if internal
  1248. * operations specific to Spectral chipset generation 2.
  1249. *
  1250. * Initializes target_if_spectral_ops specific to Spectral chipset generation 2.
  1251. *
  1252. * Return: None
  1253. */
  1254. static void
  1255. target_if_init_spectral_ops_gen2(void)
  1256. {
  1257. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1258. p_sops->spectral_process_phyerr = target_if_process_phyerr_gen2;
  1259. }
  1260. /**
  1261. * target_if_init_spectral_ops_gen3() - Initialize Spectral target_if internal
  1262. * operations specific to Spectral chipset generation 3.
  1263. *
  1264. * Initializes target_if_spectral_ops specific to Spectral chipset generation 3.
  1265. *
  1266. * Return: None
  1267. */
  1268. static void
  1269. target_if_init_spectral_ops_gen3(void)
  1270. {
  1271. struct target_if_spectral_ops *p_sops = &spectral_ops;
  1272. p_sops->process_spectral_report =
  1273. target_if_spectral_process_report_gen3;
  1274. return;
  1275. }
  1276. /**
  1277. * target_if_init_spectral_ops() - Initialize target_if internal Spectral
  1278. * operations.
  1279. * @spectral: Pointer to Spectral target_if internal private data
  1280. *
  1281. * Initializes all function pointers in target_if_spectral_ops for
  1282. * all generations
  1283. *
  1284. * Return: None
  1285. */
  1286. static void
  1287. target_if_init_spectral_ops(struct target_if_spectral *spectral)
  1288. {
  1289. target_if_init_spectral_ops_common();
  1290. if (spectral->spectral_gen == SPECTRAL_GEN2)
  1291. target_if_init_spectral_ops_gen2();
  1292. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  1293. target_if_init_spectral_ops_gen3();
  1294. else
  1295. spectral_err("Invalid Spectral generation");
  1296. }
  1297. /*
  1298. * Dummy Functions:
  1299. * These functions are initially registered to avoid any crashes due to
  1300. * invocation of spectral functions before they are registered.
  1301. */
  1302. static uint64_t
  1303. null_get_tsf64(void *arg)
  1304. {
  1305. spectral_ops_not_registered("get_tsf64");
  1306. return 0;
  1307. }
  1308. static uint32_t
  1309. null_get_capability(void *arg, enum spectral_capability_type type)
  1310. {
  1311. /*
  1312. * TODO : We should have conditional compilation to get the capability
  1313. * : We have not yet attahced ATH layer here, so there is no
  1314. * : way to check the HAL capbalities
  1315. */
  1316. spectral_ops_not_registered("get_capability");
  1317. /* TODO : For the time being, we are returning TRUE */
  1318. return true;
  1319. }
  1320. static uint32_t
  1321. null_set_rxfilter(void *arg, int rxfilter)
  1322. {
  1323. spectral_ops_not_registered("set_rxfilter");
  1324. return 1;
  1325. }
  1326. static uint32_t
  1327. null_get_rxfilter(void *arg)
  1328. {
  1329. spectral_ops_not_registered("get_rxfilter");
  1330. return 0;
  1331. }
  1332. static uint32_t
  1333. null_is_spectral_active(void *arg)
  1334. {
  1335. spectral_ops_not_registered("is_spectral_active");
  1336. return 1;
  1337. }
  1338. static uint32_t
  1339. null_is_spectral_enabled(void *arg)
  1340. {
  1341. spectral_ops_not_registered("is_spectral_enabled");
  1342. return 1;
  1343. }
  1344. static uint32_t
  1345. null_start_spectral_scan(void *arg)
  1346. {
  1347. spectral_ops_not_registered("start_spectral_scan");
  1348. return 1;
  1349. }
  1350. static uint32_t
  1351. null_stop_spectral_scan(void *arg)
  1352. {
  1353. spectral_ops_not_registered("stop_spectral_scan");
  1354. return 1;
  1355. }
  1356. static uint32_t
  1357. null_get_extension_channel(void *arg)
  1358. {
  1359. spectral_ops_not_registered("get_extension_channel");
  1360. return 1;
  1361. }
  1362. static int8_t
  1363. null_get_ctl_noisefloor(void *arg)
  1364. {
  1365. spectral_ops_not_registered("get_ctl_noisefloor");
  1366. return 1;
  1367. }
  1368. static int8_t
  1369. null_get_ext_noisefloor(void *arg)
  1370. {
  1371. spectral_ops_not_registered("get_ext_noisefloor");
  1372. return 0;
  1373. }
  1374. static uint32_t
  1375. null_configure_spectral(void *arg, struct spectral_config *params)
  1376. {
  1377. spectral_ops_not_registered("configure_spectral");
  1378. return 0;
  1379. }
  1380. static uint32_t
  1381. null_get_spectral_config(void *arg, struct spectral_config *params)
  1382. {
  1383. spectral_ops_not_registered("get_spectral_config");
  1384. return 0;
  1385. }
  1386. static uint32_t
  1387. null_get_ent_spectral_mask(void *arg)
  1388. {
  1389. spectral_ops_not_registered("get_ent_spectral_mask");
  1390. return 0;
  1391. }
  1392. static uint32_t
  1393. null_get_mac_address(void *arg, char *addr)
  1394. {
  1395. spectral_ops_not_registered("get_mac_address");
  1396. return 0;
  1397. }
  1398. static uint32_t
  1399. null_get_current_channel(void *arg)
  1400. {
  1401. spectral_ops_not_registered("get_current_channel");
  1402. return 0;
  1403. }
  1404. static uint32_t
  1405. null_reset_hw(void *arg)
  1406. {
  1407. spectral_ops_not_registered("get_current_channel");
  1408. return 0;
  1409. }
  1410. static uint32_t
  1411. null_get_chain_noise_floor(void *arg, int16_t *nf_buf)
  1412. {
  1413. spectral_ops_not_registered("get_chain_noise_floor");
  1414. return 0;
  1415. }
  1416. static int
  1417. null_spectral_process_phyerr(struct target_if_spectral *spectral,
  1418. uint8_t *data,
  1419. uint32_t datalen,
  1420. struct target_if_spectral_rfqual_info *p_rfqual,
  1421. struct target_if_spectral_chan_info *p_chaninfo,
  1422. uint64_t tsf64,
  1423. struct target_if_spectral_acs_stats *acs_stats)
  1424. {
  1425. spectral_ops_not_registered("spectral_process_phyerr");
  1426. return 0;
  1427. }
  1428. static int
  1429. null_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  1430. void *payload)
  1431. {
  1432. spectral_ops_not_registered("process_spectral_report");
  1433. return 0;
  1434. }
  1435. /**
  1436. * target_if_spectral_init_dummy_function_table() -
  1437. * Initialize target_if internal
  1438. * Spectral operations to dummy functions
  1439. * @ps: Pointer to Spectral target_if internal private data
  1440. *
  1441. * Initialize all the function pointers in target_if_spectral_ops with
  1442. * dummy functions.
  1443. *
  1444. * Return: None
  1445. */
  1446. static void
  1447. target_if_spectral_init_dummy_function_table(struct target_if_spectral *ps)
  1448. {
  1449. struct target_if_spectral_ops *p_sops = GET_TARGET_IF_SPECTRAL_OPS(ps);
  1450. p_sops->get_tsf64 = null_get_tsf64;
  1451. p_sops->get_capability = null_get_capability;
  1452. p_sops->set_rxfilter = null_set_rxfilter;
  1453. p_sops->get_rxfilter = null_get_rxfilter;
  1454. p_sops->is_spectral_enabled = null_is_spectral_enabled;
  1455. p_sops->is_spectral_active = null_is_spectral_active;
  1456. p_sops->start_spectral_scan = null_start_spectral_scan;
  1457. p_sops->stop_spectral_scan = null_stop_spectral_scan;
  1458. p_sops->get_extension_channel = null_get_extension_channel;
  1459. p_sops->get_ctl_noisefloor = null_get_ctl_noisefloor;
  1460. p_sops->get_ext_noisefloor = null_get_ext_noisefloor;
  1461. p_sops->configure_spectral = null_configure_spectral;
  1462. p_sops->get_spectral_config = null_get_spectral_config;
  1463. p_sops->get_ent_spectral_mask = null_get_ent_spectral_mask;
  1464. p_sops->get_mac_address = null_get_mac_address;
  1465. p_sops->get_current_channel = null_get_current_channel;
  1466. p_sops->reset_hw = null_reset_hw;
  1467. p_sops->get_chain_noise_floor = null_get_chain_noise_floor;
  1468. p_sops->spectral_process_phyerr = null_spectral_process_phyerr;
  1469. p_sops->process_spectral_report = null_process_spectral_report;
  1470. }
  1471. /**
  1472. * target_if_spectral_register_funcs() - Initialize target_if internal Spectral
  1473. * operations
  1474. * @spectral: Pointer to Spectral target_if internal private data
  1475. * @p: Pointer to Spectral function table
  1476. *
  1477. * Return: None
  1478. */
  1479. static void
  1480. target_if_spectral_register_funcs(struct target_if_spectral *spectral,
  1481. struct target_if_spectral_ops *p)
  1482. {
  1483. struct target_if_spectral_ops *p_sops =
  1484. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1485. p_sops->get_tsf64 = p->get_tsf64;
  1486. p_sops->get_capability = p->get_capability;
  1487. p_sops->set_rxfilter = p->set_rxfilter;
  1488. p_sops->get_rxfilter = p->get_rxfilter;
  1489. p_sops->is_spectral_enabled = p->is_spectral_enabled;
  1490. p_sops->is_spectral_active = p->is_spectral_active;
  1491. p_sops->start_spectral_scan = p->start_spectral_scan;
  1492. p_sops->stop_spectral_scan = p->stop_spectral_scan;
  1493. p_sops->get_extension_channel = p->get_extension_channel;
  1494. p_sops->get_ctl_noisefloor = p->get_ctl_noisefloor;
  1495. p_sops->get_ext_noisefloor = p->get_ext_noisefloor;
  1496. p_sops->configure_spectral = p->configure_spectral;
  1497. p_sops->get_spectral_config = p->get_spectral_config;
  1498. p_sops->get_ent_spectral_mask = p->get_ent_spectral_mask;
  1499. p_sops->get_mac_address = p->get_mac_address;
  1500. p_sops->get_current_channel = p->get_current_channel;
  1501. p_sops->reset_hw = p->reset_hw;
  1502. p_sops->get_chain_noise_floor = p->get_chain_noise_floor;
  1503. p_sops->spectral_process_phyerr = p->spectral_process_phyerr;
  1504. p_sops->process_spectral_report = p->process_spectral_report;
  1505. }
  1506. /**
  1507. * target_if_spectral_clear_stats() - Clear Spectral stats
  1508. * @spectral: Pointer to Spectral target_if internal private data
  1509. *
  1510. * Function to clear spectral stats
  1511. *
  1512. * Return: None
  1513. */
  1514. static void
  1515. target_if_spectral_clear_stats(struct target_if_spectral *spectral)
  1516. {
  1517. struct target_if_spectral_ops *p_sops =
  1518. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1519. qdf_mem_zero(&spectral->spectral_stats,
  1520. sizeof(struct target_if_spectral_stats));
  1521. spectral->spectral_stats.last_reset_tstamp =
  1522. p_sops->get_tsf64(spectral);
  1523. }
  1524. /**
  1525. * target_if_spectral_check_hw_capability() - Check whether HW supports spectral
  1526. * @spectral: Pointer to Spectral target_if internal private data
  1527. *
  1528. * Function to check whether hardware supports spectral
  1529. *
  1530. * Return: True if HW supports Spectral, false if HW does not support Spectral
  1531. */
  1532. static int
  1533. target_if_spectral_check_hw_capability(struct target_if_spectral *spectral)
  1534. {
  1535. struct target_if_spectral_ops *p_sops = NULL;
  1536. struct spectral_caps *pcap = NULL;
  1537. int is_spectral_supported = true;
  1538. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1539. pcap = &spectral->capability;
  1540. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG) == false) {
  1541. is_spectral_supported = false;
  1542. spectral_info("SPECTRAL : No PHYDIAG support");
  1543. return is_spectral_supported;
  1544. }
  1545. pcap->phydiag_cap = 1;
  1546. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR) == false) {
  1547. is_spectral_supported = false;
  1548. spectral_info("SPECTRAL : No RADAR support");
  1549. return is_spectral_supported;
  1550. }
  1551. pcap->radar_cap = 1;
  1552. if (p_sops->get_capability(spectral,
  1553. SPECTRAL_CAP_SPECTRAL_SCAN) == false) {
  1554. is_spectral_supported = false;
  1555. spectral_info("SPECTRAL : No SPECTRAL SUPPORT");
  1556. return is_spectral_supported;
  1557. }
  1558. pcap->spectral_cap = 1;
  1559. if (p_sops->get_capability(spectral, SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN)
  1560. == false) {
  1561. spectral_info("SPECTRAL : No ADVANCED SPECTRAL SUPPORT");
  1562. } else {
  1563. pcap->advncd_spectral_cap = 1;
  1564. }
  1565. return is_spectral_supported;
  1566. }
  1567. /**
  1568. * target_if_spectral_init_param_defaults() - Initialize Spectral
  1569. * parameter defaults
  1570. * @spectral: Pointer to Spectral target_if internal private data
  1571. *
  1572. * It is the caller's responsibility to ensure that the Spectral parameters
  1573. * structure passed as part of Spectral target_if internal private data is
  1574. * valid.
  1575. *
  1576. * Return: None
  1577. */
  1578. static void
  1579. target_if_spectral_init_param_defaults(struct target_if_spectral *spectral)
  1580. {
  1581. struct spectral_config *params = &spectral->params;
  1582. params->ss_count = SPECTRAL_SCAN_COUNT_DEFAULT;
  1583. if (spectral->spectral_gen == SPECTRAL_GEN3)
  1584. params->ss_period = SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT;
  1585. else
  1586. params->ss_period = SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT;
  1587. params->ss_spectral_pri = SPECTRAL_SCAN_PRIORITY_DEFAULT;
  1588. params->ss_fft_size = SPECTRAL_SCAN_FFT_SIZE_DEFAULT;
  1589. params->ss_gc_ena = SPECTRAL_SCAN_GC_ENA_DEFAULT;
  1590. params->ss_restart_ena = SPECTRAL_SCAN_RESTART_ENA_DEFAULT;
  1591. params->ss_noise_floor_ref = SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT;
  1592. params->ss_init_delay = SPECTRAL_SCAN_INIT_DELAY_DEFAULT;
  1593. params->ss_nb_tone_thr = SPECTRAL_SCAN_NB_TONE_THR_DEFAULT;
  1594. params->ss_str_bin_thr = SPECTRAL_SCAN_STR_BIN_THR_DEFAULT;
  1595. params->ss_wb_rpt_mode = SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT;
  1596. params->ss_rssi_rpt_mode = SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT;
  1597. params->ss_rssi_thr = SPECTRAL_SCAN_RSSI_THR_DEFAULT;
  1598. params->ss_pwr_format = SPECTRAL_SCAN_PWR_FORMAT_DEFAULT;
  1599. params->ss_rpt_mode = SPECTRAL_SCAN_RPT_MODE_DEFAULT;
  1600. params->ss_bin_scale = SPECTRAL_SCAN_BIN_SCALE_DEFAULT;
  1601. params->ss_dbm_adj = SPECTRAL_SCAN_DBM_ADJ_DEFAULT;
  1602. /*
  1603. * XXX
  1604. * SPECTRAL_SCAN_CHN_MASK_DEFAULT (0x1) specifies that chain 0 is to be
  1605. * used
  1606. * for Spectral. This is expected to be an optimal configuration for
  1607. * most chipsets considering aspects like power save. But this can later
  1608. * optionally be changed to be set to the default system Rx chainmask
  1609. * advertised by FW (if required for some purpose), once the Convergence
  1610. * framework supports such retrieval at pdev attach time.
  1611. */
  1612. params->ss_chn_mask = SPECTRAL_SCAN_CHN_MASK_DEFAULT;
  1613. params->ss_short_report = SPECTRAL_SCAN_SHORT_REPORT_DEFAULT;
  1614. params->ss_fft_period = SPECTRAL_SCAN_FFT_PERIOD_DEFAULT;
  1615. }
  1616. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1617. /**
  1618. * target_if_spectral_detach_simulation() - De-initialize Spectral
  1619. * Simulation functionality
  1620. * @spectral: Pointer to Spectral target_if internal private data
  1621. *
  1622. * Function to de-initialize Spectral Simulation functionality
  1623. *
  1624. * Return: None
  1625. */
  1626. static void
  1627. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1628. {
  1629. target_if_spectral_sim_detach(spectral);
  1630. }
  1631. #else
  1632. static void
  1633. target_if_spectral_detach_simulation(struct target_if_spectral *spectral)
  1634. {
  1635. }
  1636. #endif
  1637. /**
  1638. * target_if_spectral_detach() - De-initialize target_if Spectral
  1639. * @pdev: Pointer to pdev object
  1640. *
  1641. * Function to detach target_if spectral
  1642. *
  1643. * Return: None
  1644. */
  1645. static void
  1646. target_if_spectral_detach(struct target_if_spectral *spectral)
  1647. {
  1648. spectral_info("spectral detach");
  1649. if (spectral) {
  1650. qdf_spinlock_destroy(&spectral->param_info.osps_lock);
  1651. target_if_spectral_detach_simulation(spectral);
  1652. qdf_spinlock_destroy(&spectral->spectral_lock);
  1653. qdf_spinlock_destroy(&spectral->noise_pwr_reports_lock);
  1654. qdf_mem_free(spectral);
  1655. spectral = NULL;
  1656. }
  1657. }
  1658. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1659. /**
  1660. * target_if_spectral_attach_simulation() - Initialize Spectral Simulation
  1661. * functionality
  1662. * @spectral: Pointer to Spectral target_if internal private data
  1663. *
  1664. * Function to initialize spectral simulation functionality
  1665. *
  1666. * Return: 0 on success, negative error code on failure
  1667. */
  1668. static int
  1669. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1670. {
  1671. if (target_if_spectral_sim_attach(spectral)) {
  1672. qdf_mem_free(spectral);
  1673. return -EPERM;
  1674. }
  1675. return 0;
  1676. }
  1677. #else
  1678. static int
  1679. target_if_spectral_attach_simulation(struct target_if_spectral *spectral)
  1680. {
  1681. return 0;
  1682. }
  1683. #endif
  1684. /**
  1685. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  1686. * functionality for the given pdev
  1687. * @pdev: Pointer to pdev object
  1688. *
  1689. * Function to initialize pointer to spectral target_if internal private data
  1690. *
  1691. * Return: On success, pointer to Spectral target_if internal private data, on
  1692. * failure, NULL
  1693. */
  1694. void *
  1695. target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev)
  1696. {
  1697. struct target_if_spectral_ops *p_sops = NULL;
  1698. struct target_if_spectral *spectral = NULL;
  1699. #ifdef CONFIG_WIN
  1700. uint32_t target_type;
  1701. uint32_t target_revision;
  1702. struct wlan_objmgr_psoc *psoc;
  1703. struct wlan_lmac_if_target_tx_ops *tx_ops;
  1704. #endif
  1705. if (!pdev) {
  1706. spectral_err("SPECTRAL: pdev is NULL!");
  1707. return NULL;
  1708. }
  1709. spectral = (struct target_if_spectral *)qdf_mem_malloc(
  1710. sizeof(struct target_if_spectral));
  1711. if (!spectral) {
  1712. spectral_err("SPECTRAL : Memory allocation failed");
  1713. return spectral;
  1714. }
  1715. qdf_mem_zero(spectral, sizeof(struct target_if_spectral));
  1716. /* Store pdev in Spectral */
  1717. spectral->pdev_obj = pdev;
  1718. #ifdef CONFIG_WIN
  1719. psoc = wlan_pdev_get_psoc(pdev);
  1720. tx_ops = &psoc->soc_cb.tx_ops.target_tx_ops;
  1721. if (tx_ops->tgt_get_tgt_type) {
  1722. target_type = tx_ops->tgt_get_tgt_type(psoc);
  1723. } else {
  1724. qdf_mem_free(spectral);
  1725. return NULL;
  1726. }
  1727. if (tx_ops->tgt_get_tgt_revision) {
  1728. target_revision = tx_ops->tgt_get_tgt_revision(psoc);
  1729. } else {
  1730. qdf_mem_free(spectral);
  1731. return NULL;
  1732. }
  1733. #endif
  1734. /* init the function ptr table */
  1735. target_if_spectral_init_dummy_function_table(spectral);
  1736. /* get spectral function table */
  1737. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1738. /* TODO : Should this be called here of after ath_attach ? */
  1739. if (p_sops->get_capability(spectral, SPECTRAL_CAP_PHYDIAG))
  1740. spectral_info("HAL_CAP_PHYDIAG : Capable");
  1741. /* TODO: Need to fix the capablity check for RADAR */
  1742. if (p_sops->get_capability(spectral, SPECTRAL_CAP_RADAR))
  1743. spectral_info("HAL_CAP_RADAR : Capable");
  1744. /* TODO : Need to fix the capablity check for SPECTRAL */
  1745. /* TODO : Should this be called here of after ath_attach ? */
  1746. if (p_sops->get_capability(spectral, SPECTRAL_CAP_SPECTRAL_SCAN))
  1747. spectral_info("HAL_CAP_SPECTRAL_SCAN : Capable");
  1748. qdf_spinlock_create(&spectral->spectral_lock);
  1749. qdf_spinlock_create(&spectral->noise_pwr_reports_lock);
  1750. target_if_spectral_clear_stats(spectral);
  1751. #ifdef CONFIG_WIN
  1752. if (target_type == TARGET_TYPE_QCA8074) {
  1753. spectral->fftbin_size_war = 1;
  1754. spectral->inband_fftbin_size_adj = 1;
  1755. } else {
  1756. spectral->fftbin_size_war = 0;
  1757. spectral->inband_fftbin_size_adj = 0;
  1758. }
  1759. if ((target_type == TARGET_TYPE_QCA8074) || (
  1760. target_type == TARGET_TYPE_QCA6290)) {
  1761. spectral->spectral_gen = SPECTRAL_GEN3;
  1762. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN3;
  1763. spectral->tag_sscan_summary_exp =
  1764. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3;
  1765. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN3;
  1766. spectral->tlvhdr_size = SPECTRAL_PHYERR_TLVSIZE_GEN3;
  1767. } else
  1768. #endif
  1769. {
  1770. spectral->spectral_gen = SPECTRAL_GEN2;
  1771. spectral->hdr_sig_exp = SPECTRAL_PHYERR_SIGNATURE_GEN2;
  1772. spectral->tag_sscan_summary_exp =
  1773. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2;
  1774. spectral->tag_sscan_fft_exp = TLV_TAG_SEARCH_FFT_REPORT_GEN2;
  1775. spectral->tlvhdr_size = sizeof(struct spectral_phyerr_tlv_gen2);
  1776. }
  1777. /* Set the default values for spectral parameters */
  1778. target_if_spectral_init_param_defaults(spectral);
  1779. /* Init spectral capability */
  1780. target_if_init_spectral_capability(spectral);
  1781. if (target_if_spectral_attach_simulation(spectral) < 0)
  1782. return NULL;
  1783. target_if_init_spectral_ops(spectral);
  1784. qdf_spinlock_create(&spectral->param_info.osps_lock);
  1785. spectral->param_info.osps_cache.osc_is_valid = 0;
  1786. target_if_spectral_register_funcs(spectral, &spectral_ops);
  1787. if (target_if_spectral_check_hw_capability(spectral) == false) {
  1788. target_if_spectral_detach(spectral);
  1789. spectral = NULL;
  1790. } else {
  1791. /*
  1792. * TODO: Once the driver architecture transitions to chipset
  1793. * versioning based checks, reflect this here.
  1794. */
  1795. spectral->is_160_format = false;
  1796. spectral->is_lb_edge_extrabins_format = false;
  1797. spectral->is_rb_edge_extrabins_format = false;
  1798. #ifdef CONFIG_WIN
  1799. if (target_type == TARGET_TYPE_QCA9984 ||
  1800. target_type == TARGET_TYPE_QCA9888) {
  1801. spectral->is_160_format = true;
  1802. spectral->is_lb_edge_extrabins_format = true;
  1803. spectral->is_rb_edge_extrabins_format = true;
  1804. } else if ((target_type == TARGET_TYPE_AR900B) &&
  1805. (target_revision == AR900B_REV_2)) {
  1806. spectral->is_rb_edge_extrabins_format = true;
  1807. }
  1808. if (target_type == TARGET_TYPE_QCA9984 ||
  1809. target_type == TARGET_TYPE_QCA9888)
  1810. spectral->is_sec80_rssi_war_required = true;
  1811. spectral->use_nl_bcast = true;
  1812. #else
  1813. spectral->use_nl_bcast = false;
  1814. #endif
  1815. }
  1816. return spectral;
  1817. }
  1818. /**
  1819. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  1820. * functionality for the given pdev
  1821. * @pdev: Pointer to pdev object
  1822. *
  1823. * Function to de-initialize pointer to spectral target_if internal private data
  1824. *
  1825. * Return: None
  1826. */
  1827. void
  1828. target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev)
  1829. {
  1830. struct target_if_spectral *spectral = NULL;
  1831. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1832. if (!spectral) {
  1833. spectral_err("SPECTRAL : Module doesn't exist");
  1834. return;
  1835. }
  1836. target_if_spectral_detach(spectral);
  1837. return;
  1838. }
  1839. /**
  1840. * target_if_set_spectral_config() - Set spectral config
  1841. * @pdev: Pointer to pdev object
  1842. * @threshtype: config type
  1843. * @value: config value
  1844. *
  1845. * API to set spectral configurations
  1846. *
  1847. * Return: 0 on success else failure
  1848. */
  1849. int
  1850. target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  1851. const uint32_t threshtype, const uint32_t value)
  1852. {
  1853. struct spectral_config params;
  1854. struct target_if_spectral_ops *p_sops = NULL;
  1855. struct target_if_spectral *spectral = NULL;
  1856. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1857. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1858. if (!spectral) {
  1859. spectral_err("spectral object is NULL");
  1860. return -EPERM;
  1861. }
  1862. switch (threshtype) {
  1863. case SPECTRAL_PARAM_FFT_PERIOD:
  1864. spectral->params.ss_fft_period = value;
  1865. break;
  1866. case SPECTRAL_PARAM_SCAN_PERIOD:
  1867. spectral->params.ss_period = value;
  1868. break;
  1869. case SPECTRAL_PARAM_SCAN_COUNT:
  1870. spectral->params.ss_count = value;
  1871. break;
  1872. case SPECTRAL_PARAM_SHORT_REPORT:
  1873. spectral->params.ss_short_report = (!!value) ? true : false;
  1874. break;
  1875. case SPECTRAL_PARAM_SPECT_PRI:
  1876. spectral->params.ss_spectral_pri = (!!value) ? true : false;
  1877. break;
  1878. case SPECTRAL_PARAM_FFT_SIZE:
  1879. spectral->params.ss_fft_size = value;
  1880. break;
  1881. case SPECTRAL_PARAM_GC_ENA:
  1882. spectral->params.ss_gc_ena = !!value;
  1883. break;
  1884. case SPECTRAL_PARAM_RESTART_ENA:
  1885. spectral->params.ss_restart_ena = !!value;
  1886. break;
  1887. case SPECTRAL_PARAM_NOISE_FLOOR_REF:
  1888. spectral->params.ss_noise_floor_ref = value;
  1889. break;
  1890. case SPECTRAL_PARAM_INIT_DELAY:
  1891. spectral->params.ss_init_delay = value;
  1892. break;
  1893. case SPECTRAL_PARAM_NB_TONE_THR:
  1894. spectral->params.ss_nb_tone_thr = value;
  1895. break;
  1896. case SPECTRAL_PARAM_STR_BIN_THR:
  1897. spectral->params.ss_str_bin_thr = value;
  1898. break;
  1899. case SPECTRAL_PARAM_WB_RPT_MODE:
  1900. spectral->params.ss_wb_rpt_mode = !!value;
  1901. break;
  1902. case SPECTRAL_PARAM_RSSI_RPT_MODE:
  1903. spectral->params.ss_rssi_rpt_mode = !!value;
  1904. break;
  1905. case SPECTRAL_PARAM_RSSI_THR:
  1906. spectral->params.ss_rssi_thr = value;
  1907. break;
  1908. case SPECTRAL_PARAM_PWR_FORMAT:
  1909. spectral->params.ss_pwr_format = !!value;
  1910. break;
  1911. case SPECTRAL_PARAM_RPT_MODE:
  1912. spectral->params.ss_rpt_mode = value;
  1913. break;
  1914. case SPECTRAL_PARAM_BIN_SCALE:
  1915. spectral->params.ss_bin_scale = value;
  1916. break;
  1917. case SPECTRAL_PARAM_DBM_ADJ:
  1918. spectral->params.ss_dbm_adj = !!value;
  1919. break;
  1920. case SPECTRAL_PARAM_CHN_MASK:
  1921. spectral->params.ss_chn_mask = value;
  1922. break;
  1923. }
  1924. p_sops->configure_spectral(spectral, &spectral->params);
  1925. /* only to validate the writes */
  1926. p_sops->get_spectral_config(spectral, &params);
  1927. return 0;
  1928. }
  1929. /**
  1930. * target_if_get_fft_bin_count() - Get fft bin count for a given fft length
  1931. * @fft_len: FFT length
  1932. * @pdev: Pointer to pdev object
  1933. *
  1934. * API to get fft bin count for a given fft length
  1935. *
  1936. * Return: FFt bin count
  1937. */
  1938. static int
  1939. target_if_get_fft_bin_count(int fft_len)
  1940. {
  1941. int bin_count = 0;
  1942. switch (fft_len) {
  1943. case 5:
  1944. bin_count = 16;
  1945. break;
  1946. case 6:
  1947. bin_count = 32;
  1948. break;
  1949. case 7:
  1950. bin_count = 64;
  1951. break;
  1952. case 8:
  1953. bin_count = 128;
  1954. break;
  1955. case 9:
  1956. bin_count = 256;
  1957. break;
  1958. default:
  1959. break;
  1960. }
  1961. return bin_count;
  1962. }
  1963. /**
  1964. * target_if_init_upper_lower_flags() - Initializes control and extension
  1965. * segment flags
  1966. * @fft_len: FFT length
  1967. * @pdev: Pointer to pdev object
  1968. *
  1969. * API to initialize the control and extension flags with the lower/upper
  1970. * segment based on the HT mode
  1971. *
  1972. * Return: FFt bin count
  1973. */
  1974. static void
  1975. target_if_init_upper_lower_flags(struct target_if_spectral *spectral)
  1976. {
  1977. int current_channel = 0;
  1978. int ext_channel = 0;
  1979. struct target_if_spectral_ops *p_sops =
  1980. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1981. current_channel = p_sops->get_current_channel(spectral);
  1982. ext_channel = p_sops->get_extension_channel(spectral);
  1983. if ((current_channel == 0) || (ext_channel == 0))
  1984. return;
  1985. if (spectral->sc_spectral_20_40_mode) {
  1986. /* HT40 mode */
  1987. if (ext_channel < current_channel) {
  1988. spectral->lower_is_extension = 1;
  1989. spectral->upper_is_control = 1;
  1990. spectral->lower_is_control = 0;
  1991. spectral->upper_is_extension = 0;
  1992. } else {
  1993. spectral->lower_is_extension = 0;
  1994. spectral->upper_is_control = 0;
  1995. spectral->lower_is_control = 1;
  1996. spectral->upper_is_extension = 1;
  1997. }
  1998. } else {
  1999. /* HT20 mode, lower is always control */
  2000. spectral->lower_is_extension = 0;
  2001. spectral->upper_is_control = 0;
  2002. spectral->lower_is_control = 1;
  2003. spectral->upper_is_extension = 0;
  2004. }
  2005. }
  2006. /**
  2007. * target_if_get_spectral_config() - Get spectral configuration
  2008. * @pdev: Pointer to pdev object
  2009. * @param: Pointer to spectral_config structure in which the configuration
  2010. * should be returned
  2011. *
  2012. * API to get the current spectral configuration
  2013. *
  2014. * Return: None
  2015. */
  2016. void
  2017. target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  2018. struct spectral_config *param)
  2019. {
  2020. struct target_if_spectral_ops *p_sops = NULL;
  2021. struct target_if_spectral *spectral = NULL;
  2022. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2023. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2024. qdf_mem_zero(param, sizeof(struct spectral_config));
  2025. p_sops->get_spectral_config(spectral, param);
  2026. }
  2027. /**
  2028. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  2029. * parameters
  2030. * @spectral: Pointer to Spectral target_if internal private data
  2031. * @spectral_params: Pointer to Spectral parameters
  2032. *
  2033. * Enable use of desired Spectral parameters by configuring them into HW, and
  2034. * starting Spectral scan
  2035. *
  2036. * Return: 0 on success, 1 on failure
  2037. */
  2038. int
  2039. target_if_spectral_scan_enable_params(struct target_if_spectral *spectral,
  2040. struct spectral_config *spectral_params)
  2041. {
  2042. int extension_channel = 0;
  2043. int current_channel = 0;
  2044. struct target_if_spectral_ops *p_sops = NULL;
  2045. struct wlan_objmgr_vdev *vdev = NULL;
  2046. if (!spectral) {
  2047. spectral_err("SPECTRAL : Spectral is NULL");
  2048. return 1;
  2049. }
  2050. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2051. if (!p_sops) {
  2052. spectral_err("SPECTRAL : p_sops is NULL");
  2053. return 1;
  2054. }
  2055. spectral->sc_spectral_noise_pwr_cal =
  2056. spectral_params->ss_spectral_pri ? 1 : 0;
  2057. /* check if extension channel is present */
  2058. extension_channel = p_sops->get_extension_channel(spectral);
  2059. current_channel = p_sops->get_current_channel(spectral);
  2060. vdev = target_if_spectral_get_vdev(spectral);
  2061. if (!vdev)
  2062. return 1;
  2063. spectral->ch_width = target_if_vdev_get_ch_width(vdev);
  2064. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2065. if (spectral->ch_width == CH_WIDTH_INVALID)
  2066. return 1;
  2067. if (spectral->capability.advncd_spectral_cap) {
  2068. spectral->lb_edge_extrabins = 0;
  2069. spectral->rb_edge_extrabins = 0;
  2070. if (spectral->is_lb_edge_extrabins_format &&
  2071. spectral->params.ss_rpt_mode == 2) {
  2072. spectral->lb_edge_extrabins = 4;
  2073. }
  2074. if (spectral->is_rb_edge_extrabins_format &&
  2075. spectral->params.ss_rpt_mode == 2) {
  2076. spectral->rb_edge_extrabins = 4;
  2077. }
  2078. if (spectral->ch_width == CH_WIDTH_20MHZ) {
  2079. spectral->sc_spectral_20_40_mode = 0;
  2080. spectral->spectral_numbins =
  2081. target_if_get_fft_bin_count(
  2082. spectral->params.ss_fft_size);
  2083. spectral->spectral_fft_len =
  2084. target_if_get_fft_bin_count(
  2085. spectral->params.ss_fft_size);
  2086. spectral->spectral_data_len =
  2087. target_if_get_fft_bin_count(
  2088. spectral->params.ss_fft_size);
  2089. /*
  2090. * Initialize classifier params to be sent to user
  2091. * space classifier
  2092. */
  2093. spectral->classifier_params.lower_chan_in_mhz =
  2094. current_channel;
  2095. spectral->classifier_params.upper_chan_in_mhz = 0;
  2096. } else if (spectral->ch_width == CH_WIDTH_40MHZ) {
  2097. /* TODO : Remove this variable */
  2098. spectral->sc_spectral_20_40_mode = 1;
  2099. spectral->spectral_numbins =
  2100. target_if_get_fft_bin_count(
  2101. spectral->params.ss_fft_size);
  2102. spectral->spectral_fft_len =
  2103. target_if_get_fft_bin_count(
  2104. spectral->params.ss_fft_size);
  2105. spectral->spectral_data_len =
  2106. target_if_get_fft_bin_count(
  2107. spectral->params.ss_fft_size);
  2108. /*
  2109. * Initialize classifier params to be sent to user
  2110. * space classifier
  2111. */
  2112. if (extension_channel < current_channel) {
  2113. spectral->classifier_params.lower_chan_in_mhz =
  2114. extension_channel;
  2115. spectral->classifier_params.upper_chan_in_mhz =
  2116. current_channel;
  2117. } else {
  2118. spectral->classifier_params.lower_chan_in_mhz =
  2119. current_channel;
  2120. spectral->classifier_params.upper_chan_in_mhz =
  2121. extension_channel;
  2122. }
  2123. } else if (spectral->ch_width == CH_WIDTH_80MHZ) {
  2124. /* Set the FFT Size */
  2125. /* TODO : Remove this variable */
  2126. spectral->sc_spectral_20_40_mode = 0;
  2127. spectral->spectral_numbins =
  2128. target_if_get_fft_bin_count(
  2129. spectral->params.ss_fft_size);
  2130. spectral->spectral_fft_len =
  2131. target_if_get_fft_bin_count(
  2132. spectral->params.ss_fft_size);
  2133. spectral->spectral_data_len =
  2134. target_if_get_fft_bin_count(
  2135. spectral->params.ss_fft_size);
  2136. /*
  2137. * Initialize classifier params to be sent to user
  2138. * space classifier
  2139. */
  2140. spectral->classifier_params.lower_chan_in_mhz =
  2141. current_channel;
  2142. spectral->classifier_params.upper_chan_in_mhz = 0;
  2143. /*
  2144. * Initialize classifier params to be sent to user
  2145. * space classifier
  2146. */
  2147. if (extension_channel < current_channel) {
  2148. spectral->classifier_params.lower_chan_in_mhz =
  2149. extension_channel;
  2150. spectral->classifier_params.upper_chan_in_mhz =
  2151. current_channel;
  2152. } else {
  2153. spectral->classifier_params.lower_chan_in_mhz =
  2154. current_channel;
  2155. spectral->classifier_params.upper_chan_in_mhz =
  2156. extension_channel;
  2157. }
  2158. } else if (spectral->ch_width == CH_WIDTH_160MHZ) {
  2159. /* Set the FFT Size */
  2160. /* The below applies to both 160 and 80+80 cases */
  2161. /* TODO : Remove this variable */
  2162. spectral->sc_spectral_20_40_mode = 0;
  2163. spectral->spectral_numbins =
  2164. target_if_get_fft_bin_count(
  2165. spectral->params.ss_fft_size);
  2166. spectral->spectral_fft_len =
  2167. target_if_get_fft_bin_count(
  2168. spectral->params.ss_fft_size);
  2169. spectral->spectral_data_len =
  2170. target_if_get_fft_bin_count(
  2171. spectral->params.ss_fft_size);
  2172. /*
  2173. * Initialize classifier params to be sent to user
  2174. * space classifier
  2175. */
  2176. spectral->classifier_params.lower_chan_in_mhz =
  2177. current_channel;
  2178. spectral->classifier_params.upper_chan_in_mhz = 0;
  2179. /*
  2180. * Initialize classifier params to be sent to user
  2181. * space classifier
  2182. */
  2183. if (extension_channel < current_channel) {
  2184. spectral->classifier_params.lower_chan_in_mhz =
  2185. extension_channel;
  2186. spectral->classifier_params.upper_chan_in_mhz =
  2187. current_channel;
  2188. } else {
  2189. spectral->classifier_params.lower_chan_in_mhz =
  2190. current_channel;
  2191. spectral->classifier_params.upper_chan_in_mhz =
  2192. extension_channel;
  2193. }
  2194. }
  2195. if (spectral->spectral_numbins) {
  2196. spectral->spectral_numbins +=
  2197. spectral->lb_edge_extrabins;
  2198. spectral->spectral_numbins +=
  2199. spectral->rb_edge_extrabins;
  2200. }
  2201. if (spectral->spectral_fft_len) {
  2202. spectral->spectral_fft_len +=
  2203. spectral->lb_edge_extrabins;
  2204. spectral->spectral_fft_len +=
  2205. spectral->rb_edge_extrabins;
  2206. }
  2207. if (spectral->spectral_data_len) {
  2208. spectral->spectral_data_len +=
  2209. spectral->lb_edge_extrabins;
  2210. spectral->spectral_data_len +=
  2211. spectral->rb_edge_extrabins;
  2212. }
  2213. } else {
  2214. /*
  2215. * The decision to find 20/40 mode is found based on the
  2216. * presence of extension channel
  2217. * instead of channel width, as the channel width can
  2218. * dynamically change
  2219. */
  2220. if (extension_channel == 0) {
  2221. spectral->spectral_numbins = SPECTRAL_HT20_NUM_BINS;
  2222. spectral->spectral_dc_index = SPECTRAL_HT20_DC_INDEX;
  2223. spectral->spectral_fft_len = SPECTRAL_HT20_FFT_LEN;
  2224. spectral->spectral_data_len =
  2225. SPECTRAL_HT20_TOTAL_DATA_LEN;
  2226. /* only valid in 20-40 mode */
  2227. spectral->spectral_lower_max_index_offset = -1;
  2228. /* only valid in 20-40 mode */
  2229. spectral->spectral_upper_max_index_offset = -1;
  2230. spectral->spectral_max_index_offset =
  2231. spectral->spectral_fft_len + 2;
  2232. spectral->sc_spectral_20_40_mode = 0;
  2233. /*
  2234. * Initialize classifier params to be sent to user
  2235. * space classifier
  2236. */
  2237. spectral->classifier_params.lower_chan_in_mhz =
  2238. current_channel;
  2239. spectral->classifier_params.upper_chan_in_mhz = 0;
  2240. } else {
  2241. spectral->spectral_numbins =
  2242. SPECTRAL_HT40_TOTAL_NUM_BINS;
  2243. spectral->spectral_fft_len = SPECTRAL_HT40_FFT_LEN;
  2244. spectral->spectral_data_len =
  2245. SPECTRAL_HT40_TOTAL_DATA_LEN;
  2246. spectral->spectral_dc_index = SPECTRAL_HT40_DC_INDEX;
  2247. /* only valid in 20 mode */
  2248. spectral->spectral_max_index_offset = -1;
  2249. spectral->spectral_lower_max_index_offset =
  2250. spectral->spectral_fft_len + 2;
  2251. spectral->spectral_upper_max_index_offset =
  2252. spectral->spectral_fft_len + 5;
  2253. spectral->sc_spectral_20_40_mode = 1;
  2254. /*
  2255. * Initialize classifier params to be sent to user
  2256. * space classifier
  2257. */
  2258. if (extension_channel < current_channel) {
  2259. spectral->classifier_params.lower_chan_in_mhz =
  2260. extension_channel;
  2261. spectral->classifier_params.upper_chan_in_mhz =
  2262. current_channel;
  2263. } else {
  2264. spectral->classifier_params.lower_chan_in_mhz =
  2265. current_channel;
  2266. spectral->classifier_params.upper_chan_in_mhz =
  2267. extension_channel;
  2268. }
  2269. }
  2270. }
  2271. spectral->send_single_packet = 0;
  2272. spectral->classifier_params.spectral_20_40_mode =
  2273. spectral->sc_spectral_20_40_mode;
  2274. spectral->classifier_params.spectral_dc_index =
  2275. spectral->spectral_dc_index;
  2276. spectral->spectral_sent_msg = 0;
  2277. spectral->classify_scan = 0;
  2278. spectral->num_spectral_data = 0;
  2279. if (!p_sops->is_spectral_active(spectral)) {
  2280. p_sops->configure_spectral(spectral, spectral_params);
  2281. p_sops->start_spectral_scan(spectral);
  2282. } else {
  2283. }
  2284. /* get current spectral configuration */
  2285. p_sops->get_spectral_config(spectral, &spectral->params);
  2286. target_if_init_upper_lower_flags(spectral);
  2287. return 0;
  2288. }
  2289. /**
  2290. * target_if_start_spectral_scan() - Start spectral scan
  2291. * @pdev: Pointer to pdev object
  2292. *
  2293. * API to start spectral scan
  2294. *
  2295. * Return: 0 in case of success, -1 on failure
  2296. */
  2297. int
  2298. target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev)
  2299. {
  2300. struct target_if_spectral_ops *p_sops = NULL;
  2301. struct target_if_spectral *spectral = NULL;
  2302. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2303. if (!spectral) {
  2304. spectral_err("SPECTRAL : Spectral LMAC object is NUll");
  2305. return -EPERM;
  2306. }
  2307. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2308. qdf_spin_lock(&spectral->spectral_lock);
  2309. target_if_spectral_scan_enable_params(spectral, &spectral->params);
  2310. qdf_spin_unlock(&spectral->spectral_lock);
  2311. return 0;
  2312. }
  2313. void
  2314. target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev)
  2315. {
  2316. struct target_if_spectral_ops *p_sops = NULL;
  2317. struct target_if_spectral *spectral = NULL;
  2318. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2319. if (!spectral) {
  2320. spectral_err("SPECTRAL : Spectral LMAC object is NUll ");
  2321. return;
  2322. }
  2323. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2324. qdf_spin_lock(&spectral->spectral_lock);
  2325. p_sops->stop_spectral_scan(spectral);
  2326. if (spectral->classify_scan) {
  2327. /* TODO : Check if this logic is necessary */
  2328. spectral->detects_control_channel = 0;
  2329. spectral->detects_extension_channel = 0;
  2330. spectral->detects_above_dc = 0;
  2331. spectral->detects_below_dc = 0;
  2332. spectral->classify_scan = 0;
  2333. }
  2334. spectral->send_single_packet = 0;
  2335. spectral->sc_spectral_scan = 0;
  2336. spectral->sc_spectral_noise_pwr_cal = 0;
  2337. /*
  2338. * Reset the priority because it stops WLAN rx.
  2339. * If it is needed to set, user has to set it explicitly
  2340. *
  2341. */
  2342. /* Reset Priority */
  2343. spectral->params.ss_spectral_pri = 0;
  2344. qdf_spin_unlock(&spectral->spectral_lock);
  2345. }
  2346. /**
  2347. * target_if_is_spectral_active() - Get whether Spectral is active
  2348. * @pdev: Pointer to pdev object
  2349. *
  2350. * API to get whether Spectral is active
  2351. *
  2352. * Return: True if Spectral is active, false if Spectral is not active
  2353. */
  2354. bool
  2355. target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev)
  2356. {
  2357. struct target_if_spectral *spectral = NULL;
  2358. struct target_if_spectral_ops *p_sops = NULL;
  2359. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2360. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2361. return p_sops->is_spectral_active(spectral);
  2362. }
  2363. /**
  2364. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  2365. * @pdev: Pointer to pdev object
  2366. *
  2367. * API to get whether Spectral is enabled
  2368. *
  2369. * Return: True if Spectral is enabled, false if Spectral is not enabled
  2370. */
  2371. bool
  2372. target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev)
  2373. {
  2374. struct target_if_spectral *spectral = NULL;
  2375. struct target_if_spectral_ops *p_sops = NULL;
  2376. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2377. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2378. return p_sops->is_spectral_enabled(spectral);
  2379. }
  2380. /**
  2381. * target_if_set_debug_level() - Set debug level for Spectral
  2382. * @pdev: Pointer to pdev object
  2383. * @debug_level: Debug level
  2384. *
  2385. * API to set the debug level for Spectral
  2386. *
  2387. * Return: 0 in case of success
  2388. */
  2389. int
  2390. target_if_set_debug_level(struct wlan_objmgr_pdev *pdev, uint32_t debug_level)
  2391. {
  2392. spectral_debug_level = (DEBUG_SPECTRAL << debug_level);
  2393. return 0;
  2394. }
  2395. /**
  2396. * target_if_get_debug_level() - Get debug level for Spectral
  2397. * @pdev: Pointer to pdev object
  2398. *
  2399. * API to get the debug level for Spectral
  2400. *
  2401. * Return: Current debug level
  2402. */
  2403. uint32_t
  2404. target_if_get_debug_level(struct wlan_objmgr_pdev *pdev)
  2405. {
  2406. return spectral_debug_level;
  2407. }
  2408. /**
  2409. * target_if_get_spectral_capinfo() - Get Spectral capability information
  2410. * @pdev: Pointer to pdev object
  2411. * @outdata: Buffer into which data should be copied
  2412. *
  2413. * API to get the spectral capability information
  2414. *
  2415. * Return: void
  2416. */
  2417. void
  2418. target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev, void *outdata)
  2419. {
  2420. struct target_if_spectral *spectral = NULL;
  2421. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2422. qdf_mem_copy(outdata, &spectral->capability,
  2423. sizeof(struct spectral_caps));
  2424. }
  2425. /**
  2426. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  2427. * @pdev: Pointer to pdev object
  2428. * @outdata: Buffer into which data should be copied
  2429. *
  2430. * API to get the spectral diagnostic statistics
  2431. *
  2432. * Return: void
  2433. */
  2434. void
  2435. target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev, void *outdata)
  2436. {
  2437. struct target_if_spectral *spectral = NULL;
  2438. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2439. qdf_mem_copy(outdata, &spectral->diag_stats,
  2440. sizeof(struct spectral_diag_stats));
  2441. }
  2442. /**
  2443. * target_if_register_wmi_spectral_cmd_ops() - Register wmi_spectral_cmd_ops
  2444. * @cmd_ops: Pointer to the structure having wmi_spectral_cmd function pointers
  2445. * @pdev: Pointer to pdev object
  2446. *
  2447. * API for register wmi_spectral_cmd_ops in spectral internal data structure
  2448. *
  2449. * Return: void
  2450. */
  2451. void
  2452. target_if_register_wmi_spectral_cmd_ops(struct wlan_objmgr_pdev *pdev,
  2453. struct wmi_spectral_cmd_ops *cmd_ops)
  2454. {
  2455. struct target_if_spectral *spectral = NULL;
  2456. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2457. spectral->param_wmi_cmd_ops.wmi_spectral_configure_cmd_send =
  2458. cmd_ops->wmi_spectral_configure_cmd_send;
  2459. spectral->param_wmi_cmd_ops.wmi_spectral_enable_cmd_send =
  2460. cmd_ops->wmi_spectral_enable_cmd_send;
  2461. }
  2462. /**
  2463. * target_if_register_netlink_cb() - Register Netlink callbacks
  2464. * @pdev: Pointer to pdev object
  2465. * @nl_cb: Netlink callbacks to register
  2466. *
  2467. * Return: void
  2468. */
  2469. static void
  2470. target_if_register_netlink_cb(
  2471. struct wlan_objmgr_pdev *pdev,
  2472. struct spectral_nl_cb *nl_cb)
  2473. {
  2474. struct target_if_spectral *spectral = NULL;
  2475. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2476. qdf_mem_copy(&spectral->nl_cb, nl_cb, sizeof(struct spectral_nl_cb));
  2477. if (spectral->use_nl_bcast)
  2478. spectral->send_phy_data = spectral->nl_cb.send_nl_bcast;
  2479. else
  2480. spectral->send_phy_data = spectral->nl_cb.send_nl_unicast;
  2481. }
  2482. /**
  2483. * target_if_use_nl_bcast() - Get whether to use broadcast/unicast while sending
  2484. * Netlink messages to the application layer
  2485. * @pdev: Pointer to pdev object
  2486. *
  2487. * Return: true for broadcast, false for unicast
  2488. */
  2489. static bool
  2490. target_if_use_nl_bcast(struct wlan_objmgr_pdev *pdev)
  2491. {
  2492. struct target_if_spectral *spectral = NULL;
  2493. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2494. return spectral->use_nl_bcast;
  2495. }
  2496. /**
  2497. * target_if_deregister_netlink_cb() - De-register Netlink callbacks
  2498. * @pdev: Pointer to pdev object
  2499. *
  2500. * Return: void
  2501. */
  2502. static void
  2503. target_if_deregister_netlink_cb(struct wlan_objmgr_pdev *pdev)
  2504. {
  2505. struct target_if_spectral *spectral = NULL;
  2506. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2507. if (!spectral) {
  2508. spectral_err("SPECTRAL : Module doesn't exist");
  2509. return;
  2510. }
  2511. qdf_mem_zero(&spectral->nl_cb, sizeof(struct spectral_nl_cb));
  2512. }
  2513. static int
  2514. target_if_process_spectral_report(struct wlan_objmgr_pdev *pdev,
  2515. void *payload)
  2516. {
  2517. struct target_if_spectral *spectral = NULL;
  2518. struct target_if_spectral_ops *p_sops = NULL;
  2519. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2520. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2521. return p_sops->process_spectral_report(pdev, payload);
  2522. }
  2523. void
  2524. target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  2525. {
  2526. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_init =
  2527. target_if_pdev_spectral_init;
  2528. tx_ops->sptrl_tx_ops.sptrlto_pdev_spectral_deinit =
  2529. target_if_pdev_spectral_deinit;
  2530. tx_ops->sptrl_tx_ops.sptrlto_set_spectral_config =
  2531. target_if_set_spectral_config;
  2532. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_config =
  2533. target_if_get_spectral_config;
  2534. tx_ops->sptrl_tx_ops.sptrlto_start_spectral_scan =
  2535. target_if_start_spectral_scan;
  2536. tx_ops->sptrl_tx_ops.sptrlto_stop_spectral_scan =
  2537. target_if_stop_spectral_scan;
  2538. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_active =
  2539. target_if_is_spectral_active;
  2540. tx_ops->sptrl_tx_ops.sptrlto_is_spectral_enabled =
  2541. target_if_is_spectral_enabled;
  2542. tx_ops->sptrl_tx_ops.sptrlto_set_debug_level =
  2543. target_if_set_debug_level;
  2544. tx_ops->sptrl_tx_ops.sptrlto_get_debug_level =
  2545. target_if_get_debug_level;
  2546. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_capinfo =
  2547. target_if_get_spectral_capinfo;
  2548. tx_ops->sptrl_tx_ops.sptrlto_get_spectral_diagstats =
  2549. target_if_get_spectral_diagstats;
  2550. tx_ops->sptrl_tx_ops.sptrlto_register_wmi_spectral_cmd_ops =
  2551. target_if_register_wmi_spectral_cmd_ops;
  2552. tx_ops->sptrl_tx_ops.sptrlto_register_netlink_cb =
  2553. target_if_register_netlink_cb;
  2554. tx_ops->sptrl_tx_ops.sptrlto_use_nl_bcast =
  2555. target_if_use_nl_bcast;
  2556. tx_ops->sptrl_tx_ops.sptrlto_deregister_netlink_cb =
  2557. target_if_deregister_netlink_cb;
  2558. tx_ops->sptrl_tx_ops.sptrlto_process_spectral_report =
  2559. target_if_process_spectral_report;
  2560. }
  2561. qdf_export_symbol(target_if_sptrl_register_tx_ops);
  2562. void
  2563. target_if_spectral_send_intf_found_msg(struct wlan_objmgr_pdev *pdev,
  2564. uint16_t cw_int, uint32_t dcs_enabled)
  2565. {
  2566. struct spectral_samp_msg *msg = NULL;
  2567. struct target_if_spectral_ops *p_sops = NULL;
  2568. struct target_if_spectral *spectral = NULL;
  2569. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2570. msg = (struct spectral_samp_msg *)spectral->nl_cb.get_nbuff(
  2571. spectral->pdev_obj);
  2572. if (msg) {
  2573. msg->int_type = cw_int ?
  2574. SPECTRAL_DCS_INT_CW : SPECTRAL_DCS_INT_WIFI;
  2575. msg->dcs_enabled = dcs_enabled;
  2576. msg->signature = SPECTRAL_SIGNATURE;
  2577. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2578. p_sops->get_mac_address(spectral, msg->macaddr);
  2579. if (spectral->send_phy_data(pdev) == 0)
  2580. spectral->spectral_sent_msg++;
  2581. }
  2582. }
  2583. qdf_export_symbol(target_if_spectral_send_intf_found_msg);