target_if_spectral_phyerr.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930
  1. /*
  2. * Copyright (c) 2011,2017-2019 The Linux Foundation. All rights reserved.
  3. *
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include <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. #ifdef DIRECT_BUF_RX_ENABLE
  31. #include <target_if_direct_buf_rx_api.h>
  32. #endif
  33. extern int spectral_debug_level;
  34. #ifdef WLAN_CONV_SPECTRAL_ENABLE
  35. #define SPECTRAL_HEXDUMP_OCTET_PRINT_SIZE (3)
  36. #define SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE (16)
  37. #define SPECTRAL_HEXDUMP_EXTRA_BUFFER_PER_LINE (16)
  38. /*
  39. * Provision for the expected hexdump line size as follows:
  40. *
  41. * Size per octet multiplied by number of octets per line
  42. * +
  43. * ASCII representation which is equivalent in print size to number of octets
  44. * per line
  45. * +
  46. * Some extra buffer
  47. */
  48. #define SPECTRAL_HEXDUMP_LINESIZE \
  49. ((SPECTRAL_HEXDUMP_OCTET_PRINT_SIZE * \
  50. SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE) + \
  51. SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE + \
  52. SPECTRAL_HEXDUMP_EXTRA_BUFFER_PER_LINE)
  53. /**
  54. * target_if_spectral_hexdump() - Print hexdump of the given buffer
  55. * @_buf: Pointer to buffer
  56. * @_len: Length of the buffer
  57. *
  58. * Print the hexdump of buffer upto given length. Print upto
  59. * SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE per line, followed by the ASCII
  60. * representation of these octets.
  61. */
  62. static inline void target_if_spectral_hexdump(unsigned char *_buf, int _len)
  63. {
  64. int i, mod;
  65. unsigned char ascii[SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE + 1];
  66. unsigned char *pc = (_buf);
  67. char hexdump_line[SPECTRAL_HEXDUMP_LINESIZE + 1];
  68. int loc = 0;
  69. qdf_mem_zero(hexdump_line, sizeof(hexdump_line));
  70. for (i = 0; i < _len; i++) {
  71. mod = i % SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE;
  72. if (!mod) {
  73. if (i) {
  74. qdf_assert_always(loc < sizeof(hexdump_line));
  75. loc += snprintf(&hexdump_line[loc],
  76. sizeof(hexdump_line) - loc,
  77. " %s", ascii);
  78. spectral_debug("%s", hexdump_line);
  79. qdf_mem_zero(hexdump_line,
  80. sizeof(hexdump_line));
  81. loc = 0;
  82. }
  83. }
  84. qdf_assert_always(loc < sizeof(hexdump_line));
  85. loc += snprintf(&hexdump_line[loc], sizeof(hexdump_line) - loc,
  86. " %02x", pc[i]);
  87. if ((pc[i] < 0x20) || (pc[i] > 0x7e))
  88. ascii[mod] = '.';
  89. else
  90. ascii[mod] = pc[i];
  91. ascii[(mod) + 1] = '\0';
  92. }
  93. while ((i % SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE) != 0) {
  94. qdf_assert_always(loc < sizeof(hexdump_line));
  95. loc += snprintf(&hexdump_line[loc], sizeof(hexdump_line) - loc,
  96. " ");
  97. i++;
  98. }
  99. qdf_assert_always(loc < sizeof(hexdump_line));
  100. snprintf(&hexdump_line[loc], sizeof(hexdump_line) - loc, " %s", ascii);
  101. spectral_debug("%s", hexdump_line);
  102. }
  103. /**
  104. * target_if_print_buf() - Prints given buffer for given length
  105. * @pbuf: Pointer to buffer
  106. * @len: length
  107. *
  108. * Prints given buffer for given length
  109. *
  110. * Return: void
  111. */
  112. static void
  113. target_if_print_buf(uint8_t *pbuf, int len)
  114. {
  115. int i = 0;
  116. for (i = 0; i < len; i++) {
  117. spectral_debug("%02X ", pbuf[i]);
  118. if (i % 32 == 31)
  119. spectral_debug("\n");
  120. }
  121. }
  122. int
  123. target_if_spectral_dump_fft(uint8_t *pfft, int fftlen)
  124. {
  125. int i = 0;
  126. /*
  127. * TODO : Do not delete the following print
  128. * The scripts used to validate Spectral depend on this Print
  129. */
  130. spectral_debug("SPECTRAL : FFT Length is 0x%x (%d)", fftlen, fftlen);
  131. spectral_debug("fft_data # ");
  132. for (i = 0; i < fftlen; i++)
  133. spectral_debug("%d ", pfft[i]);
  134. spectral_debug("\n");
  135. return 0;
  136. }
  137. void
  138. target_if_dbg_print_samp_param(struct target_if_samp_msg_params *p)
  139. {
  140. spectral_debug("\nSAMP Packet : -------------------- START --------------------");
  141. spectral_debug("Freq = %d", p->freq);
  142. spectral_debug("RSSI = %d", p->rssi);
  143. spectral_debug("Bin Count = %d", p->pwr_count);
  144. spectral_debug("Timestamp = %d", p->tstamp);
  145. spectral_debug("SAMP Packet : -------------------- END -----------------------");
  146. }
  147. void
  148. target_if_dbg_print_samp_msg(struct spectral_samp_msg *ss_msg)
  149. {
  150. int i = 0;
  151. struct spectral_samp_data *p = &ss_msg->samp_data;
  152. struct spectral_classifier_params *pc = &p->classifier_params;
  153. struct interf_src_rsp *pi = &p->interf_list;
  154. spectral_dbg_line();
  155. spectral_debug("Spectral Message");
  156. spectral_dbg_line();
  157. spectral_debug("Signature : 0x%x", ss_msg->signature);
  158. spectral_debug("Freq : %d", ss_msg->freq);
  159. spectral_debug("Freq load : %d", ss_msg->freq_loading);
  160. spectral_debug("Intfnc type : %d", ss_msg->int_type);
  161. spectral_dbg_line();
  162. spectral_debug("Spectral Data info");
  163. spectral_dbg_line();
  164. spectral_debug("data length : %d", p->spectral_data_len);
  165. spectral_debug("rssi : %d", p->spectral_rssi);
  166. spectral_debug("combined rssi : %d", p->spectral_combined_rssi);
  167. spectral_debug("upper rssi : %d", p->spectral_upper_rssi);
  168. spectral_debug("lower rssi : %d", p->spectral_lower_rssi);
  169. spectral_debug("bw info : %d", p->spectral_bwinfo);
  170. spectral_debug("timestamp : %d", p->spectral_tstamp);
  171. spectral_debug("max index : %d", p->spectral_max_index);
  172. spectral_debug("max exp : %d", p->spectral_max_exp);
  173. spectral_debug("max mag : %d", p->spectral_max_mag);
  174. spectral_debug("last timstamp : %d", p->spectral_last_tstamp);
  175. spectral_debug("upper max idx : %d", p->spectral_upper_max_index);
  176. spectral_debug("lower max idx : %d", p->spectral_lower_max_index);
  177. spectral_debug("bin power count : %d", p->bin_pwr_count);
  178. spectral_dbg_line();
  179. spectral_debug("Classifier info");
  180. spectral_dbg_line();
  181. spectral_debug("20/40 Mode : %d", pc->spectral_20_40_mode);
  182. spectral_debug("dc index : %d", pc->spectral_dc_index);
  183. spectral_debug("dc in MHz : %d", pc->spectral_dc_in_mhz);
  184. spectral_debug("upper channel : %d", pc->upper_chan_in_mhz);
  185. spectral_debug("lower channel : %d", pc->lower_chan_in_mhz);
  186. spectral_dbg_line();
  187. spectral_debug("Interference info");
  188. spectral_dbg_line();
  189. spectral_debug("inter count : %d", pi->count);
  190. for (i = 0; i < pi->count; i++) {
  191. spectral_debug("inter type : %d",
  192. pi->interf[i].interf_type);
  193. spectral_debug("min freq : %d",
  194. pi->interf[i].interf_min_freq);
  195. spectral_debug("max freq : %d",
  196. pi->interf[i].interf_max_freq);
  197. }
  198. }
  199. uint32_t
  200. target_if_get_offset_swar_sec80(uint32_t channel_width)
  201. {
  202. uint32_t offset = 0;
  203. switch (channel_width) {
  204. case CH_WIDTH_20MHZ:
  205. offset = OFFSET_CH_WIDTH_20;
  206. break;
  207. case CH_WIDTH_40MHZ:
  208. offset = OFFSET_CH_WIDTH_40;
  209. break;
  210. case CH_WIDTH_80MHZ:
  211. offset = OFFSET_CH_WIDTH_80;
  212. break;
  213. case CH_WIDTH_160MHZ:
  214. offset = OFFSET_CH_WIDTH_160;
  215. break;
  216. default:
  217. offset = OFFSET_CH_WIDTH_80;
  218. break;
  219. }
  220. return offset;
  221. }
  222. /**
  223. * target_if_dump_summary_report_gen2() - Dump Spectral Summary Report for gen2
  224. * @ptlv: Pointer to Spectral Phyerr TLV
  225. * @tlvlen: length
  226. * @is_160_format: Indicates whether information provided by HW is in altered
  227. * format for 802.11ac 160/80+80 MHz support (QCA9984 onwards)
  228. *
  229. * Dump Spectral Summary Report for gen2
  230. *
  231. * Return: Success/Failure
  232. */
  233. static int
  234. target_if_dump_summary_report_gen2(struct spectral_phyerr_tlv_gen2 *ptlv,
  235. int tlvlen, bool is_160_format)
  236. {
  237. /*
  238. * For simplicity, everything is defined as uint32_t (except one).
  239. * Proper code will later use the right sizes.
  240. */
  241. /*
  242. * For easy comparision between MDK team and OS team, the MDK script
  243. * variable names have been used
  244. */
  245. uint32_t agc_mb_gain;
  246. uint32_t sscan_gidx;
  247. uint32_t agc_total_gain;
  248. uint32_t recent_rfsat;
  249. uint32_t ob_flag;
  250. uint32_t nb_mask;
  251. uint32_t peak_mag;
  252. int16_t peak_inx;
  253. uint32_t ss_summary_A = 0;
  254. uint32_t ss_summary_B = 0;
  255. uint32_t ss_summary_C = 0;
  256. uint32_t ss_summary_D = 0;
  257. uint32_t ss_summary_E = 0;
  258. struct spectral_phyerr_hdr_gen2 *phdr =
  259. (struct spectral_phyerr_hdr_gen2 *)(
  260. (uint8_t *)ptlv +
  261. sizeof(struct spectral_phyerr_tlv_gen2));
  262. spectral_debug("SPECTRAL : SPECTRAL SUMMARY REPORT");
  263. if (is_160_format) {
  264. if (tlvlen != 20) {
  265. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  266. tlvlen);
  267. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  268. return -EPERM;
  269. }
  270. /* Doing copy as the contents may not be aligned */
  271. qdf_mem_copy(&ss_summary_A, (uint8_t *)phdr, sizeof(int));
  272. qdf_mem_copy(&ss_summary_B,
  273. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  274. sizeof(int));
  275. qdf_mem_copy(&ss_summary_C,
  276. (uint8_t *)((uint8_t *)phdr + 2 * sizeof(int)),
  277. sizeof(int));
  278. qdf_mem_copy(&ss_summary_D,
  279. (uint8_t *)((uint8_t *)phdr + 3 * sizeof(int)),
  280. sizeof(int));
  281. qdf_mem_copy(&ss_summary_E,
  282. (uint8_t *)((uint8_t *)phdr + 4 * sizeof(int)),
  283. sizeof(int));
  284. /*
  285. * The following is adapted from MDK scripts for
  286. * easier comparability
  287. */
  288. recent_rfsat = ((ss_summary_A >> 8) & 0x1);
  289. sscan_gidx = (ss_summary_A & 0xff);
  290. spectral_debug("sscan_gidx=%d, is_recent_rfsat=%d",
  291. sscan_gidx, recent_rfsat);
  292. /* First segment */
  293. agc_mb_gain = ((ss_summary_B >> 10) & 0x7f);
  294. agc_total_gain = (ss_summary_B & 0x3ff);
  295. nb_mask = ((ss_summary_C >> 22) & 0xff);
  296. ob_flag = ((ss_summary_B >> 17) & 0x1);
  297. peak_inx = (ss_summary_C & 0xfff);
  298. if (peak_inx > 2047)
  299. peak_inx = peak_inx - 4096;
  300. peak_mag = ((ss_summary_C >> 12) & 0x3ff);
  301. spectral_debug("agc_total_gain_segid0 = 0x%.2x, agc_mb_gain_segid0=%d",
  302. agc_total_gain, agc_mb_gain);
  303. spectral_debug("nb_mask_segid0 = 0x%.2x, ob_flag_segid0=%d, peak_index_segid0=%d, peak_mag_segid0=%d",
  304. nb_mask, ob_flag, peak_inx, peak_mag);
  305. /* Second segment */
  306. agc_mb_gain = ((ss_summary_D >> 10) & 0x7f);
  307. agc_total_gain = (ss_summary_D & 0x3ff);
  308. nb_mask = ((ss_summary_E >> 22) & 0xff);
  309. ob_flag = ((ss_summary_D >> 17) & 0x1);
  310. peak_inx = (ss_summary_E & 0xfff);
  311. if (peak_inx > 2047)
  312. peak_inx = peak_inx - 4096;
  313. peak_mag = ((ss_summary_E >> 12) & 0x3ff);
  314. spectral_debug("agc_total_gain_segid1 = 0x%.2x, agc_mb_gain_segid1=%d",
  315. agc_total_gain, agc_mb_gain);
  316. spectral_debug("nb_mask_segid1 = 0x%.2x, ob_flag_segid1=%d, peak_index_segid1=%d, peak_mag_segid1=%d",
  317. nb_mask, ob_flag, peak_inx, peak_mag);
  318. } else {
  319. if (tlvlen != 8) {
  320. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  321. tlvlen);
  322. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  323. return -EPERM;
  324. }
  325. /* Doing copy as the contents may not be aligned */
  326. qdf_mem_copy(&ss_summary_A, (uint8_t *)phdr, sizeof(int));
  327. qdf_mem_copy(&ss_summary_B,
  328. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  329. sizeof(int));
  330. nb_mask = ((ss_summary_B >> 22) & 0xff);
  331. ob_flag = ((ss_summary_B >> 30) & 0x1);
  332. peak_inx = (ss_summary_B & 0xfff);
  333. if (peak_inx > 2047)
  334. peak_inx = peak_inx - 4096;
  335. peak_mag = ((ss_summary_B >> 12) & 0x3ff);
  336. agc_mb_gain = ((ss_summary_A >> 24) & 0x7f);
  337. agc_total_gain = (ss_summary_A & 0x3ff);
  338. sscan_gidx = ((ss_summary_A >> 16) & 0xff);
  339. recent_rfsat = ((ss_summary_B >> 31) & 0x1);
  340. 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",
  341. nb_mask, ob_flag, peak_inx, peak_mag,
  342. agc_mb_gain, agc_total_gain, sscan_gidx,
  343. recent_rfsat);
  344. }
  345. return 0;
  346. }
  347. /**
  348. * target_if_process_sfft_report_gen2() - Process Search FFT Report
  349. * @ptlv: Pointer to Spectral Phyerr TLV
  350. * @tlvlen: length
  351. * @p_fft_info: Pointer to search fft info
  352. *
  353. * Dump Spectral Summary Report for gen2
  354. *
  355. * Return: Success/Failure
  356. */
  357. static int
  358. target_if_process_sfft_report_gen2(
  359. struct spectral_phyerr_tlv_gen2 *ptlv,
  360. int tlvlen,
  361. struct spectral_search_fft_info_gen2 *p_fft_info)
  362. {
  363. /*
  364. * For simplicity, everything is defined as uint32_t (except one).
  365. * Proper code will later use the right sizes.
  366. */
  367. /*
  368. * For easy comparision between MDK team and OS team, the MDK script
  369. * variable names have been used
  370. */
  371. uint32_t relpwr_db;
  372. uint32_t num_str_bins_ib;
  373. uint32_t base_pwr;
  374. uint32_t total_gain_info;
  375. uint32_t fft_chn_idx;
  376. int16_t peak_inx;
  377. uint32_t avgpwr_db;
  378. uint32_t peak_mag;
  379. uint32_t fft_summary_A = 0;
  380. uint32_t fft_summary_B = 0;
  381. uint8_t *tmp = (uint8_t *)ptlv;
  382. struct spectral_phyerr_hdr_gen2 *phdr =
  383. (struct spectral_phyerr_hdr_gen2 *)(
  384. tmp +
  385. sizeof(struct spectral_phyerr_tlv_gen2));
  386. /* Relook this */
  387. if (tlvlen < 8) {
  388. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  389. tlvlen);
  390. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  391. return -EPERM;
  392. }
  393. /* Doing copy as the contents may not be aligned */
  394. qdf_mem_copy(&fft_summary_A, (uint8_t *)phdr, sizeof(int));
  395. qdf_mem_copy(&fft_summary_B,
  396. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  397. sizeof(int));
  398. relpwr_db = ((fft_summary_B >> 26) & 0x3f);
  399. num_str_bins_ib = fft_summary_B & 0xff;
  400. base_pwr = ((fft_summary_A >> 14) & 0x1ff);
  401. total_gain_info = ((fft_summary_A >> 23) & 0x1ff);
  402. fft_chn_idx = ((fft_summary_A >> 12) & 0x3);
  403. peak_inx = fft_summary_A & 0xfff;
  404. if (peak_inx > 2047)
  405. peak_inx = peak_inx - 4096;
  406. avgpwr_db = ((fft_summary_B >> 18) & 0xff);
  407. peak_mag = ((fft_summary_B >> 8) & 0x3ff);
  408. /* Populate the Search FFT Info */
  409. if (p_fft_info) {
  410. p_fft_info->relpwr_db = relpwr_db;
  411. p_fft_info->num_str_bins_ib = num_str_bins_ib;
  412. p_fft_info->base_pwr = base_pwr;
  413. p_fft_info->total_gain_info = total_gain_info;
  414. p_fft_info->fft_chn_idx = fft_chn_idx;
  415. p_fft_info->peak_inx = peak_inx;
  416. p_fft_info->avgpwr_db = avgpwr_db;
  417. p_fft_info->peak_mag = peak_mag;
  418. }
  419. return 0;
  420. }
  421. /**
  422. * target_if_dump_adc_report_gen2() - Dump ADC Reports for gen2
  423. * @ptlv: Pointer to Spectral Phyerr TLV
  424. * @tlvlen: length
  425. *
  426. * Dump ADC Reports for gen2
  427. *
  428. * Return: Success/Failure
  429. */
  430. static int
  431. target_if_dump_adc_report_gen2(
  432. struct spectral_phyerr_tlv_gen2 *ptlv, int tlvlen)
  433. {
  434. int i;
  435. uint32_t *pdata;
  436. uint32_t data;
  437. /*
  438. * For simplicity, everything is defined as uint32_t (except one).
  439. * Proper code will later use the right sizes.
  440. */
  441. uint32_t samp_fmt;
  442. uint32_t chn_idx;
  443. uint32_t recent_rfsat;
  444. uint32_t agc_mb_gain;
  445. uint32_t agc_total_gain;
  446. uint32_t adc_summary = 0;
  447. uint8_t *ptmp = (uint8_t *)ptlv;
  448. spectral_debug("SPECTRAL : ADC REPORT");
  449. /* Relook this */
  450. if (tlvlen < 4) {
  451. spectral_err("Unexpected TLV length %d for ADC Report! Hexdump follows",
  452. tlvlen);
  453. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  454. return -EPERM;
  455. }
  456. qdf_mem_copy(&adc_summary, (uint8_t *)(ptlv + 4), sizeof(int));
  457. samp_fmt = ((adc_summary >> 28) & 0x1);
  458. chn_idx = ((adc_summary >> 24) & 0x3);
  459. recent_rfsat = ((adc_summary >> 23) & 0x1);
  460. agc_mb_gain = ((adc_summary >> 16) & 0x7f);
  461. agc_total_gain = adc_summary & 0x3ff;
  462. spectral_debug("samp_fmt= %u, chn_idx= %u, recent_rfsat= %u, agc_mb_gain=%u agc_total_gain=%u",
  463. samp_fmt, chn_idx, recent_rfsat, agc_mb_gain,
  464. agc_total_gain);
  465. for (i = 0; i < (tlvlen / 4); i++) {
  466. pdata = (uint32_t *)(ptmp + 4 + i * 4);
  467. data = *pdata;
  468. /* Interpreting capture format 1 */
  469. if (1) {
  470. uint8_t i1;
  471. uint8_t q1;
  472. uint8_t i2;
  473. uint8_t q2;
  474. int8_t si1;
  475. int8_t sq1;
  476. int8_t si2;
  477. int8_t sq2;
  478. i1 = data & 0xff;
  479. q1 = (data >> 8) & 0xff;
  480. i2 = (data >> 16) & 0xff;
  481. q2 = (data >> 24) & 0xff;
  482. if (i1 > 127)
  483. si1 = i1 - 256;
  484. else
  485. si1 = i1;
  486. if (q1 > 127)
  487. sq1 = q1 - 256;
  488. else
  489. sq1 = q1;
  490. if (i2 > 127)
  491. si2 = i2 - 256;
  492. else
  493. si2 = i2;
  494. if (q2 > 127)
  495. sq2 = q2 - 256;
  496. else
  497. sq2 = q2;
  498. spectral_debug("SPECTRAL ADC : Interpreting capture format 1");
  499. spectral_debug("adc_data_format_1 # %d %d %d",
  500. 2 * i, si1, sq1);
  501. spectral_debug("adc_data_format_1 # %d %d %d",
  502. 2 * i + 1, si2, sq2);
  503. }
  504. /* Interpreting capture format 0 */
  505. if (1) {
  506. uint16_t i1;
  507. uint16_t q1;
  508. int16_t si1;
  509. int16_t sq1;
  510. i1 = data & 0xffff;
  511. q1 = (data >> 16) & 0xffff;
  512. if (i1 > 32767)
  513. si1 = i1 - 65536;
  514. else
  515. si1 = i1;
  516. if (q1 > 32767)
  517. sq1 = q1 - 65536;
  518. else
  519. sq1 = q1;
  520. spectral_debug("SPECTRAL ADC : Interpreting capture format 0");
  521. spectral_debug("adc_data_format_2 # %d %d %d",
  522. i, si1, sq1);
  523. }
  524. }
  525. spectral_debug("\n");
  526. return 0;
  527. }
  528. /**
  529. * target_if_dump_sfft_report_gen2() - Process Search FFT Report for gen2
  530. * @ptlv: Pointer to Spectral Phyerr TLV
  531. * @tlvlen: length
  532. * @is_160_format: Indicates 160 format
  533. *
  534. * Process Search FFT Report for gen2
  535. *
  536. * Return: Success/Failure
  537. */
  538. static int
  539. target_if_dump_sfft_report_gen2(struct spectral_phyerr_tlv_gen2 *ptlv,
  540. int tlvlen, bool is_160_format)
  541. {
  542. int i;
  543. uint32_t fft_mag;
  544. /*
  545. * For simplicity, everything is defined as uint32_t (except one).
  546. * Proper code will later use the right sizes.
  547. */
  548. /*
  549. * For easy comparision between MDK team and OS team, the MDK script
  550. * variable names have been used
  551. */
  552. uint32_t relpwr_db;
  553. uint32_t num_str_bins_ib;
  554. uint32_t base_pwr;
  555. uint32_t total_gain_info;
  556. uint32_t fft_chn_idx;
  557. int16_t peak_inx;
  558. uint32_t avgpwr_db;
  559. uint32_t peak_mag;
  560. uint8_t segid;
  561. uint32_t fft_summary_A = 0;
  562. uint32_t fft_summary_B = 0;
  563. uint32_t fft_summary_C = 0;
  564. uint8_t *tmp = (uint8_t *)ptlv;
  565. struct spectral_phyerr_hdr_gen2 *phdr =
  566. (struct spectral_phyerr_hdr_gen2 *)(
  567. tmp +
  568. sizeof(struct spectral_phyerr_tlv_gen2));
  569. uint32_t segid_skiplen = 0;
  570. if (is_160_format)
  571. segid_skiplen = sizeof(SPECTRAL_SEGID_INFO);
  572. spectral_debug("SPECTRAL : SEARCH FFT REPORT");
  573. /* Relook this */
  574. if (tlvlen < (8 + segid_skiplen)) {
  575. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  576. tlvlen);
  577. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  578. return -EPERM;
  579. }
  580. /* Doing copy as the contents may not be aligned */
  581. qdf_mem_copy(&fft_summary_A, (uint8_t *)phdr, sizeof(int));
  582. qdf_mem_copy(&fft_summary_B,
  583. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  584. sizeof(int));
  585. if (is_160_format)
  586. qdf_mem_copy(&fft_summary_C,
  587. (uint8_t *)((uint8_t *)phdr + 2 * sizeof(int)),
  588. sizeof(int));
  589. relpwr_db = ((fft_summary_B >> 26) & 0x3f);
  590. num_str_bins_ib = fft_summary_B & 0xff;
  591. base_pwr = ((fft_summary_A >> 14) & 0x1ff);
  592. total_gain_info = ((fft_summary_A >> 23) & 0x1ff);
  593. fft_chn_idx = ((fft_summary_A >> 12) & 0x3);
  594. peak_inx = fft_summary_A & 0xfff;
  595. if (peak_inx > 2047)
  596. peak_inx = peak_inx - 4096;
  597. avgpwr_db = ((fft_summary_B >> 18) & 0xff);
  598. peak_mag = ((fft_summary_B >> 8) & 0x3ff);
  599. spectral_debug("Header A = 0x%x Header B = 0x%x",
  600. phdr->hdr_a, phdr->hdr_b);
  601. 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",
  602. base_pwr, total_gain_info, relpwr_db, num_str_bins_ib,
  603. fft_chn_idx, peak_inx, avgpwr_db, peak_mag);
  604. if (is_160_format) {
  605. segid = fft_summary_C & 0x1;
  606. spectral_debug("Segment ID: %hhu", segid);
  607. }
  608. spectral_debug("FFT bins:");
  609. for (i = 0; i < (tlvlen - 8 - segid_skiplen); i++) {
  610. fft_mag = ((uint8_t *)ptlv)[12 + segid_skiplen + i];
  611. spectral_debug("%d %d, ", i, fft_mag);
  612. }
  613. spectral_debug("\n");
  614. return 0;
  615. }
  616. #ifdef SPECTRAL_DEBUG_SAMP_MSG
  617. /**
  618. * target_if_spectral_log_SAMP_param() - Log SAMP parameters
  619. * @params: Reference to target_if_samp_msg_params
  620. *
  621. * API to log spectral SAMP message parameters
  622. *
  623. * Return: None
  624. */
  625. static void
  626. target_if_spectral_log_SAMP_param(struct target_if_samp_msg_params *params)
  627. {
  628. target_if_dbg_print_samp_param(params);
  629. }
  630. #else
  631. static void
  632. target_if_spectral_log_SAMP_param(struct target_if_samp_msg_params *params)
  633. {
  634. }
  635. #endif
  636. int
  637. target_if_process_phyerr_gen2(struct target_if_spectral *spectral,
  638. uint8_t *data,
  639. uint32_t datalen,
  640. struct target_if_spectral_rfqual_info *p_rfqual,
  641. struct target_if_spectral_chan_info *p_chaninfo,
  642. uint64_t tsf64,
  643. struct target_if_spectral_acs_stats *acs_stats)
  644. {
  645. /*
  646. * XXX : The classifier do not use all the members of the SAMP
  647. * message data format.
  648. * The classifier only depends upon the following parameters
  649. *
  650. * 1. Frequency (freq, msg->freq)
  651. * 2. Spectral RSSI (spectral_rssi,
  652. * msg->samp_data.spectral_rssi)
  653. * 3. Bin Power Count (bin_pwr_count,
  654. * msg->samp_data.bin_pwr_count)
  655. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  656. * 5. Spectral Timestamp (spectral_tstamp,
  657. * msg->samp_data.spectral_tstamp)
  658. * 6. MAC Address (macaddr, msg->macaddr)
  659. *
  660. * This function prepares the params structure and populates it
  661. * with
  662. * relevant values, this is in turn passed to
  663. * spectral_create_samp_msg()
  664. * to prepare fully formatted Spectral SAMP message
  665. *
  666. * XXX : Need to verify
  667. * 1. Order of FFT bin values
  668. *
  669. */
  670. struct target_if_samp_msg_params params;
  671. struct spectral_search_fft_info_gen2 search_fft_info;
  672. struct spectral_search_fft_info_gen2 *p_sfft = &search_fft_info;
  673. struct spectral_search_fft_info_gen2 search_fft_info_sec80;
  674. struct spectral_search_fft_info_gen2 *p_sfft_sec80 =
  675. &search_fft_info_sec80;
  676. uint32_t segid_skiplen = 0;
  677. int8_t rssi_up = 0;
  678. int8_t rssi_low = 0;
  679. int8_t chn_idx_highest_enabled = 0;
  680. int8_t chn_idx_lowest_enabled = 0;
  681. uint8_t control_rssi = 0;
  682. uint8_t extension_rssi = 0;
  683. uint8_t combined_rssi = 0;
  684. uint32_t tstamp = 0;
  685. struct target_if_spectral_ops *p_sops =
  686. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  687. struct spectral_phyerr_tlv_gen2 *ptlv =
  688. (struct spectral_phyerr_tlv_gen2 *)data;
  689. struct spectral_phyerr_tlv_gen2 *ptlv_sec80 = NULL;
  690. struct spectral_phyerr_fft_gen2 *pfft = NULL;
  691. struct spectral_phyerr_fft_gen2 *pfft_sec80 = NULL;
  692. uint8_t segid = 0;
  693. uint8_t segid_sec80 = 0;
  694. if (spectral->is_160_format)
  695. segid_skiplen = sizeof(SPECTRAL_SEGID_INFO);
  696. pfft = (struct spectral_phyerr_fft_gen2 *)(
  697. data +
  698. sizeof(struct spectral_phyerr_tlv_gen2) +
  699. sizeof(struct spectral_phyerr_hdr_gen2) +
  700. segid_skiplen);
  701. /*
  702. * XXX Extend SPECTRAL_DPRINTK() to use spectral_debug_level,
  703. * and use this facility inside spectral_dump_phyerr_data()
  704. * and supporting functions.
  705. */
  706. if (spectral_debug_level & DEBUG_SPECTRAL2)
  707. target_if_spectral_dump_phyerr_data_gen2(
  708. data, datalen,
  709. spectral->is_160_format);
  710. if (spectral_debug_level & DEBUG_SPECTRAL4) {
  711. target_if_spectral_dump_phyerr_data_gen2(
  712. data, datalen,
  713. spectral->is_160_format);
  714. spectral_debug_level = DEBUG_SPECTRAL;
  715. }
  716. if (ptlv->signature != SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  717. /*
  718. * EV# 118023: We tentatively disable the below print
  719. * and provide stats instead.
  720. */
  721. spectral->diag_stats.spectral_mismatch++;
  722. return -EPERM;
  723. }
  724. OS_MEMZERO(&params, sizeof(params));
  725. /* Gen 2 only supports normal Spectral scan currently */
  726. params.smode = SPECTRAL_SCAN_MODE_NORMAL;
  727. if (ptlv->tag == TLV_TAG_SEARCH_FFT_REPORT_GEN2) {
  728. if (spectral->is_160_format) {
  729. segid = *((SPECTRAL_SEGID_INFO *)(
  730. (uint8_t *)ptlv +
  731. sizeof(struct spectral_phyerr_tlv_gen2) +
  732. sizeof(struct spectral_phyerr_hdr_gen2)));
  733. if (segid != 0) {
  734. struct spectral_diag_stats *p_diag_stats =
  735. &spectral->diag_stats;
  736. p_diag_stats->spectral_vhtseg1id_mismatch++;
  737. return -EPERM;
  738. }
  739. }
  740. target_if_process_sfft_report_gen2(ptlv, ptlv->length,
  741. &search_fft_info);
  742. tstamp = p_sops->get_tsf64(spectral) & SPECTRAL_TSMASK;
  743. combined_rssi = p_rfqual->rssi_comb;
  744. if (spectral->upper_is_control)
  745. rssi_up = control_rssi;
  746. else
  747. rssi_up = extension_rssi;
  748. if (spectral->lower_is_control)
  749. rssi_low = control_rssi;
  750. else
  751. rssi_low = extension_rssi;
  752. params.rssi = p_rfqual->rssi_comb;
  753. params.lower_rssi = rssi_low;
  754. params.upper_rssi = rssi_up;
  755. if (spectral->sc_spectral_noise_pwr_cal) {
  756. params.chain_ctl_rssi[0] =
  757. p_rfqual->pc_rssi_info[0].rssi_pri20;
  758. params.chain_ctl_rssi[1] =
  759. p_rfqual->pc_rssi_info[1].rssi_pri20;
  760. params.chain_ctl_rssi[2] =
  761. p_rfqual->pc_rssi_info[2].rssi_pri20;
  762. params.chain_ext_rssi[0] =
  763. p_rfqual->pc_rssi_info[0].rssi_sec20;
  764. params.chain_ext_rssi[1] =
  765. p_rfqual->pc_rssi_info[1].rssi_sec20;
  766. params.chain_ext_rssi[2] =
  767. p_rfqual->pc_rssi_info[2].rssi_sec20;
  768. }
  769. /*
  770. * XXX : This actually depends on the programmed chain mask
  771. * This value decides the per-chain enable mask to select
  772. * the input ADC for search FTT.
  773. * For modes upto VHT80, if more than one chain is
  774. * enabled, the max valid chain
  775. * is used. LSB corresponds to chain zero.
  776. * For VHT80_80 and VHT160, the lowest enabled chain is
  777. * used for primary
  778. * detection and highest enabled chain is used for
  779. * secondary detection.
  780. *
  781. * XXX : The current algorithm do not use these control and
  782. * extension channel
  783. * Instead, it just relies on the combined RSSI values
  784. * only.
  785. * For fool-proof detection algorithm, we should take
  786. * these RSSI values in to account.
  787. * This is marked for future enhancements.
  788. */
  789. chn_idx_highest_enabled =
  790. ((spectral->params[params.smode].ss_chn_mask & 0x8) ? 3 :
  791. (spectral->params[params.smode].ss_chn_mask & 0x4) ? 2 :
  792. (spectral->params[params.smode].ss_chn_mask & 0x2) ? 1 : 0);
  793. chn_idx_lowest_enabled =
  794. ((spectral->params[params.smode].ss_chn_mask & 0x1) ? 0 :
  795. (spectral->params[params.smode].ss_chn_mask & 0x2) ? 1 :
  796. (spectral->params[params.smode].ss_chn_mask & 0x4) ? 2 : 3);
  797. control_rssi = (uint8_t)
  798. p_rfqual->pc_rssi_info[chn_idx_highest_enabled].rssi_pri20;
  799. extension_rssi = (uint8_t)
  800. p_rfqual->pc_rssi_info[chn_idx_highest_enabled].rssi_sec20;
  801. params.bwinfo = 0;
  802. params.tstamp = 0;
  803. params.max_mag = p_sfft->peak_mag;
  804. params.max_index = p_sfft->peak_inx;
  805. params.max_exp = 0;
  806. params.peak = 0;
  807. params.bin_pwr_data = (uint8_t *)pfft;
  808. params.freq = p_sops->get_current_channel(spectral);
  809. params.freq_loading = 0;
  810. params.interf_list.count = 0;
  811. params.max_lower_index = 0;
  812. params.max_upper_index = 0;
  813. params.nb_lower = 0;
  814. params.nb_upper = 0;
  815. /*
  816. * For modes upto VHT80, the noise floor is populated with the
  817. * one corresponding
  818. * to the highest enabled antenna chain
  819. */
  820. params.noise_floor =
  821. p_rfqual->noise_floor[chn_idx_highest_enabled];
  822. params.datalen = ptlv->length;
  823. params.pwr_count = ptlv->length -
  824. sizeof(struct spectral_phyerr_hdr_gen2) - segid_skiplen;
  825. params.tstamp = (tsf64 & SPECTRAL_TSMASK);
  826. acs_stats->ctrl_nf = params.noise_floor;
  827. acs_stats->ext_nf = params.noise_floor;
  828. acs_stats->nfc_ctl_rssi = control_rssi;
  829. acs_stats->nfc_ext_rssi = extension_rssi;
  830. if (spectral->is_160_format &&
  831. spectral->ch_width == CH_WIDTH_160MHZ) {
  832. /*
  833. * We expect to see one more Search FFT report, and it
  834. * should be equal in size to the current one.
  835. */
  836. if (datalen < (
  837. 2 * (
  838. sizeof(struct spectral_phyerr_tlv_gen2) +
  839. ptlv->length))) {
  840. struct spectral_diag_stats *p_diag_stats =
  841. &spectral->diag_stats;
  842. p_diag_stats->spectral_sec80_sfft_insufflen++;
  843. return -EPERM;
  844. }
  845. ptlv_sec80 = (struct spectral_phyerr_tlv_gen2 *)(
  846. data +
  847. sizeof(struct spectral_phyerr_tlv_gen2) +
  848. ptlv->length);
  849. if (ptlv_sec80->signature !=
  850. SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  851. spectral->diag_stats.spectral_mismatch++;
  852. return -EPERM;
  853. }
  854. if (ptlv_sec80->tag != TLV_TAG_SEARCH_FFT_REPORT_GEN2) {
  855. spectral->diag_stats.spectral_no_sec80_sfft++;
  856. return -EPERM;
  857. }
  858. segid_sec80 = *((SPECTRAL_SEGID_INFO *)(
  859. (uint8_t *)ptlv_sec80 +
  860. sizeof(struct spectral_phyerr_tlv_gen2) +
  861. sizeof(struct spectral_phyerr_hdr_gen2)));
  862. if (segid_sec80 != 1) {
  863. struct spectral_diag_stats *p_diag_stats =
  864. &spectral->diag_stats;
  865. p_diag_stats->spectral_vhtseg2id_mismatch++;
  866. return -EPERM;
  867. }
  868. params.vhtop_ch_freq_seg1 = p_chaninfo->center_freq1;
  869. params.vhtop_ch_freq_seg2 = p_chaninfo->center_freq2;
  870. target_if_process_sfft_report_gen2(
  871. ptlv_sec80,
  872. ptlv_sec80->length,
  873. &search_fft_info_sec80);
  874. pfft_sec80 = (struct spectral_phyerr_fft_gen2 *)(
  875. ((uint8_t *)ptlv_sec80) +
  876. sizeof(struct spectral_phyerr_tlv_gen2) +
  877. sizeof(struct spectral_phyerr_hdr_gen2) +
  878. segid_skiplen);
  879. /* XXX: Confirm. TBD at SoD. */
  880. params.rssi_sec80 = p_rfqual->rssi_comb;
  881. if (spectral->is_sec80_rssi_war_required)
  882. params.rssi_sec80 =
  883. target_if_get_combrssi_sec80_seg_gen2
  884. (spectral, &search_fft_info_sec80);
  885. /* XXX: Determine dynamically. TBD at SoD. */
  886. /*
  887. * For VHT80_80/VHT160, the noise floor for primary
  888. * 80MHz segment is populated with the
  889. * lowest enabled antenna chain and the noise floor for
  890. * secondary 80MHz segment is populated
  891. * with the highest enabled antenna chain
  892. */
  893. params.noise_floor_sec80 =
  894. p_rfqual->noise_floor[chn_idx_highest_enabled];
  895. params.noise_floor =
  896. p_rfqual->noise_floor[chn_idx_lowest_enabled];
  897. params.max_mag_sec80 = p_sfft_sec80->peak_mag;
  898. params.max_index_sec80 = p_sfft_sec80->peak_inx;
  899. /* XXX Does this definition of datalen *still hold? */
  900. params.datalen_sec80 = ptlv_sec80->length;
  901. params.pwr_count_sec80 =
  902. ptlv_sec80->length -
  903. sizeof(struct spectral_phyerr_hdr_gen2) -
  904. segid_skiplen;
  905. params.bin_pwr_data_sec80 = (uint8_t *)pfft_sec80;
  906. }
  907. qdf_mem_copy(&params.classifier_params,
  908. &spectral->classifier_params,
  909. sizeof(struct spectral_classifier_params));
  910. target_if_spectral_log_SAMP_param(&params);
  911. target_if_spectral_create_samp_msg(spectral, &params);
  912. }
  913. return 0;
  914. }
  915. int
  916. target_if_spectral_dump_hdr_gen2(struct spectral_phyerr_hdr_gen2 *phdr)
  917. {
  918. uint32_t a = 0;
  919. uint32_t b = 0;
  920. qdf_mem_copy(&a, (uint8_t *)phdr, sizeof(int));
  921. qdf_mem_copy(&b,
  922. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  923. sizeof(int));
  924. spectral_debug("SPECTRAL : HEADER A 0x%x (%d)", a, a);
  925. spectral_debug("SPECTRAL : HEADER B 0x%x (%d)", b, b);
  926. return 0;
  927. }
  928. int8_t
  929. target_if_get_combrssi_sec80_seg_gen2(
  930. struct target_if_spectral *spectral,
  931. struct spectral_search_fft_info_gen2 *p_sfft_sec80)
  932. {
  933. uint32_t avgpwr_db = 0;
  934. uint32_t total_gain_db = 0;
  935. uint32_t offset = 0;
  936. int8_t comb_rssi = 0;
  937. /* Obtain required parameters for algorithm from search FFT report */
  938. avgpwr_db = p_sfft_sec80->avgpwr_db;
  939. total_gain_db = p_sfft_sec80->total_gain_info;
  940. /* Calculate offset */
  941. offset = target_if_get_offset_swar_sec80(spectral->ch_width);
  942. /* Calculate RSSI */
  943. comb_rssi = ((avgpwr_db - total_gain_db) + offset);
  944. return comb_rssi;
  945. }
  946. int
  947. target_if_spectral_dump_tlv_gen2(
  948. struct spectral_phyerr_tlv_gen2 *ptlv, bool is_160_format)
  949. {
  950. int ret = 0;
  951. /*
  952. * TODO : Do not delete the following print
  953. * The scripts used to validate Spectral depend on this Print
  954. */
  955. spectral_debug("SPECTRAL : TLV Length is 0x%x (%d)",
  956. ptlv->length, ptlv->length);
  957. switch (ptlv->tag) {
  958. case TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2:
  959. ret =
  960. target_if_dump_summary_report_gen2(
  961. ptlv, ptlv->length, is_160_format);
  962. break;
  963. case TLV_TAG_SEARCH_FFT_REPORT_GEN2:
  964. ret =
  965. target_if_dump_sfft_report_gen2(ptlv, ptlv->length,
  966. is_160_format);
  967. break;
  968. case TLV_TAG_ADC_REPORT_GEN2:
  969. ret = target_if_dump_adc_report_gen2(ptlv, ptlv->length);
  970. break;
  971. default:
  972. spectral_warn("INVALID TLV");
  973. ret = -1;
  974. break;
  975. }
  976. return ret;
  977. }
  978. int
  979. target_if_spectral_dump_phyerr_data_gen2(uint8_t *data, uint32_t datalen,
  980. bool is_160_format)
  981. {
  982. struct spectral_phyerr_tlv_gen2 *ptlv = NULL;
  983. uint32_t bytes_processed = 0;
  984. uint32_t bytes_remaining = datalen;
  985. uint32_t curr_tlv_complete_size = 0;
  986. if (datalen < sizeof(struct spectral_phyerr_tlv_gen2)) {
  987. spectral_err("Total PHY error data length %u too short to contain any TLVs",
  988. datalen);
  989. return -EPERM;
  990. }
  991. while (bytes_processed < datalen) {
  992. if (bytes_remaining < sizeof(struct spectral_phyerr_tlv_gen2)) {
  993. spectral_err("Remaining PHY error data length %u too short to contain a TLV",
  994. bytes_remaining);
  995. return -EPERM;
  996. }
  997. ptlv = (struct spectral_phyerr_tlv_gen2 *)(data +
  998. bytes_processed);
  999. if (ptlv->signature != SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  1000. spectral_err("Invalid signature 0x%x!",
  1001. ptlv->signature);
  1002. return -EPERM;
  1003. }
  1004. curr_tlv_complete_size =
  1005. sizeof(struct spectral_phyerr_tlv_gen2) +
  1006. ptlv->length;
  1007. if (curr_tlv_complete_size > bytes_remaining) {
  1008. spectral_err("TLV size %d greater than number of bytes remaining %d",
  1009. curr_tlv_complete_size, bytes_remaining);
  1010. return -EPERM;
  1011. }
  1012. if (target_if_spectral_dump_tlv_gen2(ptlv, is_160_format) == -1)
  1013. return -EPERM;
  1014. bytes_processed += curr_tlv_complete_size;
  1015. bytes_remaining = datalen - bytes_processed;
  1016. }
  1017. return 0;
  1018. }
  1019. int
  1020. target_if_process_sfft_report_gen3(
  1021. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  1022. struct spectral_search_fft_info_gen3 *p_sfft)
  1023. {
  1024. /*
  1025. * For simplicity, everything is defined as uint32_t (except one).
  1026. * Proper code will later use the right sizes.
  1027. */
  1028. /*
  1029. * For easy comparision between MDK team and OS team, the MDK script
  1030. * variable names have been used
  1031. */
  1032. int32_t peak_sidx;
  1033. int32_t peak_mag;
  1034. /* Populate the Search FFT Info */
  1035. if (p_sfft) {
  1036. p_sfft->timestamp = p_fft_report->fft_timestamp;
  1037. p_sfft->fft_detector_id = get_bitfield(p_fft_report->hdr_a,
  1038. 2, 0);
  1039. p_sfft->fft_num = get_bitfield(p_fft_report->hdr_a, 3, 2);
  1040. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  1041. 12, 5);
  1042. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 17);
  1043. p_sfft->fft_peak_sidx = unsigned_to_signed(peak_sidx, 11);
  1044. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_a, 3, 28);
  1045. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  1046. 9, 0);
  1047. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  1048. 8, 9);
  1049. p_sfft->fft_num_str_bins_ib = get_bitfield(p_fft_report->hdr_c,
  1050. 8, 0);
  1051. peak_mag = get_bitfield(p_fft_report->hdr_c, 10, 8);
  1052. p_sfft->fft_peak_mag = unsigned_to_signed(peak_mag, 10);
  1053. p_sfft->fft_avgpwr_db = get_bitfield(p_fft_report->hdr_c,
  1054. 7, 18);
  1055. p_sfft->fft_relpwr_db = get_bitfield(p_fft_report->hdr_c,
  1056. 7, 25);
  1057. }
  1058. return 0;
  1059. }
  1060. int
  1061. target_if_dump_fft_report_gen3(struct target_if_spectral *spectral,
  1062. enum spectral_scan_mode smode,
  1063. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  1064. struct spectral_search_fft_info_gen3 *p_sfft)
  1065. {
  1066. int i = 0;
  1067. int fft_mag = 0;
  1068. int fft_hdr_length = (p_fft_report->fft_hdr_length * 4);
  1069. int report_len = (fft_hdr_length + 8);
  1070. int fft_bin_len = (fft_hdr_length - 16);
  1071. int fft_bin_len_to_dump = fft_bin_len;
  1072. int fft_bin_len_adj = 0;
  1073. int fft_bin_len_inband_tfer = 0;
  1074. if ((spectral->params[smode].ss_rpt_mode == 1) &&
  1075. spectral->null_fftbin_adj) {
  1076. /* fft_bin_len_adj is intentionally left at 0. */
  1077. fft_bin_len_to_dump = 0;
  1078. } else {
  1079. /*
  1080. * Divide fft bin length by appropriate factor depending
  1081. * on the value of fftbin_size_war.
  1082. */
  1083. if (spectral->fftbin_size_war ==
  1084. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE)
  1085. fft_bin_len_adj = fft_bin_len >> 2;
  1086. else if (spectral->fftbin_size_war ==
  1087. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  1088. /* Ideally we should be dividing fft bin length by 2.
  1089. * Due to a HW bug, actual length is two times the
  1090. * expected length.
  1091. */
  1092. fft_bin_len_adj = fft_bin_len >> 2;
  1093. } else
  1094. fft_bin_len_adj = fft_bin_len;
  1095. if ((spectral->params[smode].ss_rpt_mode == 2) &&
  1096. spectral->inband_fftbin_size_adj) {
  1097. fft_bin_len_adj >>= 1;
  1098. fft_bin_len_inband_tfer = fft_bin_len >> 1;
  1099. fft_bin_len_to_dump = fft_bin_len_inband_tfer;
  1100. }
  1101. }
  1102. spectral_debug("#############################################################");
  1103. spectral_debug("Spectral search fft_report");
  1104. spectral_debug("fft_timestamp = 0x%x\nfft_hdr_length = %d(32 bit words)\nfft_hdr_tag = 0x%x\nfft_hdr_sig = 0x%x",
  1105. p_fft_report->fft_timestamp,
  1106. p_fft_report->fft_hdr_length,
  1107. p_fft_report->fft_hdr_tag, p_fft_report->fft_hdr_sig);
  1108. spectral_debug("Length field in search fft report is %d(0x%x) bytes",
  1109. fft_hdr_length, fft_hdr_length);
  1110. spectral_debug("Total length of search fft report is %d(0x%x) bytes",
  1111. report_len, report_len);
  1112. spectral_debug("Target reported fftbins in report is %d(0x%x)",
  1113. fft_bin_len,
  1114. fft_bin_len);
  1115. if ((spectral->params[smode].ss_rpt_mode == 1) &&
  1116. spectral->null_fftbin_adj)
  1117. spectral_debug("WAR: Considering number of FFT bins as 0");
  1118. else if ((spectral->params[smode].ss_rpt_mode == 2) &&
  1119. spectral->inband_fftbin_size_adj) {
  1120. spectral_debug("FW fftbins actually transferred (in-band report mode) "
  1121. "%d(0x%x)",
  1122. fft_bin_len_inband_tfer, fft_bin_len_inband_tfer);
  1123. }
  1124. spectral_debug("Actual number of fftbins in report is %d(0x%x)\n",
  1125. fft_bin_len_adj, fft_bin_len_adj);
  1126. spectral_debug("fft_detector_id = %u\nfft_num = %u\nfft_radar_check = %u\nfft_peak_sidx = %d\nfft_chn_idx = %u\nfft_base_pwr_db = %u\nfft_total_gain_db = %u\nfft_num_str_bins_ib = %u\nfft_peak_mag = %d\nfft_avgpwr_db = %u\nfft_relpwr_db = %u",
  1127. p_sfft->fft_detector_id,
  1128. p_sfft->fft_num,
  1129. p_sfft->fft_radar_check,
  1130. p_sfft->fft_peak_sidx,
  1131. p_sfft->fft_chn_idx,
  1132. p_sfft->fft_base_pwr_db,
  1133. p_sfft->fft_total_gain_db,
  1134. p_sfft->fft_num_str_bins_ib,
  1135. p_sfft->fft_peak_mag,
  1136. p_sfft->fft_avgpwr_db, p_sfft->fft_relpwr_db);
  1137. if (fft_bin_len_to_dump > 0) {
  1138. spectral_debug("FFT bins:");
  1139. for (i = 0; i < fft_bin_len_to_dump; i++) {
  1140. if (i % 16 == 0)
  1141. spectral_debug("\n%d :", i);
  1142. fft_mag =
  1143. ((uint8_t *)p_fft_report)[SPECTRAL_FFT_BINS_POS + i];
  1144. spectral_debug("%d ", fft_mag);
  1145. }
  1146. }
  1147. spectral_debug("\n");
  1148. spectral_debug("#############################################################");
  1149. return 0;
  1150. }
  1151. QDF_STATUS
  1152. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  1153. uint8_t detector_id) {
  1154. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1155. if (spectral->ch_width != CH_WIDTH_160MHZ)
  1156. return QDF_STATUS_E_FAILURE;
  1157. /* agile reports should not be coupled with 160 MHz state machine
  1158. * for normal Spectral
  1159. */
  1160. if (detector_id == SPECTRAL_DETECTOR_AGILE)
  1161. return QDF_STATUS_SUCCESS;
  1162. switch (spectral->state_160mhz_delivery) {
  1163. case SPECTRAL_REPORT_WAIT_PRIMARY80:
  1164. if (detector_id == SPECTRAL_DETECTOR_PRIMARY)
  1165. spectral->state_160mhz_delivery =
  1166. SPECTRAL_REPORT_RX_PRIMARY80;
  1167. else {
  1168. status = QDF_STATUS_E_FAILURE;
  1169. spectral->diag_stats.spectral_vhtseg1id_mismatch++;
  1170. }
  1171. break;
  1172. case SPECTRAL_REPORT_WAIT_SECONDARY80:
  1173. if (detector_id == SPECTRAL_DETECTOR_SECONDARY)
  1174. spectral->state_160mhz_delivery =
  1175. SPECTRAL_REPORT_RX_SECONDARY80;
  1176. else {
  1177. spectral->state_160mhz_delivery =
  1178. SPECTRAL_REPORT_WAIT_PRIMARY80;
  1179. status = QDF_STATUS_E_FAILURE;
  1180. spectral->diag_stats.spectral_vhtseg2id_mismatch++;
  1181. }
  1182. break;
  1183. case SPECTRAL_REPORT_RX_SECONDARY80:
  1184. /* We don't care about detector id in this state. */
  1185. reset_160mhz_delivery_state_machine(spectral,
  1186. SPECTRAL_SCAN_MODE_NORMAL);
  1187. break;
  1188. case SPECTRAL_REPORT_RX_PRIMARY80:
  1189. /* We don't care about detector id in this state */
  1190. spectral->state_160mhz_delivery =
  1191. SPECTRAL_REPORT_WAIT_SECONDARY80;
  1192. break;
  1193. default:
  1194. break;
  1195. }
  1196. return status;
  1197. }
  1198. #ifdef DIRECT_BUF_RX_ENABLE
  1199. /**
  1200. * target_if_get_detector_id_sscan_report_gen3() - Get Spectral detector id
  1201. * @data: Pointer to Spectral summary report / Spectral
  1202. * search FFT report
  1203. *
  1204. * Get Spectral detector id from Spectral summary report / Spectral
  1205. * search FFT report
  1206. *
  1207. * Return: detector id
  1208. */
  1209. static uint8_t
  1210. target_if_get_detector_id_sscan_report_gen3(uint8_t *data) {
  1211. struct spectral_sscan_report_gen3 *psscan_report;
  1212. uint8_t detector_id;
  1213. psscan_report = (struct spectral_sscan_report_gen3 *)data;
  1214. detector_id = get_bitfield(psscan_report->hdr_a,
  1215. SSCAN_REPORT_DETECTOR_ID_SIZE_GEN3,
  1216. SSCAN_REPORT_DETECTOR_ID_POS_GEN3);
  1217. return detector_id;
  1218. }
  1219. /**
  1220. * target_if_consume_sscan_report_gen3() - Consume spectral summary report
  1221. * @spectral: Pointer to spectral object
  1222. * @data: Pointer to spectral summary
  1223. *
  1224. * Consume spectral summary report for gen3
  1225. *
  1226. * Return: void
  1227. */
  1228. static void
  1229. target_if_consume_sscan_report_gen3(struct target_if_spectral *spectral,
  1230. uint8_t *data,
  1231. struct sscan_report_fields_gen3 *fields) {
  1232. struct spectral_sscan_report_gen3 *psscan_report;
  1233. psscan_report = (struct spectral_sscan_report_gen3 *)data;
  1234. fields->sscan_agc_total_gain = get_bitfield(psscan_report->hdr_a, 8, 0);
  1235. fields->inband_pwr_db = get_bitfield(psscan_report->hdr_a, 10, 18);
  1236. fields->sscan_gainchange = get_bitfield(psscan_report->hdr_b, 1, 30);
  1237. }
  1238. /**
  1239. * target_if_verify_sig_and_tag_gen3() - Verify tag and signature
  1240. * of spectral report
  1241. * @spectral: Pointer to spectral object
  1242. * @data: Pointer to spectral summary report
  1243. * @exp_tag: iexpected tag value
  1244. *
  1245. * Process fft report for gen3
  1246. *
  1247. * Return: SUCCESS/FAILURE
  1248. */
  1249. static int
  1250. target_if_verify_sig_and_tag_gen3(struct target_if_spectral *spectral,
  1251. uint8_t *data, uint8_t exp_tag)
  1252. {
  1253. uint8_t tag = 0;
  1254. uint8_t signature = 0;
  1255. /* Peek into the data to figure out whether
  1256. * 1) Signature matches the expected value
  1257. * 2) What is inside the package (TAG ID is used for finding this)
  1258. */
  1259. tag = *(data + PHYERR_HDR_TAG_POS);
  1260. signature = *(data + PHYERR_HDR_SIG_POS);
  1261. if (signature != SPECTRAL_PHYERR_SIGNATURE_GEN3) {
  1262. spectral->diag_stats.spectral_mismatch++;
  1263. return -EINVAL;
  1264. }
  1265. if (tag != exp_tag) {
  1266. spectral->diag_stats.spectral_mismatch++;
  1267. return -EINVAL;
  1268. }
  1269. return 0;
  1270. }
  1271. static uint8_t
  1272. target_if_spectral_get_lowest_chn_idx(uint8_t chainmask)
  1273. {
  1274. uint8_t idx;
  1275. for (idx = 0; idx < DBR_MAX_CHAINS; idx++) {
  1276. if (chainmask & 0x1)
  1277. break;
  1278. chainmask >>= 1;
  1279. }
  1280. return idx;
  1281. }
  1282. static QDF_STATUS
  1283. target_if_get_spectral_mode(enum spectral_detector_id detector_id,
  1284. enum spectral_scan_mode *smode) {
  1285. switch (detector_id) {
  1286. case SPECTRAL_DETECTOR_PRIMARY:
  1287. case SPECTRAL_DETECTOR_SECONDARY:
  1288. *smode = SPECTRAL_SCAN_MODE_NORMAL;
  1289. break;
  1290. case SPECTRAL_DETECTOR_AGILE:
  1291. *smode = SPECTRAL_SCAN_MODE_AGILE;
  1292. break;
  1293. default:
  1294. spectral_err("Invalid Spectral detector id");
  1295. return QDF_STATUS_E_FAILURE;
  1296. }
  1297. return QDF_STATUS_SUCCESS;
  1298. }
  1299. int
  1300. target_if_consume_spectral_report_gen3(
  1301. struct target_if_spectral *spectral,
  1302. struct spectral_report *report)
  1303. {
  1304. /*
  1305. * XXX : The classifier do not use all the members of the SAMP
  1306. * message data format.
  1307. * The classifier only depends upon the following parameters
  1308. *
  1309. * 1. Frequency (freq, msg->freq)
  1310. * 2. Spectral RSSI (spectral_rssi,
  1311. * msg->samp_data.spectral_rssi)
  1312. * 3. Bin Power Count (bin_pwr_count,
  1313. * msg->samp_data.bin_pwr_count)
  1314. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  1315. * 5. Spectral Timestamp (spectral_tstamp,
  1316. * msg->samp_data.spectral_tstamp)
  1317. * 6. MAC Address (macaddr, msg->macaddr)
  1318. *
  1319. * This function prepares the params structure and populates it
  1320. * with
  1321. * relevant values, this is in turn passed to
  1322. * spectral_create_samp_msg()
  1323. * to prepare fully formatted Spectral SAMP message
  1324. *
  1325. * XXX : Need to verify
  1326. * 1. Order of FFT bin values
  1327. *
  1328. */
  1329. uint64_t tsf64 = 0;
  1330. struct target_if_samp_msg_params params = {0};
  1331. struct spectral_search_fft_info_gen3 search_fft_info;
  1332. struct spectral_search_fft_info_gen3 *p_sfft = &search_fft_info;
  1333. int8_t chn_idx_lowest_enabled = 0;
  1334. int fft_hdr_length = 0;
  1335. int report_len = 0;
  1336. int fft_bin_len = 0;
  1337. struct target_if_spectral_ops *p_sops =
  1338. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1339. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  1340. int8_t rssi;
  1341. uint8_t *data = report->data;
  1342. struct wlan_objmgr_vdev *vdev;
  1343. uint8_t vdev_rxchainmask;
  1344. struct sscan_report_fields_gen3 sscan_report_fields;
  1345. enum spectral_detector_id detector_id;
  1346. QDF_STATUS ret;
  1347. params.smode = SPECTRAL_SCAN_MODE_NORMAL;
  1348. /* Process Spectral scan summary report */
  1349. if (target_if_verify_sig_and_tag_gen3(
  1350. spectral, data,
  1351. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3) != 0) {
  1352. spectral_err_rl("Wrong tag/sig in sscan summary");
  1353. goto fail;
  1354. }
  1355. detector_id = target_if_get_detector_id_sscan_report_gen3(data);
  1356. if (detector_id > SPECTRAL_DETECTOR_AGILE) {
  1357. spectral->diag_stats.spectral_invalid_detector_id++;
  1358. spectral_err("Invalid detector id %u, expected is 0/1/2",
  1359. detector_id);
  1360. goto fail;
  1361. }
  1362. target_if_consume_sscan_report_gen3(spectral, data,
  1363. &sscan_report_fields);
  1364. /* Advance buf pointer to the search fft report */
  1365. data += sizeof(struct spectral_sscan_report_gen3);
  1366. if ((detector_id == SPECTRAL_DETECTOR_AGILE) ||
  1367. is_primaryseg_expected(spectral)) {
  1368. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  1369. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  1370. params.agc_total_gain =
  1371. sscan_report_fields.sscan_agc_total_gain;
  1372. params.gainchange = sscan_report_fields.sscan_gainchange;
  1373. /* Process Spectral search FFT report */
  1374. if (target_if_verify_sig_and_tag_gen3(
  1375. spectral, data,
  1376. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  1377. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  1378. detector_id);
  1379. goto fail;
  1380. }
  1381. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  1382. fft_hdr_length = p_fft_report->fft_hdr_length * 4;
  1383. if (fft_hdr_length < 16) {
  1384. spectral_err("Wrong TLV length %u, detector id = %d",
  1385. fft_hdr_length, detector_id);
  1386. goto fail;
  1387. }
  1388. report_len = (fft_hdr_length + 8);
  1389. target_if_process_sfft_report_gen3(p_fft_report, p_sfft);
  1390. /* It is expected to have same detector id for
  1391. * summary and fft report
  1392. */
  1393. if (detector_id != p_sfft->fft_detector_id) {
  1394. spectral_err_rl
  1395. ("Different detid in ssummary(%u) and sfft(%u)",
  1396. detector_id, p_sfft->fft_detector_id);
  1397. goto fail;
  1398. }
  1399. if (detector_id > SPECTRAL_DETECTOR_AGILE) {
  1400. spectral->diag_stats.spectral_invalid_detector_id++;
  1401. spectral_err("Invalid detector id %u, expected is 0/2",
  1402. detector_id);
  1403. goto fail;
  1404. }
  1405. ret = target_if_get_spectral_mode(detector_id, &params.smode);
  1406. if (QDF_IS_STATUS_ERROR(ret)) {
  1407. spectral_err_rl("Failed to get mode from detid= %u",
  1408. detector_id);
  1409. goto fail;
  1410. }
  1411. if ((spectral->params[params.smode].ss_rpt_mode == 1) &&
  1412. spectral->null_fftbin_adj) {
  1413. /*
  1414. * No FFT bins are expected. Explicitly set FFT bin
  1415. * length to 0.
  1416. */
  1417. fft_bin_len = 0;
  1418. } else {
  1419. fft_bin_len = (fft_hdr_length - 16);
  1420. /*
  1421. * Divide fft bin length by appropriate factor depending
  1422. * on the value of fftbin_size_war.
  1423. */
  1424. if (spectral->fftbin_size_war ==
  1425. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE)
  1426. fft_bin_len >>= 2;
  1427. else if (spectral->fftbin_size_war ==
  1428. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  1429. /* Ideally we should be dividing fft bin length
  1430. * by 2. Due to a HW bug, actual length is two
  1431. * times the expected length.
  1432. */
  1433. fft_bin_len >>= 2;
  1434. }
  1435. if ((spectral->params[params.smode].ss_rpt_mode == 2) &&
  1436. spectral->inband_fftbin_size_adj) {
  1437. fft_bin_len >>= 1;
  1438. }
  1439. }
  1440. if (report->reset_delay) {
  1441. enum spectral_scan_mode mode =
  1442. SPECTRAL_SCAN_MODE_NORMAL;
  1443. /* Adjust the offset for all the Spectral modes.
  1444. * Target will be sending the non zero reset delay for
  1445. * the first Spectral report after reset. This delay is
  1446. * common for all the Spectral modes.
  1447. */
  1448. for (; mode < SPECTRAL_SCAN_MODE_MAX; mode++)
  1449. spectral->timestamp_war_offset[mode] +=
  1450. (report->reset_delay +
  1451. spectral->last_fft_timestamp[mode]);
  1452. }
  1453. tsf64 = p_sfft->timestamp;
  1454. spectral->last_fft_timestamp[params.smode] = p_sfft->timestamp;
  1455. tsf64 += spectral->timestamp_war_offset[params.smode];
  1456. /* Take care of state transitions for 160 MHz and 80p80 */
  1457. if (spectral->ch_width == CH_WIDTH_160MHZ) {
  1458. ret = target_if_160mhz_delivery_state_change(
  1459. spectral,
  1460. detector_id);
  1461. if (ret != QDF_STATUS_SUCCESS)
  1462. goto fail;
  1463. }
  1464. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  1465. target_if_dump_fft_report_gen3(spectral, params.smode,
  1466. p_fft_report, p_sfft);
  1467. params.rssi = rssi;
  1468. vdev = target_if_spectral_get_vdev(spectral);
  1469. if (!vdev) {
  1470. spectral_info("First vdev is NULL");
  1471. reset_160mhz_delivery_state_machine
  1472. (spectral,
  1473. SPECTRAL_SCAN_MODE_NORMAL);
  1474. return -EPERM;
  1475. }
  1476. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  1477. QDF_ASSERT(vdev_rxchainmask != 0);
  1478. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1479. chn_idx_lowest_enabled =
  1480. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  1481. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  1482. spectral_err("Invalid chain index, detector id = %u",
  1483. detector_id);
  1484. goto fail;
  1485. }
  1486. params.max_mag = p_sfft->fft_peak_mag;
  1487. params.bin_pwr_data = (uint8_t *)((uint8_t *)p_fft_report +
  1488. SPECTRAL_FFT_BINS_POS);
  1489. params.freq = p_sops->get_current_channel(spectral);
  1490. /*
  1491. * For modes upto VHT80, the noise floor is populated with
  1492. * the one corresponding
  1493. * to the highest enabled antenna chain
  1494. */
  1495. /* TODO: Fill proper values once FW provides them*/
  1496. params.noise_floor =
  1497. report->noisefloor[chn_idx_lowest_enabled];
  1498. params.datalen = (fft_hdr_length * 4);
  1499. params.pwr_count = fft_bin_len;
  1500. params.tstamp = (tsf64 & SPECTRAL_TSMASK);
  1501. } else if (is_secondaryseg_expected(spectral)) {
  1502. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  1503. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  1504. params.agc_total_gain_sec80 =
  1505. sscan_report_fields.sscan_agc_total_gain;
  1506. params.gainchange_sec80 = sscan_report_fields.sscan_gainchange;
  1507. /* Process Spectral search FFT report */
  1508. if (target_if_verify_sig_and_tag_gen3(
  1509. spectral, data,
  1510. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  1511. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  1512. detector_id);
  1513. goto fail;
  1514. }
  1515. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  1516. fft_hdr_length = p_fft_report->fft_hdr_length * 4;
  1517. if (fft_hdr_length < 16) {
  1518. spectral_err("Wrong TLV length %u, detector id = %u",
  1519. fft_hdr_length, detector_id);
  1520. goto fail;
  1521. }
  1522. report_len = (fft_hdr_length + 8);
  1523. target_if_process_sfft_report_gen3(p_fft_report, p_sfft);
  1524. /* It is expected to have same detector id for
  1525. * summary and fft report
  1526. */
  1527. if (detector_id != p_sfft->fft_detector_id) {
  1528. spectral_err_rl
  1529. ("Different detid in ssummary(%u) and sfft(%u)",
  1530. detector_id, p_sfft->fft_detector_id);
  1531. goto fail;
  1532. }
  1533. if (detector_id > SPECTRAL_DETECTOR_AGILE) {
  1534. spectral->diag_stats.spectral_invalid_detector_id++;
  1535. spectral_err("Invalid detector id %u, expected is 1",
  1536. detector_id);
  1537. goto fail;
  1538. }
  1539. ret = target_if_get_spectral_mode(detector_id, &params.smode);
  1540. if (QDF_IS_STATUS_ERROR(ret)) {
  1541. spectral_err("Failed to get mode from detid= %u",
  1542. detector_id);
  1543. goto fail;
  1544. }
  1545. if ((spectral->params[params.smode].ss_rpt_mode == 1) &&
  1546. spectral->null_fftbin_adj) {
  1547. /*
  1548. * No FFT bins are expected. Explicitly set FFT bin
  1549. * length to 0.
  1550. */
  1551. fft_bin_len = 0;
  1552. } else {
  1553. fft_bin_len = (fft_hdr_length - 16);
  1554. /*
  1555. * Divide fft bin length by appropriate factor depending
  1556. * on the value of fftbin_size_war.
  1557. */
  1558. if (spectral->fftbin_size_war ==
  1559. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE)
  1560. fft_bin_len >>= 2;
  1561. else if (spectral->fftbin_size_war ==
  1562. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  1563. /* Ideally we should be dividing fft bin length
  1564. * by 2. Due to a HW bug, actual length is two
  1565. * times the expected length.
  1566. */
  1567. fft_bin_len >>= 2;
  1568. }
  1569. if ((spectral->params[params.smode].ss_rpt_mode == 2) &&
  1570. spectral->inband_fftbin_size_adj) {
  1571. fft_bin_len >>= 1;
  1572. }
  1573. }
  1574. /* Take care of state transitions for 160 MHz and 80p80 */
  1575. if (spectral->ch_width == CH_WIDTH_160MHZ) {
  1576. ret = target_if_160mhz_delivery_state_change(
  1577. spectral,
  1578. detector_id);
  1579. if (ret != QDF_STATUS_SUCCESS)
  1580. goto fail;
  1581. }
  1582. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  1583. target_if_dump_fft_report_gen3(spectral, params.smode,
  1584. p_fft_report, p_sfft);
  1585. params.vhtop_ch_freq_seg1 = 0;
  1586. params.vhtop_ch_freq_seg2 = 0;
  1587. params.rssi_sec80 = rssi;
  1588. vdev = target_if_spectral_get_vdev(spectral);
  1589. if (!vdev) {
  1590. spectral_info("First vdev is NULL");
  1591. reset_160mhz_delivery_state_machine
  1592. (spectral,
  1593. SPECTRAL_SCAN_MODE_NORMAL);
  1594. return -EPERM;
  1595. }
  1596. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  1597. QDF_ASSERT(vdev_rxchainmask != 0);
  1598. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1599. chn_idx_lowest_enabled =
  1600. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  1601. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  1602. spectral_err("Invalid chain index");
  1603. goto fail;
  1604. }
  1605. /* Need to change this as per FW team's inputs */
  1606. params.noise_floor_sec80 =
  1607. report->noisefloor[chn_idx_lowest_enabled];
  1608. params.max_mag_sec80 = p_sfft->fft_peak_mag;
  1609. /* params.max_index_sec80 = p_sfft->peak_inx; */
  1610. /* XXX Does this definition of datalen *still hold? */
  1611. params.datalen_sec80 = fft_hdr_length * 4;
  1612. params.pwr_count_sec80 = fft_bin_len;
  1613. params.bin_pwr_data_sec80 =
  1614. (uint8_t *)((uint8_t *)p_fft_report +
  1615. SPECTRAL_FFT_BINS_POS);
  1616. } else {
  1617. spectral_err("Spectral state machine in undefined state");
  1618. goto fail;
  1619. }
  1620. qdf_mem_copy(&params.classifier_params,
  1621. &spectral->classifier_params,
  1622. sizeof(struct spectral_classifier_params));
  1623. target_if_spectral_log_SAMP_param(&params);
  1624. target_if_spectral_create_samp_msg(spectral, &params);
  1625. return 0;
  1626. fail:
  1627. spectral_err_rl("Error while processing Spectral report");
  1628. reset_160mhz_delivery_state_machine(spectral,
  1629. SPECTRAL_SCAN_MODE_NORMAL);
  1630. return -EPERM;
  1631. }
  1632. int target_if_spectral_process_report_gen3(
  1633. struct wlan_objmgr_pdev *pdev,
  1634. void *buf)
  1635. {
  1636. int ret = 0;
  1637. struct direct_buf_rx_data *payload = buf;
  1638. struct target_if_spectral *spectral;
  1639. struct spectral_report report;
  1640. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1641. if (!spectral) {
  1642. spectral_err("Spectral target object is null");
  1643. return -EINVAL;
  1644. }
  1645. report.data = payload->vaddr;
  1646. if (payload->meta_data_valid) {
  1647. qdf_mem_copy(report.noisefloor, payload->meta_data.noisefloor,
  1648. qdf_min(sizeof(report.noisefloor),
  1649. sizeof(payload->meta_data.noisefloor)));
  1650. report.reset_delay = payload->meta_data.reset_delay;
  1651. }
  1652. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4)) {
  1653. spectral_debug("Printing the spectral phyerr buffer for debug");
  1654. spectral_debug("Datalength of buffer = 0x%zx(%zd) bufptr = 0x%pK",
  1655. payload->dbr_len,
  1656. payload->dbr_len,
  1657. payload->vaddr);
  1658. target_if_spectral_hexdump((unsigned char *)payload->vaddr,
  1659. 1024);
  1660. }
  1661. ret = target_if_consume_spectral_report_gen3(spectral, &report);
  1662. if (spectral_debug_level & DEBUG_SPECTRAL4)
  1663. spectral_debug_level = DEBUG_SPECTRAL;
  1664. return ret;
  1665. }
  1666. #else
  1667. int target_if_spectral_process_report_gen3(
  1668. struct wlan_objmgr_pdev *pdev,
  1669. void *buf)
  1670. {
  1671. spectral_err("Direct dma support is not enabled");
  1672. return -EINVAL;
  1673. }
  1674. #endif
  1675. qdf_export_symbol(target_if_spectral_process_report_gen3);
  1676. /* END of spectral GEN III HW specific functions */
  1677. #endif /* WLAN_CONV_SPECTRAL_ENABLE */