target_if_spectral_phyerr.c 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718
  1. /*
  2. * Copyright (c) 2011,2017-2021 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 <osdep.h>
  20. #include <qdf_types.h>
  21. #include <qdf_module.h>
  22. #include <wlan_tgt_def_config.h>
  23. #include <hif.h>
  24. #include <hif_hw_version.h>
  25. #include <wmi_unified_api.h>
  26. #include <target_if_spectral.h>
  27. #include <wlan_lmac_if_def.h>
  28. #include <wlan_osif_priv.h>
  29. #include <reg_services_public_struct.h>
  30. #include <target_if.h>
  31. #ifdef DIRECT_BUF_RX_ENABLE
  32. #include <target_if_direct_buf_rx_api.h>
  33. #endif
  34. extern int spectral_debug_level;
  35. #ifdef WLAN_CONV_SPECTRAL_ENABLE
  36. #define SPECTRAL_HEXDUMP_OCTET_PRINT_SIZE (3)
  37. #define SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE (16)
  38. #define SPECTRAL_HEXDUMP_EXTRA_BUFFER_PER_LINE (16)
  39. /*
  40. * Provision for the expected hexdump line size as follows:
  41. *
  42. * Size per octet multiplied by number of octets per line
  43. * +
  44. * ASCII representation which is equivalent in print size to number of octets
  45. * per line
  46. * +
  47. * Some extra buffer
  48. */
  49. #define SPECTRAL_HEXDUMP_LINESIZE \
  50. ((SPECTRAL_HEXDUMP_OCTET_PRINT_SIZE * \
  51. SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE) + \
  52. SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE + \
  53. SPECTRAL_HEXDUMP_EXTRA_BUFFER_PER_LINE)
  54. /**
  55. * target_if_spectral_hexdump() - Print hexdump of the given buffer
  56. * @_buf: Pointer to buffer
  57. * @_len: Length of the buffer
  58. *
  59. * Print the hexdump of buffer upto given length. Print upto
  60. * SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE per line, followed by the ASCII
  61. * representation of these octets.
  62. */
  63. static inline void target_if_spectral_hexdump(unsigned char *_buf, int _len)
  64. {
  65. int i, mod;
  66. unsigned char ascii[SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE + 1];
  67. unsigned char *pc = (_buf);
  68. char hexdump_line[SPECTRAL_HEXDUMP_LINESIZE + 1];
  69. int loc = 0;
  70. qdf_mem_zero(hexdump_line, sizeof(hexdump_line));
  71. if (_len <= 0) {
  72. spectral_err("buffer len is %d, too short", _len);
  73. return;
  74. }
  75. for (i = 0; i < _len; i++) {
  76. mod = i % SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE;
  77. if (!mod) {
  78. if (i) {
  79. qdf_assert_always(loc < sizeof(hexdump_line));
  80. loc += snprintf(&hexdump_line[loc],
  81. sizeof(hexdump_line) - loc,
  82. " %s", ascii);
  83. spectral_debug("%s", hexdump_line);
  84. qdf_mem_zero(hexdump_line,
  85. sizeof(hexdump_line));
  86. loc = 0;
  87. }
  88. }
  89. qdf_assert_always(loc < sizeof(hexdump_line));
  90. loc += snprintf(&hexdump_line[loc], sizeof(hexdump_line) - loc,
  91. " %02x", pc[i]);
  92. if ((pc[i] < 0x20) || (pc[i] > 0x7e))
  93. ascii[mod] = '.';
  94. else
  95. ascii[mod] = pc[i];
  96. ascii[(mod) + 1] = '\0';
  97. }
  98. while ((i % SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE) != 0) {
  99. qdf_assert_always(loc < sizeof(hexdump_line));
  100. loc += snprintf(&hexdump_line[loc], sizeof(hexdump_line) - loc,
  101. " ");
  102. i++;
  103. }
  104. qdf_assert_always(loc < sizeof(hexdump_line));
  105. snprintf(&hexdump_line[loc], sizeof(hexdump_line) - loc, " %s", ascii);
  106. spectral_debug("%s", hexdump_line);
  107. }
  108. /**
  109. * target_if_print_buf() - Prints given buffer for given length
  110. * @pbuf: Pointer to buffer
  111. * @len: length
  112. *
  113. * Prints given buffer for given length
  114. *
  115. * Return: void
  116. */
  117. static void
  118. target_if_print_buf(uint8_t *pbuf, int len)
  119. {
  120. int i = 0;
  121. for (i = 0; i < len; i++) {
  122. spectral_debug("%02X ", pbuf[i]);
  123. if (i % 32 == 31)
  124. spectral_debug("\n");
  125. }
  126. }
  127. int
  128. target_if_spectral_dump_fft(uint8_t *pfft, int fftlen)
  129. {
  130. int i = 0;
  131. /*
  132. * TODO : Do not delete the following print
  133. * The scripts used to validate Spectral depend on this Print
  134. */
  135. spectral_debug("SPECTRAL : FFT Length is 0x%x (%d)", fftlen, fftlen);
  136. spectral_debug("fft_data # ");
  137. for (i = 0; i < fftlen; i++)
  138. spectral_debug("%d ", pfft[i]);
  139. spectral_debug("\n");
  140. return 0;
  141. }
  142. QDF_STATUS target_if_spectral_fw_hang(struct target_if_spectral *spectral)
  143. {
  144. struct crash_inject param;
  145. struct wlan_objmgr_pdev *pdev;
  146. struct wlan_objmgr_psoc *psoc;
  147. struct target_if_psoc_spectral *psoc_spectral;
  148. if (!spectral) {
  149. spectral_err("Spectral LMAC object is null");
  150. return QDF_STATUS_E_INVAL;
  151. }
  152. pdev = spectral->pdev_obj;
  153. if (!pdev) {
  154. spectral_err("pdev is null");
  155. return QDF_STATUS_E_FAILURE;
  156. }
  157. psoc = wlan_pdev_get_psoc(pdev);
  158. if (!psoc) {
  159. spectral_err("psoc is null");
  160. return QDF_STATUS_E_FAILURE;
  161. }
  162. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  163. if (!psoc_spectral) {
  164. spectral_err("spectral psoc object is null");
  165. return QDF_STATUS_E_FAILURE;
  166. }
  167. qdf_mem_set(&param, sizeof(param), 0);
  168. param.type = 1; //RECOVERY_SIM_ASSERT
  169. return psoc_spectral->wmi_ops.wmi_spectral_crash_inject(
  170. GET_WMI_HDL_FROM_PDEV(spectral->pdev_obj), &param);
  171. }
  172. void
  173. target_if_dbg_print_samp_param(struct target_if_samp_msg_params *p)
  174. {
  175. spectral_debug("\nSAMP Packet : -------------------- START --------------------");
  176. spectral_debug("Freq = %d", p->freq);
  177. spectral_debug("RSSI = %d", p->rssi);
  178. spectral_debug("Bin Count = %d", p->pwr_count);
  179. spectral_debug("Timestamp = %d", p->tstamp);
  180. spectral_debug("SAMP Packet : -------------------- END -----------------------");
  181. }
  182. void
  183. target_if_dbg_print_samp_msg(struct spectral_samp_msg *ss_msg)
  184. {
  185. int i = 0;
  186. struct spectral_samp_data *p = &ss_msg->samp_data;
  187. struct spectral_classifier_params *pc = &p->classifier_params;
  188. struct interf_src_rsp *pi = &p->interf_list;
  189. spectral_dbg_line();
  190. spectral_debug("Spectral Message");
  191. spectral_dbg_line();
  192. spectral_debug("Signature : 0x%x", ss_msg->signature);
  193. spectral_debug("Freq : %d", ss_msg->freq);
  194. spectral_debug("Freq load : %d", ss_msg->freq_loading);
  195. spectral_debug("Intfnc type : %d", ss_msg->int_type);
  196. spectral_dbg_line();
  197. spectral_debug("Spectral Data info");
  198. spectral_dbg_line();
  199. spectral_debug("data length : %d", p->spectral_data_len);
  200. spectral_debug("rssi : %d", p->spectral_rssi);
  201. spectral_debug("combined rssi : %d", p->spectral_combined_rssi);
  202. spectral_debug("upper rssi : %d", p->spectral_upper_rssi);
  203. spectral_debug("lower rssi : %d", p->spectral_lower_rssi);
  204. spectral_debug("bw info : %d", p->spectral_bwinfo);
  205. spectral_debug("timestamp : %d", p->spectral_tstamp);
  206. spectral_debug("max index : %d", p->spectral_max_index);
  207. spectral_debug("max exp : %d", p->spectral_max_exp);
  208. spectral_debug("max mag : %d", p->spectral_max_mag);
  209. spectral_debug("last timstamp : %d", p->spectral_last_tstamp);
  210. spectral_debug("upper max idx : %d", p->spectral_upper_max_index);
  211. spectral_debug("lower max idx : %d", p->spectral_lower_max_index);
  212. spectral_debug("bin power count : %d", p->bin_pwr_count);
  213. spectral_dbg_line();
  214. spectral_debug("Classifier info");
  215. spectral_dbg_line();
  216. spectral_debug("20/40 Mode : %d", pc->spectral_20_40_mode);
  217. spectral_debug("dc index : %d", pc->spectral_dc_index);
  218. spectral_debug("dc in MHz : %d", pc->spectral_dc_in_mhz);
  219. spectral_debug("upper channel : %d", pc->upper_chan_in_mhz);
  220. spectral_debug("lower channel : %d", pc->lower_chan_in_mhz);
  221. spectral_dbg_line();
  222. spectral_debug("Interference info");
  223. spectral_dbg_line();
  224. spectral_debug("inter count : %d", pi->count);
  225. for (i = 0; i < pi->count; i++) {
  226. spectral_debug("inter type : %d",
  227. pi->interf[i].interf_type);
  228. spectral_debug("min freq : %d",
  229. pi->interf[i].interf_min_freq);
  230. spectral_debug("max freq : %d",
  231. pi->interf[i].interf_max_freq);
  232. }
  233. }
  234. uint32_t
  235. target_if_get_offset_swar_sec80(uint32_t channel_width)
  236. {
  237. uint32_t offset = 0;
  238. switch (channel_width) {
  239. case CH_WIDTH_20MHZ:
  240. offset = OFFSET_CH_WIDTH_20;
  241. break;
  242. case CH_WIDTH_40MHZ:
  243. offset = OFFSET_CH_WIDTH_40;
  244. break;
  245. case CH_WIDTH_80MHZ:
  246. offset = OFFSET_CH_WIDTH_80;
  247. break;
  248. case CH_WIDTH_160MHZ:
  249. case CH_WIDTH_80P80MHZ:
  250. offset = OFFSET_CH_WIDTH_160;
  251. break;
  252. default:
  253. offset = OFFSET_CH_WIDTH_80;
  254. break;
  255. }
  256. return offset;
  257. }
  258. /**
  259. * target_if_dump_summary_report_gen2() - Dump Spectral Summary Report for gen2
  260. * @ptlv: Pointer to Spectral Phyerr TLV
  261. * @tlvlen: length
  262. * @is_160_format: Indicates whether information provided by HW is in altered
  263. * format for 802.11ac 160/80+80 MHz support (QCA9984 onwards)
  264. *
  265. * Dump Spectral Summary Report for gen2
  266. *
  267. * Return: Success/Failure
  268. */
  269. static int
  270. target_if_dump_summary_report_gen2(struct spectral_phyerr_tlv_gen2 *ptlv,
  271. int tlvlen, bool is_160_format)
  272. {
  273. /*
  274. * For simplicity, everything is defined as uint32_t (except one).
  275. * Proper code will later use the right sizes.
  276. */
  277. /*
  278. * For easy comparision between MDK team and OS team, the MDK script
  279. * variable names have been used
  280. */
  281. uint32_t agc_mb_gain;
  282. uint32_t sscan_gidx;
  283. uint32_t agc_total_gain;
  284. uint32_t recent_rfsat;
  285. uint32_t ob_flag;
  286. uint32_t nb_mask;
  287. uint32_t peak_mag;
  288. int16_t peak_inx;
  289. uint32_t ss_summary_A = 0;
  290. uint32_t ss_summary_B = 0;
  291. uint32_t ss_summary_C = 0;
  292. uint32_t ss_summary_D = 0;
  293. uint32_t ss_summary_E = 0;
  294. struct spectral_phyerr_hdr_gen2 *phdr =
  295. (struct spectral_phyerr_hdr_gen2 *)(
  296. (uint8_t *)ptlv +
  297. sizeof(struct spectral_phyerr_tlv_gen2));
  298. spectral_debug("SPECTRAL : SPECTRAL SUMMARY REPORT");
  299. if (is_160_format) {
  300. if (tlvlen != 20) {
  301. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  302. tlvlen);
  303. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  304. return -EPERM;
  305. }
  306. /* Doing copy as the contents may not be aligned */
  307. qdf_mem_copy(&ss_summary_A, (uint8_t *)phdr, sizeof(int));
  308. qdf_mem_copy(&ss_summary_B,
  309. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  310. sizeof(int));
  311. qdf_mem_copy(&ss_summary_C,
  312. (uint8_t *)((uint8_t *)phdr + 2 * sizeof(int)),
  313. sizeof(int));
  314. qdf_mem_copy(&ss_summary_D,
  315. (uint8_t *)((uint8_t *)phdr + 3 * sizeof(int)),
  316. sizeof(int));
  317. qdf_mem_copy(&ss_summary_E,
  318. (uint8_t *)((uint8_t *)phdr + 4 * sizeof(int)),
  319. sizeof(int));
  320. /*
  321. * The following is adapted from MDK scripts for
  322. * easier comparability
  323. */
  324. recent_rfsat = ((ss_summary_A >> 8) & 0x1);
  325. sscan_gidx = (ss_summary_A & 0xff);
  326. spectral_debug("sscan_gidx=%d, is_recent_rfsat=%d",
  327. sscan_gidx, recent_rfsat);
  328. /* First segment */
  329. agc_mb_gain = ((ss_summary_B >> 10) & 0x7f);
  330. agc_total_gain = (ss_summary_B & 0x3ff);
  331. nb_mask = ((ss_summary_C >> 22) & 0xff);
  332. ob_flag = ((ss_summary_B >> 17) & 0x1);
  333. peak_inx = (ss_summary_C & 0xfff);
  334. if (peak_inx > 2047)
  335. peak_inx = peak_inx - 4096;
  336. peak_mag = ((ss_summary_C >> 12) & 0x3ff);
  337. spectral_debug("agc_total_gain_segid0 = 0x%.2x, agc_mb_gain_segid0=%d",
  338. agc_total_gain, agc_mb_gain);
  339. spectral_debug("nb_mask_segid0 = 0x%.2x, ob_flag_segid0=%d, peak_index_segid0=%d, peak_mag_segid0=%d",
  340. nb_mask, ob_flag, peak_inx, peak_mag);
  341. /* Second segment */
  342. agc_mb_gain = ((ss_summary_D >> 10) & 0x7f);
  343. agc_total_gain = (ss_summary_D & 0x3ff);
  344. nb_mask = ((ss_summary_E >> 22) & 0xff);
  345. ob_flag = ((ss_summary_D >> 17) & 0x1);
  346. peak_inx = (ss_summary_E & 0xfff);
  347. if (peak_inx > 2047)
  348. peak_inx = peak_inx - 4096;
  349. peak_mag = ((ss_summary_E >> 12) & 0x3ff);
  350. spectral_debug("agc_total_gain_segid1 = 0x%.2x, agc_mb_gain_segid1=%d",
  351. agc_total_gain, agc_mb_gain);
  352. spectral_debug("nb_mask_segid1 = 0x%.2x, ob_flag_segid1=%d, peak_index_segid1=%d, peak_mag_segid1=%d",
  353. nb_mask, ob_flag, peak_inx, peak_mag);
  354. } else {
  355. if (tlvlen != 8) {
  356. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  357. tlvlen);
  358. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  359. return -EPERM;
  360. }
  361. /* Doing copy as the contents may not be aligned */
  362. qdf_mem_copy(&ss_summary_A, (uint8_t *)phdr, sizeof(int));
  363. qdf_mem_copy(&ss_summary_B,
  364. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  365. sizeof(int));
  366. nb_mask = ((ss_summary_B >> 22) & 0xff);
  367. ob_flag = ((ss_summary_B >> 30) & 0x1);
  368. peak_inx = (ss_summary_B & 0xfff);
  369. if (peak_inx > 2047)
  370. peak_inx = peak_inx - 4096;
  371. peak_mag = ((ss_summary_B >> 12) & 0x3ff);
  372. agc_mb_gain = ((ss_summary_A >> 24) & 0x7f);
  373. agc_total_gain = (ss_summary_A & 0x3ff);
  374. sscan_gidx = ((ss_summary_A >> 16) & 0xff);
  375. recent_rfsat = ((ss_summary_B >> 31) & 0x1);
  376. spectral_debug("nb_mask = 0x%.2x, ob_flag=%d, peak_index=%d, peak_mag=%d, agc_mb_gain=%d, agc_total_gain=%d, sscan_gidx=%d, recent_rfsat=%d",
  377. nb_mask, ob_flag, peak_inx, peak_mag,
  378. agc_mb_gain, agc_total_gain, sscan_gidx,
  379. recent_rfsat);
  380. }
  381. return 0;
  382. }
  383. /**
  384. * target_if_process_sfft_report_gen2() - Process Search FFT Report
  385. * @ptlv: Pointer to Spectral Phyerr TLV
  386. * @tlvlen: length
  387. * @p_fft_info: Pointer to search fft info
  388. *
  389. * Dump Spectral Summary Report for gen2
  390. *
  391. * Return: Success/Failure
  392. */
  393. static int
  394. target_if_process_sfft_report_gen2(
  395. struct spectral_phyerr_tlv_gen2 *ptlv,
  396. int tlvlen,
  397. struct spectral_search_fft_info_gen2 *p_fft_info)
  398. {
  399. /*
  400. * For simplicity, everything is defined as uint32_t (except one).
  401. * Proper code will later use the right sizes.
  402. */
  403. /*
  404. * For easy comparision between MDK team and OS team, the MDK script
  405. * variable names have been used
  406. */
  407. uint32_t relpwr_db;
  408. uint32_t num_str_bins_ib;
  409. uint32_t base_pwr;
  410. uint32_t total_gain_info;
  411. uint32_t fft_chn_idx;
  412. int16_t peak_inx;
  413. uint32_t avgpwr_db;
  414. uint32_t peak_mag;
  415. uint32_t fft_summary_A = 0;
  416. uint32_t fft_summary_B = 0;
  417. uint8_t *tmp = (uint8_t *)ptlv;
  418. struct spectral_phyerr_hdr_gen2 *phdr =
  419. (struct spectral_phyerr_hdr_gen2 *)(
  420. tmp +
  421. sizeof(struct spectral_phyerr_tlv_gen2));
  422. /* Relook this */
  423. if (tlvlen < 8) {
  424. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  425. tlvlen);
  426. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  427. return -EPERM;
  428. }
  429. /* Doing copy as the contents may not be aligned */
  430. qdf_mem_copy(&fft_summary_A, (uint8_t *)phdr, sizeof(int));
  431. qdf_mem_copy(&fft_summary_B,
  432. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  433. sizeof(int));
  434. relpwr_db = ((fft_summary_B >> 26) & 0x3f);
  435. num_str_bins_ib = fft_summary_B & 0xff;
  436. base_pwr = ((fft_summary_A >> 14) & 0x1ff);
  437. total_gain_info = ((fft_summary_A >> 23) & 0x1ff);
  438. fft_chn_idx = ((fft_summary_A >> 12) & 0x3);
  439. peak_inx = fft_summary_A & 0xfff;
  440. if (peak_inx > 2047)
  441. peak_inx = peak_inx - 4096;
  442. avgpwr_db = ((fft_summary_B >> 18) & 0xff);
  443. peak_mag = ((fft_summary_B >> 8) & 0x3ff);
  444. /* Populate the Search FFT Info */
  445. if (p_fft_info) {
  446. p_fft_info->relpwr_db = relpwr_db;
  447. p_fft_info->num_str_bins_ib = num_str_bins_ib;
  448. p_fft_info->base_pwr = base_pwr;
  449. p_fft_info->total_gain_info = total_gain_info;
  450. p_fft_info->fft_chn_idx = fft_chn_idx;
  451. p_fft_info->peak_inx = peak_inx;
  452. p_fft_info->avgpwr_db = avgpwr_db;
  453. p_fft_info->peak_mag = peak_mag;
  454. }
  455. return 0;
  456. }
  457. /**
  458. * target_if_dump_adc_report_gen2() - Dump ADC Reports for gen2
  459. * @ptlv: Pointer to Spectral Phyerr TLV
  460. * @tlvlen: length
  461. *
  462. * Dump ADC Reports for gen2
  463. *
  464. * Return: Success/Failure
  465. */
  466. static int
  467. target_if_dump_adc_report_gen2(
  468. struct spectral_phyerr_tlv_gen2 *ptlv, int tlvlen)
  469. {
  470. int i;
  471. uint32_t *pdata;
  472. uint32_t data;
  473. /*
  474. * For simplicity, everything is defined as uint32_t (except one).
  475. * Proper code will later use the right sizes.
  476. */
  477. uint32_t samp_fmt;
  478. uint32_t chn_idx;
  479. uint32_t recent_rfsat;
  480. uint32_t agc_mb_gain;
  481. uint32_t agc_total_gain;
  482. uint32_t adc_summary = 0;
  483. uint8_t *ptmp = (uint8_t *)ptlv;
  484. spectral_debug("SPECTRAL : ADC REPORT");
  485. /* Relook this */
  486. if (tlvlen < 4) {
  487. spectral_err("Unexpected TLV length %d for ADC Report! Hexdump follows",
  488. tlvlen);
  489. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  490. return -EPERM;
  491. }
  492. qdf_mem_copy(&adc_summary, (uint8_t *)(ptlv + 4), sizeof(int));
  493. samp_fmt = ((adc_summary >> 28) & 0x1);
  494. chn_idx = ((adc_summary >> 24) & 0x3);
  495. recent_rfsat = ((adc_summary >> 23) & 0x1);
  496. agc_mb_gain = ((adc_summary >> 16) & 0x7f);
  497. agc_total_gain = adc_summary & 0x3ff;
  498. spectral_debug("samp_fmt= %u, chn_idx= %u, recent_rfsat= %u, agc_mb_gain=%u agc_total_gain=%u",
  499. samp_fmt, chn_idx, recent_rfsat, agc_mb_gain,
  500. agc_total_gain);
  501. for (i = 0; i < (tlvlen / 4); i++) {
  502. pdata = (uint32_t *)(ptmp + 4 + i * 4);
  503. data = *pdata;
  504. /* Interpreting capture format 1 */
  505. if (1) {
  506. uint8_t i1;
  507. uint8_t q1;
  508. uint8_t i2;
  509. uint8_t q2;
  510. int8_t si1;
  511. int8_t sq1;
  512. int8_t si2;
  513. int8_t sq2;
  514. i1 = data & 0xff;
  515. q1 = (data >> 8) & 0xff;
  516. i2 = (data >> 16) & 0xff;
  517. q2 = (data >> 24) & 0xff;
  518. if (i1 > 127)
  519. si1 = i1 - 256;
  520. else
  521. si1 = i1;
  522. if (q1 > 127)
  523. sq1 = q1 - 256;
  524. else
  525. sq1 = q1;
  526. if (i2 > 127)
  527. si2 = i2 - 256;
  528. else
  529. si2 = i2;
  530. if (q2 > 127)
  531. sq2 = q2 - 256;
  532. else
  533. sq2 = q2;
  534. spectral_debug("SPECTRAL ADC : Interpreting capture format 1");
  535. spectral_debug("adc_data_format_1 # %d %d %d",
  536. 2 * i, si1, sq1);
  537. spectral_debug("adc_data_format_1 # %d %d %d",
  538. 2 * i + 1, si2, sq2);
  539. }
  540. /* Interpreting capture format 0 */
  541. if (1) {
  542. uint16_t i1;
  543. uint16_t q1;
  544. int16_t si1;
  545. int16_t sq1;
  546. i1 = data & 0xffff;
  547. q1 = (data >> 16) & 0xffff;
  548. if (i1 > 32767)
  549. si1 = i1 - 65536;
  550. else
  551. si1 = i1;
  552. if (q1 > 32767)
  553. sq1 = q1 - 65536;
  554. else
  555. sq1 = q1;
  556. spectral_debug("SPECTRAL ADC : Interpreting capture format 0");
  557. spectral_debug("adc_data_format_2 # %d %d %d",
  558. i, si1, sq1);
  559. }
  560. }
  561. spectral_debug("\n");
  562. return 0;
  563. }
  564. /**
  565. * target_if_dump_sfft_report_gen2() - Process Search FFT Report for gen2
  566. * @ptlv: Pointer to Spectral Phyerr TLV
  567. * @tlvlen: length
  568. * @is_160_format: Indicates 160 format
  569. *
  570. * Process Search FFT Report for gen2
  571. *
  572. * Return: Success/Failure
  573. */
  574. static int
  575. target_if_dump_sfft_report_gen2(struct spectral_phyerr_tlv_gen2 *ptlv,
  576. int tlvlen, bool is_160_format)
  577. {
  578. int i;
  579. uint32_t fft_mag;
  580. /*
  581. * For simplicity, everything is defined as uint32_t (except one).
  582. * Proper code will later use the right sizes.
  583. */
  584. /*
  585. * For easy comparision between MDK team and OS team, the MDK script
  586. * variable names have been used
  587. */
  588. uint32_t relpwr_db;
  589. uint32_t num_str_bins_ib;
  590. uint32_t base_pwr;
  591. uint32_t total_gain_info;
  592. uint32_t fft_chn_idx;
  593. int16_t peak_inx;
  594. uint32_t avgpwr_db;
  595. uint32_t peak_mag;
  596. uint8_t segid;
  597. uint32_t fft_summary_A = 0;
  598. uint32_t fft_summary_B = 0;
  599. uint32_t fft_summary_C = 0;
  600. uint8_t *tmp = (uint8_t *)ptlv;
  601. struct spectral_phyerr_hdr_gen2 *phdr =
  602. (struct spectral_phyerr_hdr_gen2 *)(
  603. tmp +
  604. sizeof(struct spectral_phyerr_tlv_gen2));
  605. uint32_t segid_skiplen = 0;
  606. if (is_160_format)
  607. segid_skiplen = sizeof(SPECTRAL_SEGID_INFO);
  608. spectral_debug("SPECTRAL : SEARCH FFT REPORT");
  609. /* Relook this */
  610. if (tlvlen < (8 + segid_skiplen)) {
  611. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  612. tlvlen);
  613. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  614. return -EPERM;
  615. }
  616. /* Doing copy as the contents may not be aligned */
  617. qdf_mem_copy(&fft_summary_A, (uint8_t *)phdr, sizeof(int));
  618. qdf_mem_copy(&fft_summary_B,
  619. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  620. sizeof(int));
  621. if (is_160_format)
  622. qdf_mem_copy(&fft_summary_C,
  623. (uint8_t *)((uint8_t *)phdr + 2 * sizeof(int)),
  624. sizeof(int));
  625. relpwr_db = ((fft_summary_B >> 26) & 0x3f);
  626. num_str_bins_ib = fft_summary_B & 0xff;
  627. base_pwr = ((fft_summary_A >> 14) & 0x1ff);
  628. total_gain_info = ((fft_summary_A >> 23) & 0x1ff);
  629. fft_chn_idx = ((fft_summary_A >> 12) & 0x3);
  630. peak_inx = fft_summary_A & 0xfff;
  631. if (peak_inx > 2047)
  632. peak_inx = peak_inx - 4096;
  633. avgpwr_db = ((fft_summary_B >> 18) & 0xff);
  634. peak_mag = ((fft_summary_B >> 8) & 0x3ff);
  635. spectral_debug("Header A = 0x%x Header B = 0x%x",
  636. phdr->hdr_a, phdr->hdr_b);
  637. spectral_debug("Base Power= 0x%x, Total Gain= %d, relpwr_db=%d, num_str_bins_ib=%d fft_chn_idx=%d peak_inx=%d avgpwr_db=%d peak_mag=%d",
  638. base_pwr, total_gain_info, relpwr_db, num_str_bins_ib,
  639. fft_chn_idx, peak_inx, avgpwr_db, peak_mag);
  640. if (is_160_format) {
  641. segid = fft_summary_C & 0x1;
  642. spectral_debug("Segment ID: %hhu", segid);
  643. }
  644. spectral_debug("FFT bins:");
  645. for (i = 0; i < (tlvlen - 8 - segid_skiplen); i++) {
  646. fft_mag = ((uint8_t *)ptlv)[12 + segid_skiplen + i];
  647. spectral_debug("%d %d, ", i, fft_mag);
  648. }
  649. spectral_debug("\n");
  650. return 0;
  651. }
  652. #ifdef SPECTRAL_DEBUG_SAMP_MSG
  653. /**
  654. * target_if_spectral_log_SAMP_param() - Log SAMP parameters
  655. * @params: Reference to target_if_samp_msg_params
  656. *
  657. * API to log spectral SAMP message parameters
  658. *
  659. * Return: None
  660. */
  661. static void
  662. target_if_spectral_log_SAMP_param(struct target_if_samp_msg_params *params)
  663. {
  664. target_if_dbg_print_samp_param(params);
  665. }
  666. #else
  667. static void
  668. target_if_spectral_log_SAMP_param(struct target_if_samp_msg_params *params)
  669. {
  670. }
  671. #endif
  672. int
  673. target_if_process_phyerr_gen2(struct target_if_spectral *spectral,
  674. uint8_t *data,
  675. uint32_t datalen,
  676. struct target_if_spectral_rfqual_info *p_rfqual,
  677. struct target_if_spectral_chan_info *p_chaninfo,
  678. uint64_t tsf64,
  679. struct target_if_spectral_acs_stats *acs_stats)
  680. {
  681. /*
  682. * XXX : The classifier do not use all the members of the SAMP
  683. * message data format.
  684. * The classifier only depends upon the following parameters
  685. *
  686. * 1. Frequency (freq, msg->freq)
  687. * 2. Spectral RSSI (spectral_rssi,
  688. * msg->samp_data.spectral_rssi)
  689. * 3. Bin Power Count (bin_pwr_count,
  690. * msg->samp_data.bin_pwr_count)
  691. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  692. * 5. Spectral Timestamp (spectral_tstamp,
  693. * msg->samp_data.spectral_tstamp)
  694. * 6. MAC Address (macaddr, msg->macaddr)
  695. *
  696. * This function prepares the params structure and populates it
  697. * with
  698. * relevant values, this is in turn passed to
  699. * spectral_create_samp_msg()
  700. * to prepare fully formatted Spectral SAMP message
  701. *
  702. * XXX : Need to verify
  703. * 1. Order of FFT bin values
  704. *
  705. */
  706. struct target_if_samp_msg_params params;
  707. struct spectral_search_fft_info_gen2 search_fft_info;
  708. struct spectral_search_fft_info_gen2 *p_sfft = &search_fft_info;
  709. struct spectral_search_fft_info_gen2 search_fft_info_sec80;
  710. struct spectral_search_fft_info_gen2 *p_sfft_sec80 =
  711. &search_fft_info_sec80;
  712. uint32_t segid_skiplen = 0;
  713. int8_t rssi_up = 0;
  714. int8_t rssi_low = 0;
  715. int8_t chn_idx_highest_enabled = 0;
  716. int8_t chn_idx_lowest_enabled = 0;
  717. uint8_t control_rssi = 0;
  718. uint8_t extension_rssi = 0;
  719. uint8_t combined_rssi = 0;
  720. uint32_t tstamp = 0;
  721. struct target_if_spectral_ops *p_sops =
  722. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  723. struct spectral_phyerr_tlv_gen2 *ptlv =
  724. (struct spectral_phyerr_tlv_gen2 *)data;
  725. struct spectral_phyerr_tlv_gen2 *ptlv_sec80 = NULL;
  726. struct spectral_phyerr_fft_gen2 *pfft = NULL;
  727. struct spectral_phyerr_fft_gen2 *pfft_sec80 = NULL;
  728. uint8_t segid = 0;
  729. uint8_t segid_sec80 = 0;
  730. enum phy_ch_width ch_width =
  731. spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  732. if (spectral->is_160_format)
  733. segid_skiplen = sizeof(SPECTRAL_SEGID_INFO);
  734. pfft = (struct spectral_phyerr_fft_gen2 *)(
  735. data +
  736. sizeof(struct spectral_phyerr_tlv_gen2) +
  737. sizeof(struct spectral_phyerr_hdr_gen2) +
  738. segid_skiplen);
  739. /*
  740. * XXX Extend SPECTRAL_DPRINTK() to use spectral_debug_level,
  741. * and use this facility inside spectral_dump_phyerr_data()
  742. * and supporting functions.
  743. */
  744. if (spectral_debug_level & DEBUG_SPECTRAL2)
  745. target_if_spectral_dump_phyerr_data_gen2(
  746. data, datalen,
  747. spectral->is_160_format);
  748. if (spectral_debug_level & DEBUG_SPECTRAL4) {
  749. target_if_spectral_dump_phyerr_data_gen2(
  750. data, datalen,
  751. spectral->is_160_format);
  752. spectral_debug_level = DEBUG_SPECTRAL;
  753. }
  754. if (ptlv->signature != SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  755. /*
  756. * EV# 118023: We tentatively disable the below print
  757. * and provide stats instead.
  758. */
  759. spectral->diag_stats.spectral_mismatch++;
  760. return -EPERM;
  761. }
  762. OS_MEMZERO(&params, sizeof(params));
  763. /* Gen 2 only supports normal Spectral scan currently */
  764. params.smode = SPECTRAL_SCAN_MODE_NORMAL;
  765. if (ptlv->tag == TLV_TAG_SEARCH_FFT_REPORT_GEN2) {
  766. if (spectral->is_160_format) {
  767. segid = *((SPECTRAL_SEGID_INFO *)(
  768. (uint8_t *)ptlv +
  769. sizeof(struct spectral_phyerr_tlv_gen2) +
  770. sizeof(struct spectral_phyerr_hdr_gen2)));
  771. if (segid != 0) {
  772. struct spectral_diag_stats *p_diag_stats =
  773. &spectral->diag_stats;
  774. p_diag_stats->spectral_vhtseg1id_mismatch++;
  775. return -EPERM;
  776. }
  777. }
  778. target_if_process_sfft_report_gen2(ptlv, ptlv->length,
  779. &search_fft_info);
  780. tstamp = p_sops->get_tsf64(spectral) & SPECTRAL_TSMASK;
  781. combined_rssi = p_rfqual->rssi_comb;
  782. if (spectral->upper_is_control)
  783. rssi_up = control_rssi;
  784. else
  785. rssi_up = extension_rssi;
  786. if (spectral->lower_is_control)
  787. rssi_low = control_rssi;
  788. else
  789. rssi_low = extension_rssi;
  790. params.rssi = p_rfqual->rssi_comb;
  791. params.lower_rssi = rssi_low;
  792. params.upper_rssi = rssi_up;
  793. if (spectral->sc_spectral_noise_pwr_cal) {
  794. params.chain_ctl_rssi[0] =
  795. p_rfqual->pc_rssi_info[0].rssi_pri20;
  796. params.chain_ctl_rssi[1] =
  797. p_rfqual->pc_rssi_info[1].rssi_pri20;
  798. params.chain_ctl_rssi[2] =
  799. p_rfqual->pc_rssi_info[2].rssi_pri20;
  800. params.chain_ext_rssi[0] =
  801. p_rfqual->pc_rssi_info[0].rssi_sec20;
  802. params.chain_ext_rssi[1] =
  803. p_rfqual->pc_rssi_info[1].rssi_sec20;
  804. params.chain_ext_rssi[2] =
  805. p_rfqual->pc_rssi_info[2].rssi_sec20;
  806. }
  807. /*
  808. * XXX : This actually depends on the programmed chain mask
  809. * This value decides the per-chain enable mask to select
  810. * the input ADC for search FTT.
  811. * For modes upto VHT80, if more than one chain is
  812. * enabled, the max valid chain
  813. * is used. LSB corresponds to chain zero.
  814. * For VHT80_80 and VHT160, the lowest enabled chain is
  815. * used for primary
  816. * detection and highest enabled chain is used for
  817. * secondary detection.
  818. *
  819. * XXX : The current algorithm do not use these control and
  820. * extension channel
  821. * Instead, it just relies on the combined RSSI values
  822. * only.
  823. * For fool-proof detection algorithm, we should take
  824. * these RSSI values in to account.
  825. * This is marked for future enhancements.
  826. */
  827. chn_idx_highest_enabled =
  828. ((spectral->params[params.smode].ss_chn_mask & 0x8) ? 3 :
  829. (spectral->params[params.smode].ss_chn_mask & 0x4) ? 2 :
  830. (spectral->params[params.smode].ss_chn_mask & 0x2) ? 1 : 0);
  831. chn_idx_lowest_enabled =
  832. ((spectral->params[params.smode].ss_chn_mask & 0x1) ? 0 :
  833. (spectral->params[params.smode].ss_chn_mask & 0x2) ? 1 :
  834. (spectral->params[params.smode].ss_chn_mask & 0x4) ? 2 : 3);
  835. control_rssi = (uint8_t)
  836. p_rfqual->pc_rssi_info[chn_idx_highest_enabled].rssi_pri20;
  837. extension_rssi = (uint8_t)
  838. p_rfqual->pc_rssi_info[chn_idx_highest_enabled].rssi_sec20;
  839. params.bwinfo = 0;
  840. params.tstamp = 0;
  841. params.max_mag = p_sfft->peak_mag;
  842. params.max_index = p_sfft->peak_inx;
  843. params.max_exp = 0;
  844. params.peak = 0;
  845. params.bin_pwr_data = (uint8_t *)pfft;
  846. params.freq = p_sops->get_current_channel(spectral,
  847. params.smode);
  848. params.freq_loading = 0;
  849. params.interf_list.count = 0;
  850. params.max_lower_index = 0;
  851. params.max_upper_index = 0;
  852. params.nb_lower = 0;
  853. params.nb_upper = 0;
  854. /*
  855. * For modes upto VHT80, the noise floor is populated with the
  856. * one corresponding
  857. * to the highest enabled antenna chain
  858. */
  859. params.noise_floor =
  860. p_rfqual->noise_floor[chn_idx_highest_enabled];
  861. params.datalen = ptlv->length;
  862. params.pwr_count = ptlv->length -
  863. sizeof(struct spectral_phyerr_hdr_gen2) - segid_skiplen;
  864. params.tstamp = (tsf64 & SPECTRAL_TSMASK);
  865. acs_stats->ctrl_nf = params.noise_floor;
  866. acs_stats->ext_nf = params.noise_floor;
  867. acs_stats->nfc_ctl_rssi = control_rssi;
  868. acs_stats->nfc_ext_rssi = extension_rssi;
  869. if (spectral->is_160_format &&
  870. is_ch_width_160_or_80p80(ch_width)) {
  871. /*
  872. * We expect to see one more Search FFT report, and it
  873. * should be equal in size to the current one.
  874. */
  875. if (datalen < (
  876. 2 * (
  877. sizeof(struct spectral_phyerr_tlv_gen2) +
  878. ptlv->length))) {
  879. struct spectral_diag_stats *p_diag_stats =
  880. &spectral->diag_stats;
  881. p_diag_stats->spectral_sec80_sfft_insufflen++;
  882. return -EPERM;
  883. }
  884. ptlv_sec80 = (struct spectral_phyerr_tlv_gen2 *)(
  885. data +
  886. sizeof(struct spectral_phyerr_tlv_gen2) +
  887. ptlv->length);
  888. if (ptlv_sec80->signature !=
  889. SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  890. spectral->diag_stats.spectral_mismatch++;
  891. return -EPERM;
  892. }
  893. if (ptlv_sec80->tag != TLV_TAG_SEARCH_FFT_REPORT_GEN2) {
  894. spectral->diag_stats.spectral_no_sec80_sfft++;
  895. return -EPERM;
  896. }
  897. segid_sec80 = *((SPECTRAL_SEGID_INFO *)(
  898. (uint8_t *)ptlv_sec80 +
  899. sizeof(struct spectral_phyerr_tlv_gen2) +
  900. sizeof(struct spectral_phyerr_hdr_gen2)));
  901. if (segid_sec80 != 1) {
  902. struct spectral_diag_stats *p_diag_stats =
  903. &spectral->diag_stats;
  904. p_diag_stats->spectral_vhtseg2id_mismatch++;
  905. return -EPERM;
  906. }
  907. params.vhtop_ch_freq_seg1 = p_chaninfo->center_freq1;
  908. params.vhtop_ch_freq_seg2 = p_chaninfo->center_freq2;
  909. target_if_process_sfft_report_gen2(
  910. ptlv_sec80,
  911. ptlv_sec80->length,
  912. &search_fft_info_sec80);
  913. pfft_sec80 = (struct spectral_phyerr_fft_gen2 *)(
  914. ((uint8_t *)ptlv_sec80) +
  915. sizeof(struct spectral_phyerr_tlv_gen2) +
  916. sizeof(struct spectral_phyerr_hdr_gen2) +
  917. segid_skiplen);
  918. /* XXX: Confirm. TBD at SoD. */
  919. params.rssi_sec80 = p_rfqual->rssi_comb;
  920. if (spectral->is_sec80_rssi_war_required)
  921. params.rssi_sec80 =
  922. target_if_get_combrssi_sec80_seg_gen2
  923. (spectral, &search_fft_info_sec80);
  924. /* XXX: Determine dynamically. TBD at SoD. */
  925. /*
  926. * For VHT80_80/VHT160, the noise floor for primary
  927. * 80MHz segment is populated with the
  928. * lowest enabled antenna chain and the noise floor for
  929. * secondary 80MHz segment is populated
  930. * with the highest enabled antenna chain
  931. */
  932. params.noise_floor_sec80 =
  933. p_rfqual->noise_floor[chn_idx_highest_enabled];
  934. params.noise_floor =
  935. p_rfqual->noise_floor[chn_idx_lowest_enabled];
  936. params.max_mag_sec80 = p_sfft_sec80->peak_mag;
  937. params.max_index_sec80 = p_sfft_sec80->peak_inx;
  938. /* XXX Does this definition of datalen *still hold? */
  939. params.datalen_sec80 = ptlv_sec80->length;
  940. params.pwr_count_sec80 =
  941. ptlv_sec80->length -
  942. sizeof(struct spectral_phyerr_hdr_gen2) -
  943. segid_skiplen;
  944. params.bin_pwr_data_sec80 = (uint8_t *)pfft_sec80;
  945. }
  946. qdf_mem_copy(&params.classifier_params,
  947. &spectral->classifier_params,
  948. sizeof(struct spectral_classifier_params));
  949. target_if_spectral_log_SAMP_param(&params);
  950. target_if_spectral_create_samp_msg(spectral, &params);
  951. }
  952. return 0;
  953. }
  954. int
  955. target_if_spectral_dump_hdr_gen2(struct spectral_phyerr_hdr_gen2 *phdr)
  956. {
  957. uint32_t a = 0;
  958. uint32_t b = 0;
  959. qdf_mem_copy(&a, (uint8_t *)phdr, sizeof(int));
  960. qdf_mem_copy(&b,
  961. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  962. sizeof(int));
  963. spectral_debug("SPECTRAL : HEADER A 0x%x (%d)", a, a);
  964. spectral_debug("SPECTRAL : HEADER B 0x%x (%d)", b, b);
  965. return 0;
  966. }
  967. int8_t
  968. target_if_get_combrssi_sec80_seg_gen2(
  969. struct target_if_spectral *spectral,
  970. struct spectral_search_fft_info_gen2 *p_sfft_sec80)
  971. {
  972. uint32_t avgpwr_db = 0;
  973. uint32_t total_gain_db = 0;
  974. uint32_t offset = 0;
  975. int8_t comb_rssi = 0;
  976. /* Obtain required parameters for algorithm from search FFT report */
  977. avgpwr_db = p_sfft_sec80->avgpwr_db;
  978. total_gain_db = p_sfft_sec80->total_gain_info;
  979. /* Calculate offset */
  980. offset = target_if_get_offset_swar_sec80(
  981. spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL]);
  982. /* Calculate RSSI */
  983. comb_rssi = ((avgpwr_db - total_gain_db) + offset);
  984. return comb_rssi;
  985. }
  986. int
  987. target_if_spectral_dump_tlv_gen2(
  988. struct spectral_phyerr_tlv_gen2 *ptlv, bool is_160_format)
  989. {
  990. int ret = 0;
  991. /*
  992. * TODO : Do not delete the following print
  993. * The scripts used to validate Spectral depend on this Print
  994. */
  995. spectral_debug("SPECTRAL : TLV Length is 0x%x (%d)",
  996. ptlv->length, ptlv->length);
  997. switch (ptlv->tag) {
  998. case TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2:
  999. ret =
  1000. target_if_dump_summary_report_gen2(
  1001. ptlv, ptlv->length, is_160_format);
  1002. break;
  1003. case TLV_TAG_SEARCH_FFT_REPORT_GEN2:
  1004. ret =
  1005. target_if_dump_sfft_report_gen2(ptlv, ptlv->length,
  1006. is_160_format);
  1007. break;
  1008. case TLV_TAG_ADC_REPORT_GEN2:
  1009. ret = target_if_dump_adc_report_gen2(ptlv, ptlv->length);
  1010. break;
  1011. default:
  1012. spectral_warn("INVALID TLV");
  1013. ret = -1;
  1014. break;
  1015. }
  1016. return ret;
  1017. }
  1018. int
  1019. target_if_spectral_dump_phyerr_data_gen2(uint8_t *data, uint32_t datalen,
  1020. bool is_160_format)
  1021. {
  1022. struct spectral_phyerr_tlv_gen2 *ptlv = NULL;
  1023. uint32_t bytes_processed = 0;
  1024. uint32_t bytes_remaining = datalen;
  1025. uint32_t curr_tlv_complete_size = 0;
  1026. if (datalen < sizeof(struct spectral_phyerr_tlv_gen2)) {
  1027. spectral_err("Total PHY error data length %u too short to contain any TLVs",
  1028. datalen);
  1029. return -EPERM;
  1030. }
  1031. while (bytes_processed < datalen) {
  1032. if (bytes_remaining < sizeof(struct spectral_phyerr_tlv_gen2)) {
  1033. spectral_err("Remaining PHY error data length %u too short to contain a TLV",
  1034. bytes_remaining);
  1035. return -EPERM;
  1036. }
  1037. ptlv = (struct spectral_phyerr_tlv_gen2 *)(data +
  1038. bytes_processed);
  1039. if (ptlv->signature != SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  1040. spectral_err("Invalid signature 0x%x!",
  1041. ptlv->signature);
  1042. return -EPERM;
  1043. }
  1044. curr_tlv_complete_size =
  1045. sizeof(struct spectral_phyerr_tlv_gen2) +
  1046. ptlv->length;
  1047. if (curr_tlv_complete_size > bytes_remaining) {
  1048. spectral_err("TLV size %d greater than number of bytes remaining %d",
  1049. curr_tlv_complete_size, bytes_remaining);
  1050. return -EPERM;
  1051. }
  1052. if (target_if_spectral_dump_tlv_gen2(ptlv, is_160_format) == -1)
  1053. return -EPERM;
  1054. bytes_processed += curr_tlv_complete_size;
  1055. bytes_remaining = datalen - bytes_processed;
  1056. }
  1057. return 0;
  1058. }
  1059. #ifdef DIRECT_BUF_RX_ENABLE
  1060. /**
  1061. * target_if_get_spectral_mode() - Get Spectral scan mode corresponding to a
  1062. * detector id
  1063. * @detector_id: detector id in the Spectral report
  1064. * @rparams: pointer to report params object
  1065. *
  1066. * Helper API to get Spectral scan mode from the detector ID. This mapping is
  1067. * target specific.
  1068. *
  1069. * Return: Spectral scan mode
  1070. */
  1071. static enum spectral_scan_mode
  1072. target_if_get_spectral_mode(enum spectral_detector_id detector_id,
  1073. struct spectral_report_params *rparams)
  1074. {
  1075. if (detector_id >= SPECTRAL_DETECTOR_ID_MAX) {
  1076. spectral_err_rl("Invalid detector id %d", detector_id);
  1077. return SPECTRAL_SCAN_MODE_INVALID;
  1078. }
  1079. return rparams->detid_mode_table[detector_id];
  1080. }
  1081. /**
  1082. * target_if_spectral_get_bin_count_after_len_adj() - Get number of FFT bins in
  1083. * Spectral FFT report
  1084. * @fft_bin_len: FFT bin length reported by target
  1085. * @rpt_mode: Spectral report mode
  1086. * @swar: Spectral FFT bin length adjustments SWAR parameters
  1087. * @fft_bin_size: Size of one FFT bin in bytes
  1088. *
  1089. * Get actual number of FFT bins in the FFT report after adjusting the length
  1090. * by applying the SWARs for getting correct length.
  1091. *
  1092. * Return: FFT bin count
  1093. */
  1094. static size_t
  1095. target_if_spectral_get_bin_count_after_len_adj(
  1096. size_t fft_bin_len, uint8_t rpt_mode,
  1097. struct spectral_fft_bin_len_adj_swar *swar,
  1098. size_t *fft_bin_size)
  1099. {
  1100. size_t fft_bin_count = fft_bin_len;
  1101. if (rpt_mode == 1 && swar->null_fftbin_adj) {
  1102. /*
  1103. * No FFT bins are expected. Explicitly set FFT bin
  1104. * count to 0.
  1105. */
  1106. fft_bin_count = 0;
  1107. *fft_bin_size = 0;
  1108. } else {
  1109. /*
  1110. * Divide fft bin length by appropriate factor depending
  1111. * on the value of fftbin_size_war.
  1112. */
  1113. switch (swar->fftbin_size_war) {
  1114. case SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE:
  1115. fft_bin_count >>= 2;
  1116. *fft_bin_size = 4;
  1117. break;
  1118. case SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE:
  1119. fft_bin_count >>= 1;
  1120. *fft_bin_size = 2;
  1121. /* Ideally we should be dividing fft bin length
  1122. * by 2. Due to a HW bug, actual length is two
  1123. * times the expected length.
  1124. */
  1125. if (swar->packmode_fftbin_size_adj)
  1126. fft_bin_count >>= 1;
  1127. break;
  1128. case SPECTRAL_FFTBIN_SIZE_NO_WAR:
  1129. *fft_bin_size = 1;
  1130. /* No length adjustment */
  1131. break;
  1132. default:
  1133. qdf_assert_always(0);
  1134. }
  1135. if (rpt_mode == 2 && swar->inband_fftbin_size_adj)
  1136. fft_bin_count >>= 1;
  1137. }
  1138. return fft_bin_count;
  1139. }
  1140. #ifndef OPTIMIZED_SAMP_MESSAGE
  1141. /**
  1142. * target_if_process_sfft_report_gen3() - Process Search FFT Report for gen3
  1143. * @p_fft_report: Pointer to fft report
  1144. * @p_sfft: Pointer to search fft report
  1145. * @rparams: pointer to report params object
  1146. *
  1147. * Process Search FFT Report for gen3
  1148. *
  1149. * Return: Success/Failure
  1150. */
  1151. static int
  1152. target_if_process_sfft_report_gen3(
  1153. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  1154. struct spectral_search_fft_info_gen3 *p_sfft,
  1155. struct spectral_report_params *rparams)
  1156. {
  1157. int32_t peak_sidx = 0;
  1158. int32_t peak_mag;
  1159. qdf_assert_always(p_fft_report);
  1160. qdf_assert_always(p_sfft);
  1161. qdf_assert_always(rparams);
  1162. /*
  1163. * For simplicity, everything is defined as uint32_t (except one).
  1164. * Proper code will later use the right sizes.
  1165. */
  1166. /*
  1167. * For easy comparision between MDK team and OS team, the MDK script
  1168. * variable names have been used
  1169. */
  1170. /* Populate the Search FFT Info */
  1171. p_sfft->timestamp = p_fft_report->fft_timestamp;
  1172. p_sfft->fft_detector_id = get_bitfield(p_fft_report->hdr_a,
  1173. 2, 0);
  1174. p_sfft->fft_num = get_bitfield(p_fft_report->hdr_a, 3, 2);
  1175. switch (rparams->version) {
  1176. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1177. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  1178. 12, 5);
  1179. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 17);
  1180. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_a, 3, 28);
  1181. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  1182. 9, 0);
  1183. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  1184. 8, 9);
  1185. break;
  1186. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1187. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  1188. 14, 5);
  1189. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 19);
  1190. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_b, 3, 0);
  1191. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  1192. 9, 3);
  1193. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  1194. 8, 12);
  1195. break;
  1196. default:
  1197. qdf_assert_always(0);
  1198. }
  1199. p_sfft->fft_peak_sidx = unsigned_to_signed(peak_sidx, 11);
  1200. p_sfft->fft_num_str_bins_ib = get_bitfield(p_fft_report->hdr_c,
  1201. 8, 0);
  1202. peak_mag = get_bitfield(p_fft_report->hdr_c, 10, 8);
  1203. p_sfft->fft_peak_mag = unsigned_to_signed(peak_mag, 10);
  1204. p_sfft->fft_avgpwr_db = get_bitfield(p_fft_report->hdr_c,
  1205. 7, 18);
  1206. p_sfft->fft_relpwr_db = get_bitfield(p_fft_report->hdr_c,
  1207. 7, 25);
  1208. return 0;
  1209. }
  1210. #endif
  1211. /**
  1212. * target_if_dump_fft_report_gen3() - Dump FFT Report for gen3
  1213. * @spectral: Pointer to Spectral object
  1214. * @smode: Spectral scan mode
  1215. * @p_fft_report: Pointer to fft report
  1216. * @p_sfft: Pointer to search fft report
  1217. *
  1218. * Dump FFT Report for gen3
  1219. *
  1220. * Return: void
  1221. */
  1222. static void
  1223. target_if_dump_fft_report_gen3(struct target_if_spectral *spectral,
  1224. enum spectral_scan_mode smode,
  1225. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  1226. struct spectral_search_fft_info_gen3 *p_sfft)
  1227. {
  1228. size_t fft_hdr_length;
  1229. size_t report_len;
  1230. size_t fft_bin_len;
  1231. size_t fft_bin_count;
  1232. size_t fft_bin_size;
  1233. size_t fft_bin_len_inband_tfer = 0;
  1234. uint8_t *fft_bin_buf = NULL;
  1235. size_t fft_bin_buf_size;
  1236. uint8_t tag, signature;
  1237. qdf_assert_always(spectral);
  1238. /* There won't be FFT report/bins in report mode 0, so return */
  1239. if (!spectral->params[smode].ss_rpt_mode)
  1240. return;
  1241. fft_hdr_length = get_bitfield(
  1242. p_fft_report->fft_hdr_lts,
  1243. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  1244. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  1245. tag = get_bitfield(p_fft_report->fft_hdr_lts,
  1246. SPECTRAL_REPORT_LTS_TAG_SIZE_GEN3,
  1247. SPECTRAL_REPORT_LTS_TAG_POS_GEN3);
  1248. signature = get_bitfield(p_fft_report->fft_hdr_lts,
  1249. SPECTRAL_REPORT_LTS_SIGNATURE_SIZE_GEN3,
  1250. SPECTRAL_REPORT_LTS_SIGNATURE_POS_GEN3);
  1251. report_len = (fft_hdr_length + 8);
  1252. fft_bin_len = fft_hdr_length - spectral->rparams.fft_report_hdr_len;
  1253. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  1254. fft_bin_len,
  1255. spectral->params[smode].ss_rpt_mode,
  1256. &spectral->len_adj_swar, &fft_bin_size);
  1257. if ((spectral->params[smode].ss_rpt_mode == 2) &&
  1258. spectral->len_adj_swar.inband_fftbin_size_adj)
  1259. fft_bin_len_inband_tfer = fft_bin_len >> 1;
  1260. spectral_debug("Spectral FFT Report");
  1261. spectral_debug("fft_timestamp = 0x%x", p_fft_report->fft_timestamp);
  1262. spectral_debug("fft_hdr_length = %zu(32 bit words)",
  1263. fft_hdr_length >> 2);
  1264. spectral_debug("fft_hdr_tag = 0x%x", tag);
  1265. spectral_debug("fft_hdr_sig = 0x%x", signature);
  1266. spectral_debug("Length field in search fft report is %zu(0x%zx) bytes",
  1267. fft_hdr_length, fft_hdr_length);
  1268. spectral_debug("Total length of search fft report is %zu(0x%zx) bytes",
  1269. report_len, report_len);
  1270. spectral_debug("Target reported fftbins in report is %zu(0x%zx)",
  1271. fft_bin_len, fft_bin_len);
  1272. if ((spectral->params[smode].ss_rpt_mode == 1) &&
  1273. spectral->len_adj_swar.null_fftbin_adj)
  1274. spectral_debug("WAR: Considering number of FFT bins as 0");
  1275. else if ((spectral->params[smode].ss_rpt_mode == 2) &&
  1276. spectral->len_adj_swar.inband_fftbin_size_adj) {
  1277. spectral_debug("FW fftbins actually transferred (in-band report mode) %zu(0x%zx)",
  1278. fft_bin_len_inband_tfer,
  1279. fft_bin_len_inband_tfer);
  1280. }
  1281. spectral_debug("Actual number of fftbins in report is %zu(0x%zx)",
  1282. fft_bin_count, fft_bin_count);
  1283. spectral_debug("fft_detector_id = %u", p_sfft->fft_detector_id);
  1284. spectral_debug("fft_num = %u", p_sfft->fft_num);
  1285. spectral_debug("fft_radar_check = %u", p_sfft->fft_radar_check);
  1286. spectral_debug("fft_peak_sidx = %d", p_sfft->fft_peak_sidx);
  1287. spectral_debug("fft_chn_idx = %u", p_sfft->fft_chn_idx);
  1288. spectral_debug("fft_base_pwr_db = %u", p_sfft->fft_base_pwr_db);
  1289. spectral_debug("fft_total_gain_db = %u", p_sfft->fft_total_gain_db);
  1290. spectral_debug("fft_num_str_bins_ib = %u", p_sfft->fft_num_str_bins_ib);
  1291. spectral_debug("fft_peak_mag = %d", p_sfft->fft_peak_mag);
  1292. spectral_debug("fft_avgpwr_db = %u", p_sfft->fft_avgpwr_db);
  1293. spectral_debug("fft_relpwr_db = %u", p_sfft->fft_relpwr_db);
  1294. fft_bin_buf_size = fft_bin_count;
  1295. if (fft_bin_count > 0) {
  1296. int idx;
  1297. if (spectral->len_adj_swar.fftbin_size_war ==
  1298. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
  1299. uint32_t *binptr_32 = (uint32_t *)&p_fft_report->buf;
  1300. uint16_t *fft_bin_buf_16 = NULL;
  1301. /* Useful width of FFT bin is 10 bits, increasing it to
  1302. * byte boundary makes it 2 bytes. Hence, buffer to be
  1303. * allocated should be of size fft_bin_count
  1304. * multiplied by 2.
  1305. */
  1306. fft_bin_buf_size <<= 1;
  1307. fft_bin_buf_16 = (uint16_t *)qdf_mem_malloc(
  1308. fft_bin_buf_size);
  1309. if (!fft_bin_buf_16) {
  1310. spectral_err("Failed to allocate memory");
  1311. return;
  1312. }
  1313. for (idx = 0; idx < fft_bin_count; idx++)
  1314. fft_bin_buf_16[idx] =
  1315. *((uint16_t *)binptr_32++);
  1316. fft_bin_buf = (uint8_t *)fft_bin_buf_16;
  1317. } else if (spectral->len_adj_swar.fftbin_size_war ==
  1318. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  1319. uint16_t *binptr_16 = (uint16_t *)&p_fft_report->buf;
  1320. uint16_t *fft_bin_buf_16 = NULL;
  1321. /* Useful width of FFT bin is 10 bits, increasing it to
  1322. * byte boundary makes it 2 bytes. Hence, buffer to be
  1323. * allocated should be of size fft_bin_count
  1324. * multiplied by 2.
  1325. */
  1326. fft_bin_buf_size <<= 1;
  1327. fft_bin_buf_16 = (uint16_t *)qdf_mem_malloc(
  1328. fft_bin_buf_size);
  1329. if (!fft_bin_buf_16) {
  1330. spectral_err("Failed to allocate memory");
  1331. return;
  1332. }
  1333. for (idx = 0; idx < fft_bin_count; idx++)
  1334. fft_bin_buf_16[idx] = *(binptr_16++);
  1335. fft_bin_buf = (uint8_t *)fft_bin_buf_16;
  1336. } else {
  1337. fft_bin_buf = (uint8_t *)&p_fft_report->buf;
  1338. }
  1339. spectral_debug("FFT bin buffer size = %zu", fft_bin_buf_size);
  1340. spectral_debug("FFT bins:");
  1341. target_if_spectral_hexdump(fft_bin_buf, fft_bin_buf_size);
  1342. if ((spectral->len_adj_swar.fftbin_size_war !=
  1343. SPECTRAL_FFTBIN_SIZE_NO_WAR) && fft_bin_buf)
  1344. qdf_mem_free(fft_bin_buf);
  1345. }
  1346. }
  1347. #endif
  1348. QDF_STATUS
  1349. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  1350. enum spectral_scan_mode smode,
  1351. uint8_t detector_id) {
  1352. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1353. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1354. spectral_err_rl("Invalid Spectral mode %d", smode);
  1355. return QDF_STATUS_E_INVAL;
  1356. }
  1357. if (!is_ch_width_160_or_80p80(spectral->ch_width[smode])) {
  1358. spectral_err_rl("Scan BW %d is not 160/80p80 for mode %d",
  1359. spectral->ch_width[smode], smode);
  1360. return QDF_STATUS_E_FAILURE;
  1361. }
  1362. switch (spectral->state_160mhz_delivery[smode]) {
  1363. case SPECTRAL_REPORT_WAIT_PRIMARY80:
  1364. if (detector_id == SPECTRAL_DETECTOR_ID_0)
  1365. spectral->state_160mhz_delivery[smode] =
  1366. SPECTRAL_REPORT_RX_PRIMARY80;
  1367. else {
  1368. status = QDF_STATUS_E_FAILURE;
  1369. spectral->diag_stats.spectral_vhtseg1id_mismatch++;
  1370. }
  1371. break;
  1372. case SPECTRAL_REPORT_WAIT_SECONDARY80:
  1373. if (detector_id == SPECTRAL_DETECTOR_ID_1)
  1374. spectral->state_160mhz_delivery[smode] =
  1375. SPECTRAL_REPORT_RX_SECONDARY80;
  1376. else {
  1377. spectral->state_160mhz_delivery[smode] =
  1378. SPECTRAL_REPORT_WAIT_PRIMARY80;
  1379. status = QDF_STATUS_E_FAILURE;
  1380. spectral->diag_stats.spectral_vhtseg2id_mismatch++;
  1381. }
  1382. break;
  1383. case SPECTRAL_REPORT_RX_SECONDARY80:
  1384. /* We don't care about detector id in this state. */
  1385. reset_160mhz_delivery_state_machine(spectral, smode);
  1386. break;
  1387. case SPECTRAL_REPORT_RX_PRIMARY80:
  1388. /* We don't care about detector id in this state */
  1389. spectral->state_160mhz_delivery[smode] =
  1390. SPECTRAL_REPORT_WAIT_SECONDARY80;
  1391. break;
  1392. default:
  1393. break;
  1394. }
  1395. return status;
  1396. }
  1397. #ifdef DIRECT_BUF_RX_ENABLE
  1398. /**
  1399. * target_if_get_detector_id_sscan_summary_report_gen3() - Get Spectral detector
  1400. * ID from Spectral summary report
  1401. * @data: Pointer to Spectral summary report
  1402. *
  1403. * Return: Detector ID
  1404. */
  1405. static uint8_t
  1406. target_if_get_detector_id_sscan_summary_report_gen3(uint8_t *data) {
  1407. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  1408. uint8_t detector_id;
  1409. qdf_assert_always(data);
  1410. psscan_summary_report =
  1411. (struct spectral_sscan_summary_report_gen3 *)data;
  1412. detector_id = get_bitfield(
  1413. psscan_summary_report->hdr_a,
  1414. SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_SIZE_GEN3,
  1415. SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_POS_GEN3);
  1416. return detector_id;
  1417. }
  1418. #ifndef OPTIMIZED_SAMP_MESSAGE
  1419. /**
  1420. * target_if_consume_sscan_summary_report_gen3() - Consume Spectral summary
  1421. * report
  1422. * @data: Pointer to Spectral summary report
  1423. * @fields: Pointer to structure to be populated with extracted fields
  1424. * @rparams: Pointer to structure with Spectral report params
  1425. *
  1426. * Consume Spectral summary report for gen3
  1427. *
  1428. * Return: void
  1429. */
  1430. static void
  1431. target_if_consume_sscan_summary_report_gen3(
  1432. uint8_t *data,
  1433. struct sscan_report_fields_gen3 *fields,
  1434. struct spectral_report_params *rparams) {
  1435. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  1436. qdf_assert_always(data);
  1437. qdf_assert_always(fields);
  1438. qdf_assert_always(rparams);
  1439. psscan_summary_report =
  1440. (struct spectral_sscan_summary_report_gen3 *)data;
  1441. fields->sscan_agc_total_gain = get_bitfield(
  1442. psscan_summary_report->hdr_a,
  1443. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_SIZE_GEN3,
  1444. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_POS_GEN3);
  1445. fields->inband_pwr_db = get_bitfield(
  1446. psscan_summary_report->hdr_a,
  1447. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_SIZE_GEN3,
  1448. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_POS_GEN3);
  1449. fields->sscan_pri80 = get_bitfield(
  1450. psscan_summary_report->hdr_a,
  1451. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_SIZE_GEN3,
  1452. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_POS_GEN3);
  1453. switch (rparams->version) {
  1454. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1455. fields->sscan_gainchange = get_bitfield(
  1456. psscan_summary_report->hdr_b,
  1457. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_SIZE_GEN3_V1,
  1458. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_POS_GEN3_V1);
  1459. break;
  1460. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1461. fields->sscan_gainchange = get_bitfield(
  1462. psscan_summary_report->hdr_c,
  1463. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_SIZE_GEN3_V2,
  1464. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_POS_GEN3_V2);
  1465. break;
  1466. default:
  1467. qdf_assert_always(0);
  1468. }
  1469. }
  1470. #endif
  1471. /**
  1472. * target_if_verify_sig_and_tag_gen3() - Verify tag and signature
  1473. * of spectral report
  1474. * @spectral: Pointer to spectral object
  1475. * @data: Pointer to spectral summary report
  1476. * @exp_tag: iexpected tag value
  1477. *
  1478. * Process fft report for gen3
  1479. *
  1480. * Return: SUCCESS/FAILURE
  1481. */
  1482. static int
  1483. target_if_verify_sig_and_tag_gen3(struct target_if_spectral *spectral,
  1484. uint8_t *data, uint8_t exp_tag)
  1485. {
  1486. uint8_t tag = 0;
  1487. uint8_t signature = 0;
  1488. uint32_t lts;
  1489. lts = *((uint32_t *)(data + SPECTRAL_PHYERR_HDR_LTS_POS));
  1490. /* Peek into the data to figure out whether
  1491. * 1) Signature matches the expected value
  1492. * 2) What is inside the package (TAG ID is used for finding this)
  1493. */
  1494. tag = get_bitfield(lts,
  1495. SPECTRAL_REPORT_LTS_TAG_SIZE_GEN3,
  1496. SPECTRAL_REPORT_LTS_TAG_POS_GEN3);
  1497. signature = get_bitfield(lts,
  1498. SPECTRAL_REPORT_LTS_SIGNATURE_SIZE_GEN3,
  1499. SPECTRAL_REPORT_LTS_SIGNATURE_POS_GEN3);
  1500. if (signature != SPECTRAL_PHYERR_SIGNATURE_GEN3) {
  1501. spectral->diag_stats.spectral_mismatch++;
  1502. return -EINVAL;
  1503. }
  1504. if (tag != exp_tag) {
  1505. spectral->diag_stats.spectral_mismatch++;
  1506. return -EINVAL;
  1507. }
  1508. return 0;
  1509. }
  1510. static uint8_t
  1511. target_if_spectral_get_lowest_chn_idx(uint8_t chainmask)
  1512. {
  1513. uint8_t idx;
  1514. for (idx = 0; idx < DBR_MAX_CHAINS; idx++) {
  1515. if (chainmask & 0x1)
  1516. break;
  1517. chainmask >>= 1;
  1518. }
  1519. return idx;
  1520. }
  1521. #ifdef DIRECT_BUF_RX_DEBUG
  1522. static void target_if_spectral_check_buffer_poisoning(
  1523. struct target_if_spectral *spectral,
  1524. struct spectral_report *report,
  1525. int num_fft_bins, enum spectral_scan_mode smode)
  1526. {
  1527. uint32_t *data;
  1528. size_t len;
  1529. size_t words_to_check =
  1530. sizeof(struct spectral_sscan_summary_report_gen3) >> 2;
  1531. bool poisoned_words_found = false;
  1532. if (!spectral) {
  1533. spectral_err_rl("Spectral LMAC object is null");
  1534. return;
  1535. }
  1536. if (!spectral->dbr_buff_debug)
  1537. return;
  1538. if (!report) {
  1539. spectral_err_rl("Spectral report is null");
  1540. return;
  1541. }
  1542. /* Add search FFT report */
  1543. if (spectral->params[smode].ss_rpt_mode > 0)
  1544. words_to_check +=
  1545. sizeof(struct spectral_phyerr_fft_report_gen3) >> 2;
  1546. /* Now add the number of FFT bins */
  1547. if (spectral->params[smode].ss_rpt_mode > 1) {
  1548. /* Caller should take care to pass correct number of FFT bins */
  1549. if (spectral->len_adj_swar.fftbin_size_war ==
  1550. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE)
  1551. words_to_check += num_fft_bins;
  1552. else if (spectral->len_adj_swar.fftbin_size_war ==
  1553. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE)
  1554. words_to_check += (num_fft_bins >> 1);
  1555. }
  1556. data = (uint32_t *)report->data;
  1557. for (len = 0; len < words_to_check; ++len) {
  1558. if (*data == MEM_POISON_SIGNATURE) {
  1559. spectral_err("Pattern(%x) found in Spectral search FFT report at position %zu in the buffer %pK",
  1560. MEM_POISON_SIGNATURE,
  1561. (len << 2), report->data);
  1562. poisoned_words_found = true;
  1563. break;
  1564. }
  1565. ++data;
  1566. }
  1567. /* Crash the FW even if one word is poisoned */
  1568. if (poisoned_words_found) {
  1569. spectral_err("Pattern(%x) found in Spectral report, Hex dump of the sfft follows",
  1570. MEM_POISON_SIGNATURE);
  1571. target_if_spectral_hexdump((unsigned char *)report->data,
  1572. words_to_check << 2);
  1573. spectral_err("Asserting the FW");
  1574. target_if_spectral_fw_hang(spectral);
  1575. }
  1576. }
  1577. static void target_if_spectral_verify_ts(struct target_if_spectral *spectral,
  1578. uint8_t *buf, uint32_t current_ts)
  1579. {
  1580. if (!spectral) {
  1581. spectral_err_rl("Spectral LMAC object is null");
  1582. return;
  1583. }
  1584. if (!spectral->dbr_buff_debug)
  1585. return;
  1586. if (spectral->prev_tstamp) {
  1587. if (current_ts == spectral->prev_tstamp) {
  1588. spectral_err("Spectral timestamp(%u) in the current buffer(%pK) is equal to the previous timestamp, same report DMAed twice? Asserting the FW",
  1589. current_ts, buf);
  1590. target_if_spectral_fw_hang(spectral);
  1591. }
  1592. }
  1593. spectral->prev_tstamp = current_ts;
  1594. }
  1595. #else
  1596. static void target_if_spectral_check_buffer_poisoning(
  1597. struct target_if_spectral *spectral,
  1598. struct spectral_report *report,
  1599. int num_fft_bins, enum spectral_scan_mode smode)
  1600. {
  1601. }
  1602. static void target_if_spectral_verify_ts(struct target_if_spectral *spectral,
  1603. uint8_t *buf, uint32_t current_ts)
  1604. {
  1605. }
  1606. #endif
  1607. /**
  1608. * target_if_spectral_get_adjusted_timestamp() - Adjust Spectral time
  1609. * stamp to account for reset in time stamp due to target reset
  1610. * @twar: Spectral time stamp WAR related information
  1611. * @raw_timestamp: Spectral time stamp reported by target
  1612. * @reset_delay: Reset delay at target
  1613. * @smode: Spectral scan mode
  1614. *
  1615. * Correct time stamp to account for reset in time stamp due to target reset
  1616. *
  1617. * Return: Adjusted time stamp
  1618. */
  1619. static uint32_t
  1620. target_if_spectral_get_adjusted_timestamp(struct spectral_timestamp_war *twar,
  1621. uint32_t raw_timestamp,
  1622. uint32_t reset_delay,
  1623. enum spectral_scan_mode smode) {
  1624. qdf_assert_always(smode < SPECTRAL_SCAN_MODE_MAX);
  1625. if (reset_delay) {
  1626. enum spectral_scan_mode m =
  1627. SPECTRAL_SCAN_MODE_NORMAL;
  1628. /* Adjust the offset for all the Spectral modes.
  1629. * Target will be sending the non zero reset delay for
  1630. * the first Spectral report after reset. This delay is
  1631. * common for all the Spectral modes.
  1632. */
  1633. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  1634. twar->timestamp_war_offset[m] += (reset_delay +
  1635. twar->last_fft_timestamp[m]);
  1636. twar->target_reset_count++;
  1637. }
  1638. twar->last_fft_timestamp[smode] = raw_timestamp;
  1639. return raw_timestamp + twar->timestamp_war_offset[smode];
  1640. }
  1641. #ifdef BIG_ENDIAN_HOST
  1642. QDF_STATUS target_if_byte_swap_spectral_headers_gen3(
  1643. struct target_if_spectral *spectral,
  1644. void *data)
  1645. {
  1646. int i;
  1647. uint32_t *ptr32;
  1648. size_t words32;
  1649. qdf_assert_always(data);
  1650. qdf_assert_always(spectral);
  1651. ptr32 = (uint32_t *)data;
  1652. /* Summary Report */
  1653. words32 = sizeof(struct spectral_sscan_summary_report_gen3) >> 2;
  1654. for (i = 0; i < words32; ++i) {
  1655. *ptr32 = qdf_le32_to_cpu(*ptr32);
  1656. ++ptr32;
  1657. }
  1658. /* No need to swap the padding bytes */
  1659. ptr32 += (spectral->rparams.ssumaary_padding_bytes >> 2);
  1660. /* Search FFT Report */
  1661. words32 = sizeof(struct spectral_phyerr_fft_report_gen3) >> 2;
  1662. for (i = 0; i < words32; ++i) {
  1663. *ptr32 = qdf_le32_to_cpu(*ptr32);
  1664. ++ptr32;
  1665. }
  1666. return QDF_STATUS_SUCCESS;
  1667. }
  1668. QDF_STATUS target_if_byte_swap_spectral_fft_bins_gen3(
  1669. struct spectral_fft_bin_len_adj_swar *swar,
  1670. void *bin_pwr_data, size_t num_fftbins)
  1671. {
  1672. int i;
  1673. uint16_t *binptr_16;
  1674. uint32_t *binptr_32;
  1675. qdf_assert_always(bin_pwr_data);
  1676. qdf_assert_always(swar);
  1677. if (swar->fftbin_size_war ==
  1678. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
  1679. binptr_32 = (uint32_t *)bin_pwr_data;
  1680. for (i = 0; i < num_fftbins; i++) {
  1681. /* Get the useful first 2 bytes of the DWORD */
  1682. binptr_16 = ((uint16_t *)binptr_32);
  1683. /* Byteswap and copy it back */
  1684. *binptr_16 = qdf_le16_to_cpu(*binptr_16);
  1685. ++binptr_32; /* Go to next DWORD */
  1686. }
  1687. } else if (swar->fftbin_size_war ==
  1688. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  1689. binptr_16 = (uint16_t *)bin_pwr_data;
  1690. for (i = 0; i < num_fftbins; i++) {
  1691. /* Byteswap the FFT bin and copy it back */
  1692. *binptr_16 = qdf_le16_to_cpu(*binptr_16);
  1693. ++binptr_16;
  1694. }
  1695. }
  1696. return QDF_STATUS_SUCCESS;
  1697. }
  1698. #endif /* BIG_ENDIAN_HOST */
  1699. #ifdef OPTIMIZED_SAMP_MESSAGE
  1700. /**
  1701. * target_if_consume_sscan_summary_report_gen3() - Consume Spectral summary
  1702. * report
  1703. * @data: Pointer to Spectral summary report
  1704. * @fields: Pointer to structure to be populated with extracted fields
  1705. * @spectral: Pointer to spectral object
  1706. *
  1707. * Consume Spectral summary report for gen3
  1708. *
  1709. * Return: Success/Failure
  1710. */
  1711. static QDF_STATUS
  1712. target_if_consume_sscan_summary_report_gen3(
  1713. uint8_t **data,
  1714. struct sscan_report_fields_gen3 *fields,
  1715. struct target_if_spectral *spectral)
  1716. {
  1717. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  1718. if (!data) {
  1719. spectral_err_rl("Summary report buffer is null");
  1720. return QDF_STATUS_E_NULL_VALUE;
  1721. }
  1722. if (!fields) {
  1723. spectral_err_rl("Invalid pointer to Summary report fields");
  1724. return QDF_STATUS_E_NULL_VALUE;
  1725. }
  1726. if (!spectral) {
  1727. spectral_err_rl("Spectral LMAC object is null");
  1728. return QDF_STATUS_E_NULL_VALUE;
  1729. }
  1730. /* Validate Spectral scan summary report */
  1731. if (target_if_verify_sig_and_tag_gen3(
  1732. spectral, *data,
  1733. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3) != 0) {
  1734. spectral_err_rl("Wrong tag/sig in sscan summary");
  1735. return QDF_STATUS_E_FAILURE;
  1736. }
  1737. fields->sscan_detector_id =
  1738. target_if_get_detector_id_sscan_summary_report_gen3(*data);
  1739. if (fields->sscan_detector_id >=
  1740. spectral->rparams.num_spectral_detectors) {
  1741. spectral->diag_stats.spectral_invalid_detector_id++;
  1742. spectral_err_rl("Invalid detector id %u, expected is 0 to %u",
  1743. fields->sscan_detector_id,
  1744. spectral->rparams.num_spectral_detectors);
  1745. return QDF_STATUS_E_FAILURE;
  1746. }
  1747. psscan_summary_report =
  1748. (struct spectral_sscan_summary_report_gen3 *)*data;
  1749. fields->sscan_agc_total_gain = get_bitfield(
  1750. psscan_summary_report->hdr_a,
  1751. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_SIZE_GEN3,
  1752. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_POS_GEN3);
  1753. fields->inband_pwr_db = get_bitfield(
  1754. psscan_summary_report->hdr_a,
  1755. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_SIZE_GEN3,
  1756. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_POS_GEN3);
  1757. fields->sscan_pri80 = get_bitfield(
  1758. psscan_summary_report->hdr_a,
  1759. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_SIZE_GEN3,
  1760. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_POS_GEN3);
  1761. switch (spectral->rparams.version) {
  1762. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1763. fields->sscan_gainchange = get_bitfield(
  1764. psscan_summary_report->hdr_b,
  1765. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_SIZE_GEN3_V1,
  1766. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_POS_GEN3_V1);
  1767. break;
  1768. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1769. fields->sscan_gainchange = get_bitfield(
  1770. psscan_summary_report->hdr_c,
  1771. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_SIZE_GEN3_V2,
  1772. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_POS_GEN3_V2);
  1773. break;
  1774. default:
  1775. qdf_assert_always(0);
  1776. }
  1777. /* Advance buf pointer to the search fft report */
  1778. *data += sizeof(struct spectral_sscan_summary_report_gen3);
  1779. *data += spectral->rparams.ssumaary_padding_bytes;
  1780. return QDF_STATUS_SUCCESS;
  1781. }
  1782. /**
  1783. * target_if_process_sfft_report_gen3() - Validate and Process Search
  1784. * FFT Report for gen3
  1785. * @data: Pointer to Spectral FFT report
  1786. * @p_sfft: Pointer to search fft report
  1787. * @spectral: Pointer to spectral object
  1788. * @sscan_detector_id: Spectral detector id extracted from Summary report
  1789. *
  1790. * Validate and Process Search FFT Report for gen3
  1791. *
  1792. * Return: Success/Failure
  1793. */
  1794. static QDF_STATUS
  1795. target_if_process_sfft_report_gen3(
  1796. uint8_t *data,
  1797. struct spectral_search_fft_info_gen3 *p_sfft,
  1798. struct target_if_spectral *spectral,
  1799. enum spectral_detector_id sscan_detector_id)
  1800. {
  1801. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  1802. int32_t peak_sidx = 0;
  1803. int32_t peak_mag;
  1804. int fft_hdr_length = 0;
  1805. struct target_if_spectral_ops *p_sops;
  1806. enum spectral_scan_mode spectral_mode;
  1807. QDF_STATUS ret;
  1808. if (!data) {
  1809. spectral_err_rl("FFT report buffer is null");
  1810. return QDF_STATUS_E_NULL_VALUE;
  1811. }
  1812. if (!p_sfft) {
  1813. spectral_err_rl("Invalid pointer to Search FFT report info");
  1814. return QDF_STATUS_E_NULL_VALUE;
  1815. }
  1816. if (!spectral) {
  1817. spectral_err_rl("Spectral LMAC object is null");
  1818. return QDF_STATUS_E_NULL_VALUE;
  1819. }
  1820. /*
  1821. * For easy comparision between MDK team and OS team, the MDK script
  1822. * variable names have been used
  1823. */
  1824. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1825. /* Validate Spectral search FFT report */
  1826. if (target_if_verify_sig_and_tag_gen3(
  1827. spectral, data, TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  1828. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  1829. sscan_detector_id);
  1830. return QDF_STATUS_E_FAILURE;
  1831. }
  1832. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  1833. fft_hdr_length = get_bitfield(
  1834. p_fft_report->fft_hdr_lts,
  1835. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  1836. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  1837. if (fft_hdr_length < 16) {
  1838. spectral_err("Wrong TLV length %u, detector id = %d",
  1839. fft_hdr_length, sscan_detector_id);
  1840. return QDF_STATUS_E_FAILURE;
  1841. }
  1842. p_sfft->fft_detector_id = get_bitfield(p_fft_report->hdr_a,
  1843. 2, 0);
  1844. /* It is expected to have same detector id for
  1845. * summary and fft report
  1846. */
  1847. if (sscan_detector_id != p_sfft->fft_detector_id) {
  1848. spectral_err_rl("Different detid in ssummary(%u) and sfft(%u)",
  1849. sscan_detector_id, p_sfft->fft_detector_id);
  1850. return QDF_STATUS_E_FAILURE;
  1851. }
  1852. if (p_sfft->fft_detector_id >
  1853. spectral->rparams.num_spectral_detectors) {
  1854. spectral->diag_stats.spectral_invalid_detector_id++;
  1855. spectral_err("Invalid detector id %u, expected is 0 to %u",
  1856. p_sfft->fft_detector_id,
  1857. spectral->rparams.num_spectral_detectors);
  1858. return QDF_STATUS_E_FAILURE;
  1859. }
  1860. /* Populate the Search FFT Info */
  1861. p_sfft->timestamp = p_fft_report->fft_timestamp;
  1862. p_sfft->fft_num = get_bitfield(p_fft_report->hdr_a, 3, 2);
  1863. switch (spectral->rparams.version) {
  1864. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1865. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  1866. 12, 5);
  1867. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 17);
  1868. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_a, 3, 28);
  1869. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  1870. 9, 0);
  1871. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  1872. 8, 9);
  1873. break;
  1874. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1875. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  1876. 14, 5);
  1877. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 19);
  1878. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_b, 3, 0);
  1879. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  1880. 9, 3);
  1881. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  1882. 8, 12);
  1883. break;
  1884. default:
  1885. qdf_assert_always(0);
  1886. }
  1887. p_sfft->fft_peak_sidx = unsigned_to_signed(peak_sidx, 11);
  1888. p_sfft->fft_num_str_bins_ib = get_bitfield(p_fft_report->hdr_c,
  1889. 8, 0);
  1890. peak_mag = get_bitfield(p_fft_report->hdr_c, 10, 8);
  1891. p_sfft->fft_peak_mag = unsigned_to_signed(peak_mag, 10);
  1892. p_sfft->fft_avgpwr_db = get_bitfield(p_fft_report->hdr_c,
  1893. 7, 18);
  1894. p_sfft->fft_relpwr_db = get_bitfield(p_fft_report->hdr_c,
  1895. 7, 25);
  1896. spectral_mode = target_if_get_spectral_mode(p_sfft->fft_detector_id,
  1897. &spectral->rparams);
  1898. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  1899. spectral_err_rl("No valid Spectral mode for detector id %u",
  1900. p_sfft->fft_detector_id);
  1901. return QDF_STATUS_E_FAILURE;
  1902. }
  1903. p_sfft->fft_bin_count =
  1904. target_if_spectral_get_bin_count_after_len_adj(
  1905. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  1906. spectral->params[spectral_mode].ss_rpt_mode,
  1907. &spectral->len_adj_swar,
  1908. (size_t *)&p_sfft->fft_bin_size);
  1909. p_sfft->bin_pwr_data = (uint8_t *)p_fft_report + SPECTRAL_FFT_BINS_POS;
  1910. /* Apply byte-swap on the FFT bins.
  1911. * NOTE: Until this point, bytes of the FFT bins could be in
  1912. * reverse order on a big-endian machine. If the consumers
  1913. * of FFT bins expects bytes in the correct order,
  1914. * they should use them only after this point.
  1915. */
  1916. if (p_sops->byte_swap_fft_bins) {
  1917. ret = p_sops->byte_swap_fft_bins(&spectral->len_adj_swar,
  1918. &p_sfft->bin_pwr_data,
  1919. p_sfft->fft_bin_count);
  1920. if (QDF_IS_STATUS_ERROR(ret)) {
  1921. spectral_err_rl("Byte-swap on the FFT bins failed");
  1922. return QDF_STATUS_E_FAILURE;
  1923. }
  1924. }
  1925. return QDF_STATUS_SUCCESS;
  1926. }
  1927. #endif /* OPTIMIZED_SAMP_MESSAGE */
  1928. int
  1929. target_if_consume_spectral_report_gen3(
  1930. struct target_if_spectral *spectral,
  1931. struct spectral_report *report)
  1932. {
  1933. /*
  1934. * XXX : The classifier do not use all the members of the SAMP
  1935. * message data format.
  1936. * The classifier only depends upon the following parameters
  1937. *
  1938. * 1. Frequency (freq, msg->freq)
  1939. * 2. Spectral RSSI (spectral_rssi,
  1940. * msg->samp_data.spectral_rssi)
  1941. * 3. Bin Power Count (bin_pwr_count,
  1942. * msg->samp_data.bin_pwr_count)
  1943. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  1944. * 5. Spectral Timestamp (spectral_tstamp,
  1945. * msg->samp_data.spectral_tstamp)
  1946. * 6. MAC Address (macaddr, msg->macaddr)
  1947. *
  1948. * This function prepares the params structure and populates it
  1949. * with
  1950. * relevant values, this is in turn passed to
  1951. * spectral_create_samp_msg()
  1952. * to prepare fully formatted Spectral SAMP message
  1953. *
  1954. * XXX : Need to verify
  1955. * 1. Order of FFT bin values
  1956. *
  1957. */
  1958. struct target_if_samp_msg_params params = {0};
  1959. struct spectral_search_fft_info_gen3 search_fft_info;
  1960. struct spectral_search_fft_info_gen3 *p_sfft = &search_fft_info;
  1961. int8_t chn_idx_lowest_enabled = 0;
  1962. int fft_hdr_length = 0;
  1963. int report_len = 0;
  1964. size_t fft_bin_count;
  1965. size_t fft_bin_size;
  1966. struct target_if_spectral_ops *p_sops =
  1967. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1968. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  1969. int8_t rssi;
  1970. uint8_t *data = report->data;
  1971. struct wlan_objmgr_vdev *vdev;
  1972. uint8_t vdev_rxchainmask;
  1973. struct sscan_report_fields_gen3 sscan_report_fields = {0};
  1974. enum spectral_detector_id detector_id;
  1975. QDF_STATUS ret;
  1976. enum spectral_scan_mode spectral_mode = SPECTRAL_SCAN_MODE_INVALID;
  1977. uint8_t *temp;
  1978. bool finite_scan = false;
  1979. /* Apply byte-swap on the headers */
  1980. if (p_sops->byte_swap_headers) {
  1981. ret = p_sops->byte_swap_headers(spectral, data);
  1982. if (QDF_IS_STATUS_ERROR(ret)) {
  1983. spectral_err_rl("Byte-swap on Spectral headers failed");
  1984. goto fail;
  1985. }
  1986. }
  1987. /* Process Spectral scan summary report */
  1988. if (target_if_verify_sig_and_tag_gen3(
  1989. spectral, data,
  1990. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3) != 0) {
  1991. spectral_err_rl("Wrong tag/sig in sscan summary");
  1992. goto fail;
  1993. }
  1994. detector_id = target_if_get_detector_id_sscan_summary_report_gen3(data);
  1995. if (detector_id >= spectral->rparams.num_spectral_detectors) {
  1996. spectral->diag_stats.spectral_invalid_detector_id++;
  1997. spectral_err("Invalid detector id %u, expected is 0/1/2",
  1998. detector_id);
  1999. goto fail;
  2000. }
  2001. spectral_mode = target_if_get_spectral_mode(detector_id,
  2002. &spectral->rparams);
  2003. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  2004. spectral_err_rl("No valid Spectral mode for detector id %u",
  2005. detector_id);
  2006. goto fail;
  2007. }
  2008. /* Drop the sample if Spectral is not active for the current mode */
  2009. if (!p_sops->is_spectral_active(spectral, spectral_mode)) {
  2010. spectral_info_rl("Spectral scan is not active");
  2011. goto fail_no_print;
  2012. }
  2013. ret = target_if_spectral_is_finite_scan(spectral, spectral_mode,
  2014. &finite_scan);
  2015. if (QDF_IS_STATUS_ERROR(ret)) {
  2016. spectral_err_rl("Failed to check scan is finite");
  2017. goto fail;
  2018. }
  2019. if (finite_scan) {
  2020. ret = target_if_spectral_finite_scan_update(spectral,
  2021. spectral_mode);
  2022. if (QDF_IS_STATUS_ERROR(ret)) {
  2023. spectral_err_rl("Failed to update scan count");
  2024. goto fail;
  2025. }
  2026. }
  2027. target_if_consume_sscan_summary_report_gen3(data, &sscan_report_fields,
  2028. &spectral->rparams);
  2029. /* Advance buf pointer to the search fft report */
  2030. data += sizeof(struct spectral_sscan_summary_report_gen3);
  2031. data += spectral->rparams.ssumaary_padding_bytes;
  2032. params.vhtop_ch_freq_seg1 = report->cfreq1;
  2033. params.vhtop_ch_freq_seg2 = report->cfreq2;
  2034. if (is_primaryseg_expected(spectral, spectral_mode)) {
  2035. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  2036. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  2037. params.agc_total_gain =
  2038. sscan_report_fields.sscan_agc_total_gain;
  2039. params.gainchange = sscan_report_fields.sscan_gainchange;
  2040. params.pri80ind = sscan_report_fields.sscan_pri80;
  2041. /* Process Spectral search FFT report */
  2042. if (target_if_verify_sig_and_tag_gen3(
  2043. spectral, data,
  2044. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  2045. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  2046. detector_id);
  2047. goto fail;
  2048. }
  2049. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  2050. fft_hdr_length = get_bitfield(
  2051. p_fft_report->fft_hdr_lts,
  2052. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  2053. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  2054. if (fft_hdr_length < 16) {
  2055. spectral_err("Wrong TLV length %u, detector id = %d",
  2056. fft_hdr_length, detector_id);
  2057. goto fail;
  2058. }
  2059. report_len = (fft_hdr_length + 8);
  2060. target_if_process_sfft_report_gen3(p_fft_report, p_sfft,
  2061. &spectral->rparams);
  2062. /* It is expected to have same detector id for
  2063. * summary and fft report
  2064. */
  2065. if (detector_id != p_sfft->fft_detector_id) {
  2066. spectral_err_rl
  2067. ("Different detid in ssummary(%u) and sfft(%u)",
  2068. detector_id, p_sfft->fft_detector_id);
  2069. goto fail;
  2070. }
  2071. if (detector_id > spectral->rparams.num_spectral_detectors) {
  2072. spectral->diag_stats.spectral_invalid_detector_id++;
  2073. spectral_err("Invalid detector id %u, expected is 0/2",
  2074. detector_id);
  2075. goto fail;
  2076. }
  2077. params.smode = spectral_mode;
  2078. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  2079. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  2080. spectral->params[spectral_mode].ss_rpt_mode,
  2081. &spectral->len_adj_swar, &fft_bin_size);
  2082. params.last_raw_timestamp = spectral->timestamp_war.
  2083. last_fft_timestamp[spectral_mode];
  2084. params.reset_delay = report->reset_delay;
  2085. params.raw_timestamp = p_sfft->timestamp;
  2086. params.tstamp = target_if_spectral_get_adjusted_timestamp(
  2087. &spectral->timestamp_war,
  2088. p_sfft->timestamp, report->reset_delay,
  2089. spectral_mode);
  2090. params.timestamp_war_offset = spectral->timestamp_war.
  2091. timestamp_war_offset[spectral_mode];
  2092. params.target_reset_count = spectral->timestamp_war.
  2093. target_reset_count;
  2094. /* Take care of state transitions for 160 MHz and 80p80 */
  2095. if (is_ch_width_160_or_80p80(spectral->ch_width
  2096. [spectral_mode]) && spectral->rparams.
  2097. fragmentation_160[spectral_mode]) {
  2098. ret = target_if_160mhz_delivery_state_change(
  2099. spectral, spectral_mode,
  2100. detector_id);
  2101. if (ret != QDF_STATUS_SUCCESS)
  2102. goto fail;
  2103. }
  2104. params.rssi = rssi;
  2105. vdev = target_if_spectral_get_vdev(spectral, spectral_mode);
  2106. if (!vdev) {
  2107. spectral_debug("First vdev is NULL");
  2108. reset_160mhz_delivery_state_machine(
  2109. spectral, spectral_mode);
  2110. return -EPERM;
  2111. }
  2112. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  2113. QDF_ASSERT(vdev_rxchainmask != 0);
  2114. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2115. chn_idx_lowest_enabled =
  2116. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  2117. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  2118. spectral_err("Invalid chain index, detector id = %u",
  2119. detector_id);
  2120. goto fail;
  2121. }
  2122. params.max_mag = p_sfft->fft_peak_mag;
  2123. params.freq = p_sops->get_current_channel(spectral,
  2124. spectral_mode);
  2125. params.agile_freq1 = spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  2126. ss_frequency.cfreq1;
  2127. params.agile_freq2 = spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  2128. ss_frequency.cfreq2;
  2129. params.noise_floor =
  2130. report->noisefloor[chn_idx_lowest_enabled];
  2131. temp = (uint8_t *)p_fft_report + SPECTRAL_FFT_BINS_POS;
  2132. if (is_ch_width_160_or_80p80(spectral->ch_width
  2133. [spectral_mode]) && !spectral->rparams.
  2134. fragmentation_160[spectral_mode]) {
  2135. struct wlan_objmgr_psoc *psoc;
  2136. struct spectral_fft_bin_markers_160_165mhz *marker;
  2137. qdf_assert_always(spectral->pdev_obj);
  2138. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  2139. qdf_assert_always(psoc);
  2140. params.agc_total_gain_sec80 =
  2141. sscan_report_fields.sscan_agc_total_gain;
  2142. params.gainchange_sec80 =
  2143. sscan_report_fields.sscan_gainchange;
  2144. params.raw_timestamp_sec80 = p_sfft->timestamp;
  2145. params.rssi_sec80 = rssi;
  2146. params.noise_floor_sec80 =
  2147. report->noisefloor[chn_idx_lowest_enabled];
  2148. params.max_mag_sec80 = p_sfft->fft_peak_mag;
  2149. params.datalen = fft_hdr_length * 2;
  2150. params.datalen_sec80 = fft_hdr_length * 2;
  2151. marker = &spectral->rparams.marker[spectral_mode];
  2152. if (!marker->is_valid) {
  2153. /* update stats */
  2154. goto fail_no_print;
  2155. }
  2156. params.bin_pwr_data = temp +
  2157. marker->start_pri80 * fft_bin_size;
  2158. params.pwr_count = marker->num_pri80;
  2159. params.bin_pwr_data_sec80 = temp +
  2160. marker->start_sec80 * fft_bin_size;
  2161. params.pwr_count_sec80 = marker->num_sec80;
  2162. if (spectral->ch_width[spectral_mode] ==
  2163. CH_WIDTH_80P80MHZ && wlan_psoc_nif_fw_ext_cap_get(
  2164. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  2165. params.bin_pwr_data_5mhz = temp +
  2166. marker->start_5mhz * fft_bin_size;
  2167. params.pwr_count_5mhz = marker->num_5mhz;
  2168. }
  2169. } else {
  2170. params.bin_pwr_data = temp;
  2171. params.pwr_count = fft_bin_count;
  2172. params.datalen = (fft_hdr_length * 4);
  2173. }
  2174. /* Apply byte-swap on the FFT bins.
  2175. * NOTE: Until this point, bytes of the FFT bins could be in
  2176. * reverse order on a big-endian machine. If the consumers
  2177. * of FFT bins expects bytes in the correct order,
  2178. * they should use them only after this point.
  2179. */
  2180. if (p_sops->byte_swap_fft_bins) {
  2181. ret = p_sops->byte_swap_fft_bins(
  2182. &spectral->len_adj_swar,
  2183. temp, fft_bin_count);
  2184. if (QDF_IS_STATUS_ERROR(ret)) {
  2185. spectral_err_rl("Byte-swap on the FFT bins failed");
  2186. goto fail;
  2187. }
  2188. }
  2189. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  2190. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  2191. p_fft_report, p_sfft);
  2192. target_if_spectral_verify_ts(spectral, report->data,
  2193. params.tstamp);
  2194. } else if (is_secondaryseg_expected(spectral, spectral_mode)) {
  2195. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  2196. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  2197. params.agc_total_gain_sec80 =
  2198. sscan_report_fields.sscan_agc_total_gain;
  2199. params.gainchange_sec80 = sscan_report_fields.sscan_gainchange;
  2200. params.pri80ind_sec80 = sscan_report_fields.sscan_pri80;
  2201. /* Process Spectral search FFT report */
  2202. if (target_if_verify_sig_and_tag_gen3(
  2203. spectral, data,
  2204. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  2205. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  2206. detector_id);
  2207. goto fail;
  2208. }
  2209. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  2210. fft_hdr_length = get_bitfield(
  2211. p_fft_report->fft_hdr_lts,
  2212. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  2213. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  2214. if (fft_hdr_length < 16) {
  2215. spectral_err("Wrong TLV length %u, detector id = %u",
  2216. fft_hdr_length, detector_id);
  2217. goto fail;
  2218. }
  2219. report_len = (fft_hdr_length + 8);
  2220. target_if_process_sfft_report_gen3(p_fft_report, p_sfft,
  2221. &spectral->rparams);
  2222. /* It is expected to have same detector id for
  2223. * summary and fft report
  2224. */
  2225. if (detector_id != p_sfft->fft_detector_id) {
  2226. spectral_err_rl
  2227. ("Different detid in ssummary(%u) and sfft(%u)",
  2228. detector_id, p_sfft->fft_detector_id);
  2229. goto fail;
  2230. }
  2231. if (detector_id > spectral->rparams.num_spectral_detectors) {
  2232. spectral->diag_stats.spectral_invalid_detector_id++;
  2233. spectral_err("Invalid detector id %u, expected is 1",
  2234. detector_id);
  2235. goto fail;
  2236. }
  2237. params.smode = spectral_mode;
  2238. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  2239. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  2240. spectral->params[spectral_mode].ss_rpt_mode,
  2241. &spectral->len_adj_swar, &fft_bin_size);
  2242. params.raw_timestamp_sec80 = p_sfft->timestamp;
  2243. /* Take care of state transitions for 160 MHz and 80p80 */
  2244. if (is_ch_width_160_or_80p80(spectral->ch_width
  2245. [spectral_mode]) && spectral->rparams.
  2246. fragmentation_160[spectral_mode]) {
  2247. ret = target_if_160mhz_delivery_state_change(
  2248. spectral, spectral_mode,
  2249. detector_id);
  2250. if (ret != QDF_STATUS_SUCCESS)
  2251. goto fail;
  2252. }
  2253. params.rssi_sec80 = rssi;
  2254. vdev = target_if_spectral_get_vdev(spectral, spectral_mode);
  2255. if (!vdev) {
  2256. spectral_info("First vdev is NULL");
  2257. reset_160mhz_delivery_state_machine
  2258. (spectral, spectral_mode);
  2259. return -EPERM;
  2260. }
  2261. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  2262. QDF_ASSERT(vdev_rxchainmask != 0);
  2263. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2264. chn_idx_lowest_enabled =
  2265. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  2266. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  2267. spectral_err("Invalid chain index");
  2268. goto fail;
  2269. }
  2270. /* Need to change this as per FW team's inputs */
  2271. params.noise_floor_sec80 =
  2272. report->noisefloor[chn_idx_lowest_enabled];
  2273. params.max_mag_sec80 = p_sfft->fft_peak_mag;
  2274. /* params.max_index_sec80 = p_sfft->peak_inx; */
  2275. /* XXX Does this definition of datalen *still hold? */
  2276. params.datalen_sec80 = fft_hdr_length * 4;
  2277. params.pwr_count_sec80 = fft_bin_count;
  2278. params.bin_pwr_data_sec80 =
  2279. (uint8_t *)((uint8_t *)p_fft_report +
  2280. SPECTRAL_FFT_BINS_POS);
  2281. /* Apply byte-swap on the FFT bins.
  2282. * NOTE: Until this point, bytes of the FFT bins could be in
  2283. * reverse order on a big-endian machine. If the consumers
  2284. * of FFT bins expects bytes in the correct order,
  2285. * they should use them only after this point.
  2286. */
  2287. if (p_sops->byte_swap_fft_bins) {
  2288. ret = p_sops->byte_swap_fft_bins(
  2289. &spectral->len_adj_swar,
  2290. params.bin_pwr_data_sec80,
  2291. fft_bin_count);
  2292. if (QDF_IS_STATUS_ERROR(ret)) {
  2293. spectral_err_rl("Byte-swap on the FFT bins failed");
  2294. goto fail;
  2295. }
  2296. }
  2297. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  2298. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  2299. p_fft_report, p_sfft);
  2300. } else {
  2301. spectral_err("Spectral state machine in undefined state");
  2302. goto fail;
  2303. }
  2304. target_if_spectral_check_buffer_poisoning(spectral, report,
  2305. fft_bin_count, spectral_mode);
  2306. qdf_mem_copy(&params.classifier_params,
  2307. &spectral->classifier_params,
  2308. sizeof(struct spectral_classifier_params));
  2309. target_if_spectral_log_SAMP_param(&params);
  2310. target_if_spectral_create_samp_msg(spectral, &params);
  2311. return 0;
  2312. fail:
  2313. spectral_err_rl("Error while processing Spectral report");
  2314. fail_no_print:
  2315. if (spectral_mode != SPECTRAL_SCAN_MODE_INVALID)
  2316. reset_160mhz_delivery_state_machine(spectral, spectral_mode);
  2317. return -EPERM;
  2318. }
  2319. int target_if_spectral_process_report_gen3(
  2320. struct wlan_objmgr_pdev *pdev,
  2321. void *buf)
  2322. {
  2323. int ret = 0;
  2324. struct direct_buf_rx_data *payload = buf;
  2325. struct target_if_spectral *spectral;
  2326. struct spectral_report report;
  2327. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2328. if (!spectral) {
  2329. spectral_err("Spectral target object is null");
  2330. return -EINVAL;
  2331. }
  2332. report.data = payload->vaddr;
  2333. if (payload->meta_data_valid) {
  2334. qdf_mem_copy(report.noisefloor, payload->meta_data.noisefloor,
  2335. qdf_min(sizeof(report.noisefloor),
  2336. sizeof(payload->meta_data.noisefloor)));
  2337. report.reset_delay = payload->meta_data.reset_delay;
  2338. report.cfreq1 = payload->meta_data.cfreq1;
  2339. report.cfreq2 = payload->meta_data.cfreq2;
  2340. report.ch_width = payload->meta_data.ch_width;
  2341. }
  2342. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4)) {
  2343. spectral_debug("Printing the spectral phyerr buffer for debug");
  2344. spectral_debug("Datalength of buffer = 0x%zx(%zd) bufptr = 0x%pK",
  2345. payload->dbr_len,
  2346. payload->dbr_len,
  2347. payload->vaddr);
  2348. target_if_spectral_hexdump((unsigned char *)payload->vaddr,
  2349. 1024);
  2350. }
  2351. ret = target_if_consume_spectral_report_gen3(spectral, &report);
  2352. if (spectral_debug_level & DEBUG_SPECTRAL4)
  2353. spectral_debug_level = DEBUG_SPECTRAL;
  2354. return ret;
  2355. }
  2356. #else
  2357. int target_if_spectral_process_report_gen3(
  2358. struct wlan_objmgr_pdev *pdev,
  2359. void *buf)
  2360. {
  2361. spectral_err("Direct dma support is not enabled");
  2362. return -EINVAL;
  2363. }
  2364. #endif
  2365. qdf_export_symbol(target_if_spectral_process_report_gen3);
  2366. /* END of spectral GEN III HW specific functions */
  2367. #endif /* WLAN_CONV_SPECTRAL_ENABLE */