target_if_spectral.c 79 KB

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