target_if_spectral.c 71 KB

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