target_if_spectral_phyerr.c 56 KB

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