target_if_spectral_phyerr.c 101 KB

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