target_if_spectral_phyerr.c 60 KB

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