target_if_spectral_phyerr.c 96 KB

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