target_if_spectral.c 80 KB

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