target_if_spectral_phyerr.c 62 KB

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