target_if_spectral.c 78 KB

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