target_if_spectral_phyerr.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646
  1. /*
  2. * Copyright (c) 2011,2017-2018 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. #ifdef CONFIG_WIN
  30. #include <osif_rawmode_sim.h>
  31. #endif /*CONFIG_WIN*/
  32. #include <reg_services_public_struct.h>
  33. #include <target_if_direct_buf_rx_api.h>
  34. extern int spectral_debug_level;
  35. #ifdef WLAN_CONV_SPECTRAL_ENABLE
  36. /**
  37. * target_if_print_buf() - Prints given buffer for given length
  38. * @pbuf: Pointer to buffer
  39. * @len: length
  40. *
  41. * Prints given buffer for given length
  42. *
  43. * Return: void
  44. */
  45. static void
  46. target_if_print_buf(uint8_t *pbuf, int len)
  47. {
  48. int i = 0;
  49. for (i = 0; i < len; i++) {
  50. spectral_debug("%02X ", pbuf[i]);
  51. if (i % 32 == 31)
  52. spectral_debug("\n");
  53. }
  54. }
  55. int
  56. target_if_spectral_dump_fft(uint8_t *pfft, int fftlen)
  57. {
  58. int i = 0;
  59. /*
  60. * TODO : Do not delete the following print
  61. * The scripts used to validate Spectral depend on this Print
  62. */
  63. spectral_debug("SPECTRAL : FFT Length is 0x%x (%d)", fftlen, fftlen);
  64. spectral_debug("fft_data # ");
  65. for (i = 0; i < fftlen; i++)
  66. spectral_debug("%d ", pfft[i]);
  67. spectral_debug("\n");
  68. return 0;
  69. }
  70. /**
  71. * target_if_spectral_send_tlv_to_host() - Send the TLV information to Host
  72. * @spectral: Pointer to target_if spectral object
  73. * @data: Pointer to the TLV
  74. * @datalen: data length
  75. *
  76. * Send the TLV information to Host
  77. *
  78. * Return: Success or failure
  79. */
  80. int
  81. target_if_spectral_send_tlv_to_host(struct target_if_spectral *spectral,
  82. uint8_t *data, uint32_t datalen)
  83. {
  84. int status = true;
  85. void *nl_data = spectral->nl_cb.get_nbuff(spectral->pdev_obj);
  86. if (nl_data) {
  87. memcpy(nl_data, data, datalen);
  88. if (spectral->send_phy_data(spectral->pdev_obj) == 0)
  89. spectral->spectral_sent_msg++;
  90. } else {
  91. status = false;
  92. }
  93. return status;
  94. }
  95. void
  96. target_if_dbg_print_samp_param(struct target_if_samp_msg_params *p)
  97. {
  98. spectral_debug("\nSAMP Packet : -------------------- START --------------------");
  99. spectral_debug("Freq = %d", p->freq);
  100. spectral_debug("RSSI = %d", p->rssi);
  101. spectral_debug("Bin Count = %d", p->pwr_count);
  102. spectral_debug("Timestamp = %d", p->tstamp);
  103. spectral_debug("SAMP Packet : -------------------- END -----------------------");
  104. }
  105. void
  106. target_if_dbg_print_samp_msg(struct spectral_samp_msg *ss_msg)
  107. {
  108. int i = 0;
  109. struct spectral_samp_data *p = &ss_msg->samp_data;
  110. struct spectral_classifier_params *pc = &p->classifier_params;
  111. struct interf_src_rsp *pi = &p->interf_list;
  112. spectral_dbg_line();
  113. spectral_debug("Spectral Message");
  114. spectral_dbg_line();
  115. spectral_debug("Signature : 0x%x", ss_msg->signature);
  116. spectral_debug("Freq : %d", ss_msg->freq);
  117. spectral_debug("Freq load : %d", ss_msg->freq_loading);
  118. spectral_debug("Intfnc type : %d", ss_msg->int_type);
  119. spectral_dbg_line();
  120. spectral_debug("Spectral Data info");
  121. spectral_dbg_line();
  122. spectral_debug("data length : %d", p->spectral_data_len);
  123. spectral_debug("rssi : %d", p->spectral_rssi);
  124. spectral_debug("combined rssi : %d", p->spectral_combined_rssi);
  125. spectral_debug("upper rssi : %d", p->spectral_upper_rssi);
  126. spectral_debug("lower rssi : %d", p->spectral_lower_rssi);
  127. spectral_debug("bw info : %d", p->spectral_bwinfo);
  128. spectral_debug("timestamp : %d", p->spectral_tstamp);
  129. spectral_debug("max index : %d", p->spectral_max_index);
  130. spectral_debug("max exp : %d", p->spectral_max_exp);
  131. spectral_debug("max mag : %d", p->spectral_max_mag);
  132. spectral_debug("last timstamp : %d", p->spectral_last_tstamp);
  133. spectral_debug("upper max idx : %d", p->spectral_upper_max_index);
  134. spectral_debug("lower max idx : %d", p->spectral_lower_max_index);
  135. spectral_debug("bin power count : %d", p->bin_pwr_count);
  136. spectral_dbg_line();
  137. spectral_debug("Classifier info");
  138. spectral_dbg_line();
  139. spectral_debug("20/40 Mode : %d", pc->spectral_20_40_mode);
  140. spectral_debug("dc index : %d", pc->spectral_dc_index);
  141. spectral_debug("dc in MHz : %d", pc->spectral_dc_in_mhz);
  142. spectral_debug("upper channel : %d", pc->upper_chan_in_mhz);
  143. spectral_debug("lower channel : %d", pc->lower_chan_in_mhz);
  144. spectral_dbg_line();
  145. spectral_debug("Interference info");
  146. spectral_dbg_line();
  147. spectral_debug("inter count : %d", pi->count);
  148. for (i = 0; i < pi->count; i++) {
  149. spectral_debug("inter type : %d",
  150. pi->interf[i].interf_type);
  151. spectral_debug("min freq : %d",
  152. pi->interf[i].interf_min_freq);
  153. spectral_debug("max freq : %d",
  154. pi->interf[i].interf_max_freq);
  155. }
  156. }
  157. uint32_t
  158. target_if_get_offset_swar_sec80(uint32_t channel_width)
  159. {
  160. uint32_t offset = 0;
  161. switch (channel_width) {
  162. case CH_WIDTH_20MHZ:
  163. offset = OFFSET_CH_WIDTH_20;
  164. break;
  165. case CH_WIDTH_40MHZ:
  166. offset = OFFSET_CH_WIDTH_40;
  167. break;
  168. case CH_WIDTH_80MHZ:
  169. offset = OFFSET_CH_WIDTH_80;
  170. break;
  171. case CH_WIDTH_160MHZ:
  172. offset = OFFSET_CH_WIDTH_160;
  173. break;
  174. default:
  175. offset = OFFSET_CH_WIDTH_80;
  176. break;
  177. }
  178. return offset;
  179. }
  180. /**
  181. * target_if_dump_summary_report_gen2() - Dump Spectral Summary Report for gen2
  182. * @ptlv: Pointer to Spectral Phyerr TLV
  183. * @tlvlen: length
  184. * @is_160_format: Indicates whether information provided by HW is in altered
  185. * format for 802.11ac 160/80+80 MHz support (QCA9984 onwards)
  186. *
  187. * Dump Spectral Summary Report for gen2
  188. *
  189. * Return: Success/Failure
  190. */
  191. static int
  192. target_if_dump_summary_report_gen2(struct spectral_phyerr_tlv_gen2 *ptlv,
  193. int tlvlen, bool is_160_format)
  194. {
  195. /*
  196. * For simplicity, everything is defined as uint32_t (except one).
  197. * Proper code will later use the right sizes.
  198. */
  199. /*
  200. * For easy comparision between MDK team and OS team, the MDK script
  201. * variable names have been used
  202. */
  203. uint32_t agc_mb_gain;
  204. uint32_t sscan_gidx;
  205. uint32_t agc_total_gain;
  206. uint32_t recent_rfsat;
  207. uint32_t ob_flag;
  208. uint32_t nb_mask;
  209. uint32_t peak_mag;
  210. int16_t peak_inx;
  211. uint32_t ss_summary_A = 0;
  212. uint32_t ss_summary_B = 0;
  213. uint32_t ss_summary_C = 0;
  214. uint32_t ss_summary_D = 0;
  215. uint32_t ss_summary_E = 0;
  216. struct spectral_phyerr_hdr_gen2 *phdr =
  217. (struct spectral_phyerr_hdr_gen2 *)(
  218. (uint8_t *)ptlv +
  219. sizeof(struct spectral_phyerr_tlv_gen2));
  220. spectral_debug("SPECTRAL : SPECTRAL SUMMARY REPORT");
  221. if (is_160_format) {
  222. if (tlvlen != 20) {
  223. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  224. tlvlen);
  225. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  226. return -EPERM;
  227. }
  228. /* Doing copy as the contents may not be aligned */
  229. qdf_mem_copy(&ss_summary_A, (uint8_t *)phdr, sizeof(int));
  230. qdf_mem_copy(&ss_summary_B,
  231. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  232. sizeof(int));
  233. qdf_mem_copy(&ss_summary_C,
  234. (uint8_t *)((uint8_t *)phdr + 2 * sizeof(int)),
  235. sizeof(int));
  236. qdf_mem_copy(&ss_summary_D,
  237. (uint8_t *)((uint8_t *)phdr + 3 * sizeof(int)),
  238. sizeof(int));
  239. qdf_mem_copy(&ss_summary_E,
  240. (uint8_t *)((uint8_t *)phdr + 4 * sizeof(int)),
  241. sizeof(int));
  242. /*
  243. * The following is adapted from MDK scripts for
  244. * easier comparability
  245. */
  246. recent_rfsat = ((ss_summary_A >> 8) & 0x1);
  247. sscan_gidx = (ss_summary_A & 0xff);
  248. spectral_debug("sscan_gidx=%d, is_recent_rfsat=%d",
  249. sscan_gidx, recent_rfsat);
  250. /* First segment */
  251. agc_mb_gain = ((ss_summary_B >> 10) & 0x7f);
  252. agc_total_gain = (ss_summary_B & 0x3ff);
  253. nb_mask = ((ss_summary_C >> 22) & 0xff);
  254. ob_flag = ((ss_summary_B >> 17) & 0x1);
  255. peak_inx = (ss_summary_C & 0xfff);
  256. if (peak_inx > 2047)
  257. peak_inx = peak_inx - 4096;
  258. peak_mag = ((ss_summary_C >> 12) & 0x3ff);
  259. spectral_debug("agc_total_gain_segid0 = 0x%.2x, agc_mb_gain_segid0=%d",
  260. agc_total_gain, agc_mb_gain);
  261. spectral_debug("nb_mask_segid0 = 0x%.2x, ob_flag_segid0=%d, peak_index_segid0=%d, peak_mag_segid0=%d",
  262. nb_mask, ob_flag, peak_inx, peak_mag);
  263. /* Second segment */
  264. agc_mb_gain = ((ss_summary_D >> 10) & 0x7f);
  265. agc_total_gain = (ss_summary_D & 0x3ff);
  266. nb_mask = ((ss_summary_E >> 22) & 0xff);
  267. ob_flag = ((ss_summary_D >> 17) & 0x1);
  268. peak_inx = (ss_summary_E & 0xfff);
  269. if (peak_inx > 2047)
  270. peak_inx = peak_inx - 4096;
  271. peak_mag = ((ss_summary_E >> 12) & 0x3ff);
  272. spectral_debug("agc_total_gain_segid1 = 0x%.2x, agc_mb_gain_segid1=%d",
  273. agc_total_gain, agc_mb_gain);
  274. spectral_debug("nb_mask_segid1 = 0x%.2x, ob_flag_segid1=%d, peak_index_segid1=%d, peak_mag_segid1=%d",
  275. nb_mask, ob_flag, peak_inx, peak_mag);
  276. } else {
  277. if (tlvlen != 8) {
  278. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  279. tlvlen);
  280. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  281. return -EPERM;
  282. }
  283. /* Doing copy as the contents may not be aligned */
  284. qdf_mem_copy(&ss_summary_A, (uint8_t *)phdr, sizeof(int));
  285. qdf_mem_copy(&ss_summary_B,
  286. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  287. sizeof(int));
  288. nb_mask = ((ss_summary_B >> 22) & 0xff);
  289. ob_flag = ((ss_summary_B >> 30) & 0x1);
  290. peak_inx = (ss_summary_B & 0xfff);
  291. if (peak_inx > 2047)
  292. peak_inx = peak_inx - 4096;
  293. peak_mag = ((ss_summary_B >> 12) & 0x3ff);
  294. agc_mb_gain = ((ss_summary_A >> 24) & 0x7f);
  295. agc_total_gain = (ss_summary_A & 0x3ff);
  296. sscan_gidx = ((ss_summary_A >> 16) & 0xff);
  297. recent_rfsat = ((ss_summary_B >> 31) & 0x1);
  298. 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",
  299. nb_mask, ob_flag, peak_inx, peak_mag,
  300. agc_mb_gain, agc_total_gain, sscan_gidx,
  301. recent_rfsat);
  302. }
  303. return 0;
  304. }
  305. /**
  306. * target_if_process_sfft_report_gen2() - Process Search FFT Report
  307. * @ptlv: Pointer to Spectral Phyerr TLV
  308. * @tlvlen: length
  309. * @p_fft_info: Pointer to search fft info
  310. *
  311. * Dump Spectral Summary Report for gen2
  312. *
  313. * Return: Success/Failure
  314. */
  315. static int
  316. target_if_process_sfft_report_gen2(
  317. struct spectral_phyerr_tlv_gen2 *ptlv,
  318. int tlvlen,
  319. struct spectral_search_fft_info_gen2 *p_fft_info)
  320. {
  321. /*
  322. * For simplicity, everything is defined as uint32_t (except one).
  323. * Proper code will later use the right sizes.
  324. */
  325. /*
  326. * For easy comparision between MDK team and OS team, the MDK script
  327. * variable names have been used
  328. */
  329. uint32_t relpwr_db;
  330. uint32_t num_str_bins_ib;
  331. uint32_t base_pwr;
  332. uint32_t total_gain_info;
  333. uint32_t fft_chn_idx;
  334. int16_t peak_inx;
  335. uint32_t avgpwr_db;
  336. uint32_t peak_mag;
  337. uint32_t fft_summary_A = 0;
  338. uint32_t fft_summary_B = 0;
  339. uint8_t *tmp = (uint8_t *)ptlv;
  340. struct spectral_phyerr_hdr_gen2 *phdr =
  341. (struct spectral_phyerr_hdr_gen2 *)(
  342. tmp +
  343. sizeof(struct spectral_phyerr_tlv_gen2));
  344. /* Relook this */
  345. if (tlvlen < 8) {
  346. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  347. tlvlen);
  348. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  349. return -EPERM;
  350. }
  351. /* Doing copy as the contents may not be aligned */
  352. qdf_mem_copy(&fft_summary_A, (uint8_t *)phdr, sizeof(int));
  353. qdf_mem_copy(&fft_summary_B,
  354. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  355. sizeof(int));
  356. relpwr_db = ((fft_summary_B >> 26) & 0x3f);
  357. num_str_bins_ib = fft_summary_B & 0xff;
  358. base_pwr = ((fft_summary_A >> 14) & 0x1ff);
  359. total_gain_info = ((fft_summary_A >> 23) & 0x1ff);
  360. fft_chn_idx = ((fft_summary_A >> 12) & 0x3);
  361. peak_inx = fft_summary_A & 0xfff;
  362. if (peak_inx > 2047)
  363. peak_inx = peak_inx - 4096;
  364. avgpwr_db = ((fft_summary_B >> 18) & 0xff);
  365. peak_mag = ((fft_summary_B >> 8) & 0x3ff);
  366. /* Populate the Search FFT Info */
  367. if (p_fft_info) {
  368. p_fft_info->relpwr_db = relpwr_db;
  369. p_fft_info->num_str_bins_ib = num_str_bins_ib;
  370. p_fft_info->base_pwr = base_pwr;
  371. p_fft_info->total_gain_info = total_gain_info;
  372. p_fft_info->fft_chn_idx = fft_chn_idx;
  373. p_fft_info->peak_inx = peak_inx;
  374. p_fft_info->avgpwr_db = avgpwr_db;
  375. p_fft_info->peak_mag = peak_mag;
  376. }
  377. return 0;
  378. }
  379. /**
  380. * target_if_dump_adc_report_gen2() - Dump ADC Reports for gen2
  381. * @ptlv: Pointer to Spectral Phyerr TLV
  382. * @tlvlen: length
  383. *
  384. * Dump ADC Reports for gen2
  385. *
  386. * Return: Success/Failure
  387. */
  388. static int
  389. target_if_dump_adc_report_gen2(
  390. struct spectral_phyerr_tlv_gen2 *ptlv, int tlvlen)
  391. {
  392. int i;
  393. uint32_t *pdata;
  394. uint32_t data;
  395. /*
  396. * For simplicity, everything is defined as uint32_t (except one).
  397. * Proper code will later use the right sizes.
  398. */
  399. uint32_t samp_fmt;
  400. uint32_t chn_idx;
  401. uint32_t recent_rfsat;
  402. uint32_t agc_mb_gain;
  403. uint32_t agc_total_gain;
  404. uint32_t adc_summary = 0;
  405. uint8_t *ptmp = (uint8_t *)ptlv;
  406. spectral_debug("SPECTRAL : ADC REPORT");
  407. /* Relook this */
  408. if (tlvlen < 4) {
  409. spectral_err("Unexpected TLV length %d for ADC Report! Hexdump follows",
  410. tlvlen);
  411. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  412. return -EPERM;
  413. }
  414. qdf_mem_copy(&adc_summary, (uint8_t *)(ptlv + 4), sizeof(int));
  415. samp_fmt = ((adc_summary >> 28) & 0x1);
  416. chn_idx = ((adc_summary >> 24) & 0x3);
  417. recent_rfsat = ((adc_summary >> 23) & 0x1);
  418. agc_mb_gain = ((adc_summary >> 16) & 0x7f);
  419. agc_total_gain = adc_summary & 0x3ff;
  420. spectral_debug("samp_fmt= %u, chn_idx= %u, recent_rfsat= %u, agc_mb_gain=%u agc_total_gain=%u",
  421. samp_fmt, chn_idx, recent_rfsat, agc_mb_gain,
  422. agc_total_gain);
  423. for (i = 0; i < (tlvlen / 4); i++) {
  424. pdata = (uint32_t *)(ptmp + 4 + i * 4);
  425. data = *pdata;
  426. /* Interpreting capture format 1 */
  427. if (1) {
  428. uint8_t i1;
  429. uint8_t q1;
  430. uint8_t i2;
  431. uint8_t q2;
  432. int8_t si1;
  433. int8_t sq1;
  434. int8_t si2;
  435. int8_t sq2;
  436. i1 = data & 0xff;
  437. q1 = (data >> 8) & 0xff;
  438. i2 = (data >> 16) & 0xff;
  439. q2 = (data >> 24) & 0xff;
  440. if (i1 > 127)
  441. si1 = i1 - 256;
  442. else
  443. si1 = i1;
  444. if (q1 > 127)
  445. sq1 = q1 - 256;
  446. else
  447. sq1 = q1;
  448. if (i2 > 127)
  449. si2 = i2 - 256;
  450. else
  451. si2 = i2;
  452. if (q2 > 127)
  453. sq2 = q2 - 256;
  454. else
  455. sq2 = q2;
  456. spectral_debug("SPECTRAL ADC : Interpreting capture format 1");
  457. spectral_debug("adc_data_format_1 # %d %d %d",
  458. 2 * i, si1, sq1);
  459. spectral_debug("adc_data_format_1 # %d %d %d",
  460. 2 * i + 1, si2, sq2);
  461. }
  462. /* Interpreting capture format 0 */
  463. if (1) {
  464. uint16_t i1;
  465. uint16_t q1;
  466. int16_t si1;
  467. int16_t sq1;
  468. i1 = data & 0xffff;
  469. q1 = (data >> 16) & 0xffff;
  470. if (i1 > 32767)
  471. si1 = i1 - 65536;
  472. else
  473. si1 = i1;
  474. if (q1 > 32767)
  475. sq1 = q1 - 65536;
  476. else
  477. sq1 = q1;
  478. spectral_debug("SPECTRAL ADC : Interpreting capture format 0");
  479. spectral_debug("adc_data_format_2 # %d %d %d",
  480. i, si1, sq1);
  481. }
  482. }
  483. spectral_debug("\n");
  484. return 0;
  485. }
  486. /**
  487. * target_if_dump_sfft_report_gen2() - Process Search FFT Report for gen2
  488. * @ptlv: Pointer to Spectral Phyerr TLV
  489. * @tlvlen: length
  490. * @is_160_format: Indicates 160 format
  491. *
  492. * Process Search FFT Report for gen2
  493. *
  494. * Return: Success/Failure
  495. */
  496. static int
  497. target_if_dump_sfft_report_gen2(struct spectral_phyerr_tlv_gen2 *ptlv,
  498. int tlvlen, bool is_160_format)
  499. {
  500. int i;
  501. uint32_t fft_mag;
  502. /*
  503. * For simplicity, everything is defined as uint32_t (except one).
  504. * Proper code will later use the right sizes.
  505. */
  506. /*
  507. * For easy comparision between MDK team and OS team, the MDK script
  508. * variable names have been used
  509. */
  510. uint32_t relpwr_db;
  511. uint32_t num_str_bins_ib;
  512. uint32_t base_pwr;
  513. uint32_t total_gain_info;
  514. uint32_t fft_chn_idx;
  515. int16_t peak_inx;
  516. uint32_t avgpwr_db;
  517. uint32_t peak_mag;
  518. uint8_t segid;
  519. uint32_t fft_summary_A = 0;
  520. uint32_t fft_summary_B = 0;
  521. uint32_t fft_summary_C = 0;
  522. uint8_t *tmp = (uint8_t *)ptlv;
  523. struct spectral_phyerr_hdr_gen2 *phdr =
  524. (struct spectral_phyerr_hdr_gen2 *)(
  525. tmp +
  526. sizeof(struct spectral_phyerr_tlv_gen2));
  527. uint32_t segid_skiplen = 0;
  528. if (is_160_format)
  529. segid_skiplen = sizeof(SPECTRAL_SEGID_INFO);
  530. spectral_debug("SPECTRAL : SEARCH FFT REPORT");
  531. /* Relook this */
  532. if (tlvlen < (8 + segid_skiplen)) {
  533. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  534. tlvlen);
  535. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  536. return -EPERM;
  537. }
  538. /* Doing copy as the contents may not be aligned */
  539. qdf_mem_copy(&fft_summary_A, (uint8_t *)phdr, sizeof(int));
  540. qdf_mem_copy(&fft_summary_B,
  541. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  542. sizeof(int));
  543. if (is_160_format)
  544. qdf_mem_copy(&fft_summary_C,
  545. (uint8_t *)((uint8_t *)phdr + 2 * sizeof(int)),
  546. sizeof(int));
  547. relpwr_db = ((fft_summary_B >> 26) & 0x3f);
  548. num_str_bins_ib = fft_summary_B & 0xff;
  549. base_pwr = ((fft_summary_A >> 14) & 0x1ff);
  550. total_gain_info = ((fft_summary_A >> 23) & 0x1ff);
  551. fft_chn_idx = ((fft_summary_A >> 12) & 0x3);
  552. peak_inx = fft_summary_A & 0xfff;
  553. if (peak_inx > 2047)
  554. peak_inx = peak_inx - 4096;
  555. avgpwr_db = ((fft_summary_B >> 18) & 0xff);
  556. peak_mag = ((fft_summary_B >> 8) & 0x3ff);
  557. spectral_debug("Header A = 0x%x Header B = 0x%x",
  558. phdr->hdr_a, phdr->hdr_b);
  559. 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",
  560. base_pwr, total_gain_info, relpwr_db, num_str_bins_ib,
  561. fft_chn_idx, peak_inx, avgpwr_db, peak_mag);
  562. if (is_160_format) {
  563. segid = fft_summary_C & 0x1;
  564. spectral_debug("Segment ID: %hhu", segid);
  565. }
  566. spectral_debug("FFT bins:");
  567. for (i = 0; i < (tlvlen - 8 - segid_skiplen); i++) {
  568. fft_mag = ((uint8_t *)ptlv)[12 + segid_skiplen + i];
  569. spectral_debug("%d %d, ", i, fft_mag);
  570. }
  571. spectral_debug("\n");
  572. return 0;
  573. }
  574. #ifdef SPECTRAL_DEBUG_SAMP_MSG
  575. /**
  576. * target_if_spectral_log_SAMP_param() - Log SAMP parameters
  577. * @params: Reference to target_if_samp_msg_params
  578. *
  579. * API to log spectral SAMP message parameters
  580. *
  581. * Return: None
  582. */
  583. static void
  584. target_if_spectral_log_SAMP_param(struct target_if_samp_msg_params *params)
  585. {
  586. target_if_dbg_print_samp_param(params);
  587. }
  588. #else
  589. static void
  590. target_if_spectral_log_SAMP_param(struct target_if_samp_msg_params *params)
  591. {
  592. }
  593. #endif
  594. int
  595. target_if_process_phyerr_gen2(struct target_if_spectral *spectral,
  596. uint8_t *data,
  597. uint32_t datalen,
  598. struct target_if_spectral_rfqual_info *p_rfqual,
  599. struct target_if_spectral_chan_info *p_chaninfo,
  600. uint64_t tsf64,
  601. struct target_if_spectral_acs_stats *acs_stats)
  602. {
  603. /*
  604. * XXX : The classifier do not use all the members of the SAMP
  605. * message data format.
  606. * The classifier only depends upon the following parameters
  607. *
  608. * 1. Frequency (freq, msg->freq)
  609. * 2. Spectral RSSI (spectral_rssi,
  610. * msg->samp_data.spectral_rssi)
  611. * 3. Bin Power Count (bin_pwr_count,
  612. * msg->samp_data.bin_pwr_count)
  613. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  614. * 5. Spectral Timestamp (spectral_tstamp,
  615. * msg->samp_data.spectral_tstamp)
  616. * 6. MAC Address (macaddr, msg->macaddr)
  617. *
  618. * This function prepares the params structure and populates it
  619. * with
  620. * relevant values, this is in turn passed to
  621. * spectral_create_samp_msg()
  622. * to prepare fully formatted Spectral SAMP message
  623. *
  624. * XXX : Need to verify
  625. * 1. Order of FFT bin values
  626. *
  627. */
  628. struct target_if_samp_msg_params params;
  629. struct spectral_search_fft_info_gen2 search_fft_info;
  630. struct spectral_search_fft_info_gen2 *p_sfft = &search_fft_info;
  631. struct spectral_search_fft_info_gen2 search_fft_info_sec80;
  632. struct spectral_search_fft_info_gen2 *p_sfft_sec80 =
  633. &search_fft_info_sec80;
  634. uint32_t segid_skiplen = 0;
  635. int8_t rssi_up = 0;
  636. int8_t rssi_low = 0;
  637. int8_t chn_idx_highest_enabled = 0;
  638. int8_t chn_idx_lowest_enabled = 0;
  639. uint8_t control_rssi = 0;
  640. uint8_t extension_rssi = 0;
  641. uint8_t combined_rssi = 0;
  642. uint32_t tstamp = 0;
  643. struct target_if_spectral_ops *p_sops =
  644. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  645. struct spectral_phyerr_tlv_gen2 *ptlv =
  646. (struct spectral_phyerr_tlv_gen2 *)data;
  647. struct spectral_phyerr_tlv_gen2 *ptlv_sec80 = NULL;
  648. struct spectral_phyerr_fft_gen2 *pfft = NULL;
  649. struct spectral_phyerr_fft_gen2 *pfft_sec80 = NULL;
  650. uint8_t segid = 0;
  651. uint8_t segid_sec80 = 0;
  652. if (spectral->is_160_format)
  653. segid_skiplen = sizeof(SPECTRAL_SEGID_INFO);
  654. pfft = (struct spectral_phyerr_fft_gen2 *)(
  655. data +
  656. sizeof(struct spectral_phyerr_tlv_gen2) +
  657. sizeof(struct spectral_phyerr_hdr_gen2) +
  658. segid_skiplen);
  659. /*
  660. * XXX Extend SPECTRAL_DPRINTK() to use spectral_debug_level,
  661. * and use this facility inside spectral_dump_phyerr_data()
  662. * and supporting functions.
  663. */
  664. if (spectral_debug_level & DEBUG_SPECTRAL2)
  665. target_if_spectral_dump_phyerr_data_gen2(
  666. data, datalen,
  667. spectral->is_160_format);
  668. if (spectral_debug_level & DEBUG_SPECTRAL4) {
  669. target_if_spectral_dump_phyerr_data_gen2(
  670. data, datalen,
  671. spectral->is_160_format);
  672. spectral_debug_level = DEBUG_SPECTRAL;
  673. }
  674. if (ptlv->signature != SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  675. /*
  676. * EV# 118023: We tentatively disable the below print
  677. * and provide stats instead.
  678. */
  679. spectral->diag_stats.spectral_mismatch++;
  680. return -EPERM;
  681. }
  682. OS_MEMZERO(&params, sizeof(params));
  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_adj = fft_bin_len >> 2;
  1027. int fft_bin_len_inband_tfer = 0;
  1028. int fft_bin_len_to_dump = fft_bin_len;
  1029. if ((spectral->params.ss_rpt_mode == 2) &&
  1030. spectral->inband_fftbin_size_adj) {
  1031. fft_bin_len_adj >>= 1;
  1032. fft_bin_len_inband_tfer = fft_bin_len >> 1;
  1033. fft_bin_len_to_dump = fft_bin_len_inband_tfer;
  1034. }
  1035. spectral_debug("#############################################################");
  1036. spectral_debug("Spectral search fft_report");
  1037. spectral_debug("fft_timestamp = 0x%x\nfft_hdr_length = %d(32 bit words)\nfft_hdr_tag = 0x%x\nfft_hdr_sig = 0x%x",
  1038. p_fft_report->fft_timestamp,
  1039. p_fft_report->fft_hdr_length,
  1040. p_fft_report->fft_hdr_tag, p_fft_report->fft_hdr_sig);
  1041. spectral_debug("Length field in search fft report is %d(0x%x) bytes",
  1042. fft_hdr_length, fft_hdr_length);
  1043. spectral_debug("Total length of search fft report is %d(0x%x) bytes",
  1044. report_len, report_len);
  1045. spectral_debug("FW reported fftbins in report is %d(0x%x)", fft_bin_len,
  1046. fft_bin_len);
  1047. if ((spectral->params.ss_rpt_mode == 2) &&
  1048. spectral->inband_fftbin_size_adj) {
  1049. spectral_debug("FW fftbins actually transferred (in-band report mode) "
  1050. "%d(0x%x)",
  1051. fft_bin_len_inband_tfer, fft_bin_len_inband_tfer);
  1052. }
  1053. spectral_debug("Actual number of fftbins in report is %d(0x%x)\n",
  1054. fft_bin_len_adj, fft_bin_len_adj);
  1055. 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",
  1056. p_sfft->fft_detector_id,
  1057. p_sfft->fft_num,
  1058. p_sfft->fft_radar_check,
  1059. p_sfft->fft_peak_sidx,
  1060. p_sfft->fft_chn_idx,
  1061. p_sfft->fft_base_pwr_db,
  1062. p_sfft->fft_total_gain_db,
  1063. p_sfft->fft_num_str_bins_ib,
  1064. p_sfft->fft_peak_mag,
  1065. p_sfft->fft_avgpwr_db, p_sfft->fft_relpwr_db);
  1066. spectral_debug("FFT bins:");
  1067. for (i = 0; i < fft_bin_len_to_dump; i++) {
  1068. if (i % 16 == 0)
  1069. spectral_debug("\n%d :", i);
  1070. fft_mag =
  1071. ((uint8_t *)p_fft_report)[SPECTRAL_FFT_BINS_POS + i];
  1072. spectral_debug("%d ", fft_mag);
  1073. }
  1074. spectral_debug("\n");
  1075. spectral_debug("#############################################################");
  1076. return 0;
  1077. }
  1078. #ifdef DIRECT_BUF_RX_ENABLE
  1079. /**
  1080. * target_if_consume_sscan_report_gen3() - Consume spectral summary report
  1081. * @spectral: Pointer to spectral object
  1082. * @data: Pointer to spectral summary
  1083. *
  1084. * Consume spectral summary report for gen3
  1085. *
  1086. * Return: void
  1087. */
  1088. static void
  1089. target_if_consume_sscan_report_gen3(struct target_if_spectral *spectral,
  1090. uint8_t *data,
  1091. struct sscan_report_fields_gen3 *fields) {
  1092. struct spectral_sscan_report_gen3 *psscan_report;
  1093. psscan_report = (struct spectral_sscan_report_gen3 *)data;
  1094. fields->sscan_agc_total_gain = get_bitfield(psscan_report->hdr_a, 8, 0);
  1095. fields->inband_pwr_db = get_bitfield(psscan_report->hdr_a, 10, 18);
  1096. fields->sscan_gainchange = get_bitfield(psscan_report->hdr_b, 1, 30);
  1097. }
  1098. /**
  1099. * target_if_verify_sig_and_tag_gen3() - Verify tag and signature
  1100. * of spectral report
  1101. * @spectral: Pointer to spectral object
  1102. * @data: Pointer to spectral summary report
  1103. * @exp_tag: iexpected tag value
  1104. *
  1105. * Process fft report for gen3
  1106. *
  1107. * Return: SUCCESS/FAILURE
  1108. */
  1109. static int
  1110. target_if_verify_sig_and_tag_gen3(struct target_if_spectral *spectral,
  1111. uint8_t *data, uint8_t exp_tag)
  1112. {
  1113. uint8_t tag = 0;
  1114. uint8_t signature = 0;
  1115. /* Peek into the data to figure out whether
  1116. * 1) Signature matches the expected value
  1117. * 2) What is inside the package (TAG ID is used for finding this)
  1118. */
  1119. tag = *(data + PHYERR_HDR_TAG_POS);
  1120. signature = *(data + PHYERR_HDR_SIG_POS);
  1121. if (signature != SPECTRAL_PHYERR_SIGNATURE_GEN3) {
  1122. if (spectral_debug_level & DEBUG_SPECTRAL4)
  1123. spectral_err("Unexpected sig %x in spectral phyerror",
  1124. signature);
  1125. spectral_err("Expected sig is %x\n",
  1126. SPECTRAL_PHYERR_SIGNATURE_GEN3);
  1127. spectral->diag_stats.spectral_mismatch++;
  1128. return -EINVAL;
  1129. }
  1130. if (tag != exp_tag) {
  1131. if (spectral_debug_level & DEBUG_SPECTRAL4)
  1132. spectral_err("Unexpected tag %x in spectral phyerror",
  1133. tag);
  1134. spectral_err("Expected tag is %x\n", exp_tag);
  1135. spectral->diag_stats.spectral_mismatch++;
  1136. return -EINVAL;
  1137. }
  1138. return 0;
  1139. }
  1140. static uint8_t
  1141. target_if_spectral_get_lowest_chn_idx(uint8_t chainmask)
  1142. {
  1143. uint8_t idx;
  1144. for (idx = 0; idx < DBR_MAX_CHAINS; idx++) {
  1145. if (chainmask & 0x1)
  1146. break;
  1147. chainmask >>= 1;
  1148. }
  1149. return idx;
  1150. }
  1151. int
  1152. target_if_consume_spectral_report_gen3(
  1153. struct target_if_spectral *spectral,
  1154. struct spectral_report *report)
  1155. {
  1156. /*
  1157. * XXX : The classifier do not use all the members of the SAMP
  1158. * message data format.
  1159. * The classifier only depends upon the following parameters
  1160. *
  1161. * 1. Frequency (freq, msg->freq)
  1162. * 2. Spectral RSSI (spectral_rssi,
  1163. * msg->samp_data.spectral_rssi)
  1164. * 3. Bin Power Count (bin_pwr_count,
  1165. * msg->samp_data.bin_pwr_count)
  1166. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  1167. * 5. Spectral Timestamp (spectral_tstamp,
  1168. * msg->samp_data.spectral_tstamp)
  1169. * 6. MAC Address (macaddr, msg->macaddr)
  1170. *
  1171. * This function prepares the params structure and populates it
  1172. * with
  1173. * relevant values, this is in turn passed to
  1174. * spectral_create_samp_msg()
  1175. * to prepare fully formatted Spectral SAMP message
  1176. *
  1177. * XXX : Need to verify
  1178. * 1. Order of FFT bin values
  1179. *
  1180. */
  1181. uint64_t tsf64 = 0;
  1182. struct target_if_samp_msg_params params;
  1183. struct spectral_search_fft_info_gen3 search_fft_info;
  1184. struct spectral_search_fft_info_gen3 *p_sfft = &search_fft_info;
  1185. int8_t rssi_up = 0;
  1186. int8_t rssi_low = 0;
  1187. int8_t chn_idx_lowest_enabled = 0;
  1188. uint8_t control_rssi = 0;
  1189. uint8_t extension_rssi = 0;
  1190. int fft_hdr_length = 0;
  1191. int report_len = 0;
  1192. int fft_bin_len = 0;
  1193. struct target_if_spectral_ops *p_sops =
  1194. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1195. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  1196. int8_t rssi;
  1197. uint8_t *data = report->data;
  1198. struct wlan_objmgr_vdev *vdev;
  1199. uint8_t vdev_rxchainmask;
  1200. struct sscan_report_fields_gen3 sscan_report_fields;
  1201. OS_MEMZERO(&params, sizeof(params));
  1202. if (target_if_verify_sig_and_tag_gen3(
  1203. spectral, data,
  1204. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3) != 0)
  1205. goto fail;
  1206. target_if_consume_sscan_report_gen3(spectral, data,
  1207. &sscan_report_fields);
  1208. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  1209. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  1210. params.agc_total_gain = sscan_report_fields.sscan_agc_total_gain;
  1211. params.gainchange = sscan_report_fields.sscan_gainchange;
  1212. /* Advance buf pointer to the search fft report */
  1213. data += sizeof(struct spectral_sscan_report_gen3);
  1214. if (target_if_verify_sig_and_tag_gen3(
  1215. spectral, data,
  1216. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0)
  1217. goto fail;
  1218. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  1219. fft_hdr_length = p_fft_report->fft_hdr_length * 4;
  1220. if (fft_hdr_length < 16) {
  1221. spectral_err("Unexpected TLV length %u for FFT Report! Hexdump follows",
  1222. fft_hdr_length);
  1223. goto fail;
  1224. }
  1225. report_len = (fft_hdr_length + 8);
  1226. fft_bin_len = (fft_hdr_length - 16);
  1227. /* Divide fft bin length by 4 if fftbin_size_war is enabled */
  1228. if (spectral->fftbin_size_war) {
  1229. fft_bin_len >>= 2;
  1230. }
  1231. if ((spectral->params.ss_rpt_mode == 2) &&
  1232. spectral->inband_fftbin_size_adj) {
  1233. fft_bin_len >>= 1;
  1234. }
  1235. tsf64 = p_fft_report->fft_timestamp;
  1236. target_if_process_sfft_report_gen3(p_fft_report, p_sfft);
  1237. if (p_sfft->fft_detector_id != 0) {
  1238. spectral_err("Expected segid is 0 but we got %d",
  1239. p_sfft->fft_detector_id);
  1240. spectral->diag_stats.spectral_vhtseg1id_mismatch++;
  1241. goto fail;
  1242. }
  1243. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  1244. target_if_dump_fft_report_gen3(spectral, p_fft_report, p_sfft);
  1245. if (spectral->upper_is_control)
  1246. rssi_up = control_rssi;
  1247. else
  1248. rssi_up = extension_rssi;
  1249. if (spectral->lower_is_control)
  1250. rssi_low = control_rssi;
  1251. else
  1252. rssi_low = extension_rssi;
  1253. params.rssi = rssi;
  1254. params.lower_rssi = rssi_low;
  1255. params.upper_rssi = rssi_up;
  1256. if (spectral->sc_spectral_noise_pwr_cal) {
  1257. /* Fill 0's till FW provides them */
  1258. params.chain_ctl_rssi[0] = 0;
  1259. params.chain_ctl_rssi[1] = 0;
  1260. params.chain_ctl_rssi[2] = 0;
  1261. params.chain_ext_rssi[0] = 0;
  1262. params.chain_ext_rssi[1] = 0;
  1263. params.chain_ext_rssi[2] = 0;
  1264. }
  1265. vdev = target_if_spectral_get_vdev(spectral);
  1266. if (!vdev)
  1267. return -ENOENT;
  1268. vdev_rxchainmask =
  1269. wlan_vdev_mlme_get_rxchainmask(vdev);
  1270. QDF_ASSERT(vdev_rxchainmask != 0);
  1271. wlan_objmgr_vdev_release_ref(vdev,
  1272. WLAN_SPECTRAL_ID);
  1273. chn_idx_lowest_enabled =
  1274. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  1275. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS)
  1276. return -EINVAL;
  1277. control_rssi = 0;
  1278. extension_rssi = 0;
  1279. params.bwinfo = 0;
  1280. params.tstamp = 0;
  1281. params.max_mag = p_sfft->fft_peak_mag;
  1282. /* params.max_index = p_sfft->peak_inx; */
  1283. params.max_exp = 0;
  1284. params.peak = 0;
  1285. params.bin_pwr_data = (uint8_t *)((uint8_t *)p_fft_report +
  1286. SPECTRAL_FFT_BINS_POS);
  1287. params.freq = p_sops->get_current_channel(spectral);
  1288. params.freq_loading = 0;
  1289. params.interf_list.count = 0;
  1290. params.max_lower_index = 0;
  1291. params.max_upper_index = 0;
  1292. params.nb_lower = 0;
  1293. params.nb_upper = 0;
  1294. /*
  1295. * For modes upto VHT80, the noise floor is populated with the one
  1296. * corresponding
  1297. * to the highest enabled antenna chain
  1298. */
  1299. /* TODO: Fill proper values once FW provides them*/
  1300. params.noise_floor = report->noisefloor[chn_idx_lowest_enabled];
  1301. params.datalen = (fft_hdr_length * 4);
  1302. params.pwr_count = fft_bin_len;
  1303. params.tstamp = (tsf64 & SPECTRAL_TSMASK);
  1304. if (spectral->ch_width == CH_WIDTH_160MHZ) {
  1305. /* We expect to see one more Search FFT report, and it should be
  1306. * equal in size to the current one.
  1307. */
  1308. /* Advance to the secondary 80 Mhz spectral report */
  1309. data += report_len;
  1310. if (target_if_verify_sig_and_tag_gen3(
  1311. spectral, data,
  1312. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3) != 0)
  1313. goto fail;
  1314. target_if_consume_sscan_report_gen3(spectral, data,
  1315. &sscan_report_fields);
  1316. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  1317. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  1318. params.agc_total_gain_sec80 =
  1319. sscan_report_fields.sscan_agc_total_gain;
  1320. params.gainchange_sec80 = sscan_report_fields.sscan_gainchange;
  1321. /* Advance buf pointer to the search fft report */
  1322. data += sizeof(struct spectral_sscan_report_gen3);
  1323. if (target_if_verify_sig_and_tag_gen3(
  1324. spectral, data,
  1325. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0)
  1326. goto fail;
  1327. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)(data);
  1328. fft_hdr_length = p_fft_report->fft_hdr_length * 4;
  1329. report_len = (fft_hdr_length + 8);
  1330. fft_bin_len = (fft_hdr_length - 16);
  1331. /* Divide fft bin length by 4 if fftbin_size_war is enabled */
  1332. if (spectral->fftbin_size_war) {
  1333. fft_bin_len >>= 2;
  1334. }
  1335. if ((spectral->params.ss_rpt_mode == 2) &&
  1336. spectral->inband_fftbin_size_adj) {
  1337. fft_bin_len >>= 1;
  1338. }
  1339. target_if_process_sfft_report_gen3(p_fft_report, p_sfft);
  1340. if (p_sfft->fft_detector_id != 1) {
  1341. spectral_err("Expected segid is 1 but we got %d",
  1342. p_sfft->fft_detector_id);
  1343. spectral->diag_stats.spectral_vhtseg2id_mismatch++;
  1344. goto fail;
  1345. }
  1346. if (spectral_debug_level &
  1347. (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  1348. target_if_dump_fft_report_gen3(spectral, p_fft_report, p_sfft);
  1349. params.vhtop_ch_freq_seg1 = 0;
  1350. params.vhtop_ch_freq_seg2 = 0;
  1351. /* XXX: Confirm. TBD at SoD. */
  1352. params.rssi_sec80 = rssi;
  1353. /* XXX: Determine dynamically. TBD at SoD. */
  1354. /*
  1355. * For VHT80_80/VHT160,the noise floor for primary 80MHz segment
  1356. * populated with the
  1357. * lowest enabled antenna chain and the nf for secondary 80MHz
  1358. * segment is populated
  1359. * with the highest enabled antenna chain
  1360. */
  1361. /* TODO: Fill proper values once FW provides them*/
  1362. params.noise_floor_sec80 = DUMMY_NF_VALUE;
  1363. params.noise_floor = DUMMY_NF_VALUE;
  1364. params.max_mag_sec80 = p_sfft->fft_peak_mag;
  1365. /* params.max_index_sec80 = p_sfft->peak_inx; */
  1366. /* XXX Does this definition of datalen *still hold? */
  1367. params.datalen_sec80 = fft_hdr_length;
  1368. params.pwr_count_sec80 = fft_bin_len;
  1369. params.bin_pwr_data_sec80 = (u_int8_t *)(
  1370. (uint8_t *)p_fft_report + SPECTRAL_FFT_BINS_POS);
  1371. }
  1372. qdf_mem_copy(&params.classifier_params,
  1373. &spectral->classifier_params,
  1374. sizeof(struct spectral_classifier_params));
  1375. target_if_spectral_log_SAMP_param(&params);
  1376. target_if_spectral_create_samp_msg(spectral, &params);
  1377. return 0;
  1378. fail:
  1379. spectral_err("Error in function while processing search fft report");
  1380. return -EPERM;
  1381. }
  1382. int target_if_spectral_process_report_gen3(
  1383. struct wlan_objmgr_pdev *pdev,
  1384. void *buf)
  1385. {
  1386. int ret = 0;
  1387. struct direct_buf_rx_data *payload = buf;
  1388. struct target_if_spectral *spectral;
  1389. struct spectral_report report;
  1390. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1391. if (spectral == NULL) {
  1392. spectral_err("Spectral target object is null");
  1393. return -EINVAL;
  1394. }
  1395. report.data = payload->vaddr;
  1396. if (payload->meta_data_valid)
  1397. qdf_mem_copy(report.noisefloor, &payload->meta_data,
  1398. sizeof(payload->meta_data));
  1399. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4)) {
  1400. spectral_debug("Printing the spectral phyerr buffer for debug");
  1401. spectral_debug("Datalength of buffer = 0x%zx(%zd) bufptr = 0x%pK",
  1402. payload->dbr_len,
  1403. payload->dbr_len,
  1404. payload->vaddr);
  1405. #ifdef CONFIG_WIN
  1406. RAWSIM_PKT_HEXDUMP((unsigned char *)payload->vaddr, 1024);
  1407. #endif
  1408. }
  1409. ret = target_if_consume_spectral_report_gen3(spectral, &report);
  1410. if (spectral_debug_level & DEBUG_SPECTRAL4)
  1411. spectral_debug_level = DEBUG_SPECTRAL;
  1412. return ret;
  1413. }
  1414. #else
  1415. int target_if_spectral_process_report_gen3(
  1416. struct wlan_objmgr_pdev *pdev,
  1417. void *buf)
  1418. {
  1419. spectral_err("Direct dma support is not enabled");
  1420. return -EINVAL;
  1421. }
  1422. #endif
  1423. qdf_export_symbol(target_if_spectral_process_report_gen3);
  1424. /* END of spectral GEN III HW specific functions */
  1425. #endif /* WLAN_CONV_SPECTRAL_ENABLE */