target_if_spectral_phyerr.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422
  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;
  1208. size_t report_len;
  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. size_t fft_bin_buf_size;
  1215. uint8_t tag, signature;
  1216. fft_hdr_length = get_bitfield(
  1217. p_fft_report->fft_hdr_lts,
  1218. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  1219. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  1220. tag = get_bitfield(p_fft_report->fft_hdr_lts,
  1221. SPECTRAL_REPORT_LTS_TAG_SIZE_GEN3,
  1222. SPECTRAL_REPORT_LTS_TAG_POS_GEN3);
  1223. signature = get_bitfield(p_fft_report->fft_hdr_lts,
  1224. SPECTRAL_REPORT_LTS_SIGNATURE_SIZE_GEN3,
  1225. SPECTRAL_REPORT_LTS_SIGNATURE_POS_GEN3);
  1226. report_len = (fft_hdr_length + 8);
  1227. fft_bin_len = fft_hdr_length - spectral->rparams.fft_report_hdr_len;
  1228. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  1229. fft_bin_len,
  1230. spectral->params[smode].ss_rpt_mode,
  1231. &spectral->len_adj_swar, &fft_bin_size);
  1232. if ((spectral->params[smode].ss_rpt_mode == 2) &&
  1233. spectral->len_adj_swar.inband_fftbin_size_adj)
  1234. fft_bin_len_inband_tfer = fft_bin_len >> 1;
  1235. spectral_debug("Spectral FFT Report");
  1236. spectral_debug("fft_timestamp = 0x%x", p_fft_report->fft_timestamp);
  1237. spectral_debug("fft_hdr_length = %zu(32 bit words)",
  1238. fft_hdr_length >> 2);
  1239. spectral_debug("fft_hdr_tag = 0x%x", tag);
  1240. spectral_debug("fft_hdr_sig = 0x%x", signature);
  1241. spectral_debug("Length field in search fft report is %zu(0x%zx) bytes",
  1242. fft_hdr_length, fft_hdr_length);
  1243. spectral_debug("Total length of search fft report is %zu(0x%zx) bytes",
  1244. report_len, report_len);
  1245. spectral_debug("Target reported fftbins in report is %zu(0x%zx)",
  1246. fft_bin_len, fft_bin_len);
  1247. if ((spectral->params[smode].ss_rpt_mode == 1) &&
  1248. spectral->len_adj_swar.null_fftbin_adj)
  1249. spectral_debug("WAR: Considering number of FFT bins as 0");
  1250. else if ((spectral->params[smode].ss_rpt_mode == 2) &&
  1251. spectral->len_adj_swar.inband_fftbin_size_adj) {
  1252. spectral_debug("FW fftbins actually transferred (in-band report mode) %zu(0x%zx)",
  1253. fft_bin_len_inband_tfer,
  1254. fft_bin_len_inband_tfer);
  1255. }
  1256. spectral_debug("Actual number of fftbins in report is %zu(0x%zx)",
  1257. fft_bin_count, fft_bin_count);
  1258. spectral_debug("fft_detector_id = %u", p_sfft->fft_detector_id);
  1259. spectral_debug("fft_num = %u", p_sfft->fft_num);
  1260. spectral_debug("fft_radar_check = %u", p_sfft->fft_radar_check);
  1261. spectral_debug("fft_peak_sidx = %d", p_sfft->fft_peak_sidx);
  1262. spectral_debug("fft_chn_idx = %u", p_sfft->fft_chn_idx);
  1263. spectral_debug("fft_base_pwr_db = %u", p_sfft->fft_base_pwr_db);
  1264. spectral_debug("fft_total_gain_db = %u", p_sfft->fft_total_gain_db);
  1265. spectral_debug("fft_num_str_bins_ib = %u", p_sfft->fft_num_str_bins_ib);
  1266. spectral_debug("fft_peak_mag = %d", p_sfft->fft_peak_mag);
  1267. spectral_debug("fft_avgpwr_db = %u", p_sfft->fft_avgpwr_db);
  1268. spectral_debug("fft_relpwr_db = %u", p_sfft->fft_relpwr_db);
  1269. fft_bin_buf_size = fft_bin_count;
  1270. if (fft_bin_count > 0) {
  1271. int idx;
  1272. if (spectral->len_adj_swar.fftbin_size_war ==
  1273. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
  1274. uint32_t *binptr_32 = (uint32_t *)&p_fft_report->buf;
  1275. uint16_t *fft_bin_buf_16 = NULL;
  1276. /* Useful width of FFT bin is 10 bits, increasing it to
  1277. * byte boundary makes it 2 bytes. Hence, buffer to be
  1278. * allocated should be of size fft_bin_count
  1279. * multiplied by 2.
  1280. */
  1281. fft_bin_buf_size <<= 1;
  1282. fft_bin_buf_16 = (uint16_t *)qdf_mem_malloc(
  1283. fft_bin_buf_size);
  1284. if (!fft_bin_buf_16) {
  1285. spectral_err("Failed to allocate memory");
  1286. return;
  1287. }
  1288. for (idx = 0; idx < fft_bin_count; idx++)
  1289. fft_bin_buf_16[idx] =
  1290. *((uint16_t *)binptr_32++);
  1291. fft_bin_buf = (uint8_t *)fft_bin_buf_16;
  1292. } else if (spectral->len_adj_swar.fftbin_size_war ==
  1293. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  1294. uint16_t *binptr_16 = (uint16_t *)&p_fft_report->buf;
  1295. uint16_t *fft_bin_buf_16 = NULL;
  1296. /* Useful width of FFT bin is 10 bits, increasing it to
  1297. * byte boundary makes it 2 bytes. Hence, buffer to be
  1298. * allocated should be of size fft_bin_count
  1299. * multiplied by 2.
  1300. */
  1301. fft_bin_buf_size <<= 1;
  1302. fft_bin_buf_16 = (uint16_t *)qdf_mem_malloc(
  1303. fft_bin_buf_size);
  1304. if (!fft_bin_buf_16) {
  1305. spectral_err("Failed to allocate memory");
  1306. return;
  1307. }
  1308. for (idx = 0; idx < fft_bin_count; idx++)
  1309. fft_bin_buf_16[idx] = *(binptr_16++);
  1310. fft_bin_buf = (uint8_t *)fft_bin_buf_16;
  1311. } else {
  1312. fft_bin_buf = (uint8_t *)&p_fft_report->buf;
  1313. }
  1314. spectral_debug("FFT bin buffer size = %zu", fft_bin_buf_size);
  1315. spectral_debug("FFT bins:");
  1316. target_if_spectral_hexdump(fft_bin_buf, fft_bin_buf_size);
  1317. if ((spectral->len_adj_swar.fftbin_size_war !=
  1318. SPECTRAL_FFTBIN_SIZE_NO_WAR) && fft_bin_buf)
  1319. qdf_mem_free(fft_bin_buf);
  1320. }
  1321. }
  1322. #endif
  1323. QDF_STATUS
  1324. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  1325. enum spectral_scan_mode smode,
  1326. uint8_t detector_id) {
  1327. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1328. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1329. spectral_err_rl("Invalid Spectral mode %d", smode);
  1330. return QDF_STATUS_E_INVAL;
  1331. }
  1332. if (!is_ch_width_160_or_80p80(spectral->ch_width[smode])) {
  1333. spectral_err_rl("Scan BW %d is not 160/80p80 for mode %d",
  1334. spectral->ch_width[smode], smode);
  1335. return QDF_STATUS_E_FAILURE;
  1336. }
  1337. switch (spectral->state_160mhz_delivery[smode]) {
  1338. case SPECTRAL_REPORT_WAIT_PRIMARY80:
  1339. if (detector_id == SPECTRAL_DETECTOR_ID_0)
  1340. spectral->state_160mhz_delivery[smode] =
  1341. SPECTRAL_REPORT_RX_PRIMARY80;
  1342. else {
  1343. status = QDF_STATUS_E_FAILURE;
  1344. spectral->diag_stats.spectral_vhtseg1id_mismatch++;
  1345. }
  1346. break;
  1347. case SPECTRAL_REPORT_WAIT_SECONDARY80:
  1348. if (detector_id == SPECTRAL_DETECTOR_ID_1)
  1349. spectral->state_160mhz_delivery[smode] =
  1350. SPECTRAL_REPORT_RX_SECONDARY80;
  1351. else {
  1352. spectral->state_160mhz_delivery[smode] =
  1353. SPECTRAL_REPORT_WAIT_PRIMARY80;
  1354. status = QDF_STATUS_E_FAILURE;
  1355. spectral->diag_stats.spectral_vhtseg2id_mismatch++;
  1356. }
  1357. break;
  1358. case SPECTRAL_REPORT_RX_SECONDARY80:
  1359. /* We don't care about detector id in this state. */
  1360. reset_160mhz_delivery_state_machine(spectral, smode);
  1361. break;
  1362. case SPECTRAL_REPORT_RX_PRIMARY80:
  1363. /* We don't care about detector id in this state */
  1364. spectral->state_160mhz_delivery[smode] =
  1365. SPECTRAL_REPORT_WAIT_SECONDARY80;
  1366. break;
  1367. default:
  1368. break;
  1369. }
  1370. return status;
  1371. }
  1372. #ifdef DIRECT_BUF_RX_ENABLE
  1373. /**
  1374. * target_if_get_detector_id_sscan_summary_report_gen3() - Get Spectral detector
  1375. * ID from Spectral summary report
  1376. * @data: Pointer to Spectral summary report
  1377. *
  1378. * Return: Detector ID
  1379. */
  1380. static uint8_t
  1381. target_if_get_detector_id_sscan_summary_report_gen3(uint8_t *data) {
  1382. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  1383. uint8_t detector_id;
  1384. qdf_assert_always(data);
  1385. psscan_summary_report =
  1386. (struct spectral_sscan_summary_report_gen3 *)data;
  1387. detector_id = get_bitfield(
  1388. psscan_summary_report->hdr_a,
  1389. SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_SIZE_GEN3,
  1390. SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_POS_GEN3);
  1391. return detector_id;
  1392. }
  1393. /**
  1394. * target_if_consume_sscan_summary_report_gen3() - Consume Spectral summary
  1395. * report
  1396. * @data: Pointer to Spectral summary report
  1397. * @fields: Pointer to structure to be populated with extracted fields
  1398. * @rparams: Pointer to structure with Spectral report params
  1399. *
  1400. * Consume Spectral summary report for gen3
  1401. *
  1402. * Return: void
  1403. */
  1404. static void
  1405. target_if_consume_sscan_summary_report_gen3(
  1406. uint8_t *data,
  1407. struct sscan_report_fields_gen3 *fields,
  1408. struct spectral_report_params *rparams) {
  1409. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  1410. qdf_assert_always(data);
  1411. qdf_assert_always(fields);
  1412. qdf_assert_always(rparams);
  1413. psscan_summary_report =
  1414. (struct spectral_sscan_summary_report_gen3 *)data;
  1415. fields->sscan_agc_total_gain = get_bitfield(
  1416. psscan_summary_report->hdr_a,
  1417. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_SIZE_GEN3,
  1418. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_POS_GEN3);
  1419. fields->inband_pwr_db = get_bitfield(
  1420. psscan_summary_report->hdr_a,
  1421. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_SIZE_GEN3,
  1422. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_POS_GEN3);
  1423. fields->sscan_pri80 = get_bitfield(
  1424. psscan_summary_report->hdr_a,
  1425. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_SIZE_GEN3,
  1426. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_POS_GEN3);
  1427. switch (rparams->version) {
  1428. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1429. fields->sscan_gainchange = get_bitfield(
  1430. psscan_summary_report->hdr_b,
  1431. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_SIZE_GEN3_V1,
  1432. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_POS_GEN3_V1);
  1433. break;
  1434. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1435. fields->sscan_gainchange = get_bitfield(
  1436. psscan_summary_report->hdr_c,
  1437. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_SIZE_GEN3_V2,
  1438. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_POS_GEN3_V2);
  1439. break;
  1440. default:
  1441. qdf_assert_always(0);
  1442. }
  1443. }
  1444. /**
  1445. * target_if_verify_sig_and_tag_gen3() - Verify tag and signature
  1446. * of spectral report
  1447. * @spectral: Pointer to spectral object
  1448. * @data: Pointer to spectral summary report
  1449. * @exp_tag: iexpected tag value
  1450. *
  1451. * Process fft report for gen3
  1452. *
  1453. * Return: SUCCESS/FAILURE
  1454. */
  1455. static int
  1456. target_if_verify_sig_and_tag_gen3(struct target_if_spectral *spectral,
  1457. uint8_t *data, uint8_t exp_tag)
  1458. {
  1459. uint8_t tag = 0;
  1460. uint8_t signature = 0;
  1461. uint32_t lts;
  1462. lts = *((uint32_t *)(data + SPECTRAL_PHYERR_HDR_LTS_POS));
  1463. /* Peek into the data to figure out whether
  1464. * 1) Signature matches the expected value
  1465. * 2) What is inside the package (TAG ID is used for finding this)
  1466. */
  1467. tag = get_bitfield(lts,
  1468. SPECTRAL_REPORT_LTS_TAG_SIZE_GEN3,
  1469. SPECTRAL_REPORT_LTS_TAG_POS_GEN3);
  1470. signature = get_bitfield(lts,
  1471. SPECTRAL_REPORT_LTS_SIGNATURE_SIZE_GEN3,
  1472. SPECTRAL_REPORT_LTS_SIGNATURE_POS_GEN3);
  1473. if (signature != SPECTRAL_PHYERR_SIGNATURE_GEN3) {
  1474. spectral->diag_stats.spectral_mismatch++;
  1475. return -EINVAL;
  1476. }
  1477. if (tag != exp_tag) {
  1478. spectral->diag_stats.spectral_mismatch++;
  1479. return -EINVAL;
  1480. }
  1481. return 0;
  1482. }
  1483. static uint8_t
  1484. target_if_spectral_get_lowest_chn_idx(uint8_t chainmask)
  1485. {
  1486. uint8_t idx;
  1487. for (idx = 0; idx < DBR_MAX_CHAINS; idx++) {
  1488. if (chainmask & 0x1)
  1489. break;
  1490. chainmask >>= 1;
  1491. }
  1492. return idx;
  1493. }
  1494. #ifdef DIRECT_BUF_RX_DEBUG
  1495. static void target_if_spectral_check_buffer_poisoning(
  1496. struct target_if_spectral *spectral,
  1497. struct spectral_report *report,
  1498. int num_fft_bins, enum spectral_scan_mode smode)
  1499. {
  1500. uint32_t *data;
  1501. size_t len;
  1502. size_t words_to_check =
  1503. sizeof(struct spectral_sscan_summary_report_gen3) >> 2;
  1504. bool poisoned_words_found = false;
  1505. if (!spectral) {
  1506. spectral_err_rl("Spectral LMAC object is null");
  1507. return;
  1508. }
  1509. if (!spectral->dbr_buff_debug)
  1510. return;
  1511. if (!report) {
  1512. spectral_err_rl("Spectral report is null");
  1513. return;
  1514. }
  1515. /* Add search FFT report */
  1516. if (spectral->params[smode].ss_rpt_mode > 0)
  1517. words_to_check +=
  1518. sizeof(struct spectral_phyerr_fft_report_gen3) >> 2;
  1519. /* Now add the number of FFT bins */
  1520. if (spectral->params[smode].ss_rpt_mode > 1) {
  1521. /* Caller should take care to pass correct number of FFT bins */
  1522. if (spectral->len_adj_swar.fftbin_size_war ==
  1523. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE)
  1524. words_to_check += num_fft_bins;
  1525. else if (spectral->len_adj_swar.fftbin_size_war ==
  1526. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE)
  1527. words_to_check += (num_fft_bins >> 1);
  1528. }
  1529. data = (uint32_t *)report->data;
  1530. for (len = 0; len < words_to_check; ++len) {
  1531. if (*data == MEM_POISON_SIGNATURE) {
  1532. spectral_err("Pattern(%x) found in Spectral search FFT report at position %zu in the buffer %pK",
  1533. MEM_POISON_SIGNATURE,
  1534. (len << 2), report->data);
  1535. poisoned_words_found = true;
  1536. break;
  1537. }
  1538. ++data;
  1539. }
  1540. /* Crash the FW even if one word is poisoned */
  1541. if (poisoned_words_found) {
  1542. spectral_err("Pattern(%x) found in Spectral report, Hex dump of the sfft follows",
  1543. MEM_POISON_SIGNATURE);
  1544. target_if_spectral_hexdump((unsigned char *)report->data,
  1545. words_to_check << 2);
  1546. spectral_err("Asserting the FW");
  1547. target_if_spectral_fw_hang(spectral);
  1548. }
  1549. }
  1550. static void target_if_spectral_verify_ts(struct target_if_spectral *spectral,
  1551. uint8_t *buf, uint32_t current_ts)
  1552. {
  1553. if (!spectral) {
  1554. spectral_err_rl("Spectral LMAC object is null");
  1555. return;
  1556. }
  1557. if (!spectral->dbr_buff_debug)
  1558. return;
  1559. if (spectral->prev_tstamp) {
  1560. if (current_ts == spectral->prev_tstamp) {
  1561. spectral_err("Spectral timestamp(%u) in the current buffer(%pK) is equal to the previous timestamp, same report DMAed twice? Asserting the FW",
  1562. current_ts, buf);
  1563. target_if_spectral_fw_hang(spectral);
  1564. }
  1565. }
  1566. spectral->prev_tstamp = current_ts;
  1567. }
  1568. #else
  1569. static void target_if_spectral_check_buffer_poisoning(
  1570. struct target_if_spectral *spectral,
  1571. struct spectral_report *report,
  1572. int num_fft_bins, enum spectral_scan_mode smode)
  1573. {
  1574. }
  1575. static void target_if_spectral_verify_ts(struct target_if_spectral *spectral,
  1576. uint8_t *buf, uint32_t current_ts)
  1577. {
  1578. }
  1579. #endif
  1580. /**
  1581. * target_if_spectral_get_adjusted_timestamp() - Adjust Spectral time
  1582. * stamp to account for reset in time stamp due to target reset
  1583. * @twar: Spectral time stamp WAR related information
  1584. * @raw_timestamp: Spectral time stamp reported by target
  1585. * @reset_delay: Reset delay at target
  1586. * @smode: Spectral scan mode
  1587. *
  1588. * Correct time stamp to account for reset in time stamp due to target reset
  1589. *
  1590. * Return: Adjusted time stamp
  1591. */
  1592. static uint32_t
  1593. target_if_spectral_get_adjusted_timestamp(struct spectral_timestamp_war *twar,
  1594. uint32_t raw_timestamp,
  1595. uint32_t reset_delay,
  1596. enum spectral_scan_mode smode) {
  1597. qdf_assert_always(smode < SPECTRAL_SCAN_MODE_MAX);
  1598. if (reset_delay) {
  1599. enum spectral_scan_mode m =
  1600. SPECTRAL_SCAN_MODE_NORMAL;
  1601. /* Adjust the offset for all the Spectral modes.
  1602. * Target will be sending the non zero reset delay for
  1603. * the first Spectral report after reset. This delay is
  1604. * common for all the Spectral modes.
  1605. */
  1606. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  1607. twar->timestamp_war_offset[m] += (reset_delay +
  1608. twar->last_fft_timestamp[m]);
  1609. twar->target_reset_count++;
  1610. }
  1611. twar->last_fft_timestamp[smode] = raw_timestamp;
  1612. return raw_timestamp + twar->timestamp_war_offset[smode];
  1613. }
  1614. #ifdef BIG_ENDIAN_HOST
  1615. QDF_STATUS target_if_byte_swap_spectral_headers_gen3(
  1616. struct target_if_spectral *spectral,
  1617. void *data)
  1618. {
  1619. int i;
  1620. uint32_t *ptr32;
  1621. size_t words32;
  1622. qdf_assert_always(data);
  1623. qdf_assert_always(spectral);
  1624. ptr32 = (uint32_t *)data;
  1625. /* Summary Report */
  1626. words32 = sizeof(struct spectral_sscan_summary_report_gen3) >> 2;
  1627. for (i = 0; i < words32; ++i) {
  1628. *ptr32 = qdf_le32_to_cpu(*ptr32);
  1629. ++ptr32;
  1630. }
  1631. /* No need to swap the padding bytes */
  1632. ptr32 += (spectral->rparams.ssumaary_padding_bytes >> 2);
  1633. /* Search FFT Report */
  1634. words32 = sizeof(struct spectral_phyerr_fft_report_gen3) >> 2;
  1635. for (i = 0; i < words32; ++i) {
  1636. *ptr32 = qdf_le32_to_cpu(*ptr32);
  1637. ++ptr32;
  1638. }
  1639. return QDF_STATUS_SUCCESS;
  1640. }
  1641. QDF_STATUS target_if_byte_swap_spectral_fft_bins_gen3(
  1642. struct spectral_fft_bin_len_adj_swar *swar,
  1643. void *bin_pwr_data, size_t num_fftbins)
  1644. {
  1645. int i;
  1646. uint16_t *binptr_16;
  1647. uint32_t *binptr_32;
  1648. qdf_assert_always(bin_pwr_data);
  1649. qdf_assert_always(swar);
  1650. if (swar->fftbin_size_war ==
  1651. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
  1652. binptr_32 = (uint32_t *)bin_pwr_data;
  1653. for (i = 0; i < num_fftbins; i++) {
  1654. /* Get the useful first 2 bytes of the DWORD */
  1655. binptr_16 = ((uint16_t *)binptr_32);
  1656. /* Byteswap and copy it back */
  1657. *binptr_16 = qdf_le16_to_cpu(*binptr_16);
  1658. ++binptr_32; /* Go to next DWORD */
  1659. }
  1660. } else if (swar->fftbin_size_war ==
  1661. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  1662. binptr_16 = (uint16_t *)bin_pwr_data;
  1663. for (i = 0; i < num_fftbins; i++) {
  1664. /* Byteswap the FFT bin and copy it back */
  1665. *binptr_16 = qdf_le16_to_cpu(*binptr_16);
  1666. ++binptr_16;
  1667. }
  1668. }
  1669. return QDF_STATUS_SUCCESS;
  1670. }
  1671. #endif /* BIG_ENDIAN_HOST */
  1672. int
  1673. target_if_consume_spectral_report_gen3(
  1674. struct target_if_spectral *spectral,
  1675. struct spectral_report *report)
  1676. {
  1677. /*
  1678. * XXX : The classifier do not use all the members of the SAMP
  1679. * message data format.
  1680. * The classifier only depends upon the following parameters
  1681. *
  1682. * 1. Frequency (freq, msg->freq)
  1683. * 2. Spectral RSSI (spectral_rssi,
  1684. * msg->samp_data.spectral_rssi)
  1685. * 3. Bin Power Count (bin_pwr_count,
  1686. * msg->samp_data.bin_pwr_count)
  1687. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  1688. * 5. Spectral Timestamp (spectral_tstamp,
  1689. * msg->samp_data.spectral_tstamp)
  1690. * 6. MAC Address (macaddr, msg->macaddr)
  1691. *
  1692. * This function prepares the params structure and populates it
  1693. * with
  1694. * relevant values, this is in turn passed to
  1695. * spectral_create_samp_msg()
  1696. * to prepare fully formatted Spectral SAMP message
  1697. *
  1698. * XXX : Need to verify
  1699. * 1. Order of FFT bin values
  1700. *
  1701. */
  1702. struct target_if_samp_msg_params params = {0};
  1703. struct spectral_search_fft_info_gen3 search_fft_info;
  1704. struct spectral_search_fft_info_gen3 *p_sfft = &search_fft_info;
  1705. int8_t chn_idx_lowest_enabled = 0;
  1706. int fft_hdr_length = 0;
  1707. int report_len = 0;
  1708. size_t fft_bin_count;
  1709. size_t fft_bin_size;
  1710. struct target_if_spectral_ops *p_sops =
  1711. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1712. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  1713. int8_t rssi;
  1714. uint8_t *data = report->data;
  1715. struct wlan_objmgr_vdev *vdev;
  1716. uint8_t vdev_rxchainmask;
  1717. struct sscan_report_fields_gen3 sscan_report_fields = {0};
  1718. enum spectral_detector_id detector_id;
  1719. QDF_STATUS ret;
  1720. enum spectral_scan_mode spectral_mode = SPECTRAL_SCAN_MODE_INVALID;
  1721. uint8_t *temp;
  1722. bool finite_scan = false;
  1723. /* Apply byte-swap on the headers */
  1724. if (p_sops->byte_swap_headers) {
  1725. ret = p_sops->byte_swap_headers(spectral, data);
  1726. if (QDF_IS_STATUS_ERROR(ret)) {
  1727. spectral_err_rl("Byte-swap on Spectral headers failed");
  1728. goto fail;
  1729. }
  1730. }
  1731. /* Process Spectral scan summary report */
  1732. if (target_if_verify_sig_and_tag_gen3(
  1733. spectral, data,
  1734. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3) != 0) {
  1735. spectral_err_rl("Wrong tag/sig in sscan summary");
  1736. goto fail;
  1737. }
  1738. detector_id = target_if_get_detector_id_sscan_summary_report_gen3(data);
  1739. if (detector_id >= spectral->rparams.num_spectral_detectors) {
  1740. spectral->diag_stats.spectral_invalid_detector_id++;
  1741. spectral_err("Invalid detector id %u, expected is 0/1/2",
  1742. detector_id);
  1743. goto fail;
  1744. }
  1745. spectral_mode = target_if_get_spectral_mode(detector_id,
  1746. &spectral->rparams);
  1747. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  1748. spectral_err_rl("No valid Spectral mode for detector id %u",
  1749. detector_id);
  1750. goto fail;
  1751. }
  1752. /* Drop the sample if Spectral is not active for the current mode */
  1753. if (!p_sops->is_spectral_active(spectral, spectral_mode))
  1754. return -EINVAL;
  1755. ret = target_if_spectral_is_finite_scan(spectral, spectral_mode,
  1756. &finite_scan);
  1757. if (QDF_IS_STATUS_ERROR(ret)) {
  1758. spectral_err_rl("Failed to check scan is finite");
  1759. goto fail;
  1760. }
  1761. if (finite_scan) {
  1762. ret = target_if_spectral_finite_scan_update(spectral,
  1763. spectral_mode);
  1764. if (QDF_IS_STATUS_ERROR(ret)) {
  1765. spectral_err_rl("Failed to update scan count");
  1766. goto fail;
  1767. }
  1768. }
  1769. target_if_consume_sscan_summary_report_gen3(data, &sscan_report_fields,
  1770. &spectral->rparams);
  1771. /* Advance buf pointer to the search fft report */
  1772. data += sizeof(struct spectral_sscan_summary_report_gen3);
  1773. data += spectral->rparams.ssumaary_padding_bytes;
  1774. params.vhtop_ch_freq_seg1 = report->cfreq1;
  1775. params.vhtop_ch_freq_seg2 = report->cfreq2;
  1776. if (is_primaryseg_expected(spectral, spectral_mode)) {
  1777. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  1778. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  1779. params.agc_total_gain =
  1780. sscan_report_fields.sscan_agc_total_gain;
  1781. params.gainchange = sscan_report_fields.sscan_gainchange;
  1782. params.pri80ind = sscan_report_fields.sscan_pri80;
  1783. /* Process Spectral search FFT report */
  1784. if (target_if_verify_sig_and_tag_gen3(
  1785. spectral, data,
  1786. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  1787. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  1788. detector_id);
  1789. goto fail;
  1790. }
  1791. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  1792. fft_hdr_length = get_bitfield(
  1793. p_fft_report->fft_hdr_lts,
  1794. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  1795. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  1796. if (fft_hdr_length < 16) {
  1797. spectral_err("Wrong TLV length %u, detector id = %d",
  1798. fft_hdr_length, detector_id);
  1799. goto fail;
  1800. }
  1801. report_len = (fft_hdr_length + 8);
  1802. target_if_process_sfft_report_gen3(p_fft_report, p_sfft);
  1803. /* It is expected to have same detector id for
  1804. * summary and fft report
  1805. */
  1806. if (detector_id != p_sfft->fft_detector_id) {
  1807. spectral_err_rl
  1808. ("Different detid in ssummary(%u) and sfft(%u)",
  1809. detector_id, p_sfft->fft_detector_id);
  1810. goto fail;
  1811. }
  1812. if (detector_id > spectral->rparams.num_spectral_detectors) {
  1813. spectral->diag_stats.spectral_invalid_detector_id++;
  1814. spectral_err("Invalid detector id %u, expected is 0/2",
  1815. detector_id);
  1816. goto fail;
  1817. }
  1818. params.smode = spectral_mode;
  1819. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  1820. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  1821. spectral->params[spectral_mode].ss_rpt_mode,
  1822. &spectral->len_adj_swar, &fft_bin_size);
  1823. params.last_raw_timestamp = spectral->timestamp_war.
  1824. last_fft_timestamp[spectral_mode];
  1825. params.reset_delay = report->reset_delay;
  1826. params.raw_timestamp = p_sfft->timestamp;
  1827. params.tstamp = target_if_spectral_get_adjusted_timestamp(
  1828. &spectral->timestamp_war,
  1829. p_sfft->timestamp, report->reset_delay,
  1830. spectral_mode);
  1831. params.timestamp_war_offset = spectral->timestamp_war.
  1832. timestamp_war_offset[spectral_mode];
  1833. params.target_reset_count = spectral->timestamp_war.
  1834. target_reset_count;
  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. params.rssi = rssi;
  1846. vdev = target_if_spectral_get_vdev(spectral, spectral_mode);
  1847. if (!vdev) {
  1848. spectral_info("First vdev is NULL");
  1849. reset_160mhz_delivery_state_machine(
  1850. spectral, spectral_mode);
  1851. return -EPERM;
  1852. }
  1853. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  1854. QDF_ASSERT(vdev_rxchainmask != 0);
  1855. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  1856. chn_idx_lowest_enabled =
  1857. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  1858. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  1859. spectral_err("Invalid chain index, detector id = %u",
  1860. detector_id);
  1861. goto fail;
  1862. }
  1863. params.max_mag = p_sfft->fft_peak_mag;
  1864. params.freq = p_sops->get_current_channel(spectral,
  1865. spectral_mode);
  1866. params.agile_freq1 = spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  1867. ss_frequency.cfreq1;
  1868. params.agile_freq2 = spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  1869. ss_frequency.cfreq2;
  1870. params.noise_floor =
  1871. report->noisefloor[chn_idx_lowest_enabled];
  1872. temp = (uint8_t *)p_fft_report + SPECTRAL_FFT_BINS_POS;
  1873. if (is_ch_width_160_or_80p80(spectral->ch_width
  1874. [spectral_mode]) && !spectral->rparams.
  1875. fragmentation_160[spectral_mode]) {
  1876. struct wlan_objmgr_psoc *psoc;
  1877. struct spectral_fft_bin_markers_160_165mhz *marker;
  1878. qdf_assert_always(spectral->pdev_obj);
  1879. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  1880. qdf_assert_always(psoc);
  1881. params.agc_total_gain_sec80 =
  1882. sscan_report_fields.sscan_agc_total_gain;
  1883. params.gainchange_sec80 =
  1884. sscan_report_fields.sscan_gainchange;
  1885. params.raw_timestamp_sec80 = p_sfft->timestamp;
  1886. params.rssi_sec80 = rssi;
  1887. params.noise_floor_sec80 =
  1888. report->noisefloor[chn_idx_lowest_enabled];
  1889. params.max_mag_sec80 = p_sfft->fft_peak_mag;
  1890. params.datalen = fft_hdr_length * 2;
  1891. params.datalen_sec80 = fft_hdr_length * 2;
  1892. marker = &spectral->rparams.marker[spectral_mode];
  1893. if (!marker->is_valid) {
  1894. /* update stats */
  1895. goto fail_no_print;
  1896. }
  1897. params.bin_pwr_data = temp +
  1898. marker->start_pri80 * fft_bin_size;
  1899. params.pwr_count = marker->num_pri80;
  1900. params.bin_pwr_data_sec80 = temp +
  1901. marker->start_sec80 * fft_bin_size;
  1902. params.pwr_count_sec80 = marker->num_sec80;
  1903. if (spectral->ch_width[spectral_mode] ==
  1904. CH_WIDTH_80P80MHZ && wlan_psoc_nif_fw_ext_cap_get(
  1905. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  1906. params.bin_pwr_data_5mhz = temp +
  1907. marker->start_5mhz * fft_bin_size;
  1908. params.pwr_count_5mhz = marker->num_5mhz;
  1909. }
  1910. } else {
  1911. params.bin_pwr_data = temp;
  1912. params.pwr_count = fft_bin_count;
  1913. params.datalen = (fft_hdr_length * 4);
  1914. }
  1915. /* Apply byte-swap on the FFT bins.
  1916. * NOTE: Until this point, bytes of the FFT bins could be in
  1917. * reverse order on a big-endian machine. If the consumers
  1918. * of FFT bins expects bytes in the correct order,
  1919. * they should use them only after this point.
  1920. */
  1921. if (p_sops->byte_swap_fft_bins) {
  1922. ret = p_sops->byte_swap_fft_bins(
  1923. &spectral->len_adj_swar,
  1924. temp, fft_bin_count);
  1925. if (QDF_IS_STATUS_ERROR(ret)) {
  1926. spectral_err_rl("Byte-swap on the FFT bins failed");
  1927. goto fail;
  1928. }
  1929. }
  1930. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  1931. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  1932. p_fft_report, p_sfft);
  1933. target_if_spectral_verify_ts(spectral, report->data,
  1934. params.tstamp);
  1935. } else if (is_secondaryseg_expected(spectral, spectral_mode)) {
  1936. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  1937. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  1938. params.agc_total_gain_sec80 =
  1939. sscan_report_fields.sscan_agc_total_gain;
  1940. params.gainchange_sec80 = sscan_report_fields.sscan_gainchange;
  1941. params.pri80ind_sec80 = sscan_report_fields.sscan_pri80;
  1942. /* Process Spectral search FFT report */
  1943. if (target_if_verify_sig_and_tag_gen3(
  1944. spectral, data,
  1945. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  1946. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  1947. detector_id);
  1948. goto fail;
  1949. }
  1950. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  1951. fft_hdr_length = get_bitfield(
  1952. p_fft_report->fft_hdr_lts,
  1953. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  1954. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  1955. if (fft_hdr_length < 16) {
  1956. spectral_err("Wrong TLV length %u, detector id = %u",
  1957. fft_hdr_length, detector_id);
  1958. goto fail;
  1959. }
  1960. report_len = (fft_hdr_length + 8);
  1961. target_if_process_sfft_report_gen3(p_fft_report, p_sfft);
  1962. /* It is expected to have same detector id for
  1963. * summary and fft report
  1964. */
  1965. if (detector_id != p_sfft->fft_detector_id) {
  1966. spectral_err_rl
  1967. ("Different detid in ssummary(%u) and sfft(%u)",
  1968. detector_id, p_sfft->fft_detector_id);
  1969. goto fail;
  1970. }
  1971. if (detector_id > spectral->rparams.num_spectral_detectors) {
  1972. spectral->diag_stats.spectral_invalid_detector_id++;
  1973. spectral_err("Invalid detector id %u, expected is 1",
  1974. detector_id);
  1975. goto fail;
  1976. }
  1977. params.smode = spectral_mode;
  1978. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  1979. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  1980. spectral->params[spectral_mode].ss_rpt_mode,
  1981. &spectral->len_adj_swar, &fft_bin_size);
  1982. params.raw_timestamp_sec80 = p_sfft->timestamp;
  1983. /* Take care of state transitions for 160 MHz and 80p80 */
  1984. if (is_ch_width_160_or_80p80(spectral->ch_width
  1985. [spectral_mode]) && spectral->rparams.
  1986. fragmentation_160[spectral_mode]) {
  1987. ret = target_if_160mhz_delivery_state_change(
  1988. spectral, spectral_mode,
  1989. detector_id);
  1990. if (ret != QDF_STATUS_SUCCESS)
  1991. goto fail;
  1992. }
  1993. params.rssi_sec80 = rssi;
  1994. vdev = target_if_spectral_get_vdev(spectral, spectral_mode);
  1995. if (!vdev) {
  1996. spectral_info("First vdev is NULL");
  1997. reset_160mhz_delivery_state_machine
  1998. (spectral, spectral_mode);
  1999. return -EPERM;
  2000. }
  2001. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  2002. QDF_ASSERT(vdev_rxchainmask != 0);
  2003. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2004. chn_idx_lowest_enabled =
  2005. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  2006. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  2007. spectral_err("Invalid chain index");
  2008. goto fail;
  2009. }
  2010. /* Need to change this as per FW team's inputs */
  2011. params.noise_floor_sec80 =
  2012. report->noisefloor[chn_idx_lowest_enabled];
  2013. params.max_mag_sec80 = p_sfft->fft_peak_mag;
  2014. /* params.max_index_sec80 = p_sfft->peak_inx; */
  2015. /* XXX Does this definition of datalen *still hold? */
  2016. params.datalen_sec80 = fft_hdr_length * 4;
  2017. params.pwr_count_sec80 = fft_bin_count;
  2018. params.bin_pwr_data_sec80 =
  2019. (uint8_t *)((uint8_t *)p_fft_report +
  2020. SPECTRAL_FFT_BINS_POS);
  2021. /* Apply byte-swap on the FFT bins.
  2022. * NOTE: Until this point, bytes of the FFT bins could be in
  2023. * reverse order on a big-endian machine. If the consumers
  2024. * of FFT bins expects bytes in the correct order,
  2025. * they should use them only after this point.
  2026. */
  2027. if (p_sops->byte_swap_fft_bins) {
  2028. ret = p_sops->byte_swap_fft_bins(
  2029. &spectral->len_adj_swar,
  2030. params.bin_pwr_data_sec80,
  2031. fft_bin_count);
  2032. if (QDF_IS_STATUS_ERROR(ret)) {
  2033. spectral_err_rl("Byte-swap on the FFT bins failed");
  2034. goto fail;
  2035. }
  2036. }
  2037. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  2038. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  2039. p_fft_report, p_sfft);
  2040. } else {
  2041. spectral_err("Spectral state machine in undefined state");
  2042. goto fail;
  2043. }
  2044. target_if_spectral_check_buffer_poisoning(spectral, report,
  2045. fft_bin_count, spectral_mode);
  2046. qdf_mem_copy(&params.classifier_params,
  2047. &spectral->classifier_params,
  2048. sizeof(struct spectral_classifier_params));
  2049. target_if_spectral_log_SAMP_param(&params);
  2050. target_if_spectral_create_samp_msg(spectral, &params);
  2051. return 0;
  2052. fail:
  2053. spectral_err_rl("Error while processing Spectral report");
  2054. fail_no_print:
  2055. if (spectral_mode != SPECTRAL_SCAN_MODE_INVALID)
  2056. reset_160mhz_delivery_state_machine(spectral, spectral_mode);
  2057. return -EPERM;
  2058. }
  2059. int target_if_spectral_process_report_gen3(
  2060. struct wlan_objmgr_pdev *pdev,
  2061. void *buf)
  2062. {
  2063. int ret = 0;
  2064. struct direct_buf_rx_data *payload = buf;
  2065. struct target_if_spectral *spectral;
  2066. struct spectral_report report;
  2067. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2068. if (!spectral) {
  2069. spectral_err("Spectral target object is null");
  2070. return -EINVAL;
  2071. }
  2072. report.data = payload->vaddr;
  2073. if (payload->meta_data_valid) {
  2074. qdf_mem_copy(report.noisefloor, payload->meta_data.noisefloor,
  2075. qdf_min(sizeof(report.noisefloor),
  2076. sizeof(payload->meta_data.noisefloor)));
  2077. report.reset_delay = payload->meta_data.reset_delay;
  2078. report.cfreq1 = payload->meta_data.cfreq1;
  2079. report.cfreq2 = payload->meta_data.cfreq2;
  2080. report.ch_width = payload->meta_data.ch_width;
  2081. }
  2082. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4)) {
  2083. spectral_debug("Printing the spectral phyerr buffer for debug");
  2084. spectral_debug("Datalength of buffer = 0x%zx(%zd) bufptr = 0x%pK",
  2085. payload->dbr_len,
  2086. payload->dbr_len,
  2087. payload->vaddr);
  2088. target_if_spectral_hexdump((unsigned char *)payload->vaddr,
  2089. 1024);
  2090. }
  2091. ret = target_if_consume_spectral_report_gen3(spectral, &report);
  2092. if (spectral_debug_level & DEBUG_SPECTRAL4)
  2093. spectral_debug_level = DEBUG_SPECTRAL;
  2094. return ret;
  2095. }
  2096. #else
  2097. int target_if_spectral_process_report_gen3(
  2098. struct wlan_objmgr_pdev *pdev,
  2099. void *buf)
  2100. {
  2101. spectral_err("Direct dma support is not enabled");
  2102. return -EINVAL;
  2103. }
  2104. #endif
  2105. qdf_export_symbol(target_if_spectral_process_report_gen3);
  2106. /* END of spectral GEN III HW specific functions */
  2107. #endif /* WLAN_CONV_SPECTRAL_ENABLE */