target_if_spectral_phyerr.c 104 KB

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