target_if_spectral_phyerr.c 53 KB

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