target_if_spectral_phyerr.c 53 KB

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