target_if_spectral.c 71 KB

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