target_if_spectral_phyerr.c 46 KB

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