target_if_spectral.c 81 KB

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