target_if_spectral_phyerr.c 65 KB

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