target_if_spectral.c 71 KB

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