target_if_spectral_phyerr.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913
  1. /*
  2. * Copyright (c) 2011,2017-2021 The Linux Foundation. All rights reserved.
  3. *
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include <osdep.h>
  20. #include <qdf_types.h>
  21. #include <qdf_module.h>
  22. #include <wlan_tgt_def_config.h>
  23. #include <hif.h>
  24. #include <hif_hw_version.h>
  25. #include <wmi_unified_api.h>
  26. #include <target_if_spectral.h>
  27. #include <wlan_lmac_if_def.h>
  28. #include <wlan_osif_priv.h>
  29. #include <reg_services_public_struct.h>
  30. #include <target_if.h>
  31. #ifdef DIRECT_BUF_RX_ENABLE
  32. #include <target_if_direct_buf_rx_api.h>
  33. #endif
  34. extern int spectral_debug_level;
  35. #ifdef WLAN_CONV_SPECTRAL_ENABLE
  36. #define SPECTRAL_HEXDUMP_OCTET_PRINT_SIZE (3)
  37. #define SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE (16)
  38. #define SPECTRAL_HEXDUMP_EXTRA_BUFFER_PER_LINE (16)
  39. /*
  40. * Provision for the expected hexdump line size as follows:
  41. *
  42. * Size per octet multiplied by number of octets per line
  43. * +
  44. * ASCII representation which is equivalent in print size to number of octets
  45. * per line
  46. * +
  47. * Some extra buffer
  48. */
  49. #define SPECTRAL_HEXDUMP_LINESIZE \
  50. ((SPECTRAL_HEXDUMP_OCTET_PRINT_SIZE * \
  51. SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE) + \
  52. SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE + \
  53. SPECTRAL_HEXDUMP_EXTRA_BUFFER_PER_LINE)
  54. /**
  55. * target_if_spectral_hexdump() - Print hexdump of the given buffer
  56. * @_buf: Pointer to buffer
  57. * @_len: Length of the buffer
  58. *
  59. * Print the hexdump of buffer upto given length. Print upto
  60. * SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE per line, followed by the ASCII
  61. * representation of these octets.
  62. */
  63. static inline void target_if_spectral_hexdump(unsigned char *_buf, int _len)
  64. {
  65. int i, mod;
  66. unsigned char ascii[SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE + 1];
  67. unsigned char *pc = (_buf);
  68. char hexdump_line[SPECTRAL_HEXDUMP_LINESIZE + 1];
  69. int loc = 0;
  70. qdf_mem_zero(hexdump_line, sizeof(hexdump_line));
  71. if (_len <= 0) {
  72. spectral_err("buffer len is %d, too short", _len);
  73. return;
  74. }
  75. for (i = 0; i < _len; i++) {
  76. mod = i % SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE;
  77. if (!mod) {
  78. if (i) {
  79. qdf_assert_always(loc < sizeof(hexdump_line));
  80. loc += snprintf(&hexdump_line[loc],
  81. sizeof(hexdump_line) - loc,
  82. " %s", ascii);
  83. spectral_debug("%s", hexdump_line);
  84. qdf_mem_zero(hexdump_line,
  85. sizeof(hexdump_line));
  86. loc = 0;
  87. }
  88. }
  89. qdf_assert_always(loc < sizeof(hexdump_line));
  90. loc += snprintf(&hexdump_line[loc], sizeof(hexdump_line) - loc,
  91. " %02x", pc[i]);
  92. if ((pc[i] < 0x20) || (pc[i] > 0x7e))
  93. ascii[mod] = '.';
  94. else
  95. ascii[mod] = pc[i];
  96. ascii[(mod) + 1] = '\0';
  97. }
  98. while ((i % SPECTRAL_HEXDUMP_NUM_OCTETS_PER_LINE) != 0) {
  99. qdf_assert_always(loc < sizeof(hexdump_line));
  100. loc += snprintf(&hexdump_line[loc], sizeof(hexdump_line) - loc,
  101. " ");
  102. i++;
  103. }
  104. qdf_assert_always(loc < sizeof(hexdump_line));
  105. snprintf(&hexdump_line[loc], sizeof(hexdump_line) - loc, " %s", ascii);
  106. spectral_debug("%s", hexdump_line);
  107. }
  108. /**
  109. * target_if_print_buf() - Prints given buffer for given length
  110. * @pbuf: Pointer to buffer
  111. * @len: length
  112. *
  113. * Prints given buffer for given length
  114. *
  115. * Return: void
  116. */
  117. static void
  118. target_if_print_buf(uint8_t *pbuf, int len)
  119. {
  120. int i = 0;
  121. for (i = 0; i < len; i++) {
  122. spectral_debug("%02X ", pbuf[i]);
  123. if (i % 32 == 31)
  124. spectral_debug("\n");
  125. }
  126. }
  127. int
  128. target_if_spectral_dump_fft(uint8_t *pfft, int fftlen)
  129. {
  130. int i = 0;
  131. /*
  132. * TODO : Do not delete the following print
  133. * The scripts used to validate Spectral depend on this Print
  134. */
  135. spectral_debug("SPECTRAL : FFT Length is 0x%x (%d)", fftlen, fftlen);
  136. spectral_debug("fft_data # ");
  137. for (i = 0; i < fftlen; i++)
  138. spectral_debug("%d ", pfft[i]);
  139. spectral_debug("\n");
  140. return 0;
  141. }
  142. QDF_STATUS target_if_spectral_fw_hang(struct target_if_spectral *spectral)
  143. {
  144. struct crash_inject param;
  145. struct wlan_objmgr_pdev *pdev;
  146. struct wlan_objmgr_psoc *psoc;
  147. struct target_if_psoc_spectral *psoc_spectral;
  148. if (!spectral) {
  149. spectral_err("Spectral LMAC object is null");
  150. return QDF_STATUS_E_INVAL;
  151. }
  152. pdev = spectral->pdev_obj;
  153. if (!pdev) {
  154. spectral_err("pdev is null");
  155. return QDF_STATUS_E_FAILURE;
  156. }
  157. psoc = wlan_pdev_get_psoc(pdev);
  158. if (!psoc) {
  159. spectral_err("psoc is null");
  160. return QDF_STATUS_E_FAILURE;
  161. }
  162. psoc_spectral = get_target_if_spectral_handle_from_psoc(psoc);
  163. if (!psoc_spectral) {
  164. spectral_err("spectral psoc object is null");
  165. return QDF_STATUS_E_FAILURE;
  166. }
  167. qdf_mem_set(&param, sizeof(param), 0);
  168. param.type = 1; //RECOVERY_SIM_ASSERT
  169. return psoc_spectral->wmi_ops.wmi_spectral_crash_inject(
  170. GET_WMI_HDL_FROM_PDEV(spectral->pdev_obj), &param);
  171. }
  172. void
  173. target_if_dbg_print_samp_param(struct target_if_samp_msg_params *p)
  174. {
  175. spectral_debug("\nSAMP Packet : -------------------- START --------------------");
  176. spectral_debug("Freq = %d", p->freq);
  177. spectral_debug("RSSI = %d", p->rssi);
  178. spectral_debug("Bin Count = %d", p->pwr_count);
  179. spectral_debug("Timestamp = %d", p->tstamp);
  180. spectral_debug("SAMP Packet : -------------------- END -----------------------");
  181. }
  182. void
  183. target_if_dbg_print_samp_msg(struct spectral_samp_msg *ss_msg)
  184. {
  185. int i = 0;
  186. struct spectral_samp_data *p = &ss_msg->samp_data;
  187. struct spectral_classifier_params *pc = &p->classifier_params;
  188. struct interf_src_rsp *pi = &p->interf_list;
  189. spectral_dbg_line();
  190. spectral_debug("Spectral Message");
  191. spectral_dbg_line();
  192. spectral_debug("Signature : 0x%x", ss_msg->signature);
  193. spectral_debug("Freq : %d", ss_msg->freq);
  194. spectral_debug("Freq load : %d", ss_msg->freq_loading);
  195. spectral_debug("Intfnc type : %d", ss_msg->int_type);
  196. spectral_dbg_line();
  197. spectral_debug("Spectral Data info");
  198. spectral_dbg_line();
  199. spectral_debug("data length : %d", p->spectral_data_len);
  200. spectral_debug("rssi : %d", p->spectral_rssi);
  201. spectral_debug("combined rssi : %d", p->spectral_combined_rssi);
  202. spectral_debug("upper rssi : %d", p->spectral_upper_rssi);
  203. spectral_debug("lower rssi : %d", p->spectral_lower_rssi);
  204. spectral_debug("bw info : %d", p->spectral_bwinfo);
  205. spectral_debug("timestamp : %d", p->spectral_tstamp);
  206. spectral_debug("max index : %d", p->spectral_max_index);
  207. spectral_debug("max exp : %d", p->spectral_max_exp);
  208. spectral_debug("max mag : %d", p->spectral_max_mag);
  209. spectral_debug("last timstamp : %d", p->spectral_last_tstamp);
  210. spectral_debug("upper max idx : %d", p->spectral_upper_max_index);
  211. spectral_debug("lower max idx : %d", p->spectral_lower_max_index);
  212. spectral_debug("bin power count : %d", p->bin_pwr_count);
  213. spectral_dbg_line();
  214. spectral_debug("Classifier info");
  215. spectral_dbg_line();
  216. spectral_debug("20/40 Mode : %d", pc->spectral_20_40_mode);
  217. spectral_debug("dc index : %d", pc->spectral_dc_index);
  218. spectral_debug("dc in MHz : %d", pc->spectral_dc_in_mhz);
  219. spectral_debug("upper channel : %d", pc->upper_chan_in_mhz);
  220. spectral_debug("lower channel : %d", pc->lower_chan_in_mhz);
  221. spectral_dbg_line();
  222. spectral_debug("Interference info");
  223. spectral_dbg_line();
  224. spectral_debug("inter count : %d", pi->count);
  225. for (i = 0; i < pi->count; i++) {
  226. spectral_debug("inter type : %d",
  227. pi->interf[i].interf_type);
  228. spectral_debug("min freq : %d",
  229. pi->interf[i].interf_min_freq);
  230. spectral_debug("max freq : %d",
  231. pi->interf[i].interf_max_freq);
  232. }
  233. }
  234. uint32_t
  235. target_if_get_offset_swar_sec80(uint32_t channel_width)
  236. {
  237. uint32_t offset = 0;
  238. switch (channel_width) {
  239. case CH_WIDTH_20MHZ:
  240. offset = OFFSET_CH_WIDTH_20;
  241. break;
  242. case CH_WIDTH_40MHZ:
  243. offset = OFFSET_CH_WIDTH_40;
  244. break;
  245. case CH_WIDTH_80MHZ:
  246. offset = OFFSET_CH_WIDTH_80;
  247. break;
  248. case CH_WIDTH_160MHZ:
  249. case CH_WIDTH_80P80MHZ:
  250. offset = OFFSET_CH_WIDTH_160;
  251. break;
  252. default:
  253. offset = OFFSET_CH_WIDTH_80;
  254. break;
  255. }
  256. return offset;
  257. }
  258. /**
  259. * target_if_dump_summary_report_gen2() - Dump Spectral Summary Report for gen2
  260. * @ptlv: Pointer to Spectral Phyerr TLV
  261. * @tlvlen: length
  262. * @is_160_format: Indicates whether information provided by HW is in altered
  263. * format for 802.11ac 160/80+80 MHz support (QCA9984 onwards)
  264. *
  265. * Dump Spectral Summary Report for gen2
  266. *
  267. * Return: Success/Failure
  268. */
  269. static int
  270. target_if_dump_summary_report_gen2(struct spectral_phyerr_tlv_gen2 *ptlv,
  271. int tlvlen, bool is_160_format)
  272. {
  273. /*
  274. * For simplicity, everything is defined as uint32_t (except one).
  275. * Proper code will later use the right sizes.
  276. */
  277. /*
  278. * For easy comparision between MDK team and OS team, the MDK script
  279. * variable names have been used
  280. */
  281. uint32_t agc_mb_gain;
  282. uint32_t sscan_gidx;
  283. uint32_t agc_total_gain;
  284. uint32_t recent_rfsat;
  285. uint32_t ob_flag;
  286. uint32_t nb_mask;
  287. uint32_t peak_mag;
  288. int16_t peak_inx;
  289. uint32_t ss_summary_A = 0;
  290. uint32_t ss_summary_B = 0;
  291. uint32_t ss_summary_C = 0;
  292. uint32_t ss_summary_D = 0;
  293. uint32_t ss_summary_E = 0;
  294. struct spectral_phyerr_hdr_gen2 *phdr =
  295. (struct spectral_phyerr_hdr_gen2 *)(
  296. (uint8_t *)ptlv +
  297. sizeof(struct spectral_phyerr_tlv_gen2));
  298. spectral_debug("SPECTRAL : SPECTRAL SUMMARY REPORT");
  299. if (is_160_format) {
  300. if (tlvlen != 20) {
  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. qdf_mem_copy(&ss_summary_C,
  312. (uint8_t *)((uint8_t *)phdr + 2 * sizeof(int)),
  313. sizeof(int));
  314. qdf_mem_copy(&ss_summary_D,
  315. (uint8_t *)((uint8_t *)phdr + 3 * sizeof(int)),
  316. sizeof(int));
  317. qdf_mem_copy(&ss_summary_E,
  318. (uint8_t *)((uint8_t *)phdr + 4 * sizeof(int)),
  319. sizeof(int));
  320. /*
  321. * The following is adapted from MDK scripts for
  322. * easier comparability
  323. */
  324. recent_rfsat = ((ss_summary_A >> 8) & 0x1);
  325. sscan_gidx = (ss_summary_A & 0xff);
  326. spectral_debug("sscan_gidx=%d, is_recent_rfsat=%d",
  327. sscan_gidx, recent_rfsat);
  328. /* First segment */
  329. agc_mb_gain = ((ss_summary_B >> 10) & 0x7f);
  330. agc_total_gain = (ss_summary_B & 0x3ff);
  331. nb_mask = ((ss_summary_C >> 22) & 0xff);
  332. ob_flag = ((ss_summary_B >> 17) & 0x1);
  333. peak_inx = (ss_summary_C & 0xfff);
  334. if (peak_inx > 2047)
  335. peak_inx = peak_inx - 4096;
  336. peak_mag = ((ss_summary_C >> 12) & 0x3ff);
  337. spectral_debug("agc_total_gain_segid0 = 0x%.2x, agc_mb_gain_segid0=%d",
  338. agc_total_gain, agc_mb_gain);
  339. spectral_debug("nb_mask_segid0 = 0x%.2x, ob_flag_segid0=%d, peak_index_segid0=%d, peak_mag_segid0=%d",
  340. nb_mask, ob_flag, peak_inx, peak_mag);
  341. /* Second segment */
  342. agc_mb_gain = ((ss_summary_D >> 10) & 0x7f);
  343. agc_total_gain = (ss_summary_D & 0x3ff);
  344. nb_mask = ((ss_summary_E >> 22) & 0xff);
  345. ob_flag = ((ss_summary_D >> 17) & 0x1);
  346. peak_inx = (ss_summary_E & 0xfff);
  347. if (peak_inx > 2047)
  348. peak_inx = peak_inx - 4096;
  349. peak_mag = ((ss_summary_E >> 12) & 0x3ff);
  350. spectral_debug("agc_total_gain_segid1 = 0x%.2x, agc_mb_gain_segid1=%d",
  351. agc_total_gain, agc_mb_gain);
  352. spectral_debug("nb_mask_segid1 = 0x%.2x, ob_flag_segid1=%d, peak_index_segid1=%d, peak_mag_segid1=%d",
  353. nb_mask, ob_flag, peak_inx, peak_mag);
  354. } else {
  355. if (tlvlen != 8) {
  356. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  357. tlvlen);
  358. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  359. return -EPERM;
  360. }
  361. /* Doing copy as the contents may not be aligned */
  362. qdf_mem_copy(&ss_summary_A, (uint8_t *)phdr, sizeof(int));
  363. qdf_mem_copy(&ss_summary_B,
  364. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  365. sizeof(int));
  366. nb_mask = ((ss_summary_B >> 22) & 0xff);
  367. ob_flag = ((ss_summary_B >> 30) & 0x1);
  368. peak_inx = (ss_summary_B & 0xfff);
  369. if (peak_inx > 2047)
  370. peak_inx = peak_inx - 4096;
  371. peak_mag = ((ss_summary_B >> 12) & 0x3ff);
  372. agc_mb_gain = ((ss_summary_A >> 24) & 0x7f);
  373. agc_total_gain = (ss_summary_A & 0x3ff);
  374. sscan_gidx = ((ss_summary_A >> 16) & 0xff);
  375. recent_rfsat = ((ss_summary_B >> 31) & 0x1);
  376. 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",
  377. nb_mask, ob_flag, peak_inx, peak_mag,
  378. agc_mb_gain, agc_total_gain, sscan_gidx,
  379. recent_rfsat);
  380. }
  381. return 0;
  382. }
  383. /**
  384. * target_if_process_sfft_report_gen2() - Process Search FFT Report
  385. * @ptlv: Pointer to Spectral Phyerr TLV
  386. * @tlvlen: length
  387. * @p_fft_info: Pointer to search fft info
  388. *
  389. * Dump Spectral Summary Report for gen2
  390. *
  391. * Return: Success/Failure
  392. */
  393. static int
  394. target_if_process_sfft_report_gen2(
  395. struct spectral_phyerr_tlv_gen2 *ptlv,
  396. int tlvlen,
  397. struct spectral_search_fft_info_gen2 *p_fft_info)
  398. {
  399. /*
  400. * For simplicity, everything is defined as uint32_t (except one).
  401. * Proper code will later use the right sizes.
  402. */
  403. /*
  404. * For easy comparision between MDK team and OS team, the MDK script
  405. * variable names have been used
  406. */
  407. uint32_t relpwr_db;
  408. uint32_t num_str_bins_ib;
  409. uint32_t base_pwr;
  410. uint32_t total_gain_info;
  411. uint32_t fft_chn_idx;
  412. int16_t peak_inx;
  413. uint32_t avgpwr_db;
  414. uint32_t peak_mag;
  415. uint32_t fft_summary_A = 0;
  416. uint32_t fft_summary_B = 0;
  417. uint8_t *tmp = (uint8_t *)ptlv;
  418. struct spectral_phyerr_hdr_gen2 *phdr =
  419. (struct spectral_phyerr_hdr_gen2 *)(
  420. tmp +
  421. sizeof(struct spectral_phyerr_tlv_gen2));
  422. /* Relook this */
  423. if (tlvlen < 8) {
  424. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  425. tlvlen);
  426. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  427. return -EPERM;
  428. }
  429. /* Doing copy as the contents may not be aligned */
  430. qdf_mem_copy(&fft_summary_A, (uint8_t *)phdr, sizeof(int));
  431. qdf_mem_copy(&fft_summary_B,
  432. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  433. sizeof(int));
  434. relpwr_db = ((fft_summary_B >> 26) & 0x3f);
  435. num_str_bins_ib = fft_summary_B & 0xff;
  436. base_pwr = ((fft_summary_A >> 14) & 0x1ff);
  437. total_gain_info = ((fft_summary_A >> 23) & 0x1ff);
  438. fft_chn_idx = ((fft_summary_A >> 12) & 0x3);
  439. peak_inx = fft_summary_A & 0xfff;
  440. if (peak_inx > 2047)
  441. peak_inx = peak_inx - 4096;
  442. avgpwr_db = ((fft_summary_B >> 18) & 0xff);
  443. peak_mag = ((fft_summary_B >> 8) & 0x3ff);
  444. /* Populate the Search FFT Info */
  445. if (p_fft_info) {
  446. p_fft_info->relpwr_db = relpwr_db;
  447. p_fft_info->num_str_bins_ib = num_str_bins_ib;
  448. p_fft_info->base_pwr = base_pwr;
  449. p_fft_info->total_gain_info = total_gain_info;
  450. p_fft_info->fft_chn_idx = fft_chn_idx;
  451. p_fft_info->peak_inx = peak_inx;
  452. p_fft_info->avgpwr_db = avgpwr_db;
  453. p_fft_info->peak_mag = peak_mag;
  454. }
  455. return 0;
  456. }
  457. /**
  458. * target_if_dump_adc_report_gen2() - Dump ADC Reports for gen2
  459. * @ptlv: Pointer to Spectral Phyerr TLV
  460. * @tlvlen: length
  461. *
  462. * Dump ADC Reports for gen2
  463. *
  464. * Return: Success/Failure
  465. */
  466. static int
  467. target_if_dump_adc_report_gen2(
  468. struct spectral_phyerr_tlv_gen2 *ptlv, int tlvlen)
  469. {
  470. int i;
  471. uint32_t *pdata;
  472. uint32_t data;
  473. /*
  474. * For simplicity, everything is defined as uint32_t (except one).
  475. * Proper code will later use the right sizes.
  476. */
  477. uint32_t samp_fmt;
  478. uint32_t chn_idx;
  479. uint32_t recent_rfsat;
  480. uint32_t agc_mb_gain;
  481. uint32_t agc_total_gain;
  482. uint32_t adc_summary = 0;
  483. uint8_t *ptmp = (uint8_t *)ptlv;
  484. spectral_debug("SPECTRAL : ADC REPORT");
  485. /* Relook this */
  486. if (tlvlen < 4) {
  487. spectral_err("Unexpected TLV length %d for ADC Report! Hexdump follows",
  488. tlvlen);
  489. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  490. return -EPERM;
  491. }
  492. qdf_mem_copy(&adc_summary, (uint8_t *)(ptlv + 4), sizeof(int));
  493. samp_fmt = ((adc_summary >> 28) & 0x1);
  494. chn_idx = ((adc_summary >> 24) & 0x3);
  495. recent_rfsat = ((adc_summary >> 23) & 0x1);
  496. agc_mb_gain = ((adc_summary >> 16) & 0x7f);
  497. agc_total_gain = adc_summary & 0x3ff;
  498. spectral_debug("samp_fmt= %u, chn_idx= %u, recent_rfsat= %u, agc_mb_gain=%u agc_total_gain=%u",
  499. samp_fmt, chn_idx, recent_rfsat, agc_mb_gain,
  500. agc_total_gain);
  501. for (i = 0; i < (tlvlen / 4); i++) {
  502. pdata = (uint32_t *)(ptmp + 4 + i * 4);
  503. data = *pdata;
  504. /* Interpreting capture format 1 */
  505. if (1) {
  506. uint8_t i1;
  507. uint8_t q1;
  508. uint8_t i2;
  509. uint8_t q2;
  510. int8_t si1;
  511. int8_t sq1;
  512. int8_t si2;
  513. int8_t sq2;
  514. i1 = data & 0xff;
  515. q1 = (data >> 8) & 0xff;
  516. i2 = (data >> 16) & 0xff;
  517. q2 = (data >> 24) & 0xff;
  518. if (i1 > 127)
  519. si1 = i1 - 256;
  520. else
  521. si1 = i1;
  522. if (q1 > 127)
  523. sq1 = q1 - 256;
  524. else
  525. sq1 = q1;
  526. if (i2 > 127)
  527. si2 = i2 - 256;
  528. else
  529. si2 = i2;
  530. if (q2 > 127)
  531. sq2 = q2 - 256;
  532. else
  533. sq2 = q2;
  534. spectral_debug("SPECTRAL ADC : Interpreting capture format 1");
  535. spectral_debug("adc_data_format_1 # %d %d %d",
  536. 2 * i, si1, sq1);
  537. spectral_debug("adc_data_format_1 # %d %d %d",
  538. 2 * i + 1, si2, sq2);
  539. }
  540. /* Interpreting capture format 0 */
  541. if (1) {
  542. uint16_t i1;
  543. uint16_t q1;
  544. int16_t si1;
  545. int16_t sq1;
  546. i1 = data & 0xffff;
  547. q1 = (data >> 16) & 0xffff;
  548. if (i1 > 32767)
  549. si1 = i1 - 65536;
  550. else
  551. si1 = i1;
  552. if (q1 > 32767)
  553. sq1 = q1 - 65536;
  554. else
  555. sq1 = q1;
  556. spectral_debug("SPECTRAL ADC : Interpreting capture format 0");
  557. spectral_debug("adc_data_format_2 # %d %d %d",
  558. i, si1, sq1);
  559. }
  560. }
  561. spectral_debug("\n");
  562. return 0;
  563. }
  564. /**
  565. * target_if_dump_sfft_report_gen2() - Process Search FFT Report for gen2
  566. * @ptlv: Pointer to Spectral Phyerr TLV
  567. * @tlvlen: length
  568. * @is_160_format: Indicates 160 format
  569. *
  570. * Process Search FFT Report for gen2
  571. *
  572. * Return: Success/Failure
  573. */
  574. static int
  575. target_if_dump_sfft_report_gen2(struct spectral_phyerr_tlv_gen2 *ptlv,
  576. int tlvlen, bool is_160_format)
  577. {
  578. int i;
  579. uint32_t fft_mag;
  580. /*
  581. * For simplicity, everything is defined as uint32_t (except one).
  582. * Proper code will later use the right sizes.
  583. */
  584. /*
  585. * For easy comparision between MDK team and OS team, the MDK script
  586. * variable names have been used
  587. */
  588. uint32_t relpwr_db;
  589. uint32_t num_str_bins_ib;
  590. uint32_t base_pwr;
  591. uint32_t total_gain_info;
  592. uint32_t fft_chn_idx;
  593. int16_t peak_inx;
  594. uint32_t avgpwr_db;
  595. uint32_t peak_mag;
  596. uint8_t segid;
  597. uint32_t fft_summary_A = 0;
  598. uint32_t fft_summary_B = 0;
  599. uint32_t fft_summary_C = 0;
  600. uint8_t *tmp = (uint8_t *)ptlv;
  601. struct spectral_phyerr_hdr_gen2 *phdr =
  602. (struct spectral_phyerr_hdr_gen2 *)(
  603. tmp +
  604. sizeof(struct spectral_phyerr_tlv_gen2));
  605. uint32_t segid_skiplen = 0;
  606. if (is_160_format)
  607. segid_skiplen = sizeof(SPECTRAL_SEGID_INFO);
  608. spectral_debug("SPECTRAL : SEARCH FFT REPORT");
  609. /* Relook this */
  610. if (tlvlen < (8 + segid_skiplen)) {
  611. spectral_err("Unexpected TLV length %d for Spectral Summary Report! Hexdump follows",
  612. tlvlen);
  613. target_if_print_buf((uint8_t *)ptlv, tlvlen + 4);
  614. return -EPERM;
  615. }
  616. /* Doing copy as the contents may not be aligned */
  617. qdf_mem_copy(&fft_summary_A, (uint8_t *)phdr, sizeof(int));
  618. qdf_mem_copy(&fft_summary_B,
  619. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  620. sizeof(int));
  621. if (is_160_format)
  622. qdf_mem_copy(&fft_summary_C,
  623. (uint8_t *)((uint8_t *)phdr + 2 * sizeof(int)),
  624. sizeof(int));
  625. relpwr_db = ((fft_summary_B >> 26) & 0x3f);
  626. num_str_bins_ib = fft_summary_B & 0xff;
  627. base_pwr = ((fft_summary_A >> 14) & 0x1ff);
  628. total_gain_info = ((fft_summary_A >> 23) & 0x1ff);
  629. fft_chn_idx = ((fft_summary_A >> 12) & 0x3);
  630. peak_inx = fft_summary_A & 0xfff;
  631. if (peak_inx > 2047)
  632. peak_inx = peak_inx - 4096;
  633. avgpwr_db = ((fft_summary_B >> 18) & 0xff);
  634. peak_mag = ((fft_summary_B >> 8) & 0x3ff);
  635. spectral_debug("Header A = 0x%x Header B = 0x%x",
  636. phdr->hdr_a, phdr->hdr_b);
  637. 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",
  638. base_pwr, total_gain_info, relpwr_db, num_str_bins_ib,
  639. fft_chn_idx, peak_inx, avgpwr_db, peak_mag);
  640. if (is_160_format) {
  641. segid = fft_summary_C & 0x1;
  642. spectral_debug("Segment ID: %hhu", segid);
  643. }
  644. spectral_debug("FFT bins:");
  645. for (i = 0; i < (tlvlen - 8 - segid_skiplen); i++) {
  646. fft_mag = ((uint8_t *)ptlv)[12 + segid_skiplen + i];
  647. spectral_debug("%d %d, ", i, fft_mag);
  648. }
  649. spectral_debug("\n");
  650. return 0;
  651. }
  652. #ifdef SPECTRAL_DEBUG_SAMP_MSG
  653. /**
  654. * target_if_spectral_log_SAMP_param() - Log SAMP parameters
  655. * @params: Reference to target_if_samp_msg_params
  656. *
  657. * API to log spectral SAMP message parameters
  658. *
  659. * Return: None
  660. */
  661. static void
  662. target_if_spectral_log_SAMP_param(struct target_if_samp_msg_params *params)
  663. {
  664. target_if_dbg_print_samp_param(params);
  665. }
  666. #else
  667. static void
  668. target_if_spectral_log_SAMP_param(struct target_if_samp_msg_params *params)
  669. {
  670. }
  671. #endif
  672. int
  673. target_if_process_phyerr_gen2(struct target_if_spectral *spectral,
  674. uint8_t *data,
  675. uint32_t datalen,
  676. struct target_if_spectral_rfqual_info *p_rfqual,
  677. struct target_if_spectral_chan_info *p_chaninfo,
  678. uint64_t tsf64,
  679. struct target_if_spectral_acs_stats *acs_stats)
  680. {
  681. /*
  682. * XXX : The classifier do not use all the members of the SAMP
  683. * message data format.
  684. * The classifier only depends upon the following parameters
  685. *
  686. * 1. Frequency (freq, msg->freq)
  687. * 2. Spectral RSSI (spectral_rssi,
  688. * msg->samp_data.spectral_rssi)
  689. * 3. Bin Power Count (bin_pwr_count,
  690. * msg->samp_data.bin_pwr_count)
  691. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  692. * 5. Spectral Timestamp (spectral_tstamp,
  693. * msg->samp_data.spectral_tstamp)
  694. * 6. MAC Address (macaddr, msg->macaddr)
  695. *
  696. * This function prepares the params structure and populates it
  697. * with
  698. * relevant values, this is in turn passed to
  699. * spectral_create_samp_msg()
  700. * to prepare fully formatted Spectral SAMP message
  701. *
  702. * XXX : Need to verify
  703. * 1. Order of FFT bin values
  704. *
  705. */
  706. struct target_if_samp_msg_params params;
  707. struct spectral_search_fft_info_gen2 search_fft_info;
  708. struct spectral_search_fft_info_gen2 *p_sfft = &search_fft_info;
  709. struct spectral_search_fft_info_gen2 search_fft_info_sec80;
  710. struct spectral_search_fft_info_gen2 *p_sfft_sec80 =
  711. &search_fft_info_sec80;
  712. uint32_t segid_skiplen = 0;
  713. int8_t rssi_up = 0;
  714. int8_t rssi_low = 0;
  715. int8_t chn_idx_highest_enabled = 0;
  716. int8_t chn_idx_lowest_enabled = 0;
  717. uint8_t control_rssi = 0;
  718. uint8_t extension_rssi = 0;
  719. uint8_t combined_rssi = 0;
  720. uint32_t tstamp = 0;
  721. struct target_if_spectral_ops *p_sops =
  722. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  723. struct spectral_phyerr_tlv_gen2 *ptlv =
  724. (struct spectral_phyerr_tlv_gen2 *)data;
  725. struct spectral_phyerr_tlv_gen2 *ptlv_sec80 = NULL;
  726. struct spectral_phyerr_fft_gen2 *pfft = NULL;
  727. struct spectral_phyerr_fft_gen2 *pfft_sec80 = NULL;
  728. uint8_t segid = 0;
  729. uint8_t segid_sec80 = 0;
  730. enum phy_ch_width ch_width =
  731. spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  732. if (spectral->is_160_format)
  733. segid_skiplen = sizeof(SPECTRAL_SEGID_INFO);
  734. pfft = (struct spectral_phyerr_fft_gen2 *)(
  735. data +
  736. sizeof(struct spectral_phyerr_tlv_gen2) +
  737. sizeof(struct spectral_phyerr_hdr_gen2) +
  738. segid_skiplen);
  739. /*
  740. * XXX Extend SPECTRAL_DPRINTK() to use spectral_debug_level,
  741. * and use this facility inside spectral_dump_phyerr_data()
  742. * and supporting functions.
  743. */
  744. if (spectral_debug_level & DEBUG_SPECTRAL2)
  745. target_if_spectral_dump_phyerr_data_gen2(
  746. data, datalen,
  747. spectral->is_160_format);
  748. if (spectral_debug_level & DEBUG_SPECTRAL4) {
  749. target_if_spectral_dump_phyerr_data_gen2(
  750. data, datalen,
  751. spectral->is_160_format);
  752. spectral_debug_level = DEBUG_SPECTRAL;
  753. }
  754. if (ptlv->signature != SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  755. /*
  756. * EV# 118023: We tentatively disable the below print
  757. * and provide stats instead.
  758. */
  759. spectral->diag_stats.spectral_mismatch++;
  760. return -EPERM;
  761. }
  762. OS_MEMZERO(&params, sizeof(params));
  763. /* Gen 2 only supports normal Spectral scan currently */
  764. params.smode = SPECTRAL_SCAN_MODE_NORMAL;
  765. if (ptlv->tag == TLV_TAG_SEARCH_FFT_REPORT_GEN2) {
  766. if (spectral->is_160_format) {
  767. segid = *((SPECTRAL_SEGID_INFO *)(
  768. (uint8_t *)ptlv +
  769. sizeof(struct spectral_phyerr_tlv_gen2) +
  770. sizeof(struct spectral_phyerr_hdr_gen2)));
  771. if (segid != 0) {
  772. struct spectral_diag_stats *p_diag_stats =
  773. &spectral->diag_stats;
  774. p_diag_stats->spectral_vhtseg1id_mismatch++;
  775. return -EPERM;
  776. }
  777. }
  778. target_if_process_sfft_report_gen2(ptlv, ptlv->length,
  779. &search_fft_info);
  780. tstamp = p_sops->get_tsf64(spectral) & SPECTRAL_TSMASK;
  781. combined_rssi = p_rfqual->rssi_comb;
  782. if (spectral->upper_is_control)
  783. rssi_up = control_rssi;
  784. else
  785. rssi_up = extension_rssi;
  786. if (spectral->lower_is_control)
  787. rssi_low = control_rssi;
  788. else
  789. rssi_low = extension_rssi;
  790. params.rssi = p_rfqual->rssi_comb;
  791. params.lower_rssi = rssi_low;
  792. params.upper_rssi = rssi_up;
  793. if (spectral->sc_spectral_noise_pwr_cal) {
  794. params.chain_ctl_rssi[0] =
  795. p_rfqual->pc_rssi_info[0].rssi_pri20;
  796. params.chain_ctl_rssi[1] =
  797. p_rfqual->pc_rssi_info[1].rssi_pri20;
  798. params.chain_ctl_rssi[2] =
  799. p_rfqual->pc_rssi_info[2].rssi_pri20;
  800. params.chain_ext_rssi[0] =
  801. p_rfqual->pc_rssi_info[0].rssi_sec20;
  802. params.chain_ext_rssi[1] =
  803. p_rfqual->pc_rssi_info[1].rssi_sec20;
  804. params.chain_ext_rssi[2] =
  805. p_rfqual->pc_rssi_info[2].rssi_sec20;
  806. }
  807. /*
  808. * XXX : This actually depends on the programmed chain mask
  809. * This value decides the per-chain enable mask to select
  810. * the input ADC for search FTT.
  811. * For modes upto VHT80, if more than one chain is
  812. * enabled, the max valid chain
  813. * is used. LSB corresponds to chain zero.
  814. * For VHT80_80 and VHT160, the lowest enabled chain is
  815. * used for primary
  816. * detection and highest enabled chain is used for
  817. * secondary detection.
  818. *
  819. * XXX : The current algorithm do not use these control and
  820. * extension channel
  821. * Instead, it just relies on the combined RSSI values
  822. * only.
  823. * For fool-proof detection algorithm, we should take
  824. * these RSSI values in to account.
  825. * This is marked for future enhancements.
  826. */
  827. chn_idx_highest_enabled =
  828. ((spectral->params[params.smode].ss_chn_mask & 0x8) ? 3 :
  829. (spectral->params[params.smode].ss_chn_mask & 0x4) ? 2 :
  830. (spectral->params[params.smode].ss_chn_mask & 0x2) ? 1 : 0);
  831. chn_idx_lowest_enabled =
  832. ((spectral->params[params.smode].ss_chn_mask & 0x1) ? 0 :
  833. (spectral->params[params.smode].ss_chn_mask & 0x2) ? 1 :
  834. (spectral->params[params.smode].ss_chn_mask & 0x4) ? 2 : 3);
  835. control_rssi = (uint8_t)
  836. p_rfqual->pc_rssi_info[chn_idx_highest_enabled].rssi_pri20;
  837. extension_rssi = (uint8_t)
  838. p_rfqual->pc_rssi_info[chn_idx_highest_enabled].rssi_sec20;
  839. params.bwinfo = 0;
  840. params.tstamp = 0;
  841. params.max_mag = p_sfft->peak_mag;
  842. params.max_index = p_sfft->peak_inx;
  843. params.max_exp = 0;
  844. params.peak = 0;
  845. params.bin_pwr_data = (uint8_t *)pfft;
  846. params.freq = p_sops->get_current_channel(spectral,
  847. params.smode);
  848. params.freq_loading = 0;
  849. params.interf_list.count = 0;
  850. params.max_lower_index = 0;
  851. params.max_upper_index = 0;
  852. params.nb_lower = 0;
  853. params.nb_upper = 0;
  854. /*
  855. * For modes upto VHT80, the noise floor is populated with the
  856. * one corresponding
  857. * to the highest enabled antenna chain
  858. */
  859. params.noise_floor =
  860. p_rfqual->noise_floor[chn_idx_highest_enabled];
  861. params.datalen = ptlv->length;
  862. params.pwr_count = ptlv->length -
  863. sizeof(struct spectral_phyerr_hdr_gen2) - segid_skiplen;
  864. params.tstamp = (tsf64 & SPECTRAL_TSMASK);
  865. acs_stats->ctrl_nf = params.noise_floor;
  866. acs_stats->ext_nf = params.noise_floor;
  867. acs_stats->nfc_ctl_rssi = control_rssi;
  868. acs_stats->nfc_ext_rssi = extension_rssi;
  869. if (spectral->is_160_format &&
  870. is_ch_width_160_or_80p80(ch_width)) {
  871. /*
  872. * We expect to see one more Search FFT report, and it
  873. * should be equal in size to the current one.
  874. */
  875. if (datalen < (
  876. 2 * (
  877. sizeof(struct spectral_phyerr_tlv_gen2) +
  878. ptlv->length))) {
  879. struct spectral_diag_stats *p_diag_stats =
  880. &spectral->diag_stats;
  881. p_diag_stats->spectral_sec80_sfft_insufflen++;
  882. return -EPERM;
  883. }
  884. ptlv_sec80 = (struct spectral_phyerr_tlv_gen2 *)(
  885. data +
  886. sizeof(struct spectral_phyerr_tlv_gen2) +
  887. ptlv->length);
  888. if (ptlv_sec80->signature !=
  889. SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  890. spectral->diag_stats.spectral_mismatch++;
  891. return -EPERM;
  892. }
  893. if (ptlv_sec80->tag != TLV_TAG_SEARCH_FFT_REPORT_GEN2) {
  894. spectral->diag_stats.spectral_no_sec80_sfft++;
  895. return -EPERM;
  896. }
  897. segid_sec80 = *((SPECTRAL_SEGID_INFO *)(
  898. (uint8_t *)ptlv_sec80 +
  899. sizeof(struct spectral_phyerr_tlv_gen2) +
  900. sizeof(struct spectral_phyerr_hdr_gen2)));
  901. if (segid_sec80 != 1) {
  902. struct spectral_diag_stats *p_diag_stats =
  903. &spectral->diag_stats;
  904. p_diag_stats->spectral_vhtseg2id_mismatch++;
  905. return -EPERM;
  906. }
  907. params.vhtop_ch_freq_seg1 = p_chaninfo->center_freq1;
  908. params.vhtop_ch_freq_seg2 = p_chaninfo->center_freq2;
  909. target_if_process_sfft_report_gen2(
  910. ptlv_sec80,
  911. ptlv_sec80->length,
  912. &search_fft_info_sec80);
  913. pfft_sec80 = (struct spectral_phyerr_fft_gen2 *)(
  914. ((uint8_t *)ptlv_sec80) +
  915. sizeof(struct spectral_phyerr_tlv_gen2) +
  916. sizeof(struct spectral_phyerr_hdr_gen2) +
  917. segid_skiplen);
  918. /* XXX: Confirm. TBD at SoD. */
  919. params.rssi_sec80 = p_rfqual->rssi_comb;
  920. if (spectral->is_sec80_rssi_war_required)
  921. params.rssi_sec80 =
  922. target_if_get_combrssi_sec80_seg_gen2
  923. (spectral, &search_fft_info_sec80);
  924. /* XXX: Determine dynamically. TBD at SoD. */
  925. /*
  926. * For VHT80_80/VHT160, the noise floor for primary
  927. * 80MHz segment is populated with the
  928. * lowest enabled antenna chain and the noise floor for
  929. * secondary 80MHz segment is populated
  930. * with the highest enabled antenna chain
  931. */
  932. params.noise_floor_sec80 =
  933. p_rfqual->noise_floor[chn_idx_highest_enabled];
  934. params.noise_floor =
  935. p_rfqual->noise_floor[chn_idx_lowest_enabled];
  936. params.max_mag_sec80 = p_sfft_sec80->peak_mag;
  937. params.max_index_sec80 = p_sfft_sec80->peak_inx;
  938. /* XXX Does this definition of datalen *still hold? */
  939. params.datalen_sec80 = ptlv_sec80->length;
  940. params.pwr_count_sec80 =
  941. ptlv_sec80->length -
  942. sizeof(struct spectral_phyerr_hdr_gen2) -
  943. segid_skiplen;
  944. params.bin_pwr_data_sec80 = (uint8_t *)pfft_sec80;
  945. }
  946. qdf_mem_copy(&params.classifier_params,
  947. &spectral->classifier_params,
  948. sizeof(struct spectral_classifier_params));
  949. target_if_spectral_log_SAMP_param(&params);
  950. target_if_spectral_create_samp_msg(spectral, &params);
  951. }
  952. return 0;
  953. }
  954. int
  955. target_if_spectral_dump_hdr_gen2(struct spectral_phyerr_hdr_gen2 *phdr)
  956. {
  957. uint32_t a = 0;
  958. uint32_t b = 0;
  959. qdf_mem_copy(&a, (uint8_t *)phdr, sizeof(int));
  960. qdf_mem_copy(&b,
  961. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  962. sizeof(int));
  963. spectral_debug("SPECTRAL : HEADER A 0x%x (%d)", a, a);
  964. spectral_debug("SPECTRAL : HEADER B 0x%x (%d)", b, b);
  965. return 0;
  966. }
  967. int8_t
  968. target_if_get_combrssi_sec80_seg_gen2(
  969. struct target_if_spectral *spectral,
  970. struct spectral_search_fft_info_gen2 *p_sfft_sec80)
  971. {
  972. uint32_t avgpwr_db = 0;
  973. uint32_t total_gain_db = 0;
  974. uint32_t offset = 0;
  975. int8_t comb_rssi = 0;
  976. /* Obtain required parameters for algorithm from search FFT report */
  977. avgpwr_db = p_sfft_sec80->avgpwr_db;
  978. total_gain_db = p_sfft_sec80->total_gain_info;
  979. /* Calculate offset */
  980. offset = target_if_get_offset_swar_sec80(
  981. spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL]);
  982. /* Calculate RSSI */
  983. comb_rssi = ((avgpwr_db - total_gain_db) + offset);
  984. return comb_rssi;
  985. }
  986. int
  987. target_if_spectral_dump_tlv_gen2(
  988. struct spectral_phyerr_tlv_gen2 *ptlv, bool is_160_format)
  989. {
  990. int ret = 0;
  991. /*
  992. * TODO : Do not delete the following print
  993. * The scripts used to validate Spectral depend on this Print
  994. */
  995. spectral_debug("SPECTRAL : TLV Length is 0x%x (%d)",
  996. ptlv->length, ptlv->length);
  997. switch (ptlv->tag) {
  998. case TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2:
  999. ret =
  1000. target_if_dump_summary_report_gen2(
  1001. ptlv, ptlv->length, is_160_format);
  1002. break;
  1003. case TLV_TAG_SEARCH_FFT_REPORT_GEN2:
  1004. ret =
  1005. target_if_dump_sfft_report_gen2(ptlv, ptlv->length,
  1006. is_160_format);
  1007. break;
  1008. case TLV_TAG_ADC_REPORT_GEN2:
  1009. ret = target_if_dump_adc_report_gen2(ptlv, ptlv->length);
  1010. break;
  1011. default:
  1012. spectral_warn("INVALID TLV");
  1013. ret = -1;
  1014. break;
  1015. }
  1016. return ret;
  1017. }
  1018. int
  1019. target_if_spectral_dump_phyerr_data_gen2(uint8_t *data, uint32_t datalen,
  1020. bool is_160_format)
  1021. {
  1022. struct spectral_phyerr_tlv_gen2 *ptlv = NULL;
  1023. uint32_t bytes_processed = 0;
  1024. uint32_t bytes_remaining = datalen;
  1025. uint32_t curr_tlv_complete_size = 0;
  1026. if (datalen < sizeof(struct spectral_phyerr_tlv_gen2)) {
  1027. spectral_err("Total PHY error data length %u too short to contain any TLVs",
  1028. datalen);
  1029. return -EPERM;
  1030. }
  1031. while (bytes_processed < datalen) {
  1032. if (bytes_remaining < sizeof(struct spectral_phyerr_tlv_gen2)) {
  1033. spectral_err("Remaining PHY error data length %u too short to contain a TLV",
  1034. bytes_remaining);
  1035. return -EPERM;
  1036. }
  1037. ptlv = (struct spectral_phyerr_tlv_gen2 *)(data +
  1038. bytes_processed);
  1039. if (ptlv->signature != SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  1040. spectral_err("Invalid signature 0x%x!",
  1041. ptlv->signature);
  1042. return -EPERM;
  1043. }
  1044. curr_tlv_complete_size =
  1045. sizeof(struct spectral_phyerr_tlv_gen2) +
  1046. ptlv->length;
  1047. if (curr_tlv_complete_size > bytes_remaining) {
  1048. spectral_err("TLV size %d greater than number of bytes remaining %d",
  1049. curr_tlv_complete_size, bytes_remaining);
  1050. return -EPERM;
  1051. }
  1052. if (target_if_spectral_dump_tlv_gen2(ptlv, is_160_format) == -1)
  1053. return -EPERM;
  1054. bytes_processed += curr_tlv_complete_size;
  1055. bytes_remaining = datalen - bytes_processed;
  1056. }
  1057. return 0;
  1058. }
  1059. #ifdef DIRECT_BUF_RX_ENABLE
  1060. /**
  1061. * target_if_get_spectral_mode() - Get Spectral scan mode corresponding to a
  1062. * detector id
  1063. * @detector_id: detector id in the Spectral report
  1064. * @rparams: pointer to report params object
  1065. *
  1066. * Helper API to get Spectral scan mode from the detector ID. This mapping is
  1067. * target specific.
  1068. *
  1069. * Return: Spectral scan mode
  1070. */
  1071. static enum spectral_scan_mode
  1072. target_if_get_spectral_mode(enum spectral_detector_id detector_id,
  1073. struct spectral_report_params *rparams)
  1074. {
  1075. if (detector_id >= SPECTRAL_DETECTOR_ID_MAX) {
  1076. spectral_err_rl("Invalid detector id %d", detector_id);
  1077. return SPECTRAL_SCAN_MODE_INVALID;
  1078. }
  1079. return rparams->detid_mode_table[detector_id];
  1080. }
  1081. /**
  1082. * target_if_spectral_get_bin_count_after_len_adj() - Get number of FFT bins in
  1083. * Spectral FFT report
  1084. * @fft_bin_len: FFT bin length reported by target
  1085. * @rpt_mode: Spectral report mode
  1086. * @swar: Spectral FFT bin length adjustments SWAR parameters
  1087. * @fft_bin_size: Size of one FFT bin in bytes
  1088. *
  1089. * Get actual number of FFT bins in the FFT report after adjusting the length
  1090. * by applying the SWARs for getting correct length.
  1091. *
  1092. * Return: FFT bin count
  1093. */
  1094. static size_t
  1095. target_if_spectral_get_bin_count_after_len_adj(
  1096. size_t fft_bin_len, uint8_t rpt_mode,
  1097. struct spectral_fft_bin_len_adj_swar *swar,
  1098. size_t *fft_bin_size)
  1099. {
  1100. size_t fft_bin_count = fft_bin_len;
  1101. if (rpt_mode == 1 && swar->null_fftbin_adj) {
  1102. /*
  1103. * No FFT bins are expected. Explicitly set FFT bin
  1104. * count to 0.
  1105. */
  1106. fft_bin_count = 0;
  1107. *fft_bin_size = 0;
  1108. } else {
  1109. /*
  1110. * Divide fft bin length by appropriate factor depending
  1111. * on the value of fftbin_size_war.
  1112. */
  1113. switch (swar->fftbin_size_war) {
  1114. case SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE:
  1115. fft_bin_count >>= 2;
  1116. *fft_bin_size = 4;
  1117. break;
  1118. case SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE:
  1119. fft_bin_count >>= 1;
  1120. *fft_bin_size = 2;
  1121. /* Ideally we should be dividing fft bin length
  1122. * by 2. Due to a HW bug, actual length is two
  1123. * times the expected length.
  1124. */
  1125. if (swar->packmode_fftbin_size_adj)
  1126. fft_bin_count >>= 1;
  1127. break;
  1128. case SPECTRAL_FFTBIN_SIZE_NO_WAR:
  1129. *fft_bin_size = 1;
  1130. /* No length adjustment */
  1131. break;
  1132. default:
  1133. qdf_assert_always(0);
  1134. }
  1135. if (rpt_mode == 2 && swar->inband_fftbin_size_adj)
  1136. fft_bin_count >>= 1;
  1137. }
  1138. return fft_bin_count;
  1139. }
  1140. #ifndef OPTIMIZED_SAMP_MESSAGE
  1141. /**
  1142. * target_if_process_sfft_report_gen3() - Process Search FFT Report for gen3
  1143. * @p_fft_report: Pointer to fft report
  1144. * @p_sfft: Pointer to search fft report
  1145. * @rparams: pointer to report params object
  1146. *
  1147. * Process Search FFT Report for gen3
  1148. *
  1149. * Return: Success/Failure
  1150. */
  1151. static int
  1152. target_if_process_sfft_report_gen3(
  1153. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  1154. struct spectral_search_fft_info_gen3 *p_sfft,
  1155. struct spectral_report_params *rparams)
  1156. {
  1157. int32_t peak_sidx = 0;
  1158. int32_t peak_mag;
  1159. qdf_assert_always(p_fft_report);
  1160. qdf_assert_always(p_sfft);
  1161. qdf_assert_always(rparams);
  1162. /*
  1163. * For simplicity, everything is defined as uint32_t (except one).
  1164. * Proper code will later use the right sizes.
  1165. */
  1166. /*
  1167. * For easy comparision between MDK team and OS team, the MDK script
  1168. * variable names have been used
  1169. */
  1170. /* Populate the Search FFT Info */
  1171. p_sfft->timestamp = p_fft_report->fft_timestamp;
  1172. p_sfft->fft_detector_id = get_bitfield(p_fft_report->hdr_a,
  1173. 2, 0);
  1174. p_sfft->fft_num = get_bitfield(p_fft_report->hdr_a, 3, 2);
  1175. switch (rparams->version) {
  1176. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1177. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  1178. 12, 5);
  1179. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 17);
  1180. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_a, 3, 28);
  1181. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  1182. 9, 0);
  1183. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  1184. 8, 9);
  1185. break;
  1186. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1187. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  1188. 14, 5);
  1189. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 19);
  1190. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_b, 3, 0);
  1191. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  1192. 9, 3);
  1193. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  1194. 8, 12);
  1195. break;
  1196. default:
  1197. qdf_assert_always(0);
  1198. }
  1199. p_sfft->fft_peak_sidx = unsigned_to_signed(peak_sidx, 11);
  1200. p_sfft->fft_num_str_bins_ib = get_bitfield(p_fft_report->hdr_c,
  1201. 8, 0);
  1202. peak_mag = get_bitfield(p_fft_report->hdr_c, 10, 8);
  1203. p_sfft->fft_peak_mag = unsigned_to_signed(peak_mag, 10);
  1204. p_sfft->fft_avgpwr_db = get_bitfield(p_fft_report->hdr_c,
  1205. 7, 18);
  1206. p_sfft->fft_relpwr_db = get_bitfield(p_fft_report->hdr_c,
  1207. 7, 25);
  1208. return 0;
  1209. }
  1210. #endif
  1211. /**
  1212. * target_if_dump_fft_report_gen3() - Dump FFT Report for gen3
  1213. * @spectral: Pointer to Spectral object
  1214. * @smode: Spectral scan mode
  1215. * @p_fft_report: Pointer to fft report
  1216. * @p_sfft: Pointer to search fft report
  1217. *
  1218. * Dump FFT Report for gen3
  1219. *
  1220. * Return: void
  1221. */
  1222. static void
  1223. target_if_dump_fft_report_gen3(struct target_if_spectral *spectral,
  1224. enum spectral_scan_mode smode,
  1225. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  1226. struct spectral_search_fft_info_gen3 *p_sfft)
  1227. {
  1228. size_t fft_hdr_length;
  1229. size_t report_len;
  1230. size_t fft_bin_len;
  1231. size_t fft_bin_count;
  1232. size_t fft_bin_size;
  1233. size_t fft_bin_len_inband_tfer = 0;
  1234. uint8_t *fft_bin_buf = NULL;
  1235. size_t fft_bin_buf_size;
  1236. uint8_t tag, signature;
  1237. qdf_assert_always(spectral);
  1238. /* There won't be FFT report/bins in report mode 0, so return */
  1239. if (!spectral->params[smode].ss_rpt_mode)
  1240. return;
  1241. fft_hdr_length = get_bitfield(
  1242. p_fft_report->fft_hdr_lts,
  1243. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  1244. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  1245. tag = get_bitfield(p_fft_report->fft_hdr_lts,
  1246. SPECTRAL_REPORT_LTS_TAG_SIZE_GEN3,
  1247. SPECTRAL_REPORT_LTS_TAG_POS_GEN3);
  1248. signature = get_bitfield(p_fft_report->fft_hdr_lts,
  1249. SPECTRAL_REPORT_LTS_SIGNATURE_SIZE_GEN3,
  1250. SPECTRAL_REPORT_LTS_SIGNATURE_POS_GEN3);
  1251. report_len = (fft_hdr_length + 8);
  1252. fft_bin_len = fft_hdr_length - spectral->rparams.fft_report_hdr_len;
  1253. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  1254. fft_bin_len,
  1255. spectral->params[smode].ss_rpt_mode,
  1256. &spectral->len_adj_swar, &fft_bin_size);
  1257. if ((spectral->params[smode].ss_rpt_mode == 2) &&
  1258. spectral->len_adj_swar.inband_fftbin_size_adj)
  1259. fft_bin_len_inband_tfer = fft_bin_len >> 1;
  1260. spectral_debug("Spectral FFT Report");
  1261. spectral_debug("fft_timestamp = 0x%x", p_fft_report->fft_timestamp);
  1262. spectral_debug("fft_hdr_length = %zu(32 bit words)",
  1263. fft_hdr_length >> 2);
  1264. spectral_debug("fft_hdr_tag = 0x%x", tag);
  1265. spectral_debug("fft_hdr_sig = 0x%x", signature);
  1266. spectral_debug("Length field in search fft report is %zu(0x%zx) bytes",
  1267. fft_hdr_length, fft_hdr_length);
  1268. spectral_debug("Total length of search fft report is %zu(0x%zx) bytes",
  1269. report_len, report_len);
  1270. spectral_debug("Target reported fftbins in report is %zu(0x%zx)",
  1271. fft_bin_len, fft_bin_len);
  1272. if ((spectral->params[smode].ss_rpt_mode == 1) &&
  1273. spectral->len_adj_swar.null_fftbin_adj)
  1274. spectral_debug("WAR: Considering number of FFT bins as 0");
  1275. else if ((spectral->params[smode].ss_rpt_mode == 2) &&
  1276. spectral->len_adj_swar.inband_fftbin_size_adj) {
  1277. spectral_debug("FW fftbins actually transferred (in-band report mode) %zu(0x%zx)",
  1278. fft_bin_len_inband_tfer,
  1279. fft_bin_len_inband_tfer);
  1280. }
  1281. spectral_debug("Actual number of fftbins in report is %zu(0x%zx)",
  1282. fft_bin_count, fft_bin_count);
  1283. spectral_debug("fft_detector_id = %u", p_sfft->fft_detector_id);
  1284. spectral_debug("fft_num = %u", p_sfft->fft_num);
  1285. spectral_debug("fft_radar_check = %u", p_sfft->fft_radar_check);
  1286. spectral_debug("fft_peak_sidx = %d", p_sfft->fft_peak_sidx);
  1287. spectral_debug("fft_chn_idx = %u", p_sfft->fft_chn_idx);
  1288. spectral_debug("fft_base_pwr_db = %u", p_sfft->fft_base_pwr_db);
  1289. spectral_debug("fft_total_gain_db = %u", p_sfft->fft_total_gain_db);
  1290. spectral_debug("fft_num_str_bins_ib = %u", p_sfft->fft_num_str_bins_ib);
  1291. spectral_debug("fft_peak_mag = %d", p_sfft->fft_peak_mag);
  1292. spectral_debug("fft_avgpwr_db = %u", p_sfft->fft_avgpwr_db);
  1293. spectral_debug("fft_relpwr_db = %u", p_sfft->fft_relpwr_db);
  1294. fft_bin_buf_size = fft_bin_count;
  1295. if (fft_bin_count > 0) {
  1296. int idx;
  1297. if (spectral->len_adj_swar.fftbin_size_war ==
  1298. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
  1299. uint32_t *binptr_32 = (uint32_t *)&p_fft_report->buf;
  1300. uint16_t *fft_bin_buf_16 = NULL;
  1301. /* Useful width of FFT bin is 10 bits, increasing it to
  1302. * byte boundary makes it 2 bytes. Hence, buffer to be
  1303. * allocated should be of size fft_bin_count
  1304. * multiplied by 2.
  1305. */
  1306. fft_bin_buf_size <<= 1;
  1307. fft_bin_buf_16 = (uint16_t *)qdf_mem_malloc(
  1308. fft_bin_buf_size);
  1309. if (!fft_bin_buf_16) {
  1310. spectral_err("Failed to allocate memory");
  1311. return;
  1312. }
  1313. for (idx = 0; idx < fft_bin_count; idx++)
  1314. fft_bin_buf_16[idx] =
  1315. *((uint16_t *)binptr_32++);
  1316. fft_bin_buf = (uint8_t *)fft_bin_buf_16;
  1317. } else if (spectral->len_adj_swar.fftbin_size_war ==
  1318. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  1319. uint16_t *binptr_16 = (uint16_t *)&p_fft_report->buf;
  1320. uint16_t *fft_bin_buf_16 = NULL;
  1321. /* Useful width of FFT bin is 10 bits, increasing it to
  1322. * byte boundary makes it 2 bytes. Hence, buffer to be
  1323. * allocated should be of size fft_bin_count
  1324. * multiplied by 2.
  1325. */
  1326. fft_bin_buf_size <<= 1;
  1327. fft_bin_buf_16 = (uint16_t *)qdf_mem_malloc(
  1328. fft_bin_buf_size);
  1329. if (!fft_bin_buf_16) {
  1330. spectral_err("Failed to allocate memory");
  1331. return;
  1332. }
  1333. for (idx = 0; idx < fft_bin_count; idx++)
  1334. fft_bin_buf_16[idx] = *(binptr_16++);
  1335. fft_bin_buf = (uint8_t *)fft_bin_buf_16;
  1336. } else {
  1337. fft_bin_buf = (uint8_t *)&p_fft_report->buf;
  1338. }
  1339. spectral_debug("FFT bin buffer size = %zu", fft_bin_buf_size);
  1340. spectral_debug("FFT bins:");
  1341. target_if_spectral_hexdump(fft_bin_buf, fft_bin_buf_size);
  1342. if ((spectral->len_adj_swar.fftbin_size_war !=
  1343. SPECTRAL_FFTBIN_SIZE_NO_WAR) && fft_bin_buf)
  1344. qdf_mem_free(fft_bin_buf);
  1345. }
  1346. }
  1347. #endif
  1348. #ifdef OPTIMIZED_SAMP_MESSAGE
  1349. QDF_STATUS
  1350. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  1351. enum spectral_scan_mode smode,
  1352. uint8_t detector_id) {
  1353. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1354. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1355. spectral_err_rl("Invalid Spectral mode %d", smode);
  1356. return QDF_STATUS_E_INVAL;
  1357. }
  1358. if (!is_ch_width_160_or_80p80(spectral->report_info[smode].sscan_bw)) {
  1359. spectral_err_rl("Scan BW %d is not 160/80p80 for mode %d",
  1360. spectral->report_info[smode].sscan_bw, smode);
  1361. return QDF_STATUS_E_FAILURE;
  1362. }
  1363. switch (spectral->state_160mhz_delivery[smode]) {
  1364. case SPECTRAL_REPORT_WAIT_PRIMARY80:
  1365. if (detector_id == SPECTRAL_DETECTOR_ID_0)
  1366. spectral->state_160mhz_delivery[smode] =
  1367. SPECTRAL_REPORT_WAIT_SECONDARY80;
  1368. else {
  1369. status = QDF_STATUS_E_FAILURE;
  1370. spectral->diag_stats.spectral_vhtseg1id_mismatch++;
  1371. }
  1372. break;
  1373. case SPECTRAL_REPORT_WAIT_SECONDARY80:
  1374. if (detector_id == SPECTRAL_DETECTOR_ID_1)
  1375. spectral->state_160mhz_delivery[smode] =
  1376. SPECTRAL_REPORT_WAIT_PRIMARY80;
  1377. else {
  1378. spectral->state_160mhz_delivery[smode] =
  1379. SPECTRAL_REPORT_WAIT_PRIMARY80;
  1380. status = QDF_STATUS_E_FAILURE;
  1381. spectral->diag_stats.spectral_vhtseg2id_mismatch++;
  1382. }
  1383. break;
  1384. default:
  1385. break;
  1386. }
  1387. return status;
  1388. }
  1389. #else
  1390. QDF_STATUS
  1391. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  1392. enum spectral_scan_mode smode,
  1393. uint8_t detector_id) {
  1394. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1395. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1396. spectral_err_rl("Invalid Spectral mode %d", smode);
  1397. return QDF_STATUS_E_INVAL;
  1398. }
  1399. if (!is_ch_width_160_or_80p80(spectral->ch_width[smode])) {
  1400. spectral_err_rl("Scan BW %d is not 160/80p80 for mode %d",
  1401. spectral->ch_width[smode], smode);
  1402. return QDF_STATUS_E_FAILURE;
  1403. }
  1404. switch (spectral->state_160mhz_delivery[smode]) {
  1405. case SPECTRAL_REPORT_WAIT_PRIMARY80:
  1406. if (detector_id == SPECTRAL_DETECTOR_ID_0)
  1407. spectral->state_160mhz_delivery[smode] =
  1408. SPECTRAL_REPORT_RX_PRIMARY80;
  1409. else {
  1410. status = QDF_STATUS_E_FAILURE;
  1411. spectral->diag_stats.spectral_vhtseg1id_mismatch++;
  1412. }
  1413. break;
  1414. case SPECTRAL_REPORT_WAIT_SECONDARY80:
  1415. if (detector_id == SPECTRAL_DETECTOR_ID_1)
  1416. spectral->state_160mhz_delivery[smode] =
  1417. SPECTRAL_REPORT_RX_SECONDARY80;
  1418. else {
  1419. spectral->state_160mhz_delivery[smode] =
  1420. SPECTRAL_REPORT_WAIT_PRIMARY80;
  1421. status = QDF_STATUS_E_FAILURE;
  1422. spectral->diag_stats.spectral_vhtseg2id_mismatch++;
  1423. }
  1424. break;
  1425. case SPECTRAL_REPORT_RX_SECONDARY80:
  1426. /* We don't care about detector id in this state. */
  1427. reset_160mhz_delivery_state_machine(spectral, smode);
  1428. break;
  1429. case SPECTRAL_REPORT_RX_PRIMARY80:
  1430. /* We don't care about detector id in this state */
  1431. spectral->state_160mhz_delivery[smode] =
  1432. SPECTRAL_REPORT_WAIT_SECONDARY80;
  1433. break;
  1434. default:
  1435. break;
  1436. }
  1437. return status;
  1438. }
  1439. #endif /* OPTIMIZED_SAMP_MESSAGE */
  1440. #ifdef DIRECT_BUF_RX_ENABLE
  1441. /**
  1442. * target_if_get_detector_id_sscan_summary_report_gen3() - Get Spectral detector
  1443. * ID from Spectral summary report
  1444. * @data: Pointer to Spectral summary report
  1445. *
  1446. * Return: Detector ID
  1447. */
  1448. static uint8_t
  1449. target_if_get_detector_id_sscan_summary_report_gen3(uint8_t *data) {
  1450. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  1451. uint8_t detector_id;
  1452. qdf_assert_always(data);
  1453. psscan_summary_report =
  1454. (struct spectral_sscan_summary_report_gen3 *)data;
  1455. detector_id = get_bitfield(
  1456. psscan_summary_report->hdr_a,
  1457. SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_SIZE_GEN3,
  1458. SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_POS_GEN3);
  1459. return detector_id;
  1460. }
  1461. #ifndef OPTIMIZED_SAMP_MESSAGE
  1462. /**
  1463. * target_if_consume_sscan_summary_report_gen3() - Consume Spectral summary
  1464. * report
  1465. * @data: Pointer to Spectral summary report
  1466. * @fields: Pointer to structure to be populated with extracted fields
  1467. * @rparams: Pointer to structure with Spectral report params
  1468. *
  1469. * Consume Spectral summary report for gen3
  1470. *
  1471. * Return: void
  1472. */
  1473. static void
  1474. target_if_consume_sscan_summary_report_gen3(
  1475. uint8_t *data,
  1476. struct sscan_report_fields_gen3 *fields,
  1477. struct spectral_report_params *rparams) {
  1478. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  1479. qdf_assert_always(data);
  1480. qdf_assert_always(fields);
  1481. qdf_assert_always(rparams);
  1482. psscan_summary_report =
  1483. (struct spectral_sscan_summary_report_gen3 *)data;
  1484. fields->sscan_agc_total_gain = get_bitfield(
  1485. psscan_summary_report->hdr_a,
  1486. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_SIZE_GEN3,
  1487. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_POS_GEN3);
  1488. fields->inband_pwr_db = get_bitfield(
  1489. psscan_summary_report->hdr_a,
  1490. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_SIZE_GEN3,
  1491. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_POS_GEN3);
  1492. fields->sscan_pri80 = get_bitfield(
  1493. psscan_summary_report->hdr_a,
  1494. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_SIZE_GEN3,
  1495. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_POS_GEN3);
  1496. switch (rparams->version) {
  1497. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1498. fields->sscan_gainchange = get_bitfield(
  1499. psscan_summary_report->hdr_b,
  1500. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_SIZE_GEN3_V1,
  1501. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_POS_GEN3_V1);
  1502. break;
  1503. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1504. fields->sscan_gainchange = get_bitfield(
  1505. psscan_summary_report->hdr_c,
  1506. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_SIZE_GEN3_V2,
  1507. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_POS_GEN3_V2);
  1508. break;
  1509. default:
  1510. qdf_assert_always(0);
  1511. }
  1512. }
  1513. #endif
  1514. /**
  1515. * target_if_verify_sig_and_tag_gen3() - Verify tag and signature
  1516. * of spectral report
  1517. * @spectral: Pointer to spectral object
  1518. * @data: Pointer to spectral summary report
  1519. * @exp_tag: iexpected tag value
  1520. *
  1521. * Process fft report for gen3
  1522. *
  1523. * Return: SUCCESS/FAILURE
  1524. */
  1525. static int
  1526. target_if_verify_sig_and_tag_gen3(struct target_if_spectral *spectral,
  1527. uint8_t *data, uint8_t exp_tag)
  1528. {
  1529. uint8_t tag = 0;
  1530. uint8_t signature = 0;
  1531. uint32_t lts;
  1532. lts = *((uint32_t *)(data + SPECTRAL_PHYERR_HDR_LTS_POS));
  1533. /* Peek into the data to figure out whether
  1534. * 1) Signature matches the expected value
  1535. * 2) What is inside the package (TAG ID is used for finding this)
  1536. */
  1537. tag = get_bitfield(lts,
  1538. SPECTRAL_REPORT_LTS_TAG_SIZE_GEN3,
  1539. SPECTRAL_REPORT_LTS_TAG_POS_GEN3);
  1540. signature = get_bitfield(lts,
  1541. SPECTRAL_REPORT_LTS_SIGNATURE_SIZE_GEN3,
  1542. SPECTRAL_REPORT_LTS_SIGNATURE_POS_GEN3);
  1543. if (signature != SPECTRAL_PHYERR_SIGNATURE_GEN3) {
  1544. spectral->diag_stats.spectral_mismatch++;
  1545. return -EINVAL;
  1546. }
  1547. if (tag != exp_tag) {
  1548. spectral->diag_stats.spectral_mismatch++;
  1549. return -EINVAL;
  1550. }
  1551. return 0;
  1552. }
  1553. static uint8_t
  1554. target_if_spectral_get_lowest_chn_idx(uint8_t chainmask)
  1555. {
  1556. uint8_t idx;
  1557. for (idx = 0; idx < DBR_MAX_CHAINS; idx++) {
  1558. if (chainmask & 0x1)
  1559. break;
  1560. chainmask >>= 1;
  1561. }
  1562. return idx;
  1563. }
  1564. #ifdef DIRECT_BUF_RX_DEBUG
  1565. static void target_if_spectral_check_buffer_poisoning(
  1566. struct target_if_spectral *spectral,
  1567. struct spectral_report *report,
  1568. int num_fft_bins, enum spectral_scan_mode smode)
  1569. {
  1570. uint32_t *data;
  1571. size_t len;
  1572. size_t words_to_check =
  1573. sizeof(struct spectral_sscan_summary_report_gen3) >> 2;
  1574. bool poisoned_words_found = false;
  1575. if (!spectral) {
  1576. spectral_err_rl("Spectral LMAC object is null");
  1577. return;
  1578. }
  1579. if (!spectral->dbr_buff_debug)
  1580. return;
  1581. if (!report) {
  1582. spectral_err_rl("Spectral report is null");
  1583. return;
  1584. }
  1585. /* Add search FFT report */
  1586. if (spectral->params[smode].ss_rpt_mode > 0)
  1587. words_to_check +=
  1588. sizeof(struct spectral_phyerr_fft_report_gen3) >> 2;
  1589. /* Now add the number of FFT bins */
  1590. if (spectral->params[smode].ss_rpt_mode > 1) {
  1591. /* Caller should take care to pass correct number of FFT bins */
  1592. if (spectral->len_adj_swar.fftbin_size_war ==
  1593. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE)
  1594. words_to_check += num_fft_bins;
  1595. else if (spectral->len_adj_swar.fftbin_size_war ==
  1596. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE)
  1597. words_to_check += (num_fft_bins >> 1);
  1598. }
  1599. data = (uint32_t *)report->data;
  1600. for (len = 0; len < words_to_check; ++len) {
  1601. if (*data == MEM_POISON_SIGNATURE) {
  1602. spectral_err("Pattern(%x) found in Spectral search FFT report at position %zu in the buffer %pK",
  1603. MEM_POISON_SIGNATURE,
  1604. (len << 2), report->data);
  1605. poisoned_words_found = true;
  1606. break;
  1607. }
  1608. ++data;
  1609. }
  1610. /* Crash the FW even if one word is poisoned */
  1611. if (poisoned_words_found) {
  1612. spectral_err("Pattern(%x) found in Spectral report, Hex dump of the sfft follows",
  1613. MEM_POISON_SIGNATURE);
  1614. target_if_spectral_hexdump((unsigned char *)report->data,
  1615. words_to_check << 2);
  1616. spectral_err("Asserting the FW");
  1617. target_if_spectral_fw_hang(spectral);
  1618. }
  1619. }
  1620. static void target_if_spectral_verify_ts(struct target_if_spectral *spectral,
  1621. uint8_t *buf, uint32_t current_ts)
  1622. {
  1623. if (!spectral) {
  1624. spectral_err_rl("Spectral LMAC object is null");
  1625. return;
  1626. }
  1627. if (!spectral->dbr_buff_debug)
  1628. return;
  1629. if (spectral->prev_tstamp) {
  1630. if (current_ts == spectral->prev_tstamp) {
  1631. spectral_err("Spectral timestamp(%u) in the current buffer(%pK) is equal to the previous timestamp, same report DMAed twice? Asserting the FW",
  1632. current_ts, buf);
  1633. target_if_spectral_fw_hang(spectral);
  1634. }
  1635. }
  1636. spectral->prev_tstamp = current_ts;
  1637. }
  1638. #else
  1639. static void target_if_spectral_check_buffer_poisoning(
  1640. struct target_if_spectral *spectral,
  1641. struct spectral_report *report,
  1642. int num_fft_bins, enum spectral_scan_mode smode)
  1643. {
  1644. }
  1645. static void target_if_spectral_verify_ts(struct target_if_spectral *spectral,
  1646. uint8_t *buf, uint32_t current_ts)
  1647. {
  1648. }
  1649. #endif
  1650. /**
  1651. * target_if_spectral_get_adjusted_timestamp() - Adjust Spectral time
  1652. * stamp to account for reset in time stamp due to target reset
  1653. * @twar: Spectral time stamp WAR related information
  1654. * @raw_timestamp: Spectral time stamp reported by target
  1655. * @reset_delay: Reset delay at target
  1656. * @smode: Spectral scan mode
  1657. *
  1658. * Correct time stamp to account for reset in time stamp due to target reset
  1659. *
  1660. * Return: Adjusted time stamp
  1661. */
  1662. static uint32_t
  1663. target_if_spectral_get_adjusted_timestamp(struct spectral_timestamp_war *twar,
  1664. uint32_t raw_timestamp,
  1665. uint32_t reset_delay,
  1666. enum spectral_scan_mode smode) {
  1667. qdf_assert_always(smode < SPECTRAL_SCAN_MODE_MAX);
  1668. if (reset_delay) {
  1669. enum spectral_scan_mode m =
  1670. SPECTRAL_SCAN_MODE_NORMAL;
  1671. /* Adjust the offset for all the Spectral modes.
  1672. * Target will be sending the non zero reset delay for
  1673. * the first Spectral report after reset. This delay is
  1674. * common for all the Spectral modes.
  1675. */
  1676. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  1677. twar->timestamp_war_offset[m] += (reset_delay +
  1678. twar->last_fft_timestamp[m]);
  1679. twar->target_reset_count++;
  1680. }
  1681. twar->last_fft_timestamp[smode] = raw_timestamp;
  1682. return raw_timestamp + twar->timestamp_war_offset[smode];
  1683. }
  1684. #ifdef BIG_ENDIAN_HOST
  1685. QDF_STATUS target_if_byte_swap_spectral_headers_gen3(
  1686. struct target_if_spectral *spectral,
  1687. void *data)
  1688. {
  1689. int i;
  1690. uint32_t *ptr32;
  1691. size_t words32;
  1692. qdf_assert_always(data);
  1693. qdf_assert_always(spectral);
  1694. ptr32 = (uint32_t *)data;
  1695. /* Summary Report */
  1696. words32 = sizeof(struct spectral_sscan_summary_report_gen3) >> 2;
  1697. for (i = 0; i < words32; ++i) {
  1698. *ptr32 = qdf_le32_to_cpu(*ptr32);
  1699. ++ptr32;
  1700. }
  1701. /* No need to swap the padding bytes */
  1702. ptr32 += (spectral->rparams.ssumaary_padding_bytes >> 2);
  1703. /* Search FFT Report */
  1704. words32 = sizeof(struct spectral_phyerr_fft_report_gen3) >> 2;
  1705. for (i = 0; i < words32; ++i) {
  1706. *ptr32 = qdf_le32_to_cpu(*ptr32);
  1707. ++ptr32;
  1708. }
  1709. return QDF_STATUS_SUCCESS;
  1710. }
  1711. QDF_STATUS target_if_byte_swap_spectral_fft_bins_gen3(
  1712. struct spectral_fft_bin_len_adj_swar *swar,
  1713. void *bin_pwr_data, size_t num_fftbins)
  1714. {
  1715. int i;
  1716. uint16_t *binptr_16;
  1717. uint32_t *binptr_32;
  1718. qdf_assert_always(bin_pwr_data);
  1719. qdf_assert_always(swar);
  1720. if (swar->fftbin_size_war ==
  1721. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
  1722. binptr_32 = (uint32_t *)bin_pwr_data;
  1723. for (i = 0; i < num_fftbins; i++) {
  1724. /* Get the useful first 2 bytes of the DWORD */
  1725. binptr_16 = ((uint16_t *)binptr_32);
  1726. /* Byteswap and copy it back */
  1727. *binptr_16 = qdf_le16_to_cpu(*binptr_16);
  1728. ++binptr_32; /* Go to next DWORD */
  1729. }
  1730. } else if (swar->fftbin_size_war ==
  1731. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  1732. binptr_16 = (uint16_t *)bin_pwr_data;
  1733. for (i = 0; i < num_fftbins; i++) {
  1734. /* Byteswap the FFT bin and copy it back */
  1735. *binptr_16 = qdf_le16_to_cpu(*binptr_16);
  1736. ++binptr_16;
  1737. }
  1738. }
  1739. return QDF_STATUS_SUCCESS;
  1740. }
  1741. #endif /* BIG_ENDIAN_HOST */
  1742. #ifdef OPTIMIZED_SAMP_MESSAGE
  1743. /**
  1744. * target_if_consume_sscan_summary_report_gen3() - Consume Spectral summary
  1745. * report
  1746. * @data: Pointer to Spectral summary report
  1747. * @fields: Pointer to structure to be populated with extracted fields
  1748. * @spectral: Pointer to spectral object
  1749. *
  1750. * Consume Spectral summary report for gen3
  1751. *
  1752. * Return: Success/Failure
  1753. */
  1754. static QDF_STATUS
  1755. target_if_consume_sscan_summary_report_gen3(
  1756. uint8_t **data,
  1757. struct sscan_report_fields_gen3 *fields,
  1758. struct target_if_spectral *spectral)
  1759. {
  1760. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  1761. if (!data) {
  1762. spectral_err_rl("Summary report buffer is null");
  1763. return QDF_STATUS_E_NULL_VALUE;
  1764. }
  1765. if (!fields) {
  1766. spectral_err_rl("Invalid pointer to Summary report fields");
  1767. return QDF_STATUS_E_NULL_VALUE;
  1768. }
  1769. if (!spectral) {
  1770. spectral_err_rl("Spectral LMAC object is null");
  1771. return QDF_STATUS_E_NULL_VALUE;
  1772. }
  1773. /* Validate Spectral scan summary report */
  1774. if (target_if_verify_sig_and_tag_gen3(
  1775. spectral, *data,
  1776. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3) != 0) {
  1777. spectral_err_rl("Wrong tag/sig in sscan summary");
  1778. return QDF_STATUS_E_FAILURE;
  1779. }
  1780. fields->sscan_detector_id =
  1781. target_if_get_detector_id_sscan_summary_report_gen3(*data);
  1782. if (fields->sscan_detector_id >=
  1783. spectral->rparams.num_spectral_detectors) {
  1784. spectral->diag_stats.spectral_invalid_detector_id++;
  1785. spectral_err_rl("Invalid detector id %u, expected is 0 to %u",
  1786. fields->sscan_detector_id,
  1787. spectral->rparams.num_spectral_detectors);
  1788. return QDF_STATUS_E_FAILURE;
  1789. }
  1790. psscan_summary_report =
  1791. (struct spectral_sscan_summary_report_gen3 *)*data;
  1792. fields->sscan_agc_total_gain = get_bitfield(
  1793. psscan_summary_report->hdr_a,
  1794. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_SIZE_GEN3,
  1795. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_POS_GEN3);
  1796. fields->inband_pwr_db = get_bitfield(
  1797. psscan_summary_report->hdr_a,
  1798. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_SIZE_GEN3,
  1799. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_POS_GEN3);
  1800. fields->sscan_pri80 = get_bitfield(
  1801. psscan_summary_report->hdr_a,
  1802. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_SIZE_GEN3,
  1803. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_POS_GEN3);
  1804. switch (spectral->rparams.version) {
  1805. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1806. fields->sscan_gainchange = get_bitfield(
  1807. psscan_summary_report->hdr_b,
  1808. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_SIZE_GEN3_V1,
  1809. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_POS_GEN3_V1);
  1810. break;
  1811. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1812. fields->sscan_gainchange = get_bitfield(
  1813. psscan_summary_report->hdr_c,
  1814. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_SIZE_GEN3_V2,
  1815. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_POS_GEN3_V2);
  1816. break;
  1817. default:
  1818. qdf_assert_always(0);
  1819. }
  1820. /* Advance buf pointer to the search fft report */
  1821. *data += sizeof(struct spectral_sscan_summary_report_gen3);
  1822. *data += spectral->rparams.ssumaary_padding_bytes;
  1823. return QDF_STATUS_SUCCESS;
  1824. }
  1825. /**
  1826. * target_if_process_sfft_report_gen3() - Validate and Process Search
  1827. * FFT Report for gen3
  1828. * @data: Pointer to Spectral FFT report
  1829. * @p_sfft: Pointer to search fft report
  1830. * @spectral: Pointer to spectral object
  1831. * @sscan_detector_id: Spectral detector id extracted from Summary report
  1832. *
  1833. * Validate and Process Search FFT Report for gen3
  1834. *
  1835. * Return: Success/Failure
  1836. */
  1837. static QDF_STATUS
  1838. target_if_process_sfft_report_gen3(
  1839. uint8_t *data,
  1840. struct spectral_search_fft_info_gen3 *p_sfft,
  1841. struct target_if_spectral *spectral,
  1842. enum spectral_detector_id sscan_detector_id)
  1843. {
  1844. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  1845. int32_t peak_sidx = 0;
  1846. int32_t peak_mag;
  1847. int fft_hdr_length = 0;
  1848. struct target_if_spectral_ops *p_sops;
  1849. enum spectral_scan_mode spectral_mode;
  1850. QDF_STATUS ret;
  1851. if (!data) {
  1852. spectral_err_rl("FFT report buffer is null");
  1853. return QDF_STATUS_E_NULL_VALUE;
  1854. }
  1855. if (!p_sfft) {
  1856. spectral_err_rl("Invalid pointer to Search FFT report info");
  1857. return QDF_STATUS_E_NULL_VALUE;
  1858. }
  1859. if (!spectral) {
  1860. spectral_err_rl("Spectral LMAC object is null");
  1861. return QDF_STATUS_E_NULL_VALUE;
  1862. }
  1863. /*
  1864. * For easy comparision between MDK team and OS team, the MDK script
  1865. * variable names have been used
  1866. */
  1867. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1868. /* Validate Spectral search FFT report */
  1869. if (target_if_verify_sig_and_tag_gen3(
  1870. spectral, data, TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  1871. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  1872. sscan_detector_id);
  1873. return QDF_STATUS_E_FAILURE;
  1874. }
  1875. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  1876. fft_hdr_length = get_bitfield(
  1877. p_fft_report->fft_hdr_lts,
  1878. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  1879. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  1880. if (fft_hdr_length < 16) {
  1881. spectral_err("Wrong TLV length %u, detector id = %d",
  1882. fft_hdr_length, sscan_detector_id);
  1883. return QDF_STATUS_E_FAILURE;
  1884. }
  1885. p_sfft->fft_detector_id = get_bitfield(p_fft_report->hdr_a,
  1886. 2, 0);
  1887. /* It is expected to have same detector id for
  1888. * summary and fft report
  1889. */
  1890. if (sscan_detector_id != p_sfft->fft_detector_id) {
  1891. spectral_err_rl("Different detid in ssummary(%u) and sfft(%u)",
  1892. sscan_detector_id, p_sfft->fft_detector_id);
  1893. return QDF_STATUS_E_FAILURE;
  1894. }
  1895. if (p_sfft->fft_detector_id >
  1896. spectral->rparams.num_spectral_detectors) {
  1897. spectral->diag_stats.spectral_invalid_detector_id++;
  1898. spectral_err("Invalid detector id %u, expected is 0 to %u",
  1899. p_sfft->fft_detector_id,
  1900. spectral->rparams.num_spectral_detectors);
  1901. return QDF_STATUS_E_FAILURE;
  1902. }
  1903. /* Populate the Search FFT Info */
  1904. p_sfft->timestamp = p_fft_report->fft_timestamp;
  1905. p_sfft->fft_num = get_bitfield(p_fft_report->hdr_a, 3, 2);
  1906. switch (spectral->rparams.version) {
  1907. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1908. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  1909. 12, 5);
  1910. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 17);
  1911. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_a, 3, 28);
  1912. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  1913. 9, 0);
  1914. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  1915. 8, 9);
  1916. break;
  1917. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1918. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  1919. 14, 5);
  1920. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 19);
  1921. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_b, 3, 0);
  1922. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  1923. 9, 3);
  1924. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  1925. 8, 12);
  1926. break;
  1927. default:
  1928. qdf_assert_always(0);
  1929. }
  1930. p_sfft->fft_peak_sidx = unsigned_to_signed(peak_sidx, 11);
  1931. p_sfft->fft_num_str_bins_ib = get_bitfield(p_fft_report->hdr_c,
  1932. 8, 0);
  1933. peak_mag = get_bitfield(p_fft_report->hdr_c, 10, 8);
  1934. p_sfft->fft_peak_mag = unsigned_to_signed(peak_mag, 10);
  1935. p_sfft->fft_avgpwr_db = get_bitfield(p_fft_report->hdr_c,
  1936. 7, 18);
  1937. p_sfft->fft_relpwr_db = get_bitfield(p_fft_report->hdr_c,
  1938. 7, 25);
  1939. spectral_mode = target_if_get_spectral_mode(p_sfft->fft_detector_id,
  1940. &spectral->rparams);
  1941. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  1942. spectral_err_rl("No valid Spectral mode for detector id %u",
  1943. p_sfft->fft_detector_id);
  1944. return QDF_STATUS_E_FAILURE;
  1945. }
  1946. p_sfft->fft_bin_count =
  1947. target_if_spectral_get_bin_count_after_len_adj(
  1948. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  1949. spectral->params[spectral_mode].ss_rpt_mode,
  1950. &spectral->len_adj_swar,
  1951. (size_t *)&p_sfft->fft_bin_size);
  1952. p_sfft->bin_pwr_data = (uint8_t *)p_fft_report + SPECTRAL_FFT_BINS_POS;
  1953. /* Apply byte-swap on the FFT bins.
  1954. * NOTE: Until this point, bytes of the FFT bins could be in
  1955. * reverse order on a big-endian machine. If the consumers
  1956. * of FFT bins expects bytes in the correct order,
  1957. * they should use them only after this point.
  1958. */
  1959. if (p_sops->byte_swap_fft_bins) {
  1960. ret = p_sops->byte_swap_fft_bins(&spectral->len_adj_swar,
  1961. &p_sfft->bin_pwr_data,
  1962. p_sfft->fft_bin_count);
  1963. if (QDF_IS_STATUS_ERROR(ret)) {
  1964. spectral_err_rl("Byte-swap on the FFT bins failed");
  1965. return QDF_STATUS_E_FAILURE;
  1966. }
  1967. }
  1968. return QDF_STATUS_SUCCESS;
  1969. }
  1970. int
  1971. target_if_consume_spectral_report_gen3(
  1972. struct target_if_spectral *spectral,
  1973. struct spectral_report *report)
  1974. {
  1975. /*
  1976. * XXX : The classifier do not use all the members of the SAMP
  1977. * message data format.
  1978. * The classifier only depends upon the following parameters
  1979. *
  1980. * 1. Frequency
  1981. * 2. Spectral RSSI
  1982. * 3. Bin Power Count
  1983. * 4. Bin Power values
  1984. * 5. Spectral Timestamp
  1985. * 6. MAC Address
  1986. *
  1987. * This function processes the Spectral summary and FFT reports
  1988. * and passes the processed information
  1989. * target_if_spectral_fill_samp_msg()
  1990. * to prepare fully formatted Spectral SAMP message
  1991. *
  1992. * XXX : Need to verify
  1993. * 1. Order of FFT bin values
  1994. *
  1995. */
  1996. struct target_if_samp_msg_params params = {0};
  1997. struct spectral_search_fft_info_gen3 search_fft_info;
  1998. struct spectral_search_fft_info_gen3 *p_sfft = &search_fft_info;
  1999. struct target_if_spectral_ops *p_sops;
  2000. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  2001. uint8_t *data;
  2002. struct sscan_report_fields_gen3 sscan_report_fields = {0};
  2003. QDF_STATUS ret;
  2004. enum spectral_scan_mode spectral_mode = SPECTRAL_SCAN_MODE_INVALID;
  2005. bool finite_scan = false;
  2006. if (!spectral) {
  2007. spectral_err_rl("Spectral LMAC object is null");
  2008. goto fail_no_print;
  2009. }
  2010. if (!report) {
  2011. spectral_err_rl("Spectral report is null");
  2012. goto fail_no_print;
  2013. }
  2014. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2015. data = report->data;
  2016. /* Apply byte-swap on the headers */
  2017. if (p_sops->byte_swap_headers) {
  2018. ret = p_sops->byte_swap_headers(spectral, data);
  2019. if (QDF_IS_STATUS_ERROR(ret)) {
  2020. spectral_err_rl("Byte-swap on Spectral headers failed");
  2021. goto fail;
  2022. }
  2023. }
  2024. /* Validate and Process Spectral scan summary report */
  2025. ret = target_if_consume_sscan_summary_report_gen3(&data,
  2026. &sscan_report_fields,
  2027. spectral);
  2028. if (QDF_IS_STATUS_ERROR(ret)) {
  2029. spectral_err_rl("Failed to process Spectral summary report");
  2030. goto fail;
  2031. }
  2032. spectral_mode = target_if_get_spectral_mode(
  2033. sscan_report_fields.sscan_detector_id,
  2034. &spectral->rparams);
  2035. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  2036. spectral_err_rl("No valid Spectral mode for detector id %u",
  2037. sscan_report_fields.sscan_detector_id);
  2038. goto fail;
  2039. }
  2040. /* Drop the sample if Spectral is not active for the current mode */
  2041. if (!p_sops->is_spectral_active(spectral, spectral_mode)) {
  2042. spectral_info_rl("Spectral scan is not active");
  2043. goto fail_no_print;
  2044. }
  2045. ret = target_if_spectral_is_finite_scan(spectral, spectral_mode,
  2046. &finite_scan);
  2047. if (QDF_IS_STATUS_ERROR(ret)) {
  2048. spectral_err_rl("Failed to check scan is finite");
  2049. goto fail;
  2050. }
  2051. if (finite_scan) {
  2052. ret = target_if_spectral_finite_scan_update(spectral,
  2053. spectral_mode);
  2054. if (QDF_IS_STATUS_ERROR(ret)) {
  2055. spectral_err_rl("Failed to update scan count");
  2056. goto fail;
  2057. }
  2058. }
  2059. /* Validate and Process the search FFT report */
  2060. ret = target_if_process_sfft_report_gen3(
  2061. data, p_sfft,
  2062. spectral,
  2063. sscan_report_fields.sscan_detector_id);
  2064. if (QDF_IS_STATUS_ERROR(ret)) {
  2065. spectral_err_rl("Failed to process search FFT report");
  2066. goto fail;
  2067. }
  2068. /* Check FFT report are in order for 160 MHz and 80p80 */
  2069. if (is_ch_width_160_or_80p80(
  2070. spectral->report_info[spectral_mode].sscan_bw) &&
  2071. spectral->rparams.fragmentation_160[spectral_mode]) {
  2072. ret = target_if_160mhz_delivery_state_change(
  2073. spectral, spectral_mode,
  2074. p_sfft->fft_detector_id);
  2075. if (ret != QDF_STATUS_SUCCESS)
  2076. goto fail;
  2077. }
  2078. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  2079. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  2080. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  2081. p_fft_report, p_sfft);
  2082. target_if_spectral_check_buffer_poisoning(spectral, report,
  2083. p_sfft->fft_bin_count,
  2084. spectral_mode);
  2085. /* Fill SAMP message */
  2086. ret = target_if_spectral_fill_samp_msg(spectral, &params);
  2087. if (QDF_IS_STATUS_ERROR(ret)) {
  2088. spectral_err_rl("Failed to fill the SAMP msg");
  2089. goto fail;
  2090. }
  2091. return 0;
  2092. fail:
  2093. spectral_err_rl("Error while processing Spectral report");
  2094. fail_no_print:
  2095. if (spectral_mode != SPECTRAL_SCAN_MODE_INVALID)
  2096. reset_160mhz_delivery_state_machine(spectral, spectral_mode);
  2097. return -EPERM;
  2098. }
  2099. #else
  2100. int
  2101. target_if_consume_spectral_report_gen3(
  2102. struct target_if_spectral *spectral,
  2103. struct spectral_report *report)
  2104. {
  2105. /*
  2106. * XXX : The classifier do not use all the members of the SAMP
  2107. * message data format.
  2108. * The classifier only depends upon the following parameters
  2109. *
  2110. * 1. Frequency (freq, msg->freq)
  2111. * 2. Spectral RSSI (spectral_rssi,
  2112. * msg->samp_data.spectral_rssi)
  2113. * 3. Bin Power Count (bin_pwr_count,
  2114. * msg->samp_data.bin_pwr_count)
  2115. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  2116. * 5. Spectral Timestamp (spectral_tstamp,
  2117. * msg->samp_data.spectral_tstamp)
  2118. * 6. MAC Address (macaddr, msg->macaddr)
  2119. *
  2120. * This function prepares the params structure and populates it
  2121. * with
  2122. * relevant values, this is in turn passed to
  2123. * spectral_create_samp_msg()
  2124. * to prepare fully formatted Spectral SAMP message
  2125. *
  2126. * XXX : Need to verify
  2127. * 1. Order of FFT bin values
  2128. *
  2129. */
  2130. struct target_if_samp_msg_params params = {0};
  2131. struct spectral_search_fft_info_gen3 search_fft_info;
  2132. struct spectral_search_fft_info_gen3 *p_sfft = &search_fft_info;
  2133. int8_t chn_idx_lowest_enabled = 0;
  2134. int fft_hdr_length = 0;
  2135. int report_len = 0;
  2136. size_t fft_bin_count;
  2137. size_t fft_bin_size;
  2138. struct target_if_spectral_ops *p_sops =
  2139. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2140. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  2141. int8_t rssi;
  2142. uint8_t *data = report->data;
  2143. struct wlan_objmgr_vdev *vdev;
  2144. uint8_t vdev_rxchainmask;
  2145. struct sscan_report_fields_gen3 sscan_report_fields = {0};
  2146. enum spectral_detector_id detector_id;
  2147. QDF_STATUS ret;
  2148. enum spectral_scan_mode spectral_mode = SPECTRAL_SCAN_MODE_INVALID;
  2149. uint8_t *temp;
  2150. bool finite_scan = false;
  2151. /* Apply byte-swap on the headers */
  2152. if (p_sops->byte_swap_headers) {
  2153. ret = p_sops->byte_swap_headers(spectral, data);
  2154. if (QDF_IS_STATUS_ERROR(ret)) {
  2155. spectral_err_rl("Byte-swap on Spectral headers failed");
  2156. goto fail;
  2157. }
  2158. }
  2159. /* Process Spectral scan summary report */
  2160. if (target_if_verify_sig_and_tag_gen3(
  2161. spectral, data,
  2162. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3) != 0) {
  2163. spectral_err_rl("Wrong tag/sig in sscan summary");
  2164. goto fail;
  2165. }
  2166. detector_id = target_if_get_detector_id_sscan_summary_report_gen3(data);
  2167. if (detector_id >= spectral->rparams.num_spectral_detectors) {
  2168. spectral->diag_stats.spectral_invalid_detector_id++;
  2169. spectral_err("Invalid detector id %u, expected is 0/1/2",
  2170. detector_id);
  2171. goto fail;
  2172. }
  2173. spectral_mode = target_if_get_spectral_mode(detector_id,
  2174. &spectral->rparams);
  2175. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  2176. spectral_err_rl("No valid Spectral mode for detector id %u",
  2177. detector_id);
  2178. goto fail;
  2179. }
  2180. /* Drop the sample if Spectral is not active for the current mode */
  2181. if (!p_sops->is_spectral_active(spectral, spectral_mode)) {
  2182. spectral_info_rl("Spectral scan is not active");
  2183. goto fail_no_print;
  2184. }
  2185. ret = target_if_spectral_is_finite_scan(spectral, spectral_mode,
  2186. &finite_scan);
  2187. if (QDF_IS_STATUS_ERROR(ret)) {
  2188. spectral_err_rl("Failed to check scan is finite");
  2189. goto fail;
  2190. }
  2191. if (finite_scan) {
  2192. ret = target_if_spectral_finite_scan_update(spectral,
  2193. spectral_mode);
  2194. if (QDF_IS_STATUS_ERROR(ret)) {
  2195. spectral_err_rl("Failed to update scan count");
  2196. goto fail;
  2197. }
  2198. }
  2199. target_if_consume_sscan_summary_report_gen3(data, &sscan_report_fields,
  2200. &spectral->rparams);
  2201. /* Advance buf pointer to the search fft report */
  2202. data += sizeof(struct spectral_sscan_summary_report_gen3);
  2203. data += spectral->rparams.ssumaary_padding_bytes;
  2204. params.vhtop_ch_freq_seg1 = report->cfreq1;
  2205. params.vhtop_ch_freq_seg2 = report->cfreq2;
  2206. if (is_primaryseg_expected(spectral, spectral_mode)) {
  2207. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  2208. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  2209. params.agc_total_gain =
  2210. sscan_report_fields.sscan_agc_total_gain;
  2211. params.gainchange = sscan_report_fields.sscan_gainchange;
  2212. params.pri80ind = sscan_report_fields.sscan_pri80;
  2213. /* Process Spectral search FFT report */
  2214. if (target_if_verify_sig_and_tag_gen3(
  2215. spectral, data,
  2216. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  2217. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  2218. detector_id);
  2219. goto fail;
  2220. }
  2221. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  2222. fft_hdr_length = get_bitfield(
  2223. p_fft_report->fft_hdr_lts,
  2224. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  2225. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  2226. if (fft_hdr_length < 16) {
  2227. spectral_err("Wrong TLV length %u, detector id = %d",
  2228. fft_hdr_length, detector_id);
  2229. goto fail;
  2230. }
  2231. report_len = (fft_hdr_length + 8);
  2232. target_if_process_sfft_report_gen3(p_fft_report, p_sfft,
  2233. &spectral->rparams);
  2234. /* It is expected to have same detector id for
  2235. * summary and fft report
  2236. */
  2237. if (detector_id != p_sfft->fft_detector_id) {
  2238. spectral_err_rl
  2239. ("Different detid in ssummary(%u) and sfft(%u)",
  2240. detector_id, p_sfft->fft_detector_id);
  2241. goto fail;
  2242. }
  2243. if (detector_id > spectral->rparams.num_spectral_detectors) {
  2244. spectral->diag_stats.spectral_invalid_detector_id++;
  2245. spectral_err("Invalid detector id %u, expected is 0/2",
  2246. detector_id);
  2247. goto fail;
  2248. }
  2249. params.smode = spectral_mode;
  2250. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  2251. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  2252. spectral->params[spectral_mode].ss_rpt_mode,
  2253. &spectral->len_adj_swar, &fft_bin_size);
  2254. params.last_raw_timestamp = spectral->timestamp_war.
  2255. last_fft_timestamp[spectral_mode];
  2256. params.reset_delay = report->reset_delay;
  2257. params.raw_timestamp = p_sfft->timestamp;
  2258. params.tstamp = target_if_spectral_get_adjusted_timestamp(
  2259. &spectral->timestamp_war,
  2260. p_sfft->timestamp, report->reset_delay,
  2261. spectral_mode);
  2262. params.timestamp_war_offset = spectral->timestamp_war.
  2263. timestamp_war_offset[spectral_mode];
  2264. params.target_reset_count = spectral->timestamp_war.
  2265. target_reset_count;
  2266. /* Take care of state transitions for 160 MHz and 80p80 */
  2267. if (is_ch_width_160_or_80p80(spectral->ch_width
  2268. [spectral_mode]) && spectral->rparams.
  2269. fragmentation_160[spectral_mode]) {
  2270. ret = target_if_160mhz_delivery_state_change(
  2271. spectral, spectral_mode,
  2272. detector_id);
  2273. if (ret != QDF_STATUS_SUCCESS)
  2274. goto fail;
  2275. }
  2276. params.rssi = rssi;
  2277. vdev = target_if_spectral_get_vdev(spectral, spectral_mode);
  2278. if (!vdev) {
  2279. spectral_debug("First vdev is NULL");
  2280. reset_160mhz_delivery_state_machine(
  2281. spectral, spectral_mode);
  2282. return -EPERM;
  2283. }
  2284. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  2285. QDF_ASSERT(vdev_rxchainmask != 0);
  2286. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2287. chn_idx_lowest_enabled =
  2288. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  2289. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  2290. spectral_err("Invalid chain index, detector id = %u",
  2291. detector_id);
  2292. goto fail;
  2293. }
  2294. params.max_mag = p_sfft->fft_peak_mag;
  2295. params.freq = p_sops->get_current_channel(spectral,
  2296. spectral_mode);
  2297. params.agile_freq1 = spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  2298. ss_frequency.cfreq1;
  2299. params.agile_freq2 = spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  2300. ss_frequency.cfreq2;
  2301. params.noise_floor =
  2302. report->noisefloor[chn_idx_lowest_enabled];
  2303. temp = (uint8_t *)p_fft_report + SPECTRAL_FFT_BINS_POS;
  2304. if (is_ch_width_160_or_80p80(spectral->ch_width
  2305. [spectral_mode]) && !spectral->rparams.
  2306. fragmentation_160[spectral_mode]) {
  2307. struct wlan_objmgr_psoc *psoc;
  2308. struct spectral_fft_bin_markers_160_165mhz *marker;
  2309. qdf_assert_always(spectral->pdev_obj);
  2310. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  2311. qdf_assert_always(psoc);
  2312. params.agc_total_gain_sec80 =
  2313. sscan_report_fields.sscan_agc_total_gain;
  2314. params.gainchange_sec80 =
  2315. sscan_report_fields.sscan_gainchange;
  2316. params.raw_timestamp_sec80 = p_sfft->timestamp;
  2317. params.rssi_sec80 = rssi;
  2318. params.noise_floor_sec80 =
  2319. report->noisefloor[chn_idx_lowest_enabled];
  2320. params.max_mag_sec80 = p_sfft->fft_peak_mag;
  2321. params.datalen = fft_hdr_length * 2;
  2322. params.datalen_sec80 = fft_hdr_length * 2;
  2323. marker = &spectral->rparams.marker[spectral_mode];
  2324. if (!marker->is_valid) {
  2325. /* update stats */
  2326. goto fail_no_print;
  2327. }
  2328. params.bin_pwr_data = temp +
  2329. marker->start_pri80 * fft_bin_size;
  2330. params.pwr_count = marker->num_pri80;
  2331. params.bin_pwr_data_sec80 = temp +
  2332. marker->start_sec80 * fft_bin_size;
  2333. params.pwr_count_sec80 = marker->num_sec80;
  2334. if (spectral->ch_width[spectral_mode] ==
  2335. CH_WIDTH_80P80MHZ && wlan_psoc_nif_fw_ext_cap_get(
  2336. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  2337. params.bin_pwr_data_5mhz = temp +
  2338. marker->start_5mhz * fft_bin_size;
  2339. params.pwr_count_5mhz = marker->num_5mhz;
  2340. }
  2341. } else {
  2342. params.bin_pwr_data = temp;
  2343. params.pwr_count = fft_bin_count;
  2344. params.datalen = (fft_hdr_length * 4);
  2345. }
  2346. /* Apply byte-swap on the FFT bins.
  2347. * NOTE: Until this point, bytes of the FFT bins could be in
  2348. * reverse order on a big-endian machine. If the consumers
  2349. * of FFT bins expects bytes in the correct order,
  2350. * they should use them only after this point.
  2351. */
  2352. if (p_sops->byte_swap_fft_bins) {
  2353. ret = p_sops->byte_swap_fft_bins(
  2354. &spectral->len_adj_swar,
  2355. temp, fft_bin_count);
  2356. if (QDF_IS_STATUS_ERROR(ret)) {
  2357. spectral_err_rl("Byte-swap on the FFT bins failed");
  2358. goto fail;
  2359. }
  2360. }
  2361. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  2362. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  2363. p_fft_report, p_sfft);
  2364. target_if_spectral_verify_ts(spectral, report->data,
  2365. params.tstamp);
  2366. } else if (is_secondaryseg_expected(spectral, spectral_mode)) {
  2367. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  2368. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  2369. params.agc_total_gain_sec80 =
  2370. sscan_report_fields.sscan_agc_total_gain;
  2371. params.gainchange_sec80 = sscan_report_fields.sscan_gainchange;
  2372. params.pri80ind_sec80 = sscan_report_fields.sscan_pri80;
  2373. /* Process Spectral search FFT report */
  2374. if (target_if_verify_sig_and_tag_gen3(
  2375. spectral, data,
  2376. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  2377. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  2378. detector_id);
  2379. goto fail;
  2380. }
  2381. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  2382. fft_hdr_length = get_bitfield(
  2383. p_fft_report->fft_hdr_lts,
  2384. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  2385. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  2386. if (fft_hdr_length < 16) {
  2387. spectral_err("Wrong TLV length %u, detector id = %u",
  2388. fft_hdr_length, detector_id);
  2389. goto fail;
  2390. }
  2391. report_len = (fft_hdr_length + 8);
  2392. target_if_process_sfft_report_gen3(p_fft_report, p_sfft,
  2393. &spectral->rparams);
  2394. /* It is expected to have same detector id for
  2395. * summary and fft report
  2396. */
  2397. if (detector_id != p_sfft->fft_detector_id) {
  2398. spectral_err_rl
  2399. ("Different detid in ssummary(%u) and sfft(%u)",
  2400. detector_id, p_sfft->fft_detector_id);
  2401. goto fail;
  2402. }
  2403. if (detector_id > spectral->rparams.num_spectral_detectors) {
  2404. spectral->diag_stats.spectral_invalid_detector_id++;
  2405. spectral_err("Invalid detector id %u, expected is 1",
  2406. detector_id);
  2407. goto fail;
  2408. }
  2409. params.smode = spectral_mode;
  2410. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  2411. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  2412. spectral->params[spectral_mode].ss_rpt_mode,
  2413. &spectral->len_adj_swar, &fft_bin_size);
  2414. params.raw_timestamp_sec80 = p_sfft->timestamp;
  2415. /* Take care of state transitions for 160 MHz and 80p80 */
  2416. if (is_ch_width_160_or_80p80(spectral->ch_width
  2417. [spectral_mode]) && spectral->rparams.
  2418. fragmentation_160[spectral_mode]) {
  2419. ret = target_if_160mhz_delivery_state_change(
  2420. spectral, spectral_mode,
  2421. detector_id);
  2422. if (ret != QDF_STATUS_SUCCESS)
  2423. goto fail;
  2424. }
  2425. params.rssi_sec80 = rssi;
  2426. vdev = target_if_spectral_get_vdev(spectral, spectral_mode);
  2427. if (!vdev) {
  2428. spectral_info("First vdev is NULL");
  2429. reset_160mhz_delivery_state_machine
  2430. (spectral, spectral_mode);
  2431. return -EPERM;
  2432. }
  2433. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  2434. QDF_ASSERT(vdev_rxchainmask != 0);
  2435. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2436. chn_idx_lowest_enabled =
  2437. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  2438. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  2439. spectral_err("Invalid chain index");
  2440. goto fail;
  2441. }
  2442. /* Need to change this as per FW team's inputs */
  2443. params.noise_floor_sec80 =
  2444. report->noisefloor[chn_idx_lowest_enabled];
  2445. params.max_mag_sec80 = p_sfft->fft_peak_mag;
  2446. /* params.max_index_sec80 = p_sfft->peak_inx; */
  2447. /* XXX Does this definition of datalen *still hold? */
  2448. params.datalen_sec80 = fft_hdr_length * 4;
  2449. params.pwr_count_sec80 = fft_bin_count;
  2450. params.bin_pwr_data_sec80 =
  2451. (uint8_t *)((uint8_t *)p_fft_report +
  2452. SPECTRAL_FFT_BINS_POS);
  2453. /* Apply byte-swap on the FFT bins.
  2454. * NOTE: Until this point, bytes of the FFT bins could be in
  2455. * reverse order on a big-endian machine. If the consumers
  2456. * of FFT bins expects bytes in the correct order,
  2457. * they should use them only after this point.
  2458. */
  2459. if (p_sops->byte_swap_fft_bins) {
  2460. ret = p_sops->byte_swap_fft_bins(
  2461. &spectral->len_adj_swar,
  2462. params.bin_pwr_data_sec80,
  2463. fft_bin_count);
  2464. if (QDF_IS_STATUS_ERROR(ret)) {
  2465. spectral_err_rl("Byte-swap on the FFT bins failed");
  2466. goto fail;
  2467. }
  2468. }
  2469. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  2470. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  2471. p_fft_report, p_sfft);
  2472. } else {
  2473. spectral_err("Spectral state machine in undefined state");
  2474. goto fail;
  2475. }
  2476. target_if_spectral_check_buffer_poisoning(spectral, report,
  2477. fft_bin_count, spectral_mode);
  2478. qdf_mem_copy(&params.classifier_params,
  2479. &spectral->classifier_params,
  2480. sizeof(struct spectral_classifier_params));
  2481. target_if_spectral_log_SAMP_param(&params);
  2482. target_if_spectral_create_samp_msg(spectral, &params);
  2483. return 0;
  2484. fail:
  2485. spectral_err_rl("Error while processing Spectral report");
  2486. fail_no_print:
  2487. if (spectral_mode != SPECTRAL_SCAN_MODE_INVALID)
  2488. reset_160mhz_delivery_state_machine(spectral, spectral_mode);
  2489. return -EPERM;
  2490. }
  2491. #endif /* OPTIMIZED_SAMP_MESSAGE */
  2492. int target_if_spectral_process_report_gen3(
  2493. struct wlan_objmgr_pdev *pdev,
  2494. void *buf)
  2495. {
  2496. int ret = 0;
  2497. struct direct_buf_rx_data *payload = buf;
  2498. struct target_if_spectral *spectral;
  2499. struct spectral_report report;
  2500. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2501. if (!spectral) {
  2502. spectral_err("Spectral target object is null");
  2503. return -EINVAL;
  2504. }
  2505. report.data = payload->vaddr;
  2506. if (payload->meta_data_valid) {
  2507. qdf_mem_copy(report.noisefloor, payload->meta_data.noisefloor,
  2508. qdf_min(sizeof(report.noisefloor),
  2509. sizeof(payload->meta_data.noisefloor)));
  2510. report.reset_delay = payload->meta_data.reset_delay;
  2511. report.cfreq1 = payload->meta_data.cfreq1;
  2512. report.cfreq2 = payload->meta_data.cfreq2;
  2513. report.ch_width = payload->meta_data.ch_width;
  2514. }
  2515. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4)) {
  2516. spectral_debug("Printing the spectral phyerr buffer for debug");
  2517. spectral_debug("Datalength of buffer = 0x%zx(%zd) bufptr = 0x%pK",
  2518. payload->dbr_len,
  2519. payload->dbr_len,
  2520. payload->vaddr);
  2521. target_if_spectral_hexdump((unsigned char *)payload->vaddr,
  2522. 1024);
  2523. }
  2524. ret = target_if_consume_spectral_report_gen3(spectral, &report);
  2525. if (spectral_debug_level & DEBUG_SPECTRAL4)
  2526. spectral_debug_level = DEBUG_SPECTRAL;
  2527. return ret;
  2528. }
  2529. #else
  2530. int target_if_spectral_process_report_gen3(
  2531. struct wlan_objmgr_pdev *pdev,
  2532. void *buf)
  2533. {
  2534. spectral_err("Direct dma support is not enabled");
  2535. return -EINVAL;
  2536. }
  2537. #endif
  2538. qdf_export_symbol(target_if_spectral_process_report_gen3);
  2539. /* END of spectral GEN III HW specific functions */
  2540. #endif /* WLAN_CONV_SPECTRAL_ENABLE */