target_if_spectral_phyerr.c 115 KB

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