target_if_spectral.c 79 KB

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