target_if_spectral_phyerr.c 118 KB

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