target_if_spectral.c 88 KB

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