target_if_spectral_phyerr.c 115 KB

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