target_if_spectral_phyerr.c 52 KB

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