target_if_spectral.c 81 KB

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