target_if_spectral_phyerr.c 117 KB

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