target_if_spectral_phyerr.c 119 KB

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