target_if_spectral_phyerr.c 121 KB

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