target_if_spectral.c 80 KB

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