target_if_spectral_phyerr.c 65 KB

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