target_if_spectral_phyerr.c 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169
  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. #ifdef OPTIMIZED_SAMP_MESSAGE
  673. /**
  674. * target_if_populate_fft_bins_info() - Populate the start and end bin
  675. * indices, on per-detector level.
  676. * @spectral: Pointer to target_if spectral internal structure
  677. * @smode: Spectral scan mode
  678. *
  679. * Populate the start and end bin indices, on per-detector level.
  680. *
  681. * Return: Success/Failure
  682. */
  683. static QDF_STATUS
  684. target_if_populate_fft_bins_info(struct target_if_spectral *spectral,
  685. enum spectral_scan_mode smode)
  686. {
  687. struct per_session_det_map *det_map;
  688. struct per_session_dest_det_info *dest_det_info;
  689. enum phy_ch_width ch_width;
  690. struct sscan_detector_list *detector_list;
  691. bool is_fragmentation_160;
  692. uint8_t spectral_fft_size;
  693. uint8_t rpt_mode;
  694. uint32_t num_fft_bins;
  695. uint16_t start_bin;
  696. uint8_t det;
  697. if (!spectral) {
  698. spectral_err_rl("Spectral LMAC object is null");
  699. return QDF_STATUS_E_NULL_VALUE;
  700. }
  701. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  702. spectral_err_rl("Invalid Spectral mode");
  703. return QDF_STATUS_E_FAILURE;
  704. }
  705. ch_width = spectral->report_info[smode].sscan_bw;
  706. is_fragmentation_160 = spectral->rparams.fragmentation_160[smode];
  707. spectral_fft_size = spectral->params[smode].ss_fft_size;
  708. rpt_mode = spectral->params[smode].ss_rpt_mode;
  709. num_fft_bins =
  710. target_if_spectral_get_num_fft_bins(spectral_fft_size,
  711. rpt_mode);
  712. if (num_fft_bins < 0) {
  713. spectral_err_rl("Invalid number of FFT bins %d",
  714. num_fft_bins);
  715. return QDF_STATUS_E_FAILURE;
  716. }
  717. detector_list = &spectral->detector_list[smode][ch_width];
  718. for (det = 0; det < detector_list->num_detectors; det++) {
  719. det_map = &spectral->det_map
  720. [detector_list->detectors[det]];
  721. dest_det_info = &det_map->dest_det_info[0];
  722. switch (det) {
  723. case 0:
  724. if (ch_width == CH_WIDTH_160MHZ &&
  725. is_fragmentation_160 &&
  726. spectral->report_info[smode].sscan_cfreq1 >
  727. spectral->report_info[smode].sscan_cfreq2)
  728. start_bin = num_fft_bins;
  729. else
  730. start_bin = 0;
  731. break;
  732. case 1:
  733. if (ch_width == CH_WIDTH_160MHZ &&
  734. is_fragmentation_160 &&
  735. spectral->report_info[smode].sscan_cfreq1 >
  736. spectral->report_info[smode].sscan_cfreq2)
  737. start_bin = 0;
  738. else
  739. start_bin = num_fft_bins;
  740. break;
  741. default:
  742. return QDF_STATUS_E_FAILURE;
  743. }
  744. dest_det_info->dest_start_bin_idx = start_bin;
  745. dest_det_info->dest_end_bin_idx =
  746. dest_det_info->dest_start_bin_idx +
  747. num_fft_bins - 1;
  748. dest_det_info->src_start_bin_idx = 0;
  749. }
  750. return QDF_STATUS_SUCCESS;
  751. }
  752. /**
  753. * target_if_update_session_info_from_report_ctx() - Update per-session
  754. * information from the consume report context. This includes populating start
  755. * and end bin indices, and set the start and end frequency per-detector.
  756. * @spectral: Pointer to target_if spectral internal structure
  757. * @fft_bin_size: Size of 1 FFT bin (in bytes)
  758. * @cfreq1: Center frequency of Detector 1
  759. * @cfreq2: Center frequency of Detector 2
  760. * @smode: Spectral scan mode
  761. *
  762. * Update per-session information from the consume report context.
  763. *
  764. * Return: Success/Failure
  765. */
  766. static QDF_STATUS
  767. target_if_update_session_info_from_report_ctx(
  768. struct target_if_spectral *spectral,
  769. uint8_t fft_bin_size,
  770. uint32_t cfreq1, uint32_t cfreq2,
  771. enum spectral_scan_mode smode)
  772. {
  773. struct target_if_spectral_ops *p_sops;
  774. struct per_session_report_info *rpt_info;
  775. struct per_session_det_map *det_map;
  776. struct per_session_dest_det_info *dest_det_info;
  777. enum phy_ch_width ch_width;
  778. struct wlan_objmgr_psoc *psoc;
  779. bool is_fragmentation_160;
  780. QDF_STATUS ret;
  781. if (!spectral) {
  782. spectral_err_rl("Spectral LMAC object is null");
  783. return QDF_STATUS_E_NULL_VALUE;
  784. }
  785. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  786. spectral_err_rl("Invalid Spectral mode");
  787. return QDF_STATUS_E_FAILURE;
  788. }
  789. if (!spectral->pdev_obj) {
  790. spectral_err_rl("Spectral PDEV is null");
  791. return QDF_STATUS_E_NULL_VALUE;
  792. }
  793. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  794. if (!psoc) {
  795. spectral_err_rl("psoc is null");
  796. return QDF_STATUS_E_NULL_VALUE;
  797. }
  798. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  799. rpt_info = &spectral->report_info[smode];
  800. ch_width = rpt_info->sscan_bw;
  801. is_fragmentation_160 = spectral->rparams.fragmentation_160[smode];
  802. rpt_info->pri20_freq = p_sops->get_current_channel(spectral, smode);
  803. rpt_info->cfreq1 = cfreq1;
  804. rpt_info->cfreq2 = cfreq2;
  805. /**
  806. * Convert cfreq1 and cfreq2 as per IEEE802.11 standards for gen3.
  807. * For gen2, we receive cfreq1/cfreq2 in line with IEEE802.11 standard
  808. * from the FW.
  809. * cfreq1: Centre frequency of the frequency span for 20/40/80 MHz BW.
  810. * Pri80 Segment centre frequency in MHz for 80p80/160 MHz BW.
  811. * cfreq2: For 80p80, indicates segment 2 centre frequency in MHz.
  812. * For 160MHz, indicates the center frequency of 160MHz span.
  813. *
  814. * For Agile mode, cfreq1/cfreq2 are taken as provided by user, no
  815. * conversion is done.
  816. * cfreq1: Center frequency of the span for 20/40/80/160. Frequency
  817. * value 1 for Agile 80p80.
  818. * cfreq2: Frequency value 2 for Agile 80p80.
  819. */
  820. if (spectral->spectral_gen == SPECTRAL_GEN3) {
  821. ret = target_if_get_ieee80211_format_cfreq(
  822. spectral, &rpt_info->cfreq1, &rpt_info->cfreq2,
  823. rpt_info->pri20_freq, SPECTRAL_SCAN_MODE_NORMAL);
  824. if (QDF_IS_STATUS_ERROR(ret)) {
  825. spectral_err_rl("Unable to get correct cfreq1/cfreq2");
  826. return QDF_STATUS_E_FAILURE;
  827. }
  828. }
  829. /* For Agile mode, sscan_cfreq1 and sscan_cfreq2 are populated
  830. * during Spectral start scan
  831. */
  832. if (smode == SPECTRAL_SCAN_MODE_NORMAL) {
  833. rpt_info->sscan_cfreq1 = rpt_info->cfreq1;
  834. rpt_info->sscan_cfreq2 = rpt_info->cfreq2;
  835. }
  836. if (ch_width == CH_WIDTH_80P80MHZ && wlan_psoc_nif_fw_ext_cap_get(
  837. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  838. /* Restricted 80p80 */
  839. struct spectral_fft_bin_markers_160_165mhz *marker;
  840. struct sscan_detector_list *detector_list;
  841. marker = &spectral->rparams.marker[smode];
  842. if (!marker->is_valid)
  843. return QDF_STATUS_E_FAILURE;
  844. /**
  845. * Restricted 80p80 on Pine has only 1 detector for
  846. * normal/agile spectral scan. So, detector_list will
  847. * have only one detector
  848. */
  849. detector_list = &spectral->detector_list[smode][ch_width];
  850. det_map = &spectral->det_map[detector_list->detectors[0]];
  851. dest_det_info = &det_map->dest_det_info[0];
  852. dest_det_info->dest_start_bin_idx = marker->start_pri80;
  853. dest_det_info->dest_end_bin_idx =
  854. dest_det_info->dest_start_bin_idx +
  855. marker->num_pri80 - 1;
  856. dest_det_info->src_start_bin_idx = marker->start_pri80 *
  857. fft_bin_size;
  858. dest_det_info = &det_map->dest_det_info[1];
  859. dest_det_info->dest_start_bin_idx = marker->start_sec80;
  860. dest_det_info->dest_end_bin_idx =
  861. dest_det_info->dest_start_bin_idx +
  862. marker->num_sec80 - 1;
  863. dest_det_info->src_start_bin_idx = marker->start_sec80 *
  864. fft_bin_size;
  865. dest_det_info = &det_map->dest_det_info[2];
  866. dest_det_info->dest_start_bin_idx = marker->start_5mhz;
  867. dest_det_info->dest_end_bin_idx =
  868. dest_det_info->dest_start_bin_idx +
  869. marker->num_5mhz - 1;
  870. dest_det_info->src_start_bin_idx = marker->start_5mhz *
  871. fft_bin_size;
  872. } else {
  873. ret = target_if_populate_fft_bins_info(spectral, smode);
  874. if (QDF_IS_STATUS_ERROR(ret)) {
  875. spectral_err_rl("Error in populating fft bins info");
  876. return QDF_STATUS_E_FAILURE;
  877. }
  878. }
  879. return QDF_STATUS_SUCCESS;
  880. }
  881. #endif /* OPTIMIZED_SAMP_MESSAGE */
  882. int
  883. target_if_process_phyerr_gen2(struct target_if_spectral *spectral,
  884. uint8_t *data,
  885. uint32_t datalen,
  886. struct target_if_spectral_rfqual_info *p_rfqual,
  887. struct target_if_spectral_chan_info *p_chaninfo,
  888. uint64_t tsf64,
  889. struct target_if_spectral_acs_stats *acs_stats)
  890. {
  891. /*
  892. * XXX : The classifier do not use all the members of the SAMP
  893. * message data format.
  894. * The classifier only depends upon the following parameters
  895. *
  896. * 1. Frequency (freq, msg->freq)
  897. * 2. Spectral RSSI (spectral_rssi,
  898. * msg->samp_data.spectral_rssi)
  899. * 3. Bin Power Count (bin_pwr_count,
  900. * msg->samp_data.bin_pwr_count)
  901. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  902. * 5. Spectral Timestamp (spectral_tstamp,
  903. * msg->samp_data.spectral_tstamp)
  904. * 6. MAC Address (macaddr, msg->macaddr)
  905. *
  906. * This function prepares the params structure and populates it
  907. * with
  908. * relevant values, this is in turn passed to
  909. * spectral_create_samp_msg()
  910. * to prepare fully formatted Spectral SAMP message
  911. *
  912. * XXX : Need to verify
  913. * 1. Order of FFT bin values
  914. *
  915. */
  916. struct target_if_samp_msg_params params;
  917. struct spectral_search_fft_info_gen2 search_fft_info;
  918. struct spectral_search_fft_info_gen2 *p_sfft = &search_fft_info;
  919. struct spectral_search_fft_info_gen2 search_fft_info_sec80;
  920. struct spectral_search_fft_info_gen2 *p_sfft_sec80 =
  921. &search_fft_info_sec80;
  922. uint32_t segid_skiplen = 0;
  923. int8_t rssi_up = 0;
  924. int8_t rssi_low = 0;
  925. int8_t chn_idx_highest_enabled = 0;
  926. int8_t chn_idx_lowest_enabled = 0;
  927. uint8_t control_rssi = 0;
  928. uint8_t extension_rssi = 0;
  929. uint8_t combined_rssi = 0;
  930. uint32_t tstamp = 0;
  931. struct target_if_spectral_ops *p_sops =
  932. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  933. struct spectral_phyerr_tlv_gen2 *ptlv =
  934. (struct spectral_phyerr_tlv_gen2 *)data;
  935. struct spectral_phyerr_tlv_gen2 *ptlv_sec80 = NULL;
  936. struct spectral_phyerr_fft_gen2 *pfft = NULL;
  937. struct spectral_phyerr_fft_gen2 *pfft_sec80 = NULL;
  938. uint8_t segid = 0;
  939. uint8_t segid_sec80 = 0;
  940. enum phy_ch_width ch_width =
  941. spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  942. if (spectral->is_160_format)
  943. segid_skiplen = sizeof(SPECTRAL_SEGID_INFO);
  944. pfft = (struct spectral_phyerr_fft_gen2 *)(
  945. data +
  946. sizeof(struct spectral_phyerr_tlv_gen2) +
  947. sizeof(struct spectral_phyerr_hdr_gen2) +
  948. segid_skiplen);
  949. /*
  950. * XXX Extend SPECTRAL_DPRINTK() to use spectral_debug_level,
  951. * and use this facility inside spectral_dump_phyerr_data()
  952. * and supporting functions.
  953. */
  954. if (spectral_debug_level & DEBUG_SPECTRAL2)
  955. target_if_spectral_dump_phyerr_data_gen2(
  956. data, datalen,
  957. spectral->is_160_format);
  958. if (spectral_debug_level & DEBUG_SPECTRAL4) {
  959. target_if_spectral_dump_phyerr_data_gen2(
  960. data, datalen,
  961. spectral->is_160_format);
  962. spectral_debug_level = DEBUG_SPECTRAL;
  963. }
  964. if (ptlv->signature != SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  965. /*
  966. * EV# 118023: We tentatively disable the below print
  967. * and provide stats instead.
  968. */
  969. spectral->diag_stats.spectral_mismatch++;
  970. return -EPERM;
  971. }
  972. OS_MEMZERO(&params, sizeof(params));
  973. /* Gen 2 only supports normal Spectral scan currently */
  974. params.smode = SPECTRAL_SCAN_MODE_NORMAL;
  975. if (ptlv->tag == TLV_TAG_SEARCH_FFT_REPORT_GEN2) {
  976. if (spectral->is_160_format) {
  977. segid = *((SPECTRAL_SEGID_INFO *)(
  978. (uint8_t *)ptlv +
  979. sizeof(struct spectral_phyerr_tlv_gen2) +
  980. sizeof(struct spectral_phyerr_hdr_gen2)));
  981. if (segid != 0) {
  982. struct spectral_diag_stats *p_diag_stats =
  983. &spectral->diag_stats;
  984. p_diag_stats->spectral_vhtseg1id_mismatch++;
  985. return -EPERM;
  986. }
  987. }
  988. target_if_process_sfft_report_gen2(ptlv, ptlv->length,
  989. &search_fft_info);
  990. tstamp = p_sops->get_tsf64(spectral) & SPECTRAL_TSMASK;
  991. combined_rssi = p_rfqual->rssi_comb;
  992. if (spectral->upper_is_control)
  993. rssi_up = control_rssi;
  994. else
  995. rssi_up = extension_rssi;
  996. if (spectral->lower_is_control)
  997. rssi_low = control_rssi;
  998. else
  999. rssi_low = extension_rssi;
  1000. params.rssi = p_rfqual->rssi_comb;
  1001. params.lower_rssi = rssi_low;
  1002. params.upper_rssi = rssi_up;
  1003. if (spectral->sc_spectral_noise_pwr_cal) {
  1004. params.chain_ctl_rssi[0] =
  1005. p_rfqual->pc_rssi_info[0].rssi_pri20;
  1006. params.chain_ctl_rssi[1] =
  1007. p_rfqual->pc_rssi_info[1].rssi_pri20;
  1008. params.chain_ctl_rssi[2] =
  1009. p_rfqual->pc_rssi_info[2].rssi_pri20;
  1010. params.chain_ext_rssi[0] =
  1011. p_rfqual->pc_rssi_info[0].rssi_sec20;
  1012. params.chain_ext_rssi[1] =
  1013. p_rfqual->pc_rssi_info[1].rssi_sec20;
  1014. params.chain_ext_rssi[2] =
  1015. p_rfqual->pc_rssi_info[2].rssi_sec20;
  1016. }
  1017. /*
  1018. * XXX : This actually depends on the programmed chain mask
  1019. * This value decides the per-chain enable mask to select
  1020. * the input ADC for search FTT.
  1021. * For modes upto VHT80, if more than one chain is
  1022. * enabled, the max valid chain
  1023. * is used. LSB corresponds to chain zero.
  1024. * For VHT80_80 and VHT160, the lowest enabled chain is
  1025. * used for primary
  1026. * detection and highest enabled chain is used for
  1027. * secondary detection.
  1028. *
  1029. * XXX : The current algorithm do not use these control and
  1030. * extension channel
  1031. * Instead, it just relies on the combined RSSI values
  1032. * only.
  1033. * For fool-proof detection algorithm, we should take
  1034. * these RSSI values in to account.
  1035. * This is marked for future enhancements.
  1036. */
  1037. chn_idx_highest_enabled =
  1038. ((spectral->params[params.smode].ss_chn_mask & 0x8) ? 3 :
  1039. (spectral->params[params.smode].ss_chn_mask & 0x4) ? 2 :
  1040. (spectral->params[params.smode].ss_chn_mask & 0x2) ? 1 : 0);
  1041. chn_idx_lowest_enabled =
  1042. ((spectral->params[params.smode].ss_chn_mask & 0x1) ? 0 :
  1043. (spectral->params[params.smode].ss_chn_mask & 0x2) ? 1 :
  1044. (spectral->params[params.smode].ss_chn_mask & 0x4) ? 2 : 3);
  1045. control_rssi = (uint8_t)
  1046. p_rfqual->pc_rssi_info[chn_idx_highest_enabled].rssi_pri20;
  1047. extension_rssi = (uint8_t)
  1048. p_rfqual->pc_rssi_info[chn_idx_highest_enabled].rssi_sec20;
  1049. params.bwinfo = 0;
  1050. params.tstamp = 0;
  1051. params.max_mag = p_sfft->peak_mag;
  1052. params.max_index = p_sfft->peak_inx;
  1053. params.max_exp = 0;
  1054. params.peak = 0;
  1055. params.bin_pwr_data = (uint8_t *)pfft;
  1056. params.freq = p_sops->get_current_channel(spectral,
  1057. params.smode);
  1058. params.freq_loading = 0;
  1059. params.interf_list.count = 0;
  1060. params.max_lower_index = 0;
  1061. params.max_upper_index = 0;
  1062. params.nb_lower = 0;
  1063. params.nb_upper = 0;
  1064. /*
  1065. * For modes upto VHT80, the noise floor is populated with the
  1066. * one corresponding
  1067. * to the highest enabled antenna chain
  1068. */
  1069. params.noise_floor =
  1070. p_rfqual->noise_floor[chn_idx_highest_enabled];
  1071. params.datalen = ptlv->length;
  1072. params.pwr_count = ptlv->length -
  1073. sizeof(struct spectral_phyerr_hdr_gen2) - segid_skiplen;
  1074. params.tstamp = (tsf64 & SPECTRAL_TSMASK);
  1075. acs_stats->ctrl_nf = params.noise_floor;
  1076. acs_stats->ext_nf = params.noise_floor;
  1077. acs_stats->nfc_ctl_rssi = control_rssi;
  1078. acs_stats->nfc_ext_rssi = extension_rssi;
  1079. if (spectral->is_160_format &&
  1080. is_ch_width_160_or_80p80(ch_width)) {
  1081. /*
  1082. * We expect to see one more Search FFT report, and it
  1083. * should be equal in size to the current one.
  1084. */
  1085. if (datalen < (
  1086. 2 * (
  1087. sizeof(struct spectral_phyerr_tlv_gen2) +
  1088. ptlv->length))) {
  1089. struct spectral_diag_stats *p_diag_stats =
  1090. &spectral->diag_stats;
  1091. p_diag_stats->spectral_sec80_sfft_insufflen++;
  1092. return -EPERM;
  1093. }
  1094. ptlv_sec80 = (struct spectral_phyerr_tlv_gen2 *)(
  1095. data +
  1096. sizeof(struct spectral_phyerr_tlv_gen2) +
  1097. ptlv->length);
  1098. if (ptlv_sec80->signature !=
  1099. SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  1100. spectral->diag_stats.spectral_mismatch++;
  1101. return -EPERM;
  1102. }
  1103. if (ptlv_sec80->tag != TLV_TAG_SEARCH_FFT_REPORT_GEN2) {
  1104. spectral->diag_stats.spectral_no_sec80_sfft++;
  1105. return -EPERM;
  1106. }
  1107. segid_sec80 = *((SPECTRAL_SEGID_INFO *)(
  1108. (uint8_t *)ptlv_sec80 +
  1109. sizeof(struct spectral_phyerr_tlv_gen2) +
  1110. sizeof(struct spectral_phyerr_hdr_gen2)));
  1111. if (segid_sec80 != 1) {
  1112. struct spectral_diag_stats *p_diag_stats =
  1113. &spectral->diag_stats;
  1114. p_diag_stats->spectral_vhtseg2id_mismatch++;
  1115. return -EPERM;
  1116. }
  1117. params.vhtop_ch_freq_seg1 = p_chaninfo->center_freq1;
  1118. params.vhtop_ch_freq_seg2 = p_chaninfo->center_freq2;
  1119. target_if_process_sfft_report_gen2(
  1120. ptlv_sec80,
  1121. ptlv_sec80->length,
  1122. &search_fft_info_sec80);
  1123. pfft_sec80 = (struct spectral_phyerr_fft_gen2 *)(
  1124. ((uint8_t *)ptlv_sec80) +
  1125. sizeof(struct spectral_phyerr_tlv_gen2) +
  1126. sizeof(struct spectral_phyerr_hdr_gen2) +
  1127. segid_skiplen);
  1128. /* XXX: Confirm. TBD at SoD. */
  1129. params.rssi_sec80 = p_rfqual->rssi_comb;
  1130. if (spectral->is_sec80_rssi_war_required)
  1131. params.rssi_sec80 =
  1132. target_if_get_combrssi_sec80_seg_gen2
  1133. (spectral, &search_fft_info_sec80);
  1134. /* XXX: Determine dynamically. TBD at SoD. */
  1135. /*
  1136. * For VHT80_80/VHT160, the noise floor for primary
  1137. * 80MHz segment is populated with the
  1138. * lowest enabled antenna chain and the noise floor for
  1139. * secondary 80MHz segment is populated
  1140. * with the highest enabled antenna chain
  1141. */
  1142. params.noise_floor_sec80 =
  1143. p_rfqual->noise_floor[chn_idx_highest_enabled];
  1144. params.noise_floor =
  1145. p_rfqual->noise_floor[chn_idx_lowest_enabled];
  1146. params.max_mag_sec80 = p_sfft_sec80->peak_mag;
  1147. params.max_index_sec80 = p_sfft_sec80->peak_inx;
  1148. /* XXX Does this definition of datalen *still hold? */
  1149. params.datalen_sec80 = ptlv_sec80->length;
  1150. params.pwr_count_sec80 =
  1151. ptlv_sec80->length -
  1152. sizeof(struct spectral_phyerr_hdr_gen2) -
  1153. segid_skiplen;
  1154. params.bin_pwr_data_sec80 = (uint8_t *)pfft_sec80;
  1155. }
  1156. qdf_mem_copy(&params.classifier_params,
  1157. &spectral->classifier_params,
  1158. sizeof(struct spectral_classifier_params));
  1159. target_if_spectral_log_SAMP_param(&params);
  1160. target_if_spectral_create_samp_msg(spectral, &params);
  1161. }
  1162. return 0;
  1163. }
  1164. int
  1165. target_if_spectral_dump_hdr_gen2(struct spectral_phyerr_hdr_gen2 *phdr)
  1166. {
  1167. uint32_t a = 0;
  1168. uint32_t b = 0;
  1169. qdf_mem_copy(&a, (uint8_t *)phdr, sizeof(int));
  1170. qdf_mem_copy(&b,
  1171. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  1172. sizeof(int));
  1173. spectral_debug("SPECTRAL : HEADER A 0x%x (%d)", a, a);
  1174. spectral_debug("SPECTRAL : HEADER B 0x%x (%d)", b, b);
  1175. return 0;
  1176. }
  1177. int8_t
  1178. target_if_get_combrssi_sec80_seg_gen2(
  1179. struct target_if_spectral *spectral,
  1180. struct spectral_search_fft_info_gen2 *p_sfft_sec80)
  1181. {
  1182. uint32_t avgpwr_db = 0;
  1183. uint32_t total_gain_db = 0;
  1184. uint32_t offset = 0;
  1185. int8_t comb_rssi = 0;
  1186. /* Obtain required parameters for algorithm from search FFT report */
  1187. avgpwr_db = p_sfft_sec80->avgpwr_db;
  1188. total_gain_db = p_sfft_sec80->total_gain_info;
  1189. /* Calculate offset */
  1190. offset = target_if_get_offset_swar_sec80(
  1191. spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL]);
  1192. /* Calculate RSSI */
  1193. comb_rssi = ((avgpwr_db - total_gain_db) + offset);
  1194. return comb_rssi;
  1195. }
  1196. int
  1197. target_if_spectral_dump_tlv_gen2(
  1198. struct spectral_phyerr_tlv_gen2 *ptlv, bool is_160_format)
  1199. {
  1200. int ret = 0;
  1201. /*
  1202. * TODO : Do not delete the following print
  1203. * The scripts used to validate Spectral depend on this Print
  1204. */
  1205. spectral_debug("SPECTRAL : TLV Length is 0x%x (%d)",
  1206. ptlv->length, ptlv->length);
  1207. switch (ptlv->tag) {
  1208. case TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2:
  1209. ret =
  1210. target_if_dump_summary_report_gen2(
  1211. ptlv, ptlv->length, is_160_format);
  1212. break;
  1213. case TLV_TAG_SEARCH_FFT_REPORT_GEN2:
  1214. ret =
  1215. target_if_dump_sfft_report_gen2(ptlv, ptlv->length,
  1216. is_160_format);
  1217. break;
  1218. case TLV_TAG_ADC_REPORT_GEN2:
  1219. ret = target_if_dump_adc_report_gen2(ptlv, ptlv->length);
  1220. break;
  1221. default:
  1222. spectral_warn("INVALID TLV");
  1223. ret = -1;
  1224. break;
  1225. }
  1226. return ret;
  1227. }
  1228. int
  1229. target_if_spectral_dump_phyerr_data_gen2(uint8_t *data, uint32_t datalen,
  1230. bool is_160_format)
  1231. {
  1232. struct spectral_phyerr_tlv_gen2 *ptlv = NULL;
  1233. uint32_t bytes_processed = 0;
  1234. uint32_t bytes_remaining = datalen;
  1235. uint32_t curr_tlv_complete_size = 0;
  1236. if (datalen < sizeof(struct spectral_phyerr_tlv_gen2)) {
  1237. spectral_err("Total PHY error data length %u too short to contain any TLVs",
  1238. datalen);
  1239. return -EPERM;
  1240. }
  1241. while (bytes_processed < datalen) {
  1242. if (bytes_remaining < sizeof(struct spectral_phyerr_tlv_gen2)) {
  1243. spectral_err("Remaining PHY error data length %u too short to contain a TLV",
  1244. bytes_remaining);
  1245. return -EPERM;
  1246. }
  1247. ptlv = (struct spectral_phyerr_tlv_gen2 *)(data +
  1248. bytes_processed);
  1249. if (ptlv->signature != SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  1250. spectral_err("Invalid signature 0x%x!",
  1251. ptlv->signature);
  1252. return -EPERM;
  1253. }
  1254. curr_tlv_complete_size =
  1255. sizeof(struct spectral_phyerr_tlv_gen2) +
  1256. ptlv->length;
  1257. if (curr_tlv_complete_size > bytes_remaining) {
  1258. spectral_err("TLV size %d greater than number of bytes remaining %d",
  1259. curr_tlv_complete_size, bytes_remaining);
  1260. return -EPERM;
  1261. }
  1262. if (target_if_spectral_dump_tlv_gen2(ptlv, is_160_format) == -1)
  1263. return -EPERM;
  1264. bytes_processed += curr_tlv_complete_size;
  1265. bytes_remaining = datalen - bytes_processed;
  1266. }
  1267. return 0;
  1268. }
  1269. #ifdef DIRECT_BUF_RX_ENABLE
  1270. /**
  1271. * target_if_get_spectral_mode() - Get Spectral scan mode corresponding to a
  1272. * detector id
  1273. * @detector_id: detector id in the Spectral report
  1274. * @rparams: pointer to report params object
  1275. *
  1276. * Helper API to get Spectral scan mode from the detector ID. This mapping is
  1277. * target specific.
  1278. *
  1279. * Return: Spectral scan mode
  1280. */
  1281. static enum spectral_scan_mode
  1282. target_if_get_spectral_mode(enum spectral_detector_id detector_id,
  1283. struct spectral_report_params *rparams)
  1284. {
  1285. if (detector_id >= SPECTRAL_DETECTOR_ID_MAX) {
  1286. spectral_err_rl("Invalid detector id %d", detector_id);
  1287. return SPECTRAL_SCAN_MODE_INVALID;
  1288. }
  1289. return rparams->detid_mode_table[detector_id];
  1290. }
  1291. /**
  1292. * target_if_spectral_get_bin_count_after_len_adj() - Get number of FFT bins in
  1293. * Spectral FFT report
  1294. * @fft_bin_len: FFT bin length reported by target
  1295. * @rpt_mode: Spectral report mode
  1296. * @swar: Spectral FFT bin length adjustments SWAR parameters
  1297. * @fft_bin_size: Size of one FFT bin in bytes
  1298. *
  1299. * Get actual number of FFT bins in the FFT report after adjusting the length
  1300. * by applying the SWARs for getting correct length.
  1301. *
  1302. * Return: FFT bin count
  1303. */
  1304. static size_t
  1305. target_if_spectral_get_bin_count_after_len_adj(
  1306. size_t fft_bin_len, uint8_t rpt_mode,
  1307. struct spectral_fft_bin_len_adj_swar *swar,
  1308. size_t *fft_bin_size)
  1309. {
  1310. size_t fft_bin_count = fft_bin_len;
  1311. if (rpt_mode == 1 && swar->null_fftbin_adj) {
  1312. /*
  1313. * No FFT bins are expected. Explicitly set FFT bin
  1314. * count to 0.
  1315. */
  1316. fft_bin_count = 0;
  1317. *fft_bin_size = 0;
  1318. } else {
  1319. /*
  1320. * Divide fft bin length by appropriate factor depending
  1321. * on the value of fftbin_size_war.
  1322. */
  1323. switch (swar->fftbin_size_war) {
  1324. case SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE:
  1325. fft_bin_count >>= 2;
  1326. *fft_bin_size = 4;
  1327. break;
  1328. case SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE:
  1329. fft_bin_count >>= 1;
  1330. *fft_bin_size = 2;
  1331. /* Ideally we should be dividing fft bin length
  1332. * by 2. Due to a HW bug, actual length is two
  1333. * times the expected length.
  1334. */
  1335. if (swar->packmode_fftbin_size_adj)
  1336. fft_bin_count >>= 1;
  1337. break;
  1338. case SPECTRAL_FFTBIN_SIZE_NO_WAR:
  1339. *fft_bin_size = 1;
  1340. /* No length adjustment */
  1341. break;
  1342. default:
  1343. qdf_assert_always(0);
  1344. }
  1345. if (rpt_mode == 2 && swar->inband_fftbin_size_adj)
  1346. fft_bin_count >>= 1;
  1347. }
  1348. return fft_bin_count;
  1349. }
  1350. #ifndef OPTIMIZED_SAMP_MESSAGE
  1351. /**
  1352. * target_if_process_sfft_report_gen3() - Process Search FFT Report for gen3
  1353. * @p_fft_report: Pointer to fft report
  1354. * @p_sfft: Pointer to search fft report
  1355. * @rparams: pointer to report params object
  1356. *
  1357. * Process Search FFT Report for gen3
  1358. *
  1359. * Return: Success/Failure
  1360. */
  1361. static int
  1362. target_if_process_sfft_report_gen3(
  1363. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  1364. struct spectral_search_fft_info_gen3 *p_sfft,
  1365. struct spectral_report_params *rparams)
  1366. {
  1367. int32_t peak_sidx = 0;
  1368. int32_t peak_mag;
  1369. qdf_assert_always(p_fft_report);
  1370. qdf_assert_always(p_sfft);
  1371. qdf_assert_always(rparams);
  1372. /*
  1373. * For simplicity, everything is defined as uint32_t (except one).
  1374. * Proper code will later use the right sizes.
  1375. */
  1376. /*
  1377. * For easy comparision between MDK team and OS team, the MDK script
  1378. * variable names have been used
  1379. */
  1380. /* Populate the Search FFT Info */
  1381. p_sfft->timestamp = p_fft_report->fft_timestamp;
  1382. p_sfft->fft_detector_id = get_bitfield(p_fft_report->hdr_a,
  1383. 2, 0);
  1384. p_sfft->fft_num = get_bitfield(p_fft_report->hdr_a, 3, 2);
  1385. switch (rparams->version) {
  1386. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1387. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  1388. 12, 5);
  1389. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 17);
  1390. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_a, 3, 28);
  1391. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  1392. 9, 0);
  1393. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  1394. 8, 9);
  1395. break;
  1396. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1397. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  1398. 14, 5);
  1399. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 19);
  1400. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_b, 3, 0);
  1401. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  1402. 9, 3);
  1403. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  1404. 8, 12);
  1405. break;
  1406. default:
  1407. qdf_assert_always(0);
  1408. }
  1409. p_sfft->fft_peak_sidx = unsigned_to_signed(peak_sidx, 11);
  1410. p_sfft->fft_num_str_bins_ib = get_bitfield(p_fft_report->hdr_c,
  1411. 8, 0);
  1412. peak_mag = get_bitfield(p_fft_report->hdr_c, 10, 8);
  1413. p_sfft->fft_peak_mag = unsigned_to_signed(peak_mag, 10);
  1414. p_sfft->fft_avgpwr_db = get_bitfield(p_fft_report->hdr_c,
  1415. 7, 18);
  1416. p_sfft->fft_relpwr_db = get_bitfield(p_fft_report->hdr_c,
  1417. 7, 25);
  1418. return 0;
  1419. }
  1420. #endif
  1421. /**
  1422. * target_if_dump_fft_report_gen3() - Dump FFT Report for gen3
  1423. * @spectral: Pointer to Spectral object
  1424. * @smode: Spectral scan mode
  1425. * @p_fft_report: Pointer to fft report
  1426. * @p_sfft: Pointer to search fft report
  1427. *
  1428. * Dump FFT Report for gen3
  1429. *
  1430. * Return: void
  1431. */
  1432. static void
  1433. target_if_dump_fft_report_gen3(struct target_if_spectral *spectral,
  1434. enum spectral_scan_mode smode,
  1435. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  1436. struct spectral_search_fft_info_gen3 *p_sfft)
  1437. {
  1438. size_t fft_hdr_length;
  1439. size_t report_len;
  1440. size_t fft_bin_len;
  1441. size_t fft_bin_count;
  1442. size_t fft_bin_size;
  1443. size_t fft_bin_len_inband_tfer = 0;
  1444. uint8_t *fft_bin_buf = NULL;
  1445. size_t fft_bin_buf_size;
  1446. uint8_t tag, signature;
  1447. qdf_assert_always(spectral);
  1448. /* There won't be FFT report/bins in report mode 0, so return */
  1449. if (!spectral->params[smode].ss_rpt_mode)
  1450. return;
  1451. fft_hdr_length = get_bitfield(
  1452. p_fft_report->fft_hdr_lts,
  1453. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  1454. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  1455. tag = get_bitfield(p_fft_report->fft_hdr_lts,
  1456. SPECTRAL_REPORT_LTS_TAG_SIZE_GEN3,
  1457. SPECTRAL_REPORT_LTS_TAG_POS_GEN3);
  1458. signature = get_bitfield(p_fft_report->fft_hdr_lts,
  1459. SPECTRAL_REPORT_LTS_SIGNATURE_SIZE_GEN3,
  1460. SPECTRAL_REPORT_LTS_SIGNATURE_POS_GEN3);
  1461. report_len = (fft_hdr_length + 8);
  1462. fft_bin_len = fft_hdr_length - spectral->rparams.fft_report_hdr_len;
  1463. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  1464. fft_bin_len,
  1465. spectral->params[smode].ss_rpt_mode,
  1466. &spectral->len_adj_swar, &fft_bin_size);
  1467. if ((spectral->params[smode].ss_rpt_mode == 2) &&
  1468. spectral->len_adj_swar.inband_fftbin_size_adj)
  1469. fft_bin_len_inband_tfer = fft_bin_len >> 1;
  1470. spectral_debug("Spectral FFT Report");
  1471. spectral_debug("fft_timestamp = 0x%x", p_fft_report->fft_timestamp);
  1472. spectral_debug("fft_hdr_length = %zu(32 bit words)",
  1473. fft_hdr_length >> 2);
  1474. spectral_debug("fft_hdr_tag = 0x%x", tag);
  1475. spectral_debug("fft_hdr_sig = 0x%x", signature);
  1476. spectral_debug("Length field in search fft report is %zu(0x%zx) bytes",
  1477. fft_hdr_length, fft_hdr_length);
  1478. spectral_debug("Total length of search fft report is %zu(0x%zx) bytes",
  1479. report_len, report_len);
  1480. spectral_debug("Target reported fftbins in report is %zu(0x%zx)",
  1481. fft_bin_len, fft_bin_len);
  1482. if ((spectral->params[smode].ss_rpt_mode == 1) &&
  1483. spectral->len_adj_swar.null_fftbin_adj)
  1484. spectral_debug("WAR: Considering number of FFT bins as 0");
  1485. else if ((spectral->params[smode].ss_rpt_mode == 2) &&
  1486. spectral->len_adj_swar.inband_fftbin_size_adj) {
  1487. spectral_debug("FW fftbins actually transferred (in-band report mode) %zu(0x%zx)",
  1488. fft_bin_len_inband_tfer,
  1489. fft_bin_len_inband_tfer);
  1490. }
  1491. spectral_debug("Actual number of fftbins in report is %zu(0x%zx)",
  1492. fft_bin_count, fft_bin_count);
  1493. spectral_debug("fft_detector_id = %u", p_sfft->fft_detector_id);
  1494. spectral_debug("fft_num = %u", p_sfft->fft_num);
  1495. spectral_debug("fft_radar_check = %u", p_sfft->fft_radar_check);
  1496. spectral_debug("fft_peak_sidx = %d", p_sfft->fft_peak_sidx);
  1497. spectral_debug("fft_chn_idx = %u", p_sfft->fft_chn_idx);
  1498. spectral_debug("fft_base_pwr_db = %u", p_sfft->fft_base_pwr_db);
  1499. spectral_debug("fft_total_gain_db = %u", p_sfft->fft_total_gain_db);
  1500. spectral_debug("fft_num_str_bins_ib = %u", p_sfft->fft_num_str_bins_ib);
  1501. spectral_debug("fft_peak_mag = %d", p_sfft->fft_peak_mag);
  1502. spectral_debug("fft_avgpwr_db = %u", p_sfft->fft_avgpwr_db);
  1503. spectral_debug("fft_relpwr_db = %u", p_sfft->fft_relpwr_db);
  1504. fft_bin_buf_size = fft_bin_count;
  1505. if (fft_bin_count > 0) {
  1506. int idx;
  1507. if (spectral->len_adj_swar.fftbin_size_war ==
  1508. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
  1509. uint32_t *binptr_32 = (uint32_t *)&p_fft_report->buf;
  1510. uint16_t *fft_bin_buf_16 = NULL;
  1511. /* Useful width of FFT bin is 10 bits, increasing it to
  1512. * byte boundary makes it 2 bytes. Hence, buffer to be
  1513. * allocated should be of size fft_bin_count
  1514. * multiplied by 2.
  1515. */
  1516. fft_bin_buf_size <<= 1;
  1517. fft_bin_buf_16 = (uint16_t *)qdf_mem_malloc(
  1518. fft_bin_buf_size);
  1519. if (!fft_bin_buf_16) {
  1520. spectral_err("Failed to allocate memory");
  1521. return;
  1522. }
  1523. for (idx = 0; idx < fft_bin_count; idx++)
  1524. fft_bin_buf_16[idx] =
  1525. *((uint16_t *)binptr_32++);
  1526. fft_bin_buf = (uint8_t *)fft_bin_buf_16;
  1527. } else if (spectral->len_adj_swar.fftbin_size_war ==
  1528. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  1529. uint16_t *binptr_16 = (uint16_t *)&p_fft_report->buf;
  1530. uint16_t *fft_bin_buf_16 = NULL;
  1531. /* Useful width of FFT bin is 10 bits, increasing it to
  1532. * byte boundary makes it 2 bytes. Hence, buffer to be
  1533. * allocated should be of size fft_bin_count
  1534. * multiplied by 2.
  1535. */
  1536. fft_bin_buf_size <<= 1;
  1537. fft_bin_buf_16 = (uint16_t *)qdf_mem_malloc(
  1538. fft_bin_buf_size);
  1539. if (!fft_bin_buf_16) {
  1540. spectral_err("Failed to allocate memory");
  1541. return;
  1542. }
  1543. for (idx = 0; idx < fft_bin_count; idx++)
  1544. fft_bin_buf_16[idx] = *(binptr_16++);
  1545. fft_bin_buf = (uint8_t *)fft_bin_buf_16;
  1546. } else {
  1547. fft_bin_buf = (uint8_t *)&p_fft_report->buf;
  1548. }
  1549. spectral_debug("FFT bin buffer size = %zu", fft_bin_buf_size);
  1550. spectral_debug("FFT bins:");
  1551. target_if_spectral_hexdump(fft_bin_buf, fft_bin_buf_size);
  1552. if ((spectral->len_adj_swar.fftbin_size_war !=
  1553. SPECTRAL_FFTBIN_SIZE_NO_WAR) && fft_bin_buf)
  1554. qdf_mem_free(fft_bin_buf);
  1555. }
  1556. }
  1557. #endif
  1558. #ifdef OPTIMIZED_SAMP_MESSAGE
  1559. QDF_STATUS
  1560. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  1561. enum spectral_scan_mode smode,
  1562. uint8_t detector_id) {
  1563. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1564. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1565. spectral_err_rl("Invalid Spectral mode %d", smode);
  1566. return QDF_STATUS_E_INVAL;
  1567. }
  1568. if (!is_ch_width_160_or_80p80(spectral->report_info[smode].sscan_bw)) {
  1569. spectral_err_rl("Scan BW %d is not 160/80p80 for mode %d",
  1570. spectral->report_info[smode].sscan_bw, smode);
  1571. return QDF_STATUS_E_FAILURE;
  1572. }
  1573. switch (spectral->state_160mhz_delivery[smode]) {
  1574. case SPECTRAL_REPORT_WAIT_PRIMARY80:
  1575. if (detector_id == SPECTRAL_DETECTOR_ID_0)
  1576. spectral->state_160mhz_delivery[smode] =
  1577. SPECTRAL_REPORT_WAIT_SECONDARY80;
  1578. else {
  1579. status = QDF_STATUS_E_FAILURE;
  1580. spectral->diag_stats.spectral_vhtseg1id_mismatch++;
  1581. }
  1582. break;
  1583. case SPECTRAL_REPORT_WAIT_SECONDARY80:
  1584. if (detector_id == SPECTRAL_DETECTOR_ID_1)
  1585. spectral->state_160mhz_delivery[smode] =
  1586. SPECTRAL_REPORT_WAIT_PRIMARY80;
  1587. else {
  1588. spectral->state_160mhz_delivery[smode] =
  1589. SPECTRAL_REPORT_WAIT_PRIMARY80;
  1590. status = QDF_STATUS_E_FAILURE;
  1591. spectral->diag_stats.spectral_vhtseg2id_mismatch++;
  1592. }
  1593. break;
  1594. default:
  1595. break;
  1596. }
  1597. return status;
  1598. }
  1599. #else
  1600. QDF_STATUS
  1601. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  1602. enum spectral_scan_mode smode,
  1603. uint8_t detector_id) {
  1604. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1605. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1606. spectral_err_rl("Invalid Spectral mode %d", smode);
  1607. return QDF_STATUS_E_INVAL;
  1608. }
  1609. if (!is_ch_width_160_or_80p80(spectral->ch_width[smode])) {
  1610. spectral_err_rl("Scan BW %d is not 160/80p80 for mode %d",
  1611. spectral->ch_width[smode], smode);
  1612. return QDF_STATUS_E_FAILURE;
  1613. }
  1614. switch (spectral->state_160mhz_delivery[smode]) {
  1615. case SPECTRAL_REPORT_WAIT_PRIMARY80:
  1616. if (detector_id == SPECTRAL_DETECTOR_ID_0)
  1617. spectral->state_160mhz_delivery[smode] =
  1618. SPECTRAL_REPORT_RX_PRIMARY80;
  1619. else {
  1620. status = QDF_STATUS_E_FAILURE;
  1621. spectral->diag_stats.spectral_vhtseg1id_mismatch++;
  1622. }
  1623. break;
  1624. case SPECTRAL_REPORT_WAIT_SECONDARY80:
  1625. if (detector_id == SPECTRAL_DETECTOR_ID_1)
  1626. spectral->state_160mhz_delivery[smode] =
  1627. SPECTRAL_REPORT_RX_SECONDARY80;
  1628. else {
  1629. spectral->state_160mhz_delivery[smode] =
  1630. SPECTRAL_REPORT_WAIT_PRIMARY80;
  1631. status = QDF_STATUS_E_FAILURE;
  1632. spectral->diag_stats.spectral_vhtseg2id_mismatch++;
  1633. }
  1634. break;
  1635. case SPECTRAL_REPORT_RX_SECONDARY80:
  1636. /* We don't care about detector id in this state. */
  1637. reset_160mhz_delivery_state_machine(spectral, smode);
  1638. break;
  1639. case SPECTRAL_REPORT_RX_PRIMARY80:
  1640. /* We don't care about detector id in this state */
  1641. spectral->state_160mhz_delivery[smode] =
  1642. SPECTRAL_REPORT_WAIT_SECONDARY80;
  1643. break;
  1644. default:
  1645. break;
  1646. }
  1647. return status;
  1648. }
  1649. #endif /* OPTIMIZED_SAMP_MESSAGE */
  1650. #ifdef DIRECT_BUF_RX_ENABLE
  1651. /**
  1652. * target_if_get_detector_id_sscan_summary_report_gen3() - Get Spectral detector
  1653. * ID from Spectral summary report
  1654. * @data: Pointer to Spectral summary report
  1655. *
  1656. * Return: Detector ID
  1657. */
  1658. static uint8_t
  1659. target_if_get_detector_id_sscan_summary_report_gen3(uint8_t *data) {
  1660. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  1661. uint8_t detector_id;
  1662. qdf_assert_always(data);
  1663. psscan_summary_report =
  1664. (struct spectral_sscan_summary_report_gen3 *)data;
  1665. detector_id = get_bitfield(
  1666. psscan_summary_report->hdr_a,
  1667. SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_SIZE_GEN3,
  1668. SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_POS_GEN3);
  1669. return detector_id;
  1670. }
  1671. #ifndef OPTIMIZED_SAMP_MESSAGE
  1672. /**
  1673. * target_if_consume_sscan_summary_report_gen3() - Consume Spectral summary
  1674. * report
  1675. * @data: Pointer to Spectral summary report
  1676. * @fields: Pointer to structure to be populated with extracted fields
  1677. * @rparams: Pointer to structure with Spectral report params
  1678. *
  1679. * Consume Spectral summary report for gen3
  1680. *
  1681. * Return: void
  1682. */
  1683. static void
  1684. target_if_consume_sscan_summary_report_gen3(
  1685. uint8_t *data,
  1686. struct sscan_report_fields_gen3 *fields,
  1687. struct spectral_report_params *rparams) {
  1688. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  1689. qdf_assert_always(data);
  1690. qdf_assert_always(fields);
  1691. qdf_assert_always(rparams);
  1692. psscan_summary_report =
  1693. (struct spectral_sscan_summary_report_gen3 *)data;
  1694. fields->sscan_agc_total_gain = get_bitfield(
  1695. psscan_summary_report->hdr_a,
  1696. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_SIZE_GEN3,
  1697. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_POS_GEN3);
  1698. fields->inband_pwr_db = get_bitfield(
  1699. psscan_summary_report->hdr_a,
  1700. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_SIZE_GEN3,
  1701. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_POS_GEN3);
  1702. fields->sscan_pri80 = get_bitfield(
  1703. psscan_summary_report->hdr_a,
  1704. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_SIZE_GEN3,
  1705. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_POS_GEN3);
  1706. switch (rparams->version) {
  1707. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  1708. fields->sscan_gainchange = get_bitfield(
  1709. psscan_summary_report->hdr_b,
  1710. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_SIZE_GEN3_V1,
  1711. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_POS_GEN3_V1);
  1712. break;
  1713. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  1714. fields->sscan_gainchange = get_bitfield(
  1715. psscan_summary_report->hdr_c,
  1716. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_SIZE_GEN3_V2,
  1717. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_POS_GEN3_V2);
  1718. break;
  1719. default:
  1720. qdf_assert_always(0);
  1721. }
  1722. }
  1723. #endif
  1724. /**
  1725. * target_if_verify_sig_and_tag_gen3() - Verify tag and signature
  1726. * of spectral report
  1727. * @spectral: Pointer to spectral object
  1728. * @data: Pointer to spectral summary report
  1729. * @exp_tag: iexpected tag value
  1730. *
  1731. * Process fft report for gen3
  1732. *
  1733. * Return: SUCCESS/FAILURE
  1734. */
  1735. static int
  1736. target_if_verify_sig_and_tag_gen3(struct target_if_spectral *spectral,
  1737. uint8_t *data, uint8_t exp_tag)
  1738. {
  1739. uint8_t tag = 0;
  1740. uint8_t signature = 0;
  1741. uint32_t lts;
  1742. lts = *((uint32_t *)(data + SPECTRAL_PHYERR_HDR_LTS_POS));
  1743. /* Peek into the data to figure out whether
  1744. * 1) Signature matches the expected value
  1745. * 2) What is inside the package (TAG ID is used for finding this)
  1746. */
  1747. tag = get_bitfield(lts,
  1748. SPECTRAL_REPORT_LTS_TAG_SIZE_GEN3,
  1749. SPECTRAL_REPORT_LTS_TAG_POS_GEN3);
  1750. signature = get_bitfield(lts,
  1751. SPECTRAL_REPORT_LTS_SIGNATURE_SIZE_GEN3,
  1752. SPECTRAL_REPORT_LTS_SIGNATURE_POS_GEN3);
  1753. if (signature != SPECTRAL_PHYERR_SIGNATURE_GEN3) {
  1754. spectral->diag_stats.spectral_mismatch++;
  1755. return -EINVAL;
  1756. }
  1757. if (tag != exp_tag) {
  1758. spectral->diag_stats.spectral_mismatch++;
  1759. return -EINVAL;
  1760. }
  1761. return 0;
  1762. }
  1763. static uint8_t
  1764. target_if_spectral_get_lowest_chn_idx(uint8_t chainmask)
  1765. {
  1766. uint8_t idx;
  1767. for (idx = 0; idx < DBR_MAX_CHAINS; idx++) {
  1768. if (chainmask & 0x1)
  1769. break;
  1770. chainmask >>= 1;
  1771. }
  1772. return idx;
  1773. }
  1774. #ifdef DIRECT_BUF_RX_DEBUG
  1775. static void target_if_spectral_check_buffer_poisoning(
  1776. struct target_if_spectral *spectral,
  1777. struct spectral_report *report,
  1778. int num_fft_bins, enum spectral_scan_mode smode)
  1779. {
  1780. uint32_t *data;
  1781. size_t len;
  1782. size_t words_to_check =
  1783. sizeof(struct spectral_sscan_summary_report_gen3) >> 2;
  1784. bool poisoned_words_found = false;
  1785. if (!spectral) {
  1786. spectral_err_rl("Spectral LMAC object is null");
  1787. return;
  1788. }
  1789. if (!spectral->dbr_buff_debug)
  1790. return;
  1791. if (!report) {
  1792. spectral_err_rl("Spectral report is null");
  1793. return;
  1794. }
  1795. /* Add search FFT report */
  1796. if (spectral->params[smode].ss_rpt_mode > 0)
  1797. words_to_check +=
  1798. sizeof(struct spectral_phyerr_fft_report_gen3) >> 2;
  1799. /* Now add the number of FFT bins */
  1800. if (spectral->params[smode].ss_rpt_mode > 1) {
  1801. /* Caller should take care to pass correct number of FFT bins */
  1802. if (spectral->len_adj_swar.fftbin_size_war ==
  1803. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE)
  1804. words_to_check += num_fft_bins;
  1805. else if (spectral->len_adj_swar.fftbin_size_war ==
  1806. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE)
  1807. words_to_check += (num_fft_bins >> 1);
  1808. }
  1809. data = (uint32_t *)report->data;
  1810. for (len = 0; len < words_to_check; ++len) {
  1811. if (*data == MEM_POISON_SIGNATURE) {
  1812. spectral_err("Pattern(%x) found in Spectral search FFT report at position %zu in the buffer %pK",
  1813. MEM_POISON_SIGNATURE,
  1814. (len << 2), report->data);
  1815. poisoned_words_found = true;
  1816. break;
  1817. }
  1818. ++data;
  1819. }
  1820. /* Crash the FW even if one word is poisoned */
  1821. if (poisoned_words_found) {
  1822. spectral_err("Pattern(%x) found in Spectral report, Hex dump of the sfft follows",
  1823. MEM_POISON_SIGNATURE);
  1824. target_if_spectral_hexdump((unsigned char *)report->data,
  1825. words_to_check << 2);
  1826. spectral_err("Asserting the FW");
  1827. target_if_spectral_fw_hang(spectral);
  1828. }
  1829. }
  1830. static void target_if_spectral_verify_ts(struct target_if_spectral *spectral,
  1831. uint8_t *buf, uint32_t current_ts)
  1832. {
  1833. if (!spectral) {
  1834. spectral_err_rl("Spectral LMAC object is null");
  1835. return;
  1836. }
  1837. if (!spectral->dbr_buff_debug)
  1838. return;
  1839. if (spectral->prev_tstamp) {
  1840. if (current_ts == spectral->prev_tstamp) {
  1841. spectral_err("Spectral timestamp(%u) in the current buffer(%pK) is equal to the previous timestamp, same report DMAed twice? Asserting the FW",
  1842. current_ts, buf);
  1843. target_if_spectral_fw_hang(spectral);
  1844. }
  1845. }
  1846. spectral->prev_tstamp = current_ts;
  1847. }
  1848. #else
  1849. static void target_if_spectral_check_buffer_poisoning(
  1850. struct target_if_spectral *spectral,
  1851. struct spectral_report *report,
  1852. int num_fft_bins, enum spectral_scan_mode smode)
  1853. {
  1854. }
  1855. static void target_if_spectral_verify_ts(struct target_if_spectral *spectral,
  1856. uint8_t *buf, uint32_t current_ts)
  1857. {
  1858. }
  1859. #endif
  1860. /**
  1861. * target_if_spectral_get_adjusted_timestamp() - Adjust Spectral time
  1862. * stamp to account for reset in time stamp due to target reset
  1863. * @twar: Spectral time stamp WAR related information
  1864. * @raw_timestamp: Spectral time stamp reported by target
  1865. * @reset_delay: Reset delay at target
  1866. * @smode: Spectral scan mode
  1867. *
  1868. * Correct time stamp to account for reset in time stamp due to target reset
  1869. *
  1870. * Return: Adjusted time stamp
  1871. */
  1872. static uint32_t
  1873. target_if_spectral_get_adjusted_timestamp(struct spectral_timestamp_war *twar,
  1874. uint32_t raw_timestamp,
  1875. uint32_t reset_delay,
  1876. enum spectral_scan_mode smode) {
  1877. qdf_assert_always(smode < SPECTRAL_SCAN_MODE_MAX);
  1878. if (reset_delay) {
  1879. enum spectral_scan_mode m =
  1880. SPECTRAL_SCAN_MODE_NORMAL;
  1881. /* Adjust the offset for all the Spectral modes.
  1882. * Target will be sending the non zero reset delay for
  1883. * the first Spectral report after reset. This delay is
  1884. * common for all the Spectral modes.
  1885. */
  1886. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  1887. twar->timestamp_war_offset[m] += (reset_delay +
  1888. twar->last_fft_timestamp[m]);
  1889. twar->target_reset_count++;
  1890. }
  1891. twar->last_fft_timestamp[smode] = raw_timestamp;
  1892. return raw_timestamp + twar->timestamp_war_offset[smode];
  1893. }
  1894. #ifdef BIG_ENDIAN_HOST
  1895. QDF_STATUS target_if_byte_swap_spectral_headers_gen3(
  1896. struct target_if_spectral *spectral,
  1897. void *data)
  1898. {
  1899. int i;
  1900. uint32_t *ptr32;
  1901. size_t words32;
  1902. qdf_assert_always(data);
  1903. qdf_assert_always(spectral);
  1904. ptr32 = (uint32_t *)data;
  1905. /* Summary Report */
  1906. words32 = sizeof(struct spectral_sscan_summary_report_gen3) >> 2;
  1907. for (i = 0; i < words32; ++i) {
  1908. *ptr32 = qdf_le32_to_cpu(*ptr32);
  1909. ++ptr32;
  1910. }
  1911. /* No need to swap the padding bytes */
  1912. ptr32 += (spectral->rparams.ssumaary_padding_bytes >> 2);
  1913. /* Search FFT Report */
  1914. words32 = sizeof(struct spectral_phyerr_fft_report_gen3) >> 2;
  1915. for (i = 0; i < words32; ++i) {
  1916. *ptr32 = qdf_le32_to_cpu(*ptr32);
  1917. ++ptr32;
  1918. }
  1919. return QDF_STATUS_SUCCESS;
  1920. }
  1921. QDF_STATUS target_if_byte_swap_spectral_fft_bins_gen3(
  1922. struct spectral_fft_bin_len_adj_swar *swar,
  1923. void *bin_pwr_data, size_t num_fftbins)
  1924. {
  1925. int i;
  1926. uint16_t *binptr_16;
  1927. uint32_t *binptr_32;
  1928. qdf_assert_always(bin_pwr_data);
  1929. qdf_assert_always(swar);
  1930. if (swar->fftbin_size_war ==
  1931. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
  1932. binptr_32 = (uint32_t *)bin_pwr_data;
  1933. for (i = 0; i < num_fftbins; i++) {
  1934. /* Get the useful first 2 bytes of the DWORD */
  1935. binptr_16 = ((uint16_t *)binptr_32);
  1936. /* Byteswap and copy it back */
  1937. *binptr_16 = qdf_le16_to_cpu(*binptr_16);
  1938. ++binptr_32; /* Go to next DWORD */
  1939. }
  1940. } else if (swar->fftbin_size_war ==
  1941. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  1942. binptr_16 = (uint16_t *)bin_pwr_data;
  1943. for (i = 0; i < num_fftbins; i++) {
  1944. /* Byteswap the FFT bin and copy it back */
  1945. *binptr_16 = qdf_le16_to_cpu(*binptr_16);
  1946. ++binptr_16;
  1947. }
  1948. }
  1949. return QDF_STATUS_SUCCESS;
  1950. }
  1951. #endif /* BIG_ENDIAN_HOST */
  1952. #ifdef OPTIMIZED_SAMP_MESSAGE
  1953. /**
  1954. * target_if_consume_sscan_summary_report_gen3() - Consume Spectral summary
  1955. * report
  1956. * @data: Pointer to Spectral summary report
  1957. * @fields: Pointer to structure to be populated with extracted fields
  1958. * @spectral: Pointer to spectral object
  1959. *
  1960. * Consume Spectral summary report for gen3
  1961. *
  1962. * Return: Success/Failure
  1963. */
  1964. static QDF_STATUS
  1965. target_if_consume_sscan_summary_report_gen3(
  1966. uint8_t **data,
  1967. struct sscan_report_fields_gen3 *fields,
  1968. struct target_if_spectral *spectral)
  1969. {
  1970. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  1971. if (!data) {
  1972. spectral_err_rl("Summary report buffer is null");
  1973. return QDF_STATUS_E_NULL_VALUE;
  1974. }
  1975. if (!fields) {
  1976. spectral_err_rl("Invalid pointer to Summary report fields");
  1977. return QDF_STATUS_E_NULL_VALUE;
  1978. }
  1979. if (!spectral) {
  1980. spectral_err_rl("Spectral LMAC object is null");
  1981. return QDF_STATUS_E_NULL_VALUE;
  1982. }
  1983. /* Validate Spectral scan summary report */
  1984. if (target_if_verify_sig_and_tag_gen3(
  1985. spectral, *data,
  1986. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3) != 0) {
  1987. spectral_err_rl("Wrong tag/sig in sscan summary");
  1988. return QDF_STATUS_E_FAILURE;
  1989. }
  1990. fields->sscan_detector_id =
  1991. target_if_get_detector_id_sscan_summary_report_gen3(*data);
  1992. if (fields->sscan_detector_id >=
  1993. spectral->rparams.num_spectral_detectors) {
  1994. spectral->diag_stats.spectral_invalid_detector_id++;
  1995. spectral_err_rl("Invalid detector id %u, expected is 0 to %u",
  1996. fields->sscan_detector_id,
  1997. spectral->rparams.num_spectral_detectors);
  1998. return QDF_STATUS_E_FAILURE;
  1999. }
  2000. psscan_summary_report =
  2001. (struct spectral_sscan_summary_report_gen3 *)*data;
  2002. fields->sscan_agc_total_gain = get_bitfield(
  2003. psscan_summary_report->hdr_a,
  2004. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_SIZE_GEN3,
  2005. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_POS_GEN3);
  2006. fields->inband_pwr_db = get_bitfield(
  2007. psscan_summary_report->hdr_a,
  2008. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_SIZE_GEN3,
  2009. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_POS_GEN3);
  2010. fields->sscan_pri80 = get_bitfield(
  2011. psscan_summary_report->hdr_a,
  2012. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_SIZE_GEN3,
  2013. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_POS_GEN3);
  2014. switch (spectral->rparams.version) {
  2015. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  2016. fields->sscan_gainchange = get_bitfield(
  2017. psscan_summary_report->hdr_b,
  2018. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_SIZE_GEN3_V1,
  2019. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_POS_GEN3_V1);
  2020. break;
  2021. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  2022. fields->sscan_gainchange = get_bitfield(
  2023. psscan_summary_report->hdr_c,
  2024. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_SIZE_GEN3_V2,
  2025. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_POS_GEN3_V2);
  2026. break;
  2027. default:
  2028. qdf_assert_always(0);
  2029. }
  2030. /* Advance buf pointer to the search fft report */
  2031. *data += sizeof(struct spectral_sscan_summary_report_gen3);
  2032. *data += spectral->rparams.ssumaary_padding_bytes;
  2033. return QDF_STATUS_SUCCESS;
  2034. }
  2035. /**
  2036. * target_if_process_sfft_report_gen3() - Validate and Process Search
  2037. * FFT Report for gen3
  2038. * @data: Pointer to Spectral FFT report
  2039. * @p_sfft: Pointer to search fft report
  2040. * @spectral: Pointer to spectral object
  2041. * @sscan_detector_id: Spectral detector id extracted from Summary report
  2042. * @reset_delay: Time taken for warm reset in usec
  2043. *
  2044. * Validate and Process Search FFT Report for gen3
  2045. *
  2046. * Return: Success/Failure
  2047. */
  2048. static QDF_STATUS
  2049. target_if_process_sfft_report_gen3(
  2050. uint8_t *data,
  2051. struct spectral_search_fft_info_gen3 *p_sfft,
  2052. struct target_if_spectral *spectral,
  2053. enum spectral_detector_id sscan_detector_id,
  2054. uint32_t reset_delay)
  2055. {
  2056. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  2057. int32_t peak_sidx = 0;
  2058. int32_t peak_mag;
  2059. int fft_hdr_length = 0;
  2060. struct target_if_spectral_ops *p_sops;
  2061. enum spectral_scan_mode spectral_mode;
  2062. QDF_STATUS ret;
  2063. if (!data) {
  2064. spectral_err_rl("FFT report buffer is null");
  2065. return QDF_STATUS_E_NULL_VALUE;
  2066. }
  2067. if (!p_sfft) {
  2068. spectral_err_rl("Invalid pointer to Search FFT report info");
  2069. return QDF_STATUS_E_NULL_VALUE;
  2070. }
  2071. if (!spectral) {
  2072. spectral_err_rl("Spectral LMAC object is null");
  2073. return QDF_STATUS_E_NULL_VALUE;
  2074. }
  2075. /*
  2076. * For easy comparision between MDK team and OS team, the MDK script
  2077. * variable names have been used
  2078. */
  2079. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2080. /* Validate Spectral search FFT report */
  2081. if (target_if_verify_sig_and_tag_gen3(
  2082. spectral, data, TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  2083. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  2084. sscan_detector_id);
  2085. return QDF_STATUS_E_FAILURE;
  2086. }
  2087. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  2088. fft_hdr_length = get_bitfield(
  2089. p_fft_report->fft_hdr_lts,
  2090. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  2091. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  2092. if (fft_hdr_length < 16) {
  2093. spectral_err("Wrong TLV length %u, detector id = %d",
  2094. fft_hdr_length, sscan_detector_id);
  2095. return QDF_STATUS_E_FAILURE;
  2096. }
  2097. p_sfft->fft_detector_id = get_bitfield(p_fft_report->hdr_a,
  2098. 2, 0);
  2099. /* It is expected to have same detector id for
  2100. * summary and fft report
  2101. */
  2102. if (sscan_detector_id != p_sfft->fft_detector_id) {
  2103. spectral_err_rl("Different detid in ssummary(%u) and sfft(%u)",
  2104. sscan_detector_id, p_sfft->fft_detector_id);
  2105. return QDF_STATUS_E_FAILURE;
  2106. }
  2107. if (p_sfft->fft_detector_id >
  2108. spectral->rparams.num_spectral_detectors) {
  2109. spectral->diag_stats.spectral_invalid_detector_id++;
  2110. spectral_err("Invalid detector id %u, expected is 0 to %u",
  2111. p_sfft->fft_detector_id,
  2112. spectral->rparams.num_spectral_detectors);
  2113. return QDF_STATUS_E_FAILURE;
  2114. }
  2115. /* Populate the Search FFT Info */
  2116. p_sfft->timestamp = p_fft_report->fft_timestamp;
  2117. p_sfft->last_raw_timestamp = spectral->timestamp_war.
  2118. last_fft_timestamp[spectral_mode];
  2119. p_sfft->adjusted_timestamp = target_if_spectral_get_adjusted_timestamp(
  2120. &spectral->timestamp_war,
  2121. p_sfft->timestamp,
  2122. reset_delay,
  2123. spectral_mode);
  2124. /* Timestamp verification */
  2125. target_if_spectral_verify_ts(spectral, data,
  2126. p_sfft->adjusted_timestamp,
  2127. p_sfft->fft_detector_id);
  2128. p_sfft->fft_num = get_bitfield(p_fft_report->hdr_a, 3, 2);
  2129. switch (spectral->rparams.version) {
  2130. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  2131. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  2132. 12, 5);
  2133. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 17);
  2134. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_a, 3, 28);
  2135. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  2136. 9, 0);
  2137. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  2138. 8, 9);
  2139. break;
  2140. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  2141. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  2142. 14, 5);
  2143. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 19);
  2144. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_b, 3, 0);
  2145. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  2146. 9, 3);
  2147. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  2148. 8, 12);
  2149. break;
  2150. default:
  2151. qdf_assert_always(0);
  2152. }
  2153. p_sfft->fft_peak_sidx = unsigned_to_signed(peak_sidx, 11);
  2154. p_sfft->fft_num_str_bins_ib = get_bitfield(p_fft_report->hdr_c,
  2155. 8, 0);
  2156. peak_mag = get_bitfield(p_fft_report->hdr_c, 10, 8);
  2157. p_sfft->fft_peak_mag = unsigned_to_signed(peak_mag, 10);
  2158. p_sfft->fft_avgpwr_db = get_bitfield(p_fft_report->hdr_c,
  2159. 7, 18);
  2160. p_sfft->fft_relpwr_db = get_bitfield(p_fft_report->hdr_c,
  2161. 7, 25);
  2162. spectral_mode = target_if_get_spectral_mode(p_sfft->fft_detector_id,
  2163. &spectral->rparams);
  2164. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  2165. spectral_err_rl("No valid Spectral mode for detector id %u",
  2166. p_sfft->fft_detector_id);
  2167. return QDF_STATUS_E_FAILURE;
  2168. }
  2169. p_sfft->fft_bin_count =
  2170. target_if_spectral_get_bin_count_after_len_adj(
  2171. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  2172. spectral->params[spectral_mode].ss_rpt_mode,
  2173. &spectral->len_adj_swar,
  2174. (size_t *)&p_sfft->fft_bin_size);
  2175. p_sfft->bin_pwr_data = (uint8_t *)p_fft_report + SPECTRAL_FFT_BINS_POS;
  2176. /* Apply byte-swap on the FFT bins.
  2177. * NOTE: Until this point, bytes of the FFT bins could be in
  2178. * reverse order on a big-endian machine. If the consumers
  2179. * of FFT bins expects bytes in the correct order,
  2180. * they should use them only after this point.
  2181. */
  2182. if (p_sops->byte_swap_fft_bins) {
  2183. ret = p_sops->byte_swap_fft_bins(&spectral->len_adj_swar,
  2184. &p_sfft->bin_pwr_data,
  2185. p_sfft->fft_bin_count);
  2186. if (QDF_IS_STATUS_ERROR(ret)) {
  2187. spectral_err_rl("Byte-swap on the FFT bins failed");
  2188. return QDF_STATUS_E_FAILURE;
  2189. }
  2190. }
  2191. return QDF_STATUS_SUCCESS;
  2192. }
  2193. int
  2194. target_if_consume_spectral_report_gen3(
  2195. struct target_if_spectral *spectral,
  2196. struct spectral_report *report)
  2197. {
  2198. /*
  2199. * XXX : The classifier do not use all the members of the SAMP
  2200. * message data format.
  2201. * The classifier only depends upon the following parameters
  2202. *
  2203. * 1. Frequency
  2204. * 2. Spectral RSSI
  2205. * 3. Bin Power Count
  2206. * 4. Bin Power values
  2207. * 5. Spectral Timestamp
  2208. * 6. MAC Address
  2209. *
  2210. * This function processes the Spectral summary and FFT reports
  2211. * and passes the processed information
  2212. * target_if_spectral_fill_samp_msg()
  2213. * to prepare fully formatted Spectral SAMP message
  2214. *
  2215. * XXX : Need to verify
  2216. * 1. Order of FFT bin values
  2217. *
  2218. */
  2219. struct target_if_samp_msg_params params = {0};
  2220. struct spectral_search_fft_info_gen3 search_fft_info;
  2221. struct spectral_search_fft_info_gen3 *p_sfft = &search_fft_info;
  2222. struct target_if_spectral_ops *p_sops;
  2223. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  2224. uint8_t *data;
  2225. struct sscan_report_fields_gen3 sscan_report_fields = {0};
  2226. QDF_STATUS ret;
  2227. enum spectral_scan_mode spectral_mode = SPECTRAL_SCAN_MODE_INVALID;
  2228. bool finite_scan = false;
  2229. if (!spectral) {
  2230. spectral_err_rl("Spectral LMAC object is null");
  2231. goto fail_no_print;
  2232. }
  2233. if (!report) {
  2234. spectral_err_rl("Spectral report is null");
  2235. goto fail_no_print;
  2236. }
  2237. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2238. data = report->data;
  2239. /* Apply byte-swap on the headers */
  2240. if (p_sops->byte_swap_headers) {
  2241. ret = p_sops->byte_swap_headers(spectral, data);
  2242. if (QDF_IS_STATUS_ERROR(ret)) {
  2243. spectral_err_rl("Byte-swap on Spectral headers failed");
  2244. goto fail;
  2245. }
  2246. }
  2247. /* Validate and Process Spectral scan summary report */
  2248. ret = target_if_consume_sscan_summary_report_gen3(&data,
  2249. &sscan_report_fields,
  2250. spectral);
  2251. if (QDF_IS_STATUS_ERROR(ret)) {
  2252. spectral_err_rl("Failed to process Spectral summary report");
  2253. goto fail;
  2254. }
  2255. spectral_mode = target_if_get_spectral_mode(
  2256. sscan_report_fields.sscan_detector_id,
  2257. &spectral->rparams);
  2258. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  2259. spectral_err_rl("No valid Spectral mode for detector id %u",
  2260. sscan_report_fields.sscan_detector_id);
  2261. goto fail;
  2262. }
  2263. /* Drop the sample if Spectral is not active for the current mode */
  2264. if (!p_sops->is_spectral_active(spectral, spectral_mode)) {
  2265. spectral_info_rl("Spectral scan is not active");
  2266. goto fail_no_print;
  2267. }
  2268. ret = target_if_spectral_is_finite_scan(spectral, spectral_mode,
  2269. &finite_scan);
  2270. if (QDF_IS_STATUS_ERROR(ret)) {
  2271. spectral_err_rl("Failed to check scan is finite");
  2272. goto fail;
  2273. }
  2274. if (finite_scan) {
  2275. ret = target_if_spectral_finite_scan_update(spectral,
  2276. spectral_mode);
  2277. if (QDF_IS_STATUS_ERROR(ret)) {
  2278. spectral_err_rl("Failed to update scan count");
  2279. goto fail;
  2280. }
  2281. }
  2282. /* Validate and Process the search FFT report */
  2283. ret = target_if_process_sfft_report_gen3(
  2284. data, p_sfft,
  2285. spectral,
  2286. sscan_report_fields.sscan_detector_id,
  2287. report->reset_delay);
  2288. if (QDF_IS_STATUS_ERROR(ret)) {
  2289. spectral_err_rl("Failed to process search FFT report");
  2290. goto fail;
  2291. }
  2292. ret = target_if_update_session_info_from_report_ctx(
  2293. spectral,
  2294. p_sfft->fft_bin_size,
  2295. report->cfreq1, report->cfreq2,
  2296. spectral_mode);
  2297. if (QDF_IS_STATUS_ERROR(ret)) {
  2298. spectral_err_rl("Failed to update per-session info");
  2299. goto fail;
  2300. }
  2301. /* Check FFT report are in order for 160 MHz and 80p80 */
  2302. if (is_ch_width_160_or_80p80(
  2303. spectral->report_info[spectral_mode].sscan_bw) &&
  2304. spectral->rparams.fragmentation_160[spectral_mode]) {
  2305. ret = target_if_160mhz_delivery_state_change(
  2306. spectral, spectral_mode,
  2307. p_sfft->fft_detector_id);
  2308. if (ret != QDF_STATUS_SUCCESS)
  2309. goto fail;
  2310. }
  2311. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  2312. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  2313. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  2314. p_fft_report, p_sfft);
  2315. target_if_spectral_check_buffer_poisoning(spectral, report,
  2316. p_sfft->fft_bin_count,
  2317. spectral_mode);
  2318. /* Fill SAMP message */
  2319. ret = target_if_spectral_fill_samp_msg(spectral, &params);
  2320. if (QDF_IS_STATUS_ERROR(ret)) {
  2321. spectral_err_rl("Failed to fill the SAMP msg");
  2322. goto fail;
  2323. }
  2324. return 0;
  2325. fail:
  2326. spectral_err_rl("Error while processing Spectral report");
  2327. fail_no_print:
  2328. if (spectral_mode != SPECTRAL_SCAN_MODE_INVALID)
  2329. reset_160mhz_delivery_state_machine(spectral, spectral_mode);
  2330. return -EPERM;
  2331. }
  2332. #else
  2333. int
  2334. target_if_consume_spectral_report_gen3(
  2335. struct target_if_spectral *spectral,
  2336. struct spectral_report *report)
  2337. {
  2338. /*
  2339. * XXX : The classifier do not use all the members of the SAMP
  2340. * message data format.
  2341. * The classifier only depends upon the following parameters
  2342. *
  2343. * 1. Frequency (freq, msg->freq)
  2344. * 2. Spectral RSSI (spectral_rssi,
  2345. * msg->samp_data.spectral_rssi)
  2346. * 3. Bin Power Count (bin_pwr_count,
  2347. * msg->samp_data.bin_pwr_count)
  2348. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  2349. * 5. Spectral Timestamp (spectral_tstamp,
  2350. * msg->samp_data.spectral_tstamp)
  2351. * 6. MAC Address (macaddr, msg->macaddr)
  2352. *
  2353. * This function prepares the params structure and populates it
  2354. * with
  2355. * relevant values, this is in turn passed to
  2356. * spectral_create_samp_msg()
  2357. * to prepare fully formatted Spectral SAMP message
  2358. *
  2359. * XXX : Need to verify
  2360. * 1. Order of FFT bin values
  2361. *
  2362. */
  2363. struct target_if_samp_msg_params params = {0};
  2364. struct spectral_search_fft_info_gen3 search_fft_info;
  2365. struct spectral_search_fft_info_gen3 *p_sfft = &search_fft_info;
  2366. int8_t chn_idx_lowest_enabled = 0;
  2367. int fft_hdr_length = 0;
  2368. int report_len = 0;
  2369. size_t fft_bin_count;
  2370. size_t fft_bin_size;
  2371. struct target_if_spectral_ops *p_sops =
  2372. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2373. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  2374. int8_t rssi;
  2375. uint8_t *data = report->data;
  2376. struct wlan_objmgr_vdev *vdev;
  2377. uint8_t vdev_rxchainmask;
  2378. struct sscan_report_fields_gen3 sscan_report_fields = {0};
  2379. enum spectral_detector_id detector_id;
  2380. QDF_STATUS ret;
  2381. enum spectral_scan_mode spectral_mode = SPECTRAL_SCAN_MODE_INVALID;
  2382. uint8_t *temp;
  2383. bool finite_scan = false;
  2384. /* Apply byte-swap on the headers */
  2385. if (p_sops->byte_swap_headers) {
  2386. ret = p_sops->byte_swap_headers(spectral, data);
  2387. if (QDF_IS_STATUS_ERROR(ret)) {
  2388. spectral_err_rl("Byte-swap on Spectral headers failed");
  2389. goto fail;
  2390. }
  2391. }
  2392. /* Process Spectral scan summary report */
  2393. if (target_if_verify_sig_and_tag_gen3(
  2394. spectral, data,
  2395. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3) != 0) {
  2396. spectral_err_rl("Wrong tag/sig in sscan summary");
  2397. goto fail;
  2398. }
  2399. detector_id = target_if_get_detector_id_sscan_summary_report_gen3(data);
  2400. if (detector_id >= spectral->rparams.num_spectral_detectors) {
  2401. spectral->diag_stats.spectral_invalid_detector_id++;
  2402. spectral_err("Invalid detector id %u, expected is 0/1/2",
  2403. detector_id);
  2404. goto fail;
  2405. }
  2406. spectral_mode = target_if_get_spectral_mode(detector_id,
  2407. &spectral->rparams);
  2408. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  2409. spectral_err_rl("No valid Spectral mode for detector id %u",
  2410. detector_id);
  2411. goto fail;
  2412. }
  2413. /* Drop the sample if Spectral is not active for the current mode */
  2414. if (!p_sops->is_spectral_active(spectral, spectral_mode)) {
  2415. spectral_info_rl("Spectral scan is not active");
  2416. goto fail_no_print;
  2417. }
  2418. ret = target_if_spectral_is_finite_scan(spectral, spectral_mode,
  2419. &finite_scan);
  2420. if (QDF_IS_STATUS_ERROR(ret)) {
  2421. spectral_err_rl("Failed to check scan is finite");
  2422. goto fail;
  2423. }
  2424. if (finite_scan) {
  2425. ret = target_if_spectral_finite_scan_update(spectral,
  2426. spectral_mode);
  2427. if (QDF_IS_STATUS_ERROR(ret)) {
  2428. spectral_err_rl("Failed to update scan count");
  2429. goto fail;
  2430. }
  2431. }
  2432. target_if_consume_sscan_summary_report_gen3(data, &sscan_report_fields,
  2433. &spectral->rparams);
  2434. /* Advance buf pointer to the search fft report */
  2435. data += sizeof(struct spectral_sscan_summary_report_gen3);
  2436. data += spectral->rparams.ssumaary_padding_bytes;
  2437. params.vhtop_ch_freq_seg1 = report->cfreq1;
  2438. params.vhtop_ch_freq_seg2 = report->cfreq2;
  2439. if (is_primaryseg_expected(spectral, spectral_mode)) {
  2440. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  2441. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  2442. params.agc_total_gain =
  2443. sscan_report_fields.sscan_agc_total_gain;
  2444. params.gainchange = sscan_report_fields.sscan_gainchange;
  2445. params.pri80ind = sscan_report_fields.sscan_pri80;
  2446. /* Process Spectral search FFT report */
  2447. if (target_if_verify_sig_and_tag_gen3(
  2448. spectral, data,
  2449. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  2450. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  2451. detector_id);
  2452. goto fail;
  2453. }
  2454. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  2455. fft_hdr_length = get_bitfield(
  2456. p_fft_report->fft_hdr_lts,
  2457. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  2458. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  2459. if (fft_hdr_length < 16) {
  2460. spectral_err("Wrong TLV length %u, detector id = %d",
  2461. fft_hdr_length, detector_id);
  2462. goto fail;
  2463. }
  2464. report_len = (fft_hdr_length + 8);
  2465. target_if_process_sfft_report_gen3(p_fft_report, p_sfft,
  2466. &spectral->rparams);
  2467. /* It is expected to have same detector id for
  2468. * summary and fft report
  2469. */
  2470. if (detector_id != p_sfft->fft_detector_id) {
  2471. spectral_err_rl
  2472. ("Different detid in ssummary(%u) and sfft(%u)",
  2473. detector_id, p_sfft->fft_detector_id);
  2474. goto fail;
  2475. }
  2476. if (detector_id > spectral->rparams.num_spectral_detectors) {
  2477. spectral->diag_stats.spectral_invalid_detector_id++;
  2478. spectral_err("Invalid detector id %u, expected is 0/2",
  2479. detector_id);
  2480. goto fail;
  2481. }
  2482. params.smode = spectral_mode;
  2483. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  2484. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  2485. spectral->params[spectral_mode].ss_rpt_mode,
  2486. &spectral->len_adj_swar, &fft_bin_size);
  2487. params.last_raw_timestamp = spectral->timestamp_war.
  2488. last_fft_timestamp[spectral_mode];
  2489. params.reset_delay = report->reset_delay;
  2490. params.raw_timestamp = p_sfft->timestamp;
  2491. params.tstamp = target_if_spectral_get_adjusted_timestamp(
  2492. &spectral->timestamp_war,
  2493. p_sfft->timestamp, report->reset_delay,
  2494. spectral_mode);
  2495. params.timestamp_war_offset = spectral->timestamp_war.
  2496. timestamp_war_offset[spectral_mode];
  2497. params.target_reset_count = spectral->timestamp_war.
  2498. target_reset_count;
  2499. /* Take care of state transitions for 160 MHz and 80p80 */
  2500. if (is_ch_width_160_or_80p80(spectral->ch_width
  2501. [spectral_mode]) && spectral->rparams.
  2502. fragmentation_160[spectral_mode]) {
  2503. ret = target_if_160mhz_delivery_state_change(
  2504. spectral, spectral_mode,
  2505. detector_id);
  2506. if (ret != QDF_STATUS_SUCCESS)
  2507. goto fail;
  2508. }
  2509. params.rssi = rssi;
  2510. vdev = target_if_spectral_get_vdev(spectral, spectral_mode);
  2511. if (!vdev) {
  2512. spectral_debug("First vdev is NULL");
  2513. reset_160mhz_delivery_state_machine(
  2514. spectral, spectral_mode);
  2515. return -EPERM;
  2516. }
  2517. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  2518. QDF_ASSERT(vdev_rxchainmask != 0);
  2519. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2520. chn_idx_lowest_enabled =
  2521. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  2522. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  2523. spectral_err("Invalid chain index, detector id = %u",
  2524. detector_id);
  2525. goto fail;
  2526. }
  2527. params.max_mag = p_sfft->fft_peak_mag;
  2528. params.freq = p_sops->get_current_channel(spectral,
  2529. spectral_mode);
  2530. params.agile_freq1 = spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  2531. ss_frequency.cfreq1;
  2532. params.agile_freq2 = spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  2533. ss_frequency.cfreq2;
  2534. params.noise_floor =
  2535. report->noisefloor[chn_idx_lowest_enabled];
  2536. temp = (uint8_t *)p_fft_report + SPECTRAL_FFT_BINS_POS;
  2537. if (is_ch_width_160_or_80p80(spectral->ch_width
  2538. [spectral_mode]) && !spectral->rparams.
  2539. fragmentation_160[spectral_mode]) {
  2540. struct wlan_objmgr_psoc *psoc;
  2541. struct spectral_fft_bin_markers_160_165mhz *marker;
  2542. qdf_assert_always(spectral->pdev_obj);
  2543. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  2544. qdf_assert_always(psoc);
  2545. params.agc_total_gain_sec80 =
  2546. sscan_report_fields.sscan_agc_total_gain;
  2547. params.gainchange_sec80 =
  2548. sscan_report_fields.sscan_gainchange;
  2549. params.raw_timestamp_sec80 = p_sfft->timestamp;
  2550. params.rssi_sec80 = rssi;
  2551. params.noise_floor_sec80 =
  2552. report->noisefloor[chn_idx_lowest_enabled];
  2553. params.max_mag_sec80 = p_sfft->fft_peak_mag;
  2554. params.datalen = fft_hdr_length * 2;
  2555. params.datalen_sec80 = fft_hdr_length * 2;
  2556. marker = &spectral->rparams.marker[spectral_mode];
  2557. if (!marker->is_valid) {
  2558. /* update stats */
  2559. goto fail_no_print;
  2560. }
  2561. params.bin_pwr_data = temp +
  2562. marker->start_pri80 * fft_bin_size;
  2563. params.pwr_count = marker->num_pri80;
  2564. params.bin_pwr_data_sec80 = temp +
  2565. marker->start_sec80 * fft_bin_size;
  2566. params.pwr_count_sec80 = marker->num_sec80;
  2567. if (spectral->ch_width[spectral_mode] ==
  2568. CH_WIDTH_80P80MHZ && wlan_psoc_nif_fw_ext_cap_get(
  2569. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  2570. params.bin_pwr_data_5mhz = temp +
  2571. marker->start_5mhz * fft_bin_size;
  2572. params.pwr_count_5mhz = marker->num_5mhz;
  2573. }
  2574. } else {
  2575. params.bin_pwr_data = temp;
  2576. params.pwr_count = fft_bin_count;
  2577. params.datalen = (fft_hdr_length * 4);
  2578. }
  2579. /* Apply byte-swap on the FFT bins.
  2580. * NOTE: Until this point, bytes of the FFT bins could be in
  2581. * reverse order on a big-endian machine. If the consumers
  2582. * of FFT bins expects bytes in the correct order,
  2583. * they should use them only after this point.
  2584. */
  2585. if (p_sops->byte_swap_fft_bins) {
  2586. ret = p_sops->byte_swap_fft_bins(
  2587. &spectral->len_adj_swar,
  2588. temp, fft_bin_count);
  2589. if (QDF_IS_STATUS_ERROR(ret)) {
  2590. spectral_err_rl("Byte-swap on the FFT bins failed");
  2591. goto fail;
  2592. }
  2593. }
  2594. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  2595. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  2596. p_fft_report, p_sfft);
  2597. target_if_spectral_verify_ts(spectral, report->data,
  2598. params.tstamp);
  2599. } else if (is_secondaryseg_expected(spectral, spectral_mode)) {
  2600. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  2601. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  2602. params.agc_total_gain_sec80 =
  2603. sscan_report_fields.sscan_agc_total_gain;
  2604. params.gainchange_sec80 = sscan_report_fields.sscan_gainchange;
  2605. params.pri80ind_sec80 = sscan_report_fields.sscan_pri80;
  2606. /* Process Spectral search FFT report */
  2607. if (target_if_verify_sig_and_tag_gen3(
  2608. spectral, data,
  2609. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  2610. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  2611. detector_id);
  2612. goto fail;
  2613. }
  2614. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  2615. fft_hdr_length = get_bitfield(
  2616. p_fft_report->fft_hdr_lts,
  2617. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  2618. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  2619. if (fft_hdr_length < 16) {
  2620. spectral_err("Wrong TLV length %u, detector id = %u",
  2621. fft_hdr_length, detector_id);
  2622. goto fail;
  2623. }
  2624. report_len = (fft_hdr_length + 8);
  2625. target_if_process_sfft_report_gen3(p_fft_report, p_sfft,
  2626. &spectral->rparams);
  2627. /* It is expected to have same detector id for
  2628. * summary and fft report
  2629. */
  2630. if (detector_id != p_sfft->fft_detector_id) {
  2631. spectral_err_rl
  2632. ("Different detid in ssummary(%u) and sfft(%u)",
  2633. detector_id, p_sfft->fft_detector_id);
  2634. goto fail;
  2635. }
  2636. if (detector_id > spectral->rparams.num_spectral_detectors) {
  2637. spectral->diag_stats.spectral_invalid_detector_id++;
  2638. spectral_err("Invalid detector id %u, expected is 1",
  2639. detector_id);
  2640. goto fail;
  2641. }
  2642. params.smode = spectral_mode;
  2643. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  2644. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  2645. spectral->params[spectral_mode].ss_rpt_mode,
  2646. &spectral->len_adj_swar, &fft_bin_size);
  2647. params.raw_timestamp_sec80 = p_sfft->timestamp;
  2648. /* Take care of state transitions for 160 MHz and 80p80 */
  2649. if (is_ch_width_160_or_80p80(spectral->ch_width
  2650. [spectral_mode]) && spectral->rparams.
  2651. fragmentation_160[spectral_mode]) {
  2652. ret = target_if_160mhz_delivery_state_change(
  2653. spectral, spectral_mode,
  2654. detector_id);
  2655. if (ret != QDF_STATUS_SUCCESS)
  2656. goto fail;
  2657. }
  2658. params.rssi_sec80 = rssi;
  2659. vdev = target_if_spectral_get_vdev(spectral, spectral_mode);
  2660. if (!vdev) {
  2661. spectral_info("First vdev is NULL");
  2662. reset_160mhz_delivery_state_machine
  2663. (spectral, spectral_mode);
  2664. return -EPERM;
  2665. }
  2666. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  2667. QDF_ASSERT(vdev_rxchainmask != 0);
  2668. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2669. chn_idx_lowest_enabled =
  2670. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  2671. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  2672. spectral_err("Invalid chain index");
  2673. goto fail;
  2674. }
  2675. /* Need to change this as per FW team's inputs */
  2676. params.noise_floor_sec80 =
  2677. report->noisefloor[chn_idx_lowest_enabled];
  2678. params.max_mag_sec80 = p_sfft->fft_peak_mag;
  2679. /* params.max_index_sec80 = p_sfft->peak_inx; */
  2680. /* XXX Does this definition of datalen *still hold? */
  2681. params.datalen_sec80 = fft_hdr_length * 4;
  2682. params.pwr_count_sec80 = fft_bin_count;
  2683. params.bin_pwr_data_sec80 =
  2684. (uint8_t *)((uint8_t *)p_fft_report +
  2685. SPECTRAL_FFT_BINS_POS);
  2686. /* Apply byte-swap on the FFT bins.
  2687. * NOTE: Until this point, bytes of the FFT bins could be in
  2688. * reverse order on a big-endian machine. If the consumers
  2689. * of FFT bins expects bytes in the correct order,
  2690. * they should use them only after this point.
  2691. */
  2692. if (p_sops->byte_swap_fft_bins) {
  2693. ret = p_sops->byte_swap_fft_bins(
  2694. &spectral->len_adj_swar,
  2695. params.bin_pwr_data_sec80,
  2696. fft_bin_count);
  2697. if (QDF_IS_STATUS_ERROR(ret)) {
  2698. spectral_err_rl("Byte-swap on the FFT bins failed");
  2699. goto fail;
  2700. }
  2701. }
  2702. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  2703. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  2704. p_fft_report, p_sfft);
  2705. } else {
  2706. spectral_err("Spectral state machine in undefined state");
  2707. goto fail;
  2708. }
  2709. target_if_spectral_check_buffer_poisoning(spectral, report,
  2710. fft_bin_count, spectral_mode);
  2711. qdf_mem_copy(&params.classifier_params,
  2712. &spectral->classifier_params,
  2713. sizeof(struct spectral_classifier_params));
  2714. target_if_spectral_log_SAMP_param(&params);
  2715. target_if_spectral_create_samp_msg(spectral, &params);
  2716. return 0;
  2717. fail:
  2718. spectral_err_rl("Error while processing Spectral report");
  2719. fail_no_print:
  2720. if (spectral_mode != SPECTRAL_SCAN_MODE_INVALID)
  2721. reset_160mhz_delivery_state_machine(spectral, spectral_mode);
  2722. return -EPERM;
  2723. }
  2724. #endif /* OPTIMIZED_SAMP_MESSAGE */
  2725. int target_if_spectral_process_report_gen3(
  2726. struct wlan_objmgr_pdev *pdev,
  2727. void *buf)
  2728. {
  2729. int ret = 0;
  2730. struct direct_buf_rx_data *payload = buf;
  2731. struct target_if_spectral *spectral;
  2732. struct spectral_report report;
  2733. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  2734. if (!spectral) {
  2735. spectral_err("Spectral target object is null");
  2736. return -EINVAL;
  2737. }
  2738. report.data = payload->vaddr;
  2739. if (payload->meta_data_valid) {
  2740. qdf_mem_copy(report.noisefloor, payload->meta_data.noisefloor,
  2741. qdf_min(sizeof(report.noisefloor),
  2742. sizeof(payload->meta_data.noisefloor)));
  2743. report.reset_delay = payload->meta_data.reset_delay;
  2744. report.cfreq1 = payload->meta_data.cfreq1;
  2745. report.cfreq2 = payload->meta_data.cfreq2;
  2746. report.ch_width = payload->meta_data.ch_width;
  2747. }
  2748. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4)) {
  2749. spectral_debug("Printing the spectral phyerr buffer for debug");
  2750. spectral_debug("Datalength of buffer = 0x%zx(%zd) bufptr = 0x%pK",
  2751. payload->dbr_len,
  2752. payload->dbr_len,
  2753. payload->vaddr);
  2754. target_if_spectral_hexdump((unsigned char *)payload->vaddr,
  2755. 1024);
  2756. }
  2757. ret = target_if_consume_spectral_report_gen3(spectral, &report);
  2758. if (spectral_debug_level & DEBUG_SPECTRAL4)
  2759. spectral_debug_level = DEBUG_SPECTRAL;
  2760. return ret;
  2761. }
  2762. #else
  2763. int target_if_spectral_process_report_gen3(
  2764. struct wlan_objmgr_pdev *pdev,
  2765. void *buf)
  2766. {
  2767. spectral_err("Direct dma support is not enabled");
  2768. return -EINVAL;
  2769. }
  2770. #endif
  2771. qdf_export_symbol(target_if_spectral_process_report_gen3);
  2772. /* END of spectral GEN III HW specific functions */
  2773. #endif /* WLAN_CONV_SPECTRAL_ENABLE */