target_if_spectral_phyerr.c 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103
  1. /*
  2. * Copyright (c) 2011,2017-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  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 =
  786. wlan_reg_get_5g_bonded_channel_and_state_for_pwrmode
  787. (spectral->pdev_obj, pri20_freq, CH_WIDTH_80MHZ,
  788. &bonded_chan_ptr, REG_CURRENT_PWR_MODE);
  789. if (state == CHANNEL_STATE_DISABLE ||
  790. state == CHANNEL_STATE_INVALID) {
  791. spectral_err_rl("Channel state is disable or invalid");
  792. return QDF_STATUS_E_FAILURE;
  793. }
  794. if (!bonded_chan_ptr) {
  795. spectral_err_rl("Bonded channel is not found");
  796. return QDF_STATUS_E_FAILURE;
  797. }
  798. /* cfreq1 is the center of the pri80 segment */
  799. *cfreq1 = (bonded_chan_ptr->start_freq +
  800. bonded_chan_ptr->end_freq) >> 1;
  801. /**
  802. * cfreq2 is 85MHz away from cfreq1. Whether it is
  803. * higher or lower depends on pri20_freq's relationship
  804. * with the reported center frequency.
  805. */
  806. if (pri20_freq < reported_cfreq1)
  807. *cfreq2 = *cfreq1 + FREQ_OFFSET_85MHZ;
  808. else
  809. *cfreq2 = *cfreq1 - FREQ_OFFSET_85MHZ;
  810. } else {
  811. /* All other cases are reporting the cfreq properly */
  812. *cfreq1 = reported_cfreq1;
  813. *cfreq2 = reported_cfreq2;
  814. }
  815. return QDF_STATUS_SUCCESS;
  816. }
  817. /**
  818. * target_if_populate_det_start_end_freqs() - Populate the start and end
  819. * frequencies, on per-detector level.
  820. * @spectral: Pointer to target_if spectral internal structure
  821. * @smode: Spectral scan mode
  822. *
  823. * Populate the start and end frequencies, on per-detector level.
  824. *
  825. * Return: Success/Failure
  826. */
  827. static QDF_STATUS
  828. target_if_populate_det_start_end_freqs(struct target_if_spectral *spectral,
  829. enum spectral_scan_mode smode)
  830. {
  831. struct per_session_report_info *rpt_info;
  832. struct per_session_det_map *det_map;
  833. struct per_session_dest_det_info *dest_det_info;
  834. enum phy_ch_width ch_width;
  835. struct sscan_detector_list *detector_list;
  836. bool is_fragmentation_160;
  837. uint8_t det;
  838. uint32_t cfreq;
  839. uint32_t start_end_freq_arr[2];
  840. if (!spectral) {
  841. spectral_err_rl("Spectral LMAC object is null");
  842. return QDF_STATUS_E_NULL_VALUE;
  843. }
  844. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  845. spectral_err_rl("Invalid Spectral mode");
  846. return QDF_STATUS_E_FAILURE;
  847. }
  848. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  849. ch_width = spectral->report_info[smode].sscan_bw;
  850. is_fragmentation_160 = spectral->rparams.fragmentation_160[smode];
  851. rpt_info = &spectral->report_info[smode];
  852. qdf_spin_lock_bh(&spectral->detector_list_lock);
  853. detector_list = &spectral->detector_list[smode][ch_width];
  854. for (det = 0; det < detector_list->num_detectors; det++) {
  855. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  856. det_map = &spectral->det_map
  857. [detector_list->detectors[det]];
  858. dest_det_info = &det_map->dest_det_info[0];
  859. switch (det) {
  860. case 0:
  861. if (ch_width == CH_WIDTH_160MHZ &&
  862. is_fragmentation_160) {
  863. if (rpt_info->pri20_freq <
  864. rpt_info->sscan_cfreq1)
  865. cfreq = rpt_info->sscan_cfreq1 -
  866. FREQ_OFFSET_40MHZ;
  867. else
  868. cfreq = rpt_info->sscan_cfreq1 +
  869. FREQ_OFFSET_40MHZ;
  870. } else
  871. cfreq = rpt_info->sscan_cfreq1;
  872. break;
  873. case 1:
  874. if (ch_width == CH_WIDTH_160MHZ &&
  875. is_fragmentation_160) {
  876. if (rpt_info->pri20_freq <
  877. rpt_info->sscan_cfreq1)
  878. cfreq = rpt_info->sscan_cfreq1 +
  879. FREQ_OFFSET_40MHZ;
  880. else
  881. cfreq = rpt_info->sscan_cfreq1 -
  882. FREQ_OFFSET_40MHZ;
  883. } else
  884. cfreq = rpt_info->sscan_cfreq2;
  885. break;
  886. default:
  887. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  888. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  889. qdf_spin_unlock_bh(
  890. &spectral->session_report_info_lock);
  891. return QDF_STATUS_E_FAILURE;
  892. }
  893. /* Set start and end frequencies */
  894. target_if_spectral_set_start_end_freq(cfreq,
  895. ch_width,
  896. is_fragmentation_160,
  897. start_end_freq_arr);
  898. dest_det_info->start_freq = start_end_freq_arr[0];
  899. dest_det_info->end_freq = start_end_freq_arr[1];
  900. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  901. }
  902. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  903. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  904. return QDF_STATUS_SUCCESS;
  905. }
  906. QDF_STATUS
  907. target_if_populate_fft_bins_info(struct target_if_spectral *spectral,
  908. enum spectral_scan_mode smode)
  909. {
  910. struct per_session_det_map *det_map;
  911. struct per_session_dest_det_info *dest_det_info;
  912. enum phy_ch_width ch_width;
  913. struct sscan_detector_list *detector_list;
  914. bool is_fragmentation_160;
  915. uint8_t spectral_fft_size;
  916. uint8_t rpt_mode;
  917. uint32_t num_fft_bins;
  918. uint16_t start_bin;
  919. uint8_t det;
  920. if (!spectral) {
  921. spectral_err_rl("Spectral LMAC object is null");
  922. return QDF_STATUS_E_NULL_VALUE;
  923. }
  924. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  925. spectral_err_rl("Invalid Spectral mode");
  926. return QDF_STATUS_E_FAILURE;
  927. }
  928. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  929. ch_width = spectral->report_info[smode].sscan_bw;
  930. is_fragmentation_160 = spectral->rparams.fragmentation_160[smode];
  931. spectral_fft_size = spectral->params[smode].ss_fft_size;
  932. rpt_mode = spectral->params[smode].ss_rpt_mode;
  933. num_fft_bins =
  934. target_if_spectral_get_num_fft_bins(spectral_fft_size,
  935. rpt_mode);
  936. if (num_fft_bins < 0) {
  937. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  938. spectral_err_rl("Invalid number of FFT bins %d",
  939. num_fft_bins);
  940. return QDF_STATUS_E_FAILURE;
  941. }
  942. qdf_spin_lock_bh(&spectral->detector_list_lock);
  943. detector_list = &spectral->detector_list[smode][ch_width];
  944. for (det = 0; det < detector_list->num_detectors; det++) {
  945. uint16_t lb_extrabins_offset = 0;
  946. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  947. det_map = &spectral->det_map
  948. [detector_list->detectors[det]];
  949. dest_det_info = &det_map->dest_det_info[0];
  950. dest_det_info->lb_extrabins_num = spectral->lb_edge_extrabins;
  951. dest_det_info->rb_extrabins_num = spectral->rb_edge_extrabins;
  952. switch (det) {
  953. case 0:
  954. if (ch_width == CH_WIDTH_160MHZ &&
  955. is_fragmentation_160 &&
  956. spectral->report_info[smode].pri20_freq >
  957. spectral->report_info[smode].sscan_cfreq1) {
  958. start_bin = num_fft_bins;
  959. lb_extrabins_offset =
  960. dest_det_info->lb_extrabins_num +
  961. dest_det_info->rb_extrabins_num;
  962. } else {
  963. start_bin = 0;
  964. }
  965. break;
  966. case 1:
  967. if (ch_width == CH_WIDTH_160MHZ &&
  968. is_fragmentation_160 &&
  969. spectral->report_info[smode].pri20_freq >
  970. spectral->report_info[smode].sscan_cfreq1)
  971. start_bin = 0;
  972. else {
  973. start_bin = num_fft_bins;
  974. lb_extrabins_offset =
  975. dest_det_info->lb_extrabins_num +
  976. dest_det_info->rb_extrabins_num;
  977. }
  978. break;
  979. default:
  980. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  981. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  982. qdf_spin_unlock_bh(
  983. &spectral->session_report_info_lock);
  984. return QDF_STATUS_E_FAILURE;
  985. }
  986. dest_det_info->dest_start_bin_idx = start_bin;
  987. dest_det_info->dest_end_bin_idx =
  988. dest_det_info->dest_start_bin_idx;
  989. if (num_fft_bins > 0)
  990. dest_det_info->dest_end_bin_idx += (num_fft_bins - 1);
  991. if (dest_det_info->lb_extrabins_num) {
  992. if (is_ch_width_160_or_80p80(ch_width)) {
  993. dest_det_info->lb_extrabins_start_idx =
  994. 2 * num_fft_bins +
  995. lb_extrabins_offset;
  996. } else {
  997. dest_det_info->lb_extrabins_start_idx =
  998. num_fft_bins;
  999. }
  1000. }
  1001. if (dest_det_info->rb_extrabins_num)
  1002. dest_det_info->rb_extrabins_start_idx =
  1003. dest_det_info->lb_extrabins_start_idx +
  1004. dest_det_info->lb_extrabins_num;
  1005. dest_det_info->src_start_bin_idx = 0;
  1006. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  1007. }
  1008. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  1009. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  1010. return QDF_STATUS_SUCCESS;
  1011. }
  1012. /**
  1013. * target_if_update_session_info_from_report_ctx() - Update per-session
  1014. * information from the consume report context. This includes populating start
  1015. * and end bin indices, and set the start and end frequency per-detector.
  1016. * @spectral: Pointer to target_if spectral internal structure
  1017. * @fft_bin_size: Size of 1 FFT bin (in bytes)
  1018. * @cfreq1: Center frequency of Detector 1
  1019. * @cfreq2: Center frequency of Detector 2
  1020. * @smode: Spectral scan mode
  1021. *
  1022. * Update per-session information from the consume report context.
  1023. *
  1024. * Return: Success/Failure
  1025. */
  1026. static QDF_STATUS
  1027. target_if_update_session_info_from_report_ctx(
  1028. struct target_if_spectral *spectral,
  1029. uint8_t fft_bin_size,
  1030. uint32_t cfreq1, uint32_t cfreq2,
  1031. enum spectral_scan_mode smode)
  1032. {
  1033. struct target_if_spectral_ops *p_sops;
  1034. struct per_session_report_info *rpt_info;
  1035. struct per_session_det_map *det_map;
  1036. struct per_session_dest_det_info *dest_det_info;
  1037. enum phy_ch_width ch_width;
  1038. struct wlan_objmgr_psoc *psoc;
  1039. bool is_fragmentation_160;
  1040. uint32_t start_end_freq_arr[2];
  1041. QDF_STATUS ret;
  1042. bool is_session_info_expected;
  1043. if (!spectral) {
  1044. spectral_err_rl("Spectral LMAC object is null");
  1045. return QDF_STATUS_E_NULL_VALUE;
  1046. }
  1047. ret = spectral_is_session_info_expected_from_target(
  1048. spectral->pdev_obj,
  1049. &is_session_info_expected);
  1050. if (QDF_IS_STATUS_ERROR(ret)) {
  1051. spectral_err_rl("Failed to check if session info is expected");
  1052. return ret;
  1053. }
  1054. /* If FW sends this information, use it, no need to get it from here */
  1055. if (is_session_info_expected)
  1056. return QDF_STATUS_SUCCESS;
  1057. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1058. spectral_err_rl("Invalid Spectral mode");
  1059. return QDF_STATUS_E_FAILURE;
  1060. }
  1061. if (!spectral->pdev_obj) {
  1062. spectral_err_rl("Spectral PDEV is null");
  1063. return QDF_STATUS_E_NULL_VALUE;
  1064. }
  1065. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  1066. if (!psoc) {
  1067. spectral_err_rl("psoc is null");
  1068. return QDF_STATUS_E_NULL_VALUE;
  1069. }
  1070. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1071. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  1072. rpt_info = &spectral->report_info[smode];
  1073. ch_width = rpt_info->sscan_bw;
  1074. is_fragmentation_160 = spectral->rparams.fragmentation_160[smode];
  1075. rpt_info->pri20_freq = p_sops->get_current_channel(spectral, smode);
  1076. rpt_info->cfreq1 = cfreq1;
  1077. rpt_info->cfreq2 = cfreq2;
  1078. if (spectral_debug_level & DEBUG_SPECTRAL4)
  1079. spectral_debug("Before conversion: cfreq1: %u cfreq2: %u",
  1080. rpt_info->cfreq1, rpt_info->cfreq2);
  1081. ret = target_if_spectral_unify_cfreq_format(
  1082. spectral, &rpt_info->cfreq1, &rpt_info->cfreq2,
  1083. rpt_info->pri20_freq, rpt_info->operating_bw, smode);
  1084. if (QDF_IS_STATUS_ERROR(ret)) {
  1085. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  1086. spectral_err_rl("Unable to unify cfreq1/cfreq2");
  1087. return QDF_STATUS_E_FAILURE;
  1088. }
  1089. if (spectral_debug_level & DEBUG_SPECTRAL4)
  1090. spectral_debug("After conversion: cfreq1: %d cfreq2: %d",
  1091. rpt_info->cfreq1, rpt_info->cfreq2);
  1092. /* For Agile mode, sscan_cfreq1 and sscan_cfreq2 are populated
  1093. * during Spectral start scan
  1094. */
  1095. if (smode == SPECTRAL_SCAN_MODE_NORMAL) {
  1096. rpt_info->sscan_cfreq1 = rpt_info->cfreq1;
  1097. rpt_info->sscan_cfreq2 = rpt_info->cfreq2;
  1098. }
  1099. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  1100. if (ch_width == CH_WIDTH_80P80MHZ && wlan_psoc_nif_fw_ext_cap_get(
  1101. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  1102. /* Restricted 80p80 */
  1103. struct spectral_fft_bin_markers_160_165mhz *marker;
  1104. struct sscan_detector_list *detector_list;
  1105. marker = &spectral->rparams.marker[smode];
  1106. if (!marker->is_valid)
  1107. return QDF_STATUS_E_FAILURE;
  1108. /**
  1109. * Restricted 80p80 on Pine has only 1 detector for
  1110. * normal/agile spectral scan. So, detector_list will
  1111. * have only one detector
  1112. */
  1113. qdf_spin_lock_bh(&spectral->detector_list_lock);
  1114. detector_list = &spectral->detector_list[smode][ch_width];
  1115. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  1116. det_map = &spectral->det_map[detector_list->detectors[0]];
  1117. dest_det_info = &det_map->dest_det_info[0];
  1118. dest_det_info->dest_start_bin_idx = marker->start_pri80;
  1119. dest_det_info->dest_end_bin_idx =
  1120. dest_det_info->dest_start_bin_idx +
  1121. marker->num_pri80 - 1;
  1122. dest_det_info->src_start_bin_idx = marker->start_pri80 *
  1123. fft_bin_size;
  1124. /* Set start and end frequencies */
  1125. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  1126. target_if_spectral_set_start_end_freq(rpt_info->sscan_cfreq1,
  1127. ch_width,
  1128. is_fragmentation_160,
  1129. start_end_freq_arr);
  1130. dest_det_info->start_freq = start_end_freq_arr[0];
  1131. dest_det_info->end_freq = start_end_freq_arr[1];
  1132. dest_det_info = &det_map->dest_det_info[1];
  1133. dest_det_info->dest_start_bin_idx = marker->start_sec80;
  1134. dest_det_info->dest_end_bin_idx =
  1135. dest_det_info->dest_start_bin_idx +
  1136. marker->num_sec80 - 1;
  1137. dest_det_info->src_start_bin_idx = marker->start_sec80 *
  1138. fft_bin_size;
  1139. /* Set start and end frequencies */
  1140. target_if_spectral_set_start_end_freq(rpt_info->sscan_cfreq2,
  1141. ch_width,
  1142. is_fragmentation_160,
  1143. start_end_freq_arr);
  1144. dest_det_info->start_freq = start_end_freq_arr[0];
  1145. dest_det_info->end_freq = start_end_freq_arr[1];
  1146. dest_det_info = &det_map->dest_det_info[2];
  1147. dest_det_info->dest_start_bin_idx = marker->start_5mhz;
  1148. dest_det_info->dest_end_bin_idx =
  1149. dest_det_info->dest_start_bin_idx +
  1150. marker->num_5mhz - 1;
  1151. dest_det_info->src_start_bin_idx = marker->start_5mhz *
  1152. fft_bin_size;
  1153. /* Set start and end frequencies */
  1154. dest_det_info->start_freq =
  1155. min(det_map->dest_det_info[0].end_freq,
  1156. det_map->dest_det_info[1].end_freq);
  1157. dest_det_info->end_freq =
  1158. max(det_map->dest_det_info[0].start_freq,
  1159. det_map->dest_det_info[1].start_freq);
  1160. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  1161. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  1162. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  1163. } else {
  1164. ret = target_if_populate_fft_bins_info(spectral, smode);
  1165. if (QDF_IS_STATUS_ERROR(ret)) {
  1166. spectral_err_rl("Error in populating fft bins info");
  1167. return QDF_STATUS_E_FAILURE;
  1168. }
  1169. ret = target_if_populate_det_start_end_freqs(spectral, smode);
  1170. if (QDF_IS_STATUS_ERROR(ret)) {
  1171. spectral_err_rl("Failed to populate start/end freqs");
  1172. return QDF_STATUS_E_FAILURE;
  1173. }
  1174. }
  1175. return QDF_STATUS_SUCCESS;
  1176. }
  1177. #endif /* OPTIMIZED_SAMP_MESSAGE */
  1178. #ifdef OPTIMIZED_SAMP_MESSAGE
  1179. /**
  1180. * target_if_spectral_populate_samp_params_gen2() - Populate the SAMP params
  1181. * for gen2. SAMP params are to be used for populating SAMP msg.
  1182. * @spectral: Pointer to spectral object
  1183. * @phyerr_info: Pointer to processed phyerr info
  1184. * @params: Pointer to Spectral SAMP message fields to be populated
  1185. *
  1186. * Populate the SAMP params for gen2, which will be used to populate SAMP msg.
  1187. *
  1188. * Return: Success/Failure
  1189. */
  1190. static QDF_STATUS
  1191. target_if_spectral_populate_samp_params_gen2(
  1192. struct target_if_spectral *spectral,
  1193. struct spectral_process_phyerr_info_gen2 *phyerr_info,
  1194. struct target_if_samp_msg_params *params)
  1195. {
  1196. uint8_t chn_idx_highest_enabled;
  1197. uint8_t chn_idx_lowest_enabled;
  1198. int8_t control_rssi;
  1199. int8_t extension_rssi;
  1200. struct target_if_spectral_rfqual_info *p_rfqual;
  1201. struct spectral_search_fft_info_gen2 *p_sfft;
  1202. struct spectral_phyerr_fft_gen2 *pfft;
  1203. struct target_if_spectral_acs_stats *acs_stats;
  1204. enum phy_ch_width ch_width;
  1205. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1206. if (!spectral) {
  1207. spectral_err_rl("Spectral LMAC object is null");
  1208. return QDF_STATUS_E_NULL_VALUE;
  1209. }
  1210. if (!phyerr_info) {
  1211. spectral_err_rl("Pointer to phyerr info is null");
  1212. return QDF_STATUS_E_NULL_VALUE;
  1213. }
  1214. if (!params) {
  1215. spectral_err_rl("SAMP msg params structure is null");
  1216. return QDF_STATUS_E_NULL_VALUE;
  1217. }
  1218. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  1219. ch_width = spectral->report_info[smode].sscan_bw;
  1220. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  1221. acs_stats = phyerr_info->acs_stats;
  1222. pfft = phyerr_info->pfft;
  1223. p_sfft = phyerr_info->p_sfft;
  1224. p_rfqual = phyerr_info->p_rfqual;
  1225. params->hw_detector_id = phyerr_info->seg_id;
  1226. params->rssi = p_rfqual->rssi_comb;
  1227. if (spectral->is_sec80_rssi_war_required && phyerr_info->seg_id == 1)
  1228. params->rssi = target_if_get_combrssi_sec80_seg_gen2(spectral,
  1229. p_sfft);
  1230. chn_idx_highest_enabled =
  1231. ((spectral->params[smode].ss_chn_mask & 0x8) ? 3 :
  1232. (spectral->params[smode].ss_chn_mask & 0x4) ? 2 :
  1233. (spectral->params[smode].ss_chn_mask & 0x2) ? 1 : 0);
  1234. chn_idx_lowest_enabled =
  1235. ((spectral->params[smode].ss_chn_mask & 0x1) ? 0 :
  1236. (spectral->params[smode].ss_chn_mask & 0x2) ? 1 :
  1237. (spectral->params[smode].ss_chn_mask & 0x4) ? 2 : 3);
  1238. control_rssi =
  1239. p_rfqual->pc_rssi_info[chn_idx_highest_enabled].rssi_pri20;
  1240. extension_rssi =
  1241. p_rfqual->pc_rssi_info[chn_idx_highest_enabled].rssi_sec20;
  1242. if (spectral->upper_is_control)
  1243. params->upper_rssi = control_rssi;
  1244. else
  1245. params->upper_rssi = extension_rssi;
  1246. if (spectral->lower_is_control)
  1247. params->lower_rssi = control_rssi;
  1248. else
  1249. params->lower_rssi = extension_rssi;
  1250. if (spectral->sc_spectral_noise_pwr_cal) {
  1251. int idx;
  1252. for (idx = 0; idx < HOST_MAX_ANTENNA; idx++) {
  1253. params->chain_ctl_rssi[idx] =
  1254. p_rfqual->pc_rssi_info[idx].rssi_pri20;
  1255. params->chain_ext_rssi[idx] =
  1256. p_rfqual->pc_rssi_info[idx].rssi_sec20;
  1257. }
  1258. }
  1259. params->timestamp = (phyerr_info->tsf64 & SPECTRAL_TSMASK);
  1260. params->max_mag = p_sfft->peak_mag;
  1261. params->max_index = p_sfft->peak_inx;
  1262. /*
  1263. * For VHT80_80/VHT160, the noise floor for primary
  1264. * 80MHz segment is populated with the lowest enabled
  1265. * antenna chain and the noise floor for secondary 80MHz segment
  1266. * is populated with the highest enabled antenna chain.
  1267. * For modes upto VHT80, the noise floor is populated with the
  1268. * one corresponding to the highest enabled antenna chain.
  1269. */
  1270. if (is_ch_width_160_or_80p80(ch_width) && phyerr_info->seg_id == 0)
  1271. params->noise_floor =
  1272. p_rfqual->noise_floor[chn_idx_lowest_enabled];
  1273. else
  1274. params->noise_floor =
  1275. p_rfqual->noise_floor[chn_idx_highest_enabled];
  1276. acs_stats->ctrl_nf = params->noise_floor;
  1277. acs_stats->ext_nf = params->noise_floor;
  1278. acs_stats->nfc_ctl_rssi = control_rssi;
  1279. acs_stats->nfc_ext_rssi = extension_rssi;
  1280. params->bin_pwr_data = (uint8_t *)pfft;
  1281. return QDF_STATUS_SUCCESS;
  1282. }
  1283. int
  1284. target_if_process_phyerr_gen2(struct target_if_spectral *spectral,
  1285. uint8_t *data,
  1286. uint32_t datalen,
  1287. struct target_if_spectral_rfqual_info *p_rfqual,
  1288. struct target_if_spectral_chan_info *p_chaninfo,
  1289. uint64_t tsf64,
  1290. struct target_if_spectral_acs_stats *acs_stats)
  1291. {
  1292. /*
  1293. * XXX : The classifier do not use all the members of the SAMP
  1294. * message data format.
  1295. * The classifier only depends upon the following parameters
  1296. *
  1297. * 1. Frequency
  1298. * 2. Spectral RSSI
  1299. * 3. Bin Power Count
  1300. * 4. Bin Power values
  1301. * 5. Spectral Timestamp
  1302. * 6. MAC Address
  1303. *
  1304. * This function prepares the params structure and populates it
  1305. * with relevant values, this is in turn passed to
  1306. * spectral_fill_samp_msg()
  1307. * to prepare fully formatted Spectral SAMP message
  1308. *
  1309. * XXX : Need to verify
  1310. * 1. Order of FFT bin values
  1311. *
  1312. */
  1313. struct target_if_samp_msg_params params;
  1314. struct spectral_search_fft_info_gen2 search_fft_info;
  1315. struct spectral_search_fft_info_gen2 *p_sfft = &search_fft_info;
  1316. struct spectral_search_fft_info_gen2 search_fft_info_sec80;
  1317. struct spectral_search_fft_info_gen2 *p_sfft_sec80 =
  1318. &search_fft_info_sec80;
  1319. uint32_t segid_skiplen = 0;
  1320. struct spectral_phyerr_tlv_gen2 *ptlv = NULL;
  1321. struct spectral_phyerr_tlv_gen2 *ptlv_sec80 = NULL;
  1322. struct spectral_phyerr_fft_gen2 *pfft = NULL;
  1323. struct spectral_phyerr_fft_gen2 *pfft_sec80 = NULL;
  1324. struct spectral_process_phyerr_info_gen2 process_phyerr_fields;
  1325. struct spectral_process_phyerr_info_gen2 *phyerr_info =
  1326. &process_phyerr_fields;
  1327. uint8_t segid = 0;
  1328. uint8_t segid_sec80;
  1329. enum phy_ch_width ch_width;
  1330. QDF_STATUS ret;
  1331. struct target_if_spectral_ops *p_sops;
  1332. if (!spectral) {
  1333. spectral_err_rl("Spectral LMAC object is null");
  1334. return -EPERM;
  1335. }
  1336. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1337. /* Drop the sample if Spectral is not active */
  1338. if (!p_sops->is_spectral_active(spectral,
  1339. SPECTRAL_SCAN_MODE_NORMAL)) {
  1340. spectral_info_rl("Spectral scan is not active");
  1341. goto fail_no_print;
  1342. }
  1343. if (!data) {
  1344. spectral_err_rl("Phyerror event buffer is null");
  1345. goto fail;
  1346. }
  1347. if (!p_rfqual) {
  1348. spectral_err_rl("RF quality information is null");
  1349. goto fail;
  1350. }
  1351. if (!p_chaninfo) {
  1352. spectral_err_rl("Channel information is null");
  1353. goto fail;
  1354. }
  1355. if (!acs_stats) {
  1356. spectral_err_rl("ACS stats pointer is null");
  1357. goto fail;
  1358. }
  1359. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  1360. ch_width = spectral->report_info[SPECTRAL_SCAN_MODE_NORMAL].sscan_bw;
  1361. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  1362. ptlv = (struct spectral_phyerr_tlv_gen2 *)data;
  1363. if (spectral->is_160_format)
  1364. segid_skiplen = sizeof(SPECTRAL_SEGID_INFO);
  1365. pfft = (struct spectral_phyerr_fft_gen2 *)(
  1366. data +
  1367. sizeof(struct spectral_phyerr_tlv_gen2) +
  1368. sizeof(struct spectral_phyerr_hdr_gen2) +
  1369. segid_skiplen);
  1370. /*
  1371. * XXX Extend SPECTRAL_DPRINTK() to use spectral_debug_level,
  1372. * and use this facility inside spectral_dump_phyerr_data()
  1373. * and supporting functions.
  1374. */
  1375. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  1376. target_if_spectral_dump_phyerr_data_gen2(
  1377. data, datalen,
  1378. spectral->is_160_format);
  1379. if (ptlv->signature != SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  1380. /*
  1381. * EV# 118023: We tentatively disable the below print
  1382. * and provide stats instead.
  1383. */
  1384. spectral->diag_stats.spectral_mismatch++;
  1385. goto fail;
  1386. }
  1387. qdf_mem_zero(&params, sizeof(params));
  1388. if (ptlv->tag == TLV_TAG_SEARCH_FFT_REPORT_GEN2) {
  1389. if (spectral->is_160_format) {
  1390. segid = *((SPECTRAL_SEGID_INFO *)(
  1391. (uint8_t *)ptlv +
  1392. sizeof(struct spectral_phyerr_tlv_gen2) +
  1393. sizeof(struct spectral_phyerr_hdr_gen2)));
  1394. if (segid != 0) {
  1395. struct spectral_diag_stats *p_diag_stats =
  1396. &spectral->diag_stats;
  1397. p_diag_stats->spectral_vhtseg1id_mismatch++;
  1398. goto fail;
  1399. }
  1400. }
  1401. target_if_process_sfft_report_gen2(ptlv, ptlv->length,
  1402. p_sfft);
  1403. ret = target_if_update_session_info_from_report_ctx(
  1404. spectral, FFT_BIN_SIZE_1BYTE,
  1405. p_chaninfo->center_freq1,
  1406. p_chaninfo->center_freq2,
  1407. SPECTRAL_SCAN_MODE_NORMAL);
  1408. if (QDF_IS_STATUS_ERROR(ret)) {
  1409. spectral_err_rl("Failed to update per-session info");
  1410. goto fail;
  1411. }
  1412. phyerr_info->p_rfqual = p_rfqual;
  1413. phyerr_info->p_sfft = p_sfft;
  1414. phyerr_info->pfft = pfft;
  1415. phyerr_info->acs_stats = acs_stats;
  1416. phyerr_info->tsf64 = tsf64;
  1417. phyerr_info->seg_id = segid;
  1418. ret = target_if_spectral_populate_samp_params_gen2(spectral,
  1419. phyerr_info,
  1420. &params);
  1421. if (QDF_IS_STATUS_ERROR(ret)) {
  1422. spectral_err_rl("Failed to populate SAMP params");
  1423. goto fail;
  1424. }
  1425. ret = target_if_spectral_fill_samp_msg(spectral, &params);
  1426. if (QDF_IS_STATUS_ERROR(ret)) {
  1427. spectral_err_rl("Failed to fill the SAMP msg");
  1428. goto fail;
  1429. }
  1430. if (spectral->is_160_format &&
  1431. is_ch_width_160_or_80p80(ch_width)) {
  1432. /*
  1433. * We expect to see one more Search FFT report, and it
  1434. * should be equal in size to the current one.
  1435. */
  1436. if (datalen < (
  1437. 2 * (sizeof(struct spectral_phyerr_tlv_gen2) +
  1438. ptlv->length))) {
  1439. struct spectral_diag_stats *p_diag_stats =
  1440. &spectral->diag_stats;
  1441. p_diag_stats->spectral_sec80_sfft_insufflen++;
  1442. goto fail;
  1443. }
  1444. ptlv_sec80 = (struct spectral_phyerr_tlv_gen2 *)(
  1445. data +
  1446. sizeof(struct spectral_phyerr_tlv_gen2) +
  1447. ptlv->length);
  1448. if (ptlv_sec80->signature !=
  1449. SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  1450. spectral->diag_stats.spectral_mismatch++;
  1451. goto fail;
  1452. }
  1453. if (ptlv_sec80->tag != TLV_TAG_SEARCH_FFT_REPORT_GEN2) {
  1454. spectral->diag_stats.spectral_no_sec80_sfft++;
  1455. goto fail;
  1456. }
  1457. segid_sec80 = *((SPECTRAL_SEGID_INFO *)(
  1458. (uint8_t *)ptlv_sec80 +
  1459. sizeof(struct spectral_phyerr_tlv_gen2) +
  1460. sizeof(struct spectral_phyerr_hdr_gen2)));
  1461. if (segid_sec80 != 1) {
  1462. struct spectral_diag_stats *p_diag_stats =
  1463. &spectral->diag_stats;
  1464. p_diag_stats->spectral_vhtseg2id_mismatch++;
  1465. goto fail;
  1466. }
  1467. target_if_process_sfft_report_gen2(ptlv_sec80,
  1468. ptlv_sec80->length,
  1469. p_sfft_sec80);
  1470. pfft_sec80 = (struct spectral_phyerr_fft_gen2 *)(
  1471. ((uint8_t *)ptlv_sec80) +
  1472. sizeof(struct spectral_phyerr_tlv_gen2) +
  1473. sizeof(struct spectral_phyerr_hdr_gen2) +
  1474. segid_skiplen);
  1475. qdf_mem_zero(&params, sizeof(params));
  1476. phyerr_info->p_rfqual = p_rfqual;
  1477. phyerr_info->p_sfft = p_sfft_sec80;
  1478. phyerr_info->pfft = pfft_sec80;
  1479. phyerr_info->acs_stats = acs_stats;
  1480. phyerr_info->tsf64 = tsf64;
  1481. phyerr_info->seg_id = segid_sec80;
  1482. ret = target_if_spectral_populate_samp_params_gen2(
  1483. spectral, phyerr_info,
  1484. &params);
  1485. if (QDF_IS_STATUS_ERROR(ret)) {
  1486. spectral_err_rl("Failed to populate SAMP params");
  1487. goto fail;
  1488. }
  1489. ret = target_if_spectral_fill_samp_msg(spectral,
  1490. &params);
  1491. if (QDF_IS_STATUS_ERROR(ret)) {
  1492. spectral_err_rl("Failed to fill the SAMP msg");
  1493. goto fail;
  1494. }
  1495. }
  1496. }
  1497. if (spectral_debug_level & DEBUG_SPECTRAL4)
  1498. spectral_debug_level = DEBUG_SPECTRAL;
  1499. return 0;
  1500. fail:
  1501. spectral_err_rl("Error while processing Spectral report");
  1502. fail_no_print:
  1503. if (spectral_debug_level & DEBUG_SPECTRAL4)
  1504. spectral_debug_level = DEBUG_SPECTRAL;
  1505. free_samp_msg_skb(spectral, SPECTRAL_SCAN_MODE_NORMAL);
  1506. return -EPERM;
  1507. }
  1508. #else
  1509. int
  1510. target_if_process_phyerr_gen2(struct target_if_spectral *spectral,
  1511. uint8_t *data,
  1512. uint32_t datalen,
  1513. struct target_if_spectral_rfqual_info *p_rfqual,
  1514. struct target_if_spectral_chan_info *p_chaninfo,
  1515. uint64_t tsf64,
  1516. struct target_if_spectral_acs_stats *acs_stats)
  1517. {
  1518. /*
  1519. * XXX : The classifier do not use all the members of the SAMP
  1520. * message data format.
  1521. * The classifier only depends upon the following parameters
  1522. *
  1523. * 1. Frequency (freq, msg->freq)
  1524. * 2. Spectral RSSI (spectral_rssi,
  1525. * msg->samp_data.spectral_rssi)
  1526. * 3. Bin Power Count (bin_pwr_count,
  1527. * msg->samp_data.bin_pwr_count)
  1528. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  1529. * 5. Spectral Timestamp (spectral_tstamp,
  1530. * msg->samp_data.spectral_tstamp)
  1531. * 6. MAC Address (macaddr, msg->macaddr)
  1532. *
  1533. * This function prepares the params structure and populates it
  1534. * with
  1535. * relevant values, this is in turn passed to
  1536. * spectral_create_samp_msg()
  1537. * to prepare fully formatted Spectral SAMP message
  1538. *
  1539. * XXX : Need to verify
  1540. * 1. Order of FFT bin values
  1541. *
  1542. */
  1543. struct target_if_samp_msg_params params;
  1544. struct spectral_search_fft_info_gen2 search_fft_info;
  1545. struct spectral_search_fft_info_gen2 *p_sfft = &search_fft_info;
  1546. struct spectral_search_fft_info_gen2 search_fft_info_sec80;
  1547. struct spectral_search_fft_info_gen2 *p_sfft_sec80 =
  1548. &search_fft_info_sec80;
  1549. uint32_t segid_skiplen = 0;
  1550. int8_t rssi_up = 0;
  1551. int8_t rssi_low = 0;
  1552. int8_t chn_idx_highest_enabled = 0;
  1553. int8_t chn_idx_lowest_enabled = 0;
  1554. uint8_t control_rssi = 0;
  1555. uint8_t extension_rssi = 0;
  1556. uint8_t combined_rssi = 0;
  1557. uint32_t tstamp = 0;
  1558. struct target_if_spectral_ops *p_sops =
  1559. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1560. struct spectral_phyerr_tlv_gen2 *ptlv =
  1561. (struct spectral_phyerr_tlv_gen2 *)data;
  1562. struct spectral_phyerr_tlv_gen2 *ptlv_sec80 = NULL;
  1563. struct spectral_phyerr_fft_gen2 *pfft = NULL;
  1564. struct spectral_phyerr_fft_gen2 *pfft_sec80 = NULL;
  1565. uint8_t segid = 0;
  1566. uint8_t segid_sec80 = 0;
  1567. enum phy_ch_width ch_width =
  1568. spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  1569. if (spectral->is_160_format)
  1570. segid_skiplen = sizeof(SPECTRAL_SEGID_INFO);
  1571. pfft = (struct spectral_phyerr_fft_gen2 *)(
  1572. data +
  1573. sizeof(struct spectral_phyerr_tlv_gen2) +
  1574. sizeof(struct spectral_phyerr_hdr_gen2) +
  1575. segid_skiplen);
  1576. /*
  1577. * XXX Extend SPECTRAL_DPRINTK() to use spectral_debug_level,
  1578. * and use this facility inside spectral_dump_phyerr_data()
  1579. * and supporting functions.
  1580. */
  1581. if (spectral_debug_level & DEBUG_SPECTRAL2)
  1582. target_if_spectral_dump_phyerr_data_gen2(
  1583. data, datalen,
  1584. spectral->is_160_format);
  1585. if (spectral_debug_level & DEBUG_SPECTRAL4) {
  1586. target_if_spectral_dump_phyerr_data_gen2(
  1587. data, datalen,
  1588. spectral->is_160_format);
  1589. spectral_debug_level = DEBUG_SPECTRAL;
  1590. }
  1591. if (ptlv->signature != SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  1592. /*
  1593. * EV# 118023: We tentatively disable the below print
  1594. * and provide stats instead.
  1595. */
  1596. spectral->diag_stats.spectral_mismatch++;
  1597. return -EPERM;
  1598. }
  1599. OS_MEMZERO(&params, sizeof(params));
  1600. /* Gen 2 only supports normal Spectral scan currently */
  1601. params.smode = SPECTRAL_SCAN_MODE_NORMAL;
  1602. if (ptlv->tag == TLV_TAG_SEARCH_FFT_REPORT_GEN2) {
  1603. if (spectral->is_160_format) {
  1604. segid = *((SPECTRAL_SEGID_INFO *)(
  1605. (uint8_t *)ptlv +
  1606. sizeof(struct spectral_phyerr_tlv_gen2) +
  1607. sizeof(struct spectral_phyerr_hdr_gen2)));
  1608. if (segid != 0) {
  1609. struct spectral_diag_stats *p_diag_stats =
  1610. &spectral->diag_stats;
  1611. p_diag_stats->spectral_vhtseg1id_mismatch++;
  1612. return -EPERM;
  1613. }
  1614. }
  1615. target_if_process_sfft_report_gen2(ptlv, ptlv->length,
  1616. &search_fft_info);
  1617. tstamp = p_sops->get_tsf64(spectral) & SPECTRAL_TSMASK;
  1618. combined_rssi = p_rfqual->rssi_comb;
  1619. if (spectral->upper_is_control)
  1620. rssi_up = control_rssi;
  1621. else
  1622. rssi_up = extension_rssi;
  1623. if (spectral->lower_is_control)
  1624. rssi_low = control_rssi;
  1625. else
  1626. rssi_low = extension_rssi;
  1627. params.rssi = p_rfqual->rssi_comb;
  1628. params.lower_rssi = rssi_low;
  1629. params.upper_rssi = rssi_up;
  1630. if (spectral->sc_spectral_noise_pwr_cal) {
  1631. params.chain_ctl_rssi[0] =
  1632. p_rfqual->pc_rssi_info[0].rssi_pri20;
  1633. params.chain_ctl_rssi[1] =
  1634. p_rfqual->pc_rssi_info[1].rssi_pri20;
  1635. params.chain_ctl_rssi[2] =
  1636. p_rfqual->pc_rssi_info[2].rssi_pri20;
  1637. params.chain_ext_rssi[0] =
  1638. p_rfqual->pc_rssi_info[0].rssi_sec20;
  1639. params.chain_ext_rssi[1] =
  1640. p_rfqual->pc_rssi_info[1].rssi_sec20;
  1641. params.chain_ext_rssi[2] =
  1642. p_rfqual->pc_rssi_info[2].rssi_sec20;
  1643. }
  1644. /*
  1645. * XXX : This actually depends on the programmed chain mask
  1646. * This value decides the per-chain enable mask to select
  1647. * the input ADC for search FTT.
  1648. * For modes upto VHT80, if more than one chain is
  1649. * enabled, the max valid chain
  1650. * is used. LSB corresponds to chain zero.
  1651. * For VHT80_80 and VHT160, the lowest enabled chain is
  1652. * used for primary
  1653. * detection and highest enabled chain is used for
  1654. * secondary detection.
  1655. *
  1656. * XXX : The current algorithm do not use these control and
  1657. * extension channel
  1658. * Instead, it just relies on the combined RSSI values
  1659. * only.
  1660. * For fool-proof detection algorithm, we should take
  1661. * these RSSI values in to account.
  1662. * This is marked for future enhancements.
  1663. */
  1664. chn_idx_highest_enabled =
  1665. ((spectral->params[params.smode].ss_chn_mask & 0x8) ? 3 :
  1666. (spectral->params[params.smode].ss_chn_mask & 0x4) ? 2 :
  1667. (spectral->params[params.smode].ss_chn_mask & 0x2) ? 1 : 0);
  1668. chn_idx_lowest_enabled =
  1669. ((spectral->params[params.smode].ss_chn_mask & 0x1) ? 0 :
  1670. (spectral->params[params.smode].ss_chn_mask & 0x2) ? 1 :
  1671. (spectral->params[params.smode].ss_chn_mask & 0x4) ? 2 : 3);
  1672. control_rssi = (uint8_t)
  1673. p_rfqual->pc_rssi_info[chn_idx_highest_enabled].rssi_pri20;
  1674. extension_rssi = (uint8_t)
  1675. p_rfqual->pc_rssi_info[chn_idx_highest_enabled].rssi_sec20;
  1676. params.bwinfo = 0;
  1677. params.tstamp = 0;
  1678. params.max_mag = p_sfft->peak_mag;
  1679. params.max_index = p_sfft->peak_inx;
  1680. params.max_exp = 0;
  1681. params.peak = 0;
  1682. params.bin_pwr_data = (uint8_t *)pfft;
  1683. params.freq = p_sops->get_current_channel(spectral,
  1684. params.smode);
  1685. params.freq_loading = 0;
  1686. params.interf_list.count = 0;
  1687. params.max_lower_index = 0;
  1688. params.max_upper_index = 0;
  1689. params.nb_lower = 0;
  1690. params.nb_upper = 0;
  1691. /*
  1692. * For modes upto VHT80, the noise floor is populated with the
  1693. * one corresponding
  1694. * to the highest enabled antenna chain
  1695. */
  1696. params.noise_floor =
  1697. p_rfqual->noise_floor[chn_idx_highest_enabled];
  1698. params.datalen = ptlv->length;
  1699. params.pwr_count = ptlv->length -
  1700. sizeof(struct spectral_phyerr_hdr_gen2) - segid_skiplen;
  1701. params.tstamp = (tsf64 & SPECTRAL_TSMASK);
  1702. acs_stats->ctrl_nf = params.noise_floor;
  1703. acs_stats->ext_nf = params.noise_floor;
  1704. acs_stats->nfc_ctl_rssi = control_rssi;
  1705. acs_stats->nfc_ext_rssi = extension_rssi;
  1706. if (spectral->is_160_format &&
  1707. is_ch_width_160_or_80p80(ch_width)) {
  1708. /*
  1709. * We expect to see one more Search FFT report, and it
  1710. * should be equal in size to the current one.
  1711. */
  1712. if (datalen < (
  1713. 2 * (
  1714. sizeof(struct spectral_phyerr_tlv_gen2) +
  1715. ptlv->length))) {
  1716. struct spectral_diag_stats *p_diag_stats =
  1717. &spectral->diag_stats;
  1718. p_diag_stats->spectral_sec80_sfft_insufflen++;
  1719. return -EPERM;
  1720. }
  1721. ptlv_sec80 = (struct spectral_phyerr_tlv_gen2 *)(
  1722. data +
  1723. sizeof(struct spectral_phyerr_tlv_gen2) +
  1724. ptlv->length);
  1725. if (ptlv_sec80->signature !=
  1726. SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  1727. spectral->diag_stats.spectral_mismatch++;
  1728. return -EPERM;
  1729. }
  1730. if (ptlv_sec80->tag != TLV_TAG_SEARCH_FFT_REPORT_GEN2) {
  1731. spectral->diag_stats.spectral_no_sec80_sfft++;
  1732. return -EPERM;
  1733. }
  1734. segid_sec80 = *((SPECTRAL_SEGID_INFO *)(
  1735. (uint8_t *)ptlv_sec80 +
  1736. sizeof(struct spectral_phyerr_tlv_gen2) +
  1737. sizeof(struct spectral_phyerr_hdr_gen2)));
  1738. if (segid_sec80 != 1) {
  1739. struct spectral_diag_stats *p_diag_stats =
  1740. &spectral->diag_stats;
  1741. p_diag_stats->spectral_vhtseg2id_mismatch++;
  1742. return -EPERM;
  1743. }
  1744. params.vhtop_ch_freq_seg1 = p_chaninfo->center_freq1;
  1745. params.vhtop_ch_freq_seg2 = p_chaninfo->center_freq2;
  1746. target_if_process_sfft_report_gen2(
  1747. ptlv_sec80,
  1748. ptlv_sec80->length,
  1749. &search_fft_info_sec80);
  1750. pfft_sec80 = (struct spectral_phyerr_fft_gen2 *)(
  1751. ((uint8_t *)ptlv_sec80) +
  1752. sizeof(struct spectral_phyerr_tlv_gen2) +
  1753. sizeof(struct spectral_phyerr_hdr_gen2) +
  1754. segid_skiplen);
  1755. /* XXX: Confirm. TBD at SoD. */
  1756. params.rssi_sec80 = p_rfqual->rssi_comb;
  1757. if (spectral->is_sec80_rssi_war_required)
  1758. params.rssi_sec80 =
  1759. target_if_get_combrssi_sec80_seg_gen2
  1760. (spectral, &search_fft_info_sec80);
  1761. /* XXX: Determine dynamically. TBD at SoD. */
  1762. /*
  1763. * For VHT80_80/VHT160, the noise floor for primary
  1764. * 80MHz segment is populated with the
  1765. * lowest enabled antenna chain and the noise floor for
  1766. * secondary 80MHz segment is populated
  1767. * with the highest enabled antenna chain
  1768. */
  1769. params.noise_floor_sec80 =
  1770. p_rfqual->noise_floor[chn_idx_highest_enabled];
  1771. params.noise_floor =
  1772. p_rfqual->noise_floor[chn_idx_lowest_enabled];
  1773. params.max_mag_sec80 = p_sfft_sec80->peak_mag;
  1774. params.max_index_sec80 = p_sfft_sec80->peak_inx;
  1775. /* XXX Does this definition of datalen *still hold? */
  1776. params.datalen_sec80 = ptlv_sec80->length;
  1777. params.pwr_count_sec80 =
  1778. ptlv_sec80->length -
  1779. sizeof(struct spectral_phyerr_hdr_gen2) -
  1780. segid_skiplen;
  1781. params.bin_pwr_data_sec80 = (uint8_t *)pfft_sec80;
  1782. }
  1783. qdf_mem_copy(&params.classifier_params,
  1784. &spectral->classifier_params,
  1785. sizeof(struct spectral_classifier_params));
  1786. target_if_spectral_log_SAMP_param(&params);
  1787. target_if_spectral_create_samp_msg(spectral, &params);
  1788. }
  1789. return 0;
  1790. }
  1791. #endif /* OPTIMIZED_SAMP_MESSAGE */
  1792. int
  1793. target_if_spectral_dump_hdr_gen2(struct spectral_phyerr_hdr_gen2 *phdr)
  1794. {
  1795. uint32_t a = 0;
  1796. uint32_t b = 0;
  1797. qdf_mem_copy(&a, (uint8_t *)phdr, sizeof(int));
  1798. qdf_mem_copy(&b,
  1799. (uint8_t *)((uint8_t *)phdr + sizeof(int)),
  1800. sizeof(int));
  1801. spectral_debug("SPECTRAL : HEADER A 0x%x (%d)", a, a);
  1802. spectral_debug("SPECTRAL : HEADER B 0x%x (%d)", b, b);
  1803. return 0;
  1804. }
  1805. int8_t
  1806. target_if_get_combrssi_sec80_seg_gen2(
  1807. struct target_if_spectral *spectral,
  1808. struct spectral_search_fft_info_gen2 *p_sfft_sec80)
  1809. {
  1810. uint32_t avgpwr_db = 0;
  1811. uint32_t total_gain_db = 0;
  1812. uint32_t offset = 0;
  1813. int8_t comb_rssi = 0;
  1814. /* Obtain required parameters for algorithm from search FFT report */
  1815. avgpwr_db = p_sfft_sec80->avgpwr_db;
  1816. total_gain_db = p_sfft_sec80->total_gain_info;
  1817. /* Calculate offset */
  1818. offset = target_if_get_offset_swar_sec80(
  1819. spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL]);
  1820. /* Calculate RSSI */
  1821. comb_rssi = ((avgpwr_db - total_gain_db) + offset);
  1822. return comb_rssi;
  1823. }
  1824. int
  1825. target_if_spectral_dump_tlv_gen2(
  1826. struct spectral_phyerr_tlv_gen2 *ptlv, bool is_160_format)
  1827. {
  1828. int ret = 0;
  1829. /*
  1830. * TODO : Do not delete the following print
  1831. * The scripts used to validate Spectral depend on this Print
  1832. */
  1833. spectral_debug("SPECTRAL : TLV Length is 0x%x (%d)",
  1834. ptlv->length, ptlv->length);
  1835. switch (ptlv->tag) {
  1836. case TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2:
  1837. ret =
  1838. target_if_dump_summary_report_gen2(
  1839. ptlv, ptlv->length, is_160_format);
  1840. break;
  1841. case TLV_TAG_SEARCH_FFT_REPORT_GEN2:
  1842. ret =
  1843. target_if_dump_sfft_report_gen2(ptlv, ptlv->length,
  1844. is_160_format);
  1845. break;
  1846. case TLV_TAG_ADC_REPORT_GEN2:
  1847. ret = target_if_dump_adc_report_gen2(ptlv, ptlv->length);
  1848. break;
  1849. default:
  1850. spectral_warn("INVALID TLV");
  1851. ret = -1;
  1852. break;
  1853. }
  1854. return ret;
  1855. }
  1856. int
  1857. target_if_spectral_dump_phyerr_data_gen2(uint8_t *data, uint32_t datalen,
  1858. bool is_160_format)
  1859. {
  1860. struct spectral_phyerr_tlv_gen2 *ptlv = NULL;
  1861. uint32_t bytes_processed = 0;
  1862. uint32_t bytes_remaining = datalen;
  1863. uint32_t curr_tlv_complete_size = 0;
  1864. if (datalen < sizeof(struct spectral_phyerr_tlv_gen2)) {
  1865. spectral_err("Total PHY error data length %u too short to contain any TLVs",
  1866. datalen);
  1867. return -EPERM;
  1868. }
  1869. while (bytes_processed < datalen) {
  1870. if (bytes_remaining < sizeof(struct spectral_phyerr_tlv_gen2)) {
  1871. spectral_err("Remaining PHY error data length %u too short to contain a TLV",
  1872. bytes_remaining);
  1873. return -EPERM;
  1874. }
  1875. ptlv = (struct spectral_phyerr_tlv_gen2 *)(data +
  1876. bytes_processed);
  1877. if (ptlv->signature != SPECTRAL_PHYERR_SIGNATURE_GEN2) {
  1878. spectral_err("Invalid signature 0x%x!",
  1879. ptlv->signature);
  1880. return -EPERM;
  1881. }
  1882. curr_tlv_complete_size =
  1883. sizeof(struct spectral_phyerr_tlv_gen2) +
  1884. ptlv->length;
  1885. if (curr_tlv_complete_size > bytes_remaining) {
  1886. spectral_err("TLV size %d greater than number of bytes remaining %d",
  1887. curr_tlv_complete_size, bytes_remaining);
  1888. return -EPERM;
  1889. }
  1890. if (target_if_spectral_dump_tlv_gen2(ptlv, is_160_format) == -1)
  1891. return -EPERM;
  1892. bytes_processed += curr_tlv_complete_size;
  1893. bytes_remaining = datalen - bytes_processed;
  1894. }
  1895. return 0;
  1896. }
  1897. QDF_STATUS
  1898. target_if_spectral_copy_fft_bins(struct target_if_spectral *spectral,
  1899. const void *src_fft_buf,
  1900. void *dest_fft_buf,
  1901. uint32_t fft_bin_count,
  1902. uint32_t *bytes_copied,
  1903. uint16_t pwr_format)
  1904. {
  1905. uint16_t idx, dword_idx, fft_bin_idx;
  1906. uint8_t num_bins_per_dword, hw_fft_bin_width_bits;
  1907. uint32_t num_dwords;
  1908. uint16_t fft_bin_val;
  1909. struct spectral_report_params *rparams;
  1910. const uint32_t *dword_ptr;
  1911. uint32_t dword;
  1912. uint8_t *fft_bin_buf;
  1913. *bytes_copied = 0;
  1914. if (!spectral) {
  1915. spectral_err("spectral lmac object is NULL");
  1916. return QDF_STATUS_E_NULL_VALUE;
  1917. }
  1918. if (!src_fft_buf) {
  1919. spectral_err("source fft bin buffer is NULL");
  1920. return QDF_STATUS_E_NULL_VALUE;
  1921. }
  1922. if (!dest_fft_buf) {
  1923. spectral_err("destination fft bin buffer is NULL");
  1924. return QDF_STATUS_E_NULL_VALUE;
  1925. }
  1926. rparams = &spectral->rparams;
  1927. num_bins_per_dword = SPECTRAL_DWORD_SIZE / rparams->hw_fft_bin_width;
  1928. num_dwords = fft_bin_count / num_bins_per_dword;
  1929. hw_fft_bin_width_bits = rparams->hw_fft_bin_width * QDF_CHAR_BIT;
  1930. fft_bin_idx = 0;
  1931. dword_ptr = src_fft_buf;
  1932. fft_bin_buf = dest_fft_buf;
  1933. for (dword_idx = 0; dword_idx < num_dwords; dword_idx++) {
  1934. dword = *dword_ptr++; /* Read a DWORD */
  1935. for (idx = 0; idx < num_bins_per_dword; idx++) {
  1936. /**
  1937. * If we use QDF_GET_BITS, when hw_fft_bin_width_bits is
  1938. * 32, on certain platforms, we could end up doing a
  1939. * 32-bit left shift operation on 32-bit constant
  1940. * integer '1'. As per C standard, result of shifting an
  1941. * operand by a count greater than or equal to width
  1942. * (in bits) of the operand is undefined.
  1943. * If we use QDF_GET_BITS_64, we can avoid that.
  1944. */
  1945. fft_bin_val = (uint16_t)QDF_GET_BITS64(
  1946. dword,
  1947. idx * hw_fft_bin_width_bits,
  1948. hw_fft_bin_width_bits);
  1949. fft_bin_buf[fft_bin_idx++] =
  1950. clamp_fft_bin_value(fft_bin_val, pwr_format);
  1951. }
  1952. }
  1953. *bytes_copied = num_dwords * SPECTRAL_DWORD_SIZE;
  1954. return QDF_STATUS_SUCCESS;
  1955. }
  1956. #ifdef DIRECT_BUF_RX_ENABLE
  1957. /**
  1958. * target_if_get_spectral_mode() - Get Spectral scan mode corresponding to a
  1959. * detector id
  1960. * @detector_id: detector id in the Spectral report
  1961. * @rparams: pointer to report params object
  1962. *
  1963. * Helper API to get Spectral scan mode from the detector ID. This mapping is
  1964. * target specific.
  1965. *
  1966. * Return: Spectral scan mode
  1967. */
  1968. static enum spectral_scan_mode
  1969. target_if_get_spectral_mode(enum spectral_detector_id detector_id,
  1970. struct spectral_report_params *rparams)
  1971. {
  1972. if (detector_id >= SPECTRAL_DETECTOR_ID_MAX) {
  1973. spectral_err_rl("Invalid detector id %d", detector_id);
  1974. return SPECTRAL_SCAN_MODE_INVALID;
  1975. }
  1976. return rparams->detid_mode_table[detector_id];
  1977. }
  1978. /**
  1979. * target_if_spectral_get_bin_count_after_len_adj() - Get number of FFT bins in
  1980. * Spectral FFT report
  1981. * @fft_bin_len: FFT bin length reported by target
  1982. * @rpt_mode: Spectral report mode
  1983. * @swar: Spectral FFT bin length adjustments SWAR parameters
  1984. * @fft_bin_size: Size of one FFT bin in bytes
  1985. *
  1986. * Get actual number of FFT bins in the FFT report after adjusting the length
  1987. * by applying the SWARs for getting correct length.
  1988. *
  1989. * Return: FFT bin count
  1990. */
  1991. static size_t
  1992. target_if_spectral_get_bin_count_after_len_adj(
  1993. size_t fft_bin_len, uint8_t rpt_mode,
  1994. struct spectral_fft_bin_len_adj_swar *swar,
  1995. size_t *fft_bin_size)
  1996. {
  1997. size_t fft_bin_count = fft_bin_len;
  1998. if (rpt_mode == 1 && swar->null_fftbin_adj) {
  1999. /*
  2000. * No FFT bins are expected. Explicitly set FFT bin
  2001. * count to 0.
  2002. */
  2003. fft_bin_count = 0;
  2004. *fft_bin_size = 0;
  2005. } else {
  2006. /*
  2007. * Divide fft bin length by appropriate factor depending
  2008. * on the value of fftbin_size_war.
  2009. */
  2010. switch (swar->fftbin_size_war) {
  2011. case SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE:
  2012. fft_bin_count >>= 2;
  2013. *fft_bin_size = 4;
  2014. break;
  2015. case SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE:
  2016. fft_bin_count >>= 1;
  2017. *fft_bin_size = 2;
  2018. /* Ideally we should be dividing fft bin length
  2019. * by 2. Due to a HW bug, actual length is two
  2020. * times the expected length.
  2021. */
  2022. if (swar->packmode_fftbin_size_adj)
  2023. fft_bin_count >>= 1;
  2024. break;
  2025. case SPECTRAL_FFTBIN_SIZE_NO_WAR:
  2026. *fft_bin_size = 1;
  2027. /* No length adjustment */
  2028. break;
  2029. default:
  2030. qdf_assert_always(0);
  2031. }
  2032. if (rpt_mode == 2 && swar->inband_fftbin_size_adj)
  2033. fft_bin_count >>= 1;
  2034. }
  2035. return fft_bin_count;
  2036. }
  2037. #ifndef OPTIMIZED_SAMP_MESSAGE
  2038. /**
  2039. * target_if_process_sfft_report_gen3() - Process Search FFT Report for gen3
  2040. * @p_fft_report: Pointer to fft report
  2041. * @p_sfft: Pointer to search fft report
  2042. * @rparams: pointer to report params object
  2043. *
  2044. * Process Search FFT Report for gen3
  2045. *
  2046. * Return: Success/Failure
  2047. */
  2048. static int
  2049. target_if_process_sfft_report_gen3(
  2050. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  2051. struct spectral_search_fft_info_gen3 *p_sfft,
  2052. struct spectral_report_params *rparams)
  2053. {
  2054. int32_t peak_sidx = 0;
  2055. int32_t peak_mag;
  2056. qdf_assert_always(p_fft_report);
  2057. qdf_assert_always(p_sfft);
  2058. qdf_assert_always(rparams);
  2059. /*
  2060. * For simplicity, everything is defined as uint32_t (except one).
  2061. * Proper code will later use the right sizes.
  2062. */
  2063. /*
  2064. * For easy comparision between MDK team and OS team, the MDK script
  2065. * variable names have been used
  2066. */
  2067. /* Populate the Search FFT Info */
  2068. p_sfft->timestamp = p_fft_report->fft_timestamp;
  2069. p_sfft->fft_detector_id = get_bitfield(p_fft_report->hdr_a,
  2070. 2, 0);
  2071. p_sfft->fft_num = get_bitfield(p_fft_report->hdr_a, 3, 2);
  2072. switch (rparams->version) {
  2073. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  2074. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  2075. 12, 5);
  2076. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 17);
  2077. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_a, 3, 28);
  2078. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  2079. 9, 0);
  2080. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  2081. 8, 9);
  2082. break;
  2083. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  2084. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  2085. 14, 5);
  2086. peak_sidx = get_bitfield(p_fft_report->hdr_a, 11, 19);
  2087. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_b, 3, 0);
  2088. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  2089. 9, 3);
  2090. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  2091. 8, 12);
  2092. break;
  2093. default:
  2094. qdf_assert_always(0);
  2095. }
  2096. p_sfft->fft_peak_sidx = unsigned_to_signed(peak_sidx, 11);
  2097. p_sfft->fft_num_str_bins_ib = get_bitfield(p_fft_report->hdr_c,
  2098. 8, 0);
  2099. peak_mag = get_bitfield(p_fft_report->hdr_c, 10, 8);
  2100. p_sfft->fft_peak_mag = unsigned_to_signed(peak_mag, 10);
  2101. p_sfft->fft_avgpwr_db = get_bitfield(p_fft_report->hdr_c,
  2102. 7, 18);
  2103. p_sfft->fft_relpwr_db = get_bitfield(p_fft_report->hdr_c,
  2104. 7, 25);
  2105. return 0;
  2106. }
  2107. #endif
  2108. /**
  2109. * target_if_dump_fft_report_gen3() - Dump FFT Report for gen3
  2110. * @spectral: Pointer to Spectral object
  2111. * @smode: Spectral scan mode
  2112. * @p_fft_report: Pointer to fft report
  2113. * @p_sfft: Pointer to search fft report
  2114. *
  2115. * Dump FFT Report for gen3
  2116. *
  2117. * Return: void
  2118. */
  2119. static void
  2120. target_if_dump_fft_report_gen3(struct target_if_spectral *spectral,
  2121. enum spectral_scan_mode smode,
  2122. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  2123. struct spectral_search_fft_info_gen3 *p_sfft)
  2124. {
  2125. size_t fft_hdr_length;
  2126. size_t report_len;
  2127. size_t fft_bin_len;
  2128. size_t fft_bin_count;
  2129. size_t fft_bin_size;
  2130. size_t fft_bin_len_inband_tfer = 0;
  2131. uint8_t tag, signature;
  2132. qdf_assert_always(spectral);
  2133. /* There won't be FFT report/bins in report mode 0, so return */
  2134. if (!spectral->params[smode].ss_rpt_mode)
  2135. return;
  2136. fft_hdr_length = get_bitfield(
  2137. p_fft_report->fft_hdr_lts,
  2138. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  2139. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  2140. tag = get_bitfield(p_fft_report->fft_hdr_lts,
  2141. SPECTRAL_REPORT_LTS_TAG_SIZE_GEN3,
  2142. SPECTRAL_REPORT_LTS_TAG_POS_GEN3);
  2143. signature = get_bitfield(p_fft_report->fft_hdr_lts,
  2144. SPECTRAL_REPORT_LTS_SIGNATURE_SIZE_GEN3,
  2145. SPECTRAL_REPORT_LTS_SIGNATURE_POS_GEN3);
  2146. report_len = (fft_hdr_length + 8);
  2147. fft_bin_len = fft_hdr_length - spectral->rparams.fft_report_hdr_len;
  2148. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  2149. fft_bin_len,
  2150. spectral->params[smode].ss_rpt_mode,
  2151. &spectral->len_adj_swar, &fft_bin_size);
  2152. if ((spectral->params[smode].ss_rpt_mode == 2) &&
  2153. spectral->len_adj_swar.inband_fftbin_size_adj)
  2154. fft_bin_len_inband_tfer = fft_bin_len >> 1;
  2155. spectral_debug("Spectral FFT Report");
  2156. spectral_debug("fft_timestamp = 0x%x", p_fft_report->fft_timestamp);
  2157. spectral_debug("fft_hdr_length = %zu(32 bit words)",
  2158. fft_hdr_length >> 2);
  2159. spectral_debug("fft_hdr_tag = 0x%x", tag);
  2160. spectral_debug("fft_hdr_sig = 0x%x", signature);
  2161. spectral_debug("Length field in search fft report is %zu(0x%zx) bytes",
  2162. fft_hdr_length, fft_hdr_length);
  2163. spectral_debug("Total length of search fft report is %zu(0x%zx) bytes",
  2164. report_len, report_len);
  2165. spectral_debug("Target reported fftbins in report is %zu(0x%zx)",
  2166. fft_bin_len, fft_bin_len);
  2167. if ((spectral->params[smode].ss_rpt_mode == 1) &&
  2168. spectral->len_adj_swar.null_fftbin_adj)
  2169. spectral_debug("WAR: Considering number of FFT bins as 0");
  2170. else if ((spectral->params[smode].ss_rpt_mode == 2) &&
  2171. spectral->len_adj_swar.inband_fftbin_size_adj) {
  2172. spectral_debug("FW fftbins actually transferred (in-band report mode) %zu(0x%zx)",
  2173. fft_bin_len_inband_tfer,
  2174. fft_bin_len_inband_tfer);
  2175. }
  2176. spectral_debug("Actual number of fftbins in report is %zu(0x%zx)",
  2177. fft_bin_count, fft_bin_count);
  2178. spectral_debug("fft_detector_id = %u", p_sfft->fft_detector_id);
  2179. spectral_debug("fft_num = %u", p_sfft->fft_num);
  2180. spectral_debug("fft_radar_check = %u", p_sfft->fft_radar_check);
  2181. spectral_debug("fft_peak_sidx = %d", p_sfft->fft_peak_sidx);
  2182. spectral_debug("fft_chn_idx = %u", p_sfft->fft_chn_idx);
  2183. spectral_debug("fft_base_pwr_db = %u", p_sfft->fft_base_pwr_db);
  2184. spectral_debug("fft_total_gain_db = %u", p_sfft->fft_total_gain_db);
  2185. spectral_debug("fft_num_str_bins_ib = %u", p_sfft->fft_num_str_bins_ib);
  2186. spectral_debug("fft_peak_mag = %d", p_sfft->fft_peak_mag);
  2187. spectral_debug("fft_avgpwr_db = %u", p_sfft->fft_avgpwr_db);
  2188. spectral_debug("fft_relpwr_db = %u", p_sfft->fft_relpwr_db);
  2189. if (fft_bin_count > 0) {
  2190. uint8_t *fft_bin_buf;
  2191. uint32_t bytes_copied;
  2192. QDF_STATUS status;
  2193. fft_bin_buf = qdf_mem_malloc(fft_bin_count);
  2194. if (!fft_bin_buf) {
  2195. spectral_err_rl("memory allocation failed");
  2196. return;
  2197. }
  2198. status = target_if_spectral_copy_fft_bins(
  2199. spectral, &p_fft_report->buf,
  2200. fft_bin_buf, fft_bin_count, &bytes_copied,
  2201. spectral->params[smode].ss_pwr_format);
  2202. if (QDF_IS_STATUS_ERROR(status)) {
  2203. spectral_err_rl("Unable to populate FFT bins");
  2204. qdf_mem_free(fft_bin_buf);
  2205. return;
  2206. }
  2207. spectral_debug("FFT bin buffer size = %zu", fft_bin_count);
  2208. spectral_debug("FFT bins:");
  2209. target_if_spectral_hexdump(fft_bin_buf, fft_bin_count);
  2210. qdf_mem_free(fft_bin_buf);
  2211. }
  2212. }
  2213. #endif
  2214. #ifdef OPTIMIZED_SAMP_MESSAGE
  2215. QDF_STATUS
  2216. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  2217. enum spectral_scan_mode smode,
  2218. uint8_t detector_id) {
  2219. QDF_STATUS status = QDF_STATUS_SUCCESS;
  2220. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2221. spectral_err_rl("Invalid Spectral mode %d", smode);
  2222. return QDF_STATUS_E_INVAL;
  2223. }
  2224. if (!is_ch_width_160_or_80p80(spectral->report_info[smode].sscan_bw)) {
  2225. spectral_err_rl("Scan BW %d is not 160/80p80 for mode %d",
  2226. spectral->report_info[smode].sscan_bw, smode);
  2227. return QDF_STATUS_E_FAILURE;
  2228. }
  2229. switch (spectral->state_160mhz_delivery[smode]) {
  2230. case SPECTRAL_REPORT_WAIT_PRIMARY80:
  2231. if (detector_id == SPECTRAL_DETECTOR_ID_0)
  2232. spectral->state_160mhz_delivery[smode] =
  2233. SPECTRAL_REPORT_WAIT_SECONDARY80;
  2234. else {
  2235. status = QDF_STATUS_E_FAILURE;
  2236. spectral->diag_stats.spectral_vhtseg1id_mismatch++;
  2237. }
  2238. break;
  2239. case SPECTRAL_REPORT_WAIT_SECONDARY80:
  2240. if (detector_id == SPECTRAL_DETECTOR_ID_1)
  2241. spectral->state_160mhz_delivery[smode] =
  2242. SPECTRAL_REPORT_WAIT_PRIMARY80;
  2243. else {
  2244. spectral->state_160mhz_delivery[smode] =
  2245. SPECTRAL_REPORT_WAIT_PRIMARY80;
  2246. status = QDF_STATUS_E_FAILURE;
  2247. spectral->diag_stats.spectral_vhtseg2id_mismatch++;
  2248. }
  2249. break;
  2250. default:
  2251. break;
  2252. }
  2253. return status;
  2254. }
  2255. #else
  2256. QDF_STATUS
  2257. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  2258. enum spectral_scan_mode smode,
  2259. uint8_t detector_id) {
  2260. QDF_STATUS status = QDF_STATUS_SUCCESS;
  2261. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2262. spectral_err_rl("Invalid Spectral mode %d", smode);
  2263. return QDF_STATUS_E_INVAL;
  2264. }
  2265. if (!is_ch_width_160_or_80p80(spectral->ch_width[smode])) {
  2266. spectral_err_rl("Scan BW %d is not 160/80p80 for mode %d",
  2267. spectral->ch_width[smode], smode);
  2268. return QDF_STATUS_E_FAILURE;
  2269. }
  2270. switch (spectral->state_160mhz_delivery[smode]) {
  2271. case SPECTRAL_REPORT_WAIT_PRIMARY80:
  2272. if (detector_id == SPECTRAL_DETECTOR_ID_0)
  2273. spectral->state_160mhz_delivery[smode] =
  2274. SPECTRAL_REPORT_RX_PRIMARY80;
  2275. else {
  2276. status = QDF_STATUS_E_FAILURE;
  2277. spectral->diag_stats.spectral_vhtseg1id_mismatch++;
  2278. }
  2279. break;
  2280. case SPECTRAL_REPORT_WAIT_SECONDARY80:
  2281. if (detector_id == SPECTRAL_DETECTOR_ID_1)
  2282. spectral->state_160mhz_delivery[smode] =
  2283. SPECTRAL_REPORT_RX_SECONDARY80;
  2284. else {
  2285. spectral->state_160mhz_delivery[smode] =
  2286. SPECTRAL_REPORT_WAIT_PRIMARY80;
  2287. status = QDF_STATUS_E_FAILURE;
  2288. spectral->diag_stats.spectral_vhtseg2id_mismatch++;
  2289. }
  2290. break;
  2291. case SPECTRAL_REPORT_RX_SECONDARY80:
  2292. /* We don't care about detector id in this state. */
  2293. reset_160mhz_delivery_state_machine(spectral, smode);
  2294. break;
  2295. case SPECTRAL_REPORT_RX_PRIMARY80:
  2296. /* We don't care about detector id in this state */
  2297. spectral->state_160mhz_delivery[smode] =
  2298. SPECTRAL_REPORT_WAIT_SECONDARY80;
  2299. break;
  2300. default:
  2301. break;
  2302. }
  2303. return status;
  2304. }
  2305. #endif /* OPTIMIZED_SAMP_MESSAGE */
  2306. #ifdef DIRECT_BUF_RX_ENABLE
  2307. /**
  2308. * target_if_get_detector_id_sscan_summary_report_gen3() - Get Spectral detector
  2309. * ID from Spectral summary report
  2310. * @data: Pointer to Spectral summary report
  2311. *
  2312. * Return: Detector ID
  2313. */
  2314. static uint8_t
  2315. target_if_get_detector_id_sscan_summary_report_gen3(uint8_t *data) {
  2316. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  2317. uint8_t detector_id;
  2318. qdf_assert_always(data);
  2319. psscan_summary_report =
  2320. (struct spectral_sscan_summary_report_gen3 *)data;
  2321. detector_id = get_bitfield(
  2322. psscan_summary_report->hdr_a,
  2323. SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_SIZE_GEN3,
  2324. SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_POS_GEN3);
  2325. return detector_id;
  2326. }
  2327. #ifndef OPTIMIZED_SAMP_MESSAGE
  2328. /**
  2329. * target_if_consume_sscan_summary_report_gen3() - Consume Spectral summary
  2330. * report
  2331. * @data: Pointer to Spectral summary report
  2332. * @fields: Pointer to structure to be populated with extracted fields
  2333. * @rparams: Pointer to structure with Spectral report params
  2334. *
  2335. * Consume Spectral summary report for gen3
  2336. *
  2337. * Return: void
  2338. */
  2339. static void
  2340. target_if_consume_sscan_summary_report_gen3(
  2341. uint8_t *data,
  2342. struct sscan_report_fields_gen3 *fields,
  2343. struct spectral_report_params *rparams) {
  2344. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  2345. qdf_assert_always(data);
  2346. qdf_assert_always(fields);
  2347. qdf_assert_always(rparams);
  2348. psscan_summary_report =
  2349. (struct spectral_sscan_summary_report_gen3 *)data;
  2350. fields->sscan_agc_total_gain = get_bitfield(
  2351. psscan_summary_report->hdr_a,
  2352. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_SIZE_GEN3,
  2353. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_POS_GEN3);
  2354. fields->inband_pwr_db = get_bitfield(
  2355. psscan_summary_report->hdr_a,
  2356. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_SIZE_GEN3,
  2357. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_POS_GEN3);
  2358. fields->sscan_pri80 = get_bitfield(
  2359. psscan_summary_report->hdr_a,
  2360. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_SIZE_GEN3,
  2361. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_POS_GEN3);
  2362. switch (rparams->version) {
  2363. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  2364. fields->sscan_gainchange = get_bitfield(
  2365. psscan_summary_report->hdr_b,
  2366. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_SIZE_GEN3_V1,
  2367. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_POS_GEN3_V1);
  2368. break;
  2369. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  2370. fields->sscan_gainchange = get_bitfield(
  2371. psscan_summary_report->hdr_c,
  2372. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_SIZE_GEN3_V2,
  2373. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_POS_GEN3_V2);
  2374. break;
  2375. default:
  2376. qdf_assert_always(0);
  2377. }
  2378. }
  2379. #endif
  2380. /**
  2381. * target_if_verify_sig_and_tag_gen3() - Verify tag and signature
  2382. * of spectral report
  2383. * @spectral: Pointer to spectral object
  2384. * @data: Pointer to spectral summary report
  2385. * @exp_tag: iexpected tag value
  2386. *
  2387. * Process fft report for gen3
  2388. *
  2389. * Return: SUCCESS/FAILURE
  2390. */
  2391. static int
  2392. target_if_verify_sig_and_tag_gen3(struct target_if_spectral *spectral,
  2393. uint8_t *data, uint8_t exp_tag)
  2394. {
  2395. uint8_t tag = 0;
  2396. uint8_t signature = 0;
  2397. uint32_t lts;
  2398. lts = *((uint32_t *)(data + SPECTRAL_PHYERR_HDR_LTS_POS));
  2399. /* Peek into the data to figure out whether
  2400. * 1) Signature matches the expected value
  2401. * 2) What is inside the package (TAG ID is used for finding this)
  2402. */
  2403. tag = get_bitfield(lts,
  2404. SPECTRAL_REPORT_LTS_TAG_SIZE_GEN3,
  2405. SPECTRAL_REPORT_LTS_TAG_POS_GEN3);
  2406. signature = get_bitfield(lts,
  2407. SPECTRAL_REPORT_LTS_SIGNATURE_SIZE_GEN3,
  2408. SPECTRAL_REPORT_LTS_SIGNATURE_POS_GEN3);
  2409. if (signature != SPECTRAL_PHYERR_SIGNATURE_GEN3) {
  2410. spectral->diag_stats.spectral_mismatch++;
  2411. return -EINVAL;
  2412. }
  2413. if (tag != exp_tag) {
  2414. spectral->diag_stats.spectral_mismatch++;
  2415. return -EINVAL;
  2416. }
  2417. return 0;
  2418. }
  2419. static uint8_t
  2420. target_if_spectral_get_lowest_chn_idx(uint8_t chainmask)
  2421. {
  2422. uint8_t idx;
  2423. for (idx = 0; idx < DBR_MAX_CHAINS; idx++) {
  2424. if (chainmask & 0x1)
  2425. break;
  2426. chainmask >>= 1;
  2427. }
  2428. return idx;
  2429. }
  2430. #ifdef DIRECT_BUF_RX_DEBUG
  2431. static void target_if_spectral_check_buffer_poisoning(
  2432. struct target_if_spectral *spectral,
  2433. struct spectral_report *report,
  2434. int num_fft_bins, enum spectral_scan_mode smode)
  2435. {
  2436. uint32_t *data;
  2437. size_t len;
  2438. size_t words_to_check =
  2439. sizeof(struct spectral_sscan_summary_report_gen3) >> 2;
  2440. bool poisoned_words_found = false;
  2441. if (!spectral) {
  2442. spectral_err_rl("Spectral LMAC object is null");
  2443. return;
  2444. }
  2445. if (!spectral->dbr_buff_debug)
  2446. return;
  2447. if (!report) {
  2448. spectral_err_rl("Spectral report is null");
  2449. return;
  2450. }
  2451. /* Add search FFT report */
  2452. if (spectral->params[smode].ss_rpt_mode > 0)
  2453. words_to_check +=
  2454. sizeof(struct spectral_phyerr_fft_report_gen3) >> 2;
  2455. /* Now add the number of FFT bins */
  2456. if (spectral->params[smode].ss_rpt_mode > 1) {
  2457. /* Caller should take care to pass correct number of FFT bins */
  2458. if (spectral->len_adj_swar.fftbin_size_war ==
  2459. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE)
  2460. words_to_check += num_fft_bins;
  2461. else if (spectral->len_adj_swar.fftbin_size_war ==
  2462. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE)
  2463. words_to_check += (num_fft_bins >> 1);
  2464. }
  2465. data = (uint32_t *)report->data;
  2466. for (len = 0; len < words_to_check; ++len) {
  2467. if (*data == MEM_POISON_SIGNATURE) {
  2468. spectral_err("Pattern(%x) found in Spectral search FFT report at position %zu in the buffer %pK",
  2469. MEM_POISON_SIGNATURE,
  2470. (len << 2), report->data);
  2471. poisoned_words_found = true;
  2472. break;
  2473. }
  2474. ++data;
  2475. }
  2476. /* Crash the FW even if one word is poisoned */
  2477. if (poisoned_words_found) {
  2478. spectral_err("Pattern(%x) found in Spectral report, Hex dump of the sfft follows",
  2479. MEM_POISON_SIGNATURE);
  2480. target_if_spectral_hexdump((unsigned char *)report->data,
  2481. words_to_check << 2);
  2482. spectral_err("Asserting the FW");
  2483. target_if_spectral_fw_hang(spectral);
  2484. }
  2485. }
  2486. #ifdef OPTIMIZED_SAMP_MESSAGE
  2487. static void target_if_spectral_verify_ts(struct target_if_spectral *spectral,
  2488. uint8_t *buf, uint32_t current_ts,
  2489. uint8_t detector_id)
  2490. {
  2491. if (!spectral) {
  2492. spectral_err_rl("Spectral LMAC object is null");
  2493. return;
  2494. }
  2495. if (detector_id >= MAX_DETECTORS_PER_PDEV) {
  2496. spectral_err_rl("Spectral detector_id %d exceeds range",
  2497. detector_id);
  2498. return;
  2499. }
  2500. if (!spectral->dbr_buff_debug)
  2501. return;
  2502. if (spectral->prev_tstamp[detector_id]) {
  2503. if (current_ts == spectral->prev_tstamp[detector_id]) {
  2504. spectral_err("Spectral timestamp(%u) in the current buffer(%pK) is equal to the previous timestamp, same report DMAed twice? Asserting the FW",
  2505. current_ts, buf);
  2506. target_if_spectral_fw_hang(spectral);
  2507. }
  2508. }
  2509. spectral->prev_tstamp[detector_id] = current_ts;
  2510. }
  2511. #else
  2512. static void target_if_spectral_verify_ts(struct target_if_spectral *spectral,
  2513. uint8_t *buf, uint32_t current_ts)
  2514. {
  2515. if (!spectral) {
  2516. spectral_err_rl("Spectral LMAC object is null");
  2517. return;
  2518. }
  2519. if (!spectral->dbr_buff_debug)
  2520. return;
  2521. if (spectral->prev_tstamp) {
  2522. if (current_ts == spectral->prev_tstamp) {
  2523. spectral_err("Spectral timestamp(%u) in the current buffer(%pK) is equal to the previous timestamp, same report DMAed twice? Asserting the FW",
  2524. current_ts, buf);
  2525. target_if_spectral_fw_hang(spectral);
  2526. }
  2527. }
  2528. spectral->prev_tstamp = current_ts;
  2529. }
  2530. #endif /* OPTIMIZED_SAMP_MESSAGE */
  2531. #else
  2532. static void target_if_spectral_check_buffer_poisoning(
  2533. struct target_if_spectral *spectral,
  2534. struct spectral_report *report,
  2535. int num_fft_bins, enum spectral_scan_mode smode)
  2536. {
  2537. }
  2538. #ifdef OPTIMIZED_SAMP_MESSAGE
  2539. static void target_if_spectral_verify_ts(struct target_if_spectral *spectral,
  2540. uint8_t *buf, uint32_t current_ts,
  2541. uint8_t detector_id)
  2542. {
  2543. }
  2544. #else
  2545. static void target_if_spectral_verify_ts(struct target_if_spectral *spectral,
  2546. uint8_t *buf, uint32_t current_ts)
  2547. {
  2548. }
  2549. #endif /* OPTIMIZED_SAMP_MESSAGE */
  2550. #endif
  2551. /**
  2552. * target_if_spectral_get_adjusted_timestamp() - Adjust Spectral time
  2553. * stamp to account for reset in time stamp due to target reset
  2554. * @twar: Spectral time stamp WAR related information
  2555. * @raw_timestamp: Spectral time stamp reported by target
  2556. * @reset_delay: Reset delay at target
  2557. * @smode: Spectral scan mode
  2558. *
  2559. * Correct time stamp to account for reset in time stamp due to target reset
  2560. *
  2561. * Return: Adjusted time stamp
  2562. */
  2563. static uint32_t
  2564. target_if_spectral_get_adjusted_timestamp(struct spectral_timestamp_war *twar,
  2565. uint32_t raw_timestamp,
  2566. uint32_t reset_delay,
  2567. enum spectral_scan_mode smode) {
  2568. qdf_assert_always(smode < SPECTRAL_SCAN_MODE_MAX);
  2569. if (reset_delay) {
  2570. enum spectral_scan_mode m =
  2571. SPECTRAL_SCAN_MODE_NORMAL;
  2572. /* Adjust the offset for all the Spectral modes.
  2573. * Target will be sending the non zero reset delay for
  2574. * the first Spectral report after reset. This delay is
  2575. * common for all the Spectral modes.
  2576. */
  2577. for (; m < SPECTRAL_SCAN_MODE_MAX; m++)
  2578. twar->timestamp_war_offset[m] += (reset_delay +
  2579. twar->last_fft_timestamp[m]);
  2580. twar->target_reset_count++;
  2581. }
  2582. twar->last_fft_timestamp[smode] = raw_timestamp;
  2583. return raw_timestamp + twar->timestamp_war_offset[smode];
  2584. }
  2585. #ifdef BIG_ENDIAN_HOST
  2586. QDF_STATUS target_if_byte_swap_spectral_headers_gen3(
  2587. struct target_if_spectral *spectral,
  2588. void *data)
  2589. {
  2590. int i;
  2591. uint32_t *ptr32;
  2592. size_t words32;
  2593. qdf_assert_always(data);
  2594. qdf_assert_always(spectral);
  2595. ptr32 = (uint32_t *)data;
  2596. /* Summary Report */
  2597. words32 = sizeof(struct spectral_sscan_summary_report_gen3) >> 2;
  2598. for (i = 0; i < words32; ++i) {
  2599. *ptr32 = qdf_le32_to_cpu(*ptr32);
  2600. ++ptr32;
  2601. }
  2602. /* No need to swap the padding bytes */
  2603. ptr32 += (spectral->rparams.ssumaary_padding_bytes >> 2);
  2604. /* Search FFT Report */
  2605. words32 = sizeof(struct spectral_phyerr_fft_report_gen3) >> 2;
  2606. for (i = 0; i < words32; ++i) {
  2607. *ptr32 = qdf_le32_to_cpu(*ptr32);
  2608. ++ptr32;
  2609. }
  2610. return QDF_STATUS_SUCCESS;
  2611. }
  2612. QDF_STATUS target_if_byte_swap_spectral_fft_bins_gen3(
  2613. const struct spectral_report_params *rparams,
  2614. void *bin_pwr_data, size_t num_fftbins)
  2615. {
  2616. uint16_t dword_idx, num_dwords;
  2617. uint8_t num_bins_per_dword;
  2618. uint32_t *dword_ptr;
  2619. qdf_assert_always(bin_pwr_data);
  2620. qdf_assert_always(rparams);
  2621. num_bins_per_dword = SPECTRAL_DWORD_SIZE / rparams->hw_fft_bin_width;
  2622. num_dwords = num_fftbins / num_bins_per_dword;
  2623. dword_ptr = (uint32_t *)bin_pwr_data;
  2624. for (dword_idx = 0; dword_idx < num_dwords; dword_idx++) {
  2625. /* Read a DWORD, byteswap it, and copy it back */
  2626. *dword_ptr = qdf_le32_to_cpu(*dword_ptr);
  2627. ++dword_ptr;
  2628. }
  2629. return QDF_STATUS_SUCCESS;
  2630. }
  2631. #endif /* BIG_ENDIAN_HOST */
  2632. #ifdef OPTIMIZED_SAMP_MESSAGE
  2633. /**
  2634. * target_if_consume_sscan_summary_report_gen3() - Consume Spectral summary
  2635. * report
  2636. * @data: Pointer to Spectral summary report
  2637. * @fields: Pointer to structure to be populated with extracted fields
  2638. * @spectral: Pointer to spectral object
  2639. *
  2640. * Consume Spectral summary report for gen3
  2641. *
  2642. * Return: Success/Failure
  2643. */
  2644. static QDF_STATUS
  2645. target_if_consume_sscan_summary_report_gen3(
  2646. uint8_t **data,
  2647. struct sscan_report_fields_gen3 *fields,
  2648. struct target_if_spectral *spectral)
  2649. {
  2650. struct spectral_sscan_summary_report_gen3 *psscan_summary_report;
  2651. if (!data) {
  2652. spectral_err_rl("Summary report buffer is null");
  2653. return QDF_STATUS_E_NULL_VALUE;
  2654. }
  2655. if (!fields) {
  2656. spectral_err_rl("Invalid pointer to Summary report fields");
  2657. return QDF_STATUS_E_NULL_VALUE;
  2658. }
  2659. if (!spectral) {
  2660. spectral_err_rl("Spectral LMAC object is null");
  2661. return QDF_STATUS_E_NULL_VALUE;
  2662. }
  2663. /* Validate Spectral scan summary report */
  2664. if (target_if_verify_sig_and_tag_gen3(
  2665. spectral, *data,
  2666. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3) != 0) {
  2667. spectral_err_rl("Wrong tag/sig in sscan summary");
  2668. return QDF_STATUS_E_FAILURE;
  2669. }
  2670. fields->sscan_detector_id =
  2671. target_if_get_detector_id_sscan_summary_report_gen3(*data);
  2672. if (fields->sscan_detector_id >=
  2673. spectral->rparams.num_spectral_detectors) {
  2674. spectral->diag_stats.spectral_invalid_detector_id++;
  2675. spectral_err_rl("Invalid detector id %u, expected is 0 to %u",
  2676. fields->sscan_detector_id,
  2677. spectral->rparams.num_spectral_detectors);
  2678. return QDF_STATUS_E_FAILURE;
  2679. }
  2680. psscan_summary_report =
  2681. (struct spectral_sscan_summary_report_gen3 *)*data;
  2682. fields->sscan_agc_total_gain = get_bitfield(
  2683. psscan_summary_report->hdr_a,
  2684. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_SIZE_GEN3,
  2685. SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_POS_GEN3);
  2686. fields->inband_pwr_db = get_bitfield(
  2687. psscan_summary_report->hdr_a,
  2688. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_SIZE_GEN3,
  2689. SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_POS_GEN3);
  2690. fields->sscan_pri80 = get_bitfield(
  2691. psscan_summary_report->hdr_a,
  2692. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_SIZE_GEN3,
  2693. SSCAN_SUMMARY_REPORT_HDR_A_PRI80_POS_GEN3);
  2694. switch (spectral->rparams.version) {
  2695. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  2696. fields->sscan_gainchange = get_bitfield(
  2697. psscan_summary_report->hdr_b,
  2698. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_SIZE_GEN3_V1,
  2699. SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_POS_GEN3_V1);
  2700. break;
  2701. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  2702. fields->sscan_gainchange = get_bitfield(
  2703. psscan_summary_report->hdr_c,
  2704. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_SIZE_GEN3_V2,
  2705. SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_POS_GEN3_V2);
  2706. break;
  2707. default:
  2708. qdf_assert_always(0);
  2709. }
  2710. /* Advance buf pointer to the search fft report */
  2711. *data += sizeof(struct spectral_sscan_summary_report_gen3);
  2712. *data += spectral->rparams.ssumaary_padding_bytes;
  2713. return QDF_STATUS_SUCCESS;
  2714. }
  2715. /**
  2716. * target_if_process_sfft_report_gen3() - Validate and Process Search
  2717. * FFT Report for gen3
  2718. * @data: Pointer to Spectral FFT report
  2719. * @p_sfft: Pointer to search fft report
  2720. * @spectral: Pointer to spectral object
  2721. * @sscan_detector_id: Spectral detector id extracted from Summary report
  2722. * @reset_delay: Time taken for warm reset in usec
  2723. *
  2724. * Validate and Process Search FFT Report for gen3
  2725. *
  2726. * Return: Success/Failure
  2727. */
  2728. static QDF_STATUS
  2729. target_if_process_sfft_report_gen3(
  2730. uint8_t *data,
  2731. struct spectral_search_fft_info_gen3 *p_sfft,
  2732. struct target_if_spectral *spectral,
  2733. enum spectral_detector_id sscan_detector_id,
  2734. uint32_t reset_delay)
  2735. {
  2736. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  2737. int32_t peak_sidx = 0;
  2738. int32_t peak_mag;
  2739. int fft_hdr_length = 0;
  2740. struct target_if_spectral_ops *p_sops;
  2741. enum spectral_scan_mode spectral_mode;
  2742. QDF_STATUS ret;
  2743. if (!data) {
  2744. spectral_err_rl("FFT report buffer is null");
  2745. return QDF_STATUS_E_NULL_VALUE;
  2746. }
  2747. if (!p_sfft) {
  2748. spectral_err_rl("Invalid pointer to Search FFT report info");
  2749. return QDF_STATUS_E_NULL_VALUE;
  2750. }
  2751. if (!spectral) {
  2752. spectral_err_rl("Spectral LMAC object is null");
  2753. return QDF_STATUS_E_NULL_VALUE;
  2754. }
  2755. /*
  2756. * For easy comparision between MDK team and OS team, the MDK script
  2757. * variable names have been used
  2758. */
  2759. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  2760. /* Validate Spectral search FFT report */
  2761. if (target_if_verify_sig_and_tag_gen3(
  2762. spectral, data, TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  2763. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  2764. sscan_detector_id);
  2765. return QDF_STATUS_E_FAILURE;
  2766. }
  2767. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  2768. fft_hdr_length = get_bitfield(
  2769. p_fft_report->fft_hdr_lts,
  2770. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  2771. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  2772. if (fft_hdr_length < 16) {
  2773. spectral_err("Wrong TLV length %u, detector id = %d",
  2774. fft_hdr_length, sscan_detector_id);
  2775. return QDF_STATUS_E_FAILURE;
  2776. }
  2777. p_sfft->fft_detector_id = get_bitfield(
  2778. p_fft_report->hdr_a,
  2779. FFT_REPORT_HDR_A_DETECTOR_ID_SIZE_GEN3,
  2780. FFT_REPORT_HDR_A_DETECTOR_ID_POS_GEN3);
  2781. /* It is expected to have same detector id for
  2782. * summary and fft report
  2783. */
  2784. if (sscan_detector_id != p_sfft->fft_detector_id) {
  2785. spectral_err_rl("Different detid in ssummary(%u) and sfft(%u)",
  2786. sscan_detector_id, p_sfft->fft_detector_id);
  2787. return QDF_STATUS_E_FAILURE;
  2788. }
  2789. if (p_sfft->fft_detector_id >
  2790. spectral->rparams.num_spectral_detectors) {
  2791. spectral->diag_stats.spectral_invalid_detector_id++;
  2792. spectral_err("Invalid detector id %u, expected is 0 to %u",
  2793. p_sfft->fft_detector_id,
  2794. spectral->rparams.num_spectral_detectors);
  2795. return QDF_STATUS_E_FAILURE;
  2796. }
  2797. spectral_mode = target_if_get_spectral_mode(p_sfft->fft_detector_id,
  2798. &spectral->rparams);
  2799. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  2800. spectral_err_rl("No valid Spectral mode for detector id %u",
  2801. p_sfft->fft_detector_id);
  2802. return QDF_STATUS_E_FAILURE;
  2803. }
  2804. /* Populate the Search FFT Info */
  2805. p_sfft->timestamp = p_fft_report->fft_timestamp;
  2806. p_sfft->last_raw_timestamp = spectral->timestamp_war.
  2807. last_fft_timestamp[spectral_mode];
  2808. p_sfft->adjusted_timestamp = target_if_spectral_get_adjusted_timestamp(
  2809. &spectral->timestamp_war,
  2810. p_sfft->timestamp,
  2811. reset_delay,
  2812. spectral_mode);
  2813. /* Timestamp verification */
  2814. target_if_spectral_verify_ts(spectral, data,
  2815. p_sfft->adjusted_timestamp,
  2816. p_sfft->fft_detector_id);
  2817. p_sfft->fft_num = get_bitfield(p_fft_report->hdr_a,
  2818. FFT_REPORT_HDR_A_FFT_NUM_SIZE_GEN3,
  2819. FFT_REPORT_HDR_A_FFT_NUM_POS_GEN3);
  2820. switch (spectral->rparams.version) {
  2821. case SPECTRAL_REPORT_FORMAT_VERSION_1:
  2822. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  2823. FFT_REPORT_HDR_A_RADAR_CHECK_SIZE_GEN3_V1,
  2824. FFT_REPORT_HDR_A_RADAR_CHECK_POS_GEN3_V1);
  2825. peak_sidx = get_bitfield(
  2826. p_fft_report->hdr_a,
  2827. FFT_REPORT_HDR_A_PEAK_INDEX_SIZE_GEN3_V1,
  2828. FFT_REPORT_HDR_A_PEAK_INDEX_POS_GEN3_V1);
  2829. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_a,
  2830. FFT_REPORT_HDR_A_CHAIN_INDEX_SIZE_GEN3_V1,
  2831. FFT_REPORT_HDR_A_CHAIN_INDEX_POS_GEN3_V1);
  2832. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  2833. FFT_REPORT_HDR_B_BASE_PWR_SIZE_GEN3_V1,
  2834. FFT_REPORT_HDR_B_BASE_PWR_POS_GEN3_V1);
  2835. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  2836. FFT_REPORT_HDR_B_TOTAL_GAIN_SIZE_GEN3_V1,
  2837. FFT_REPORT_HDR_B_TOTAL_GAIN_POS_GEN3_V1);
  2838. break;
  2839. case SPECTRAL_REPORT_FORMAT_VERSION_2:
  2840. p_sfft->fft_radar_check = get_bitfield(p_fft_report->hdr_a,
  2841. FFT_REPORT_HDR_A_RADAR_CHECK_SIZE_GEN3_V2,
  2842. FFT_REPORT_HDR_A_RADAR_CHECK_POS_GEN3_V2);
  2843. peak_sidx = get_bitfield(
  2844. p_fft_report->hdr_a,
  2845. FFT_REPORT_HDR_A_PEAK_INDEX_SIZE_GEN3_V2,
  2846. FFT_REPORT_HDR_A_PEAK_INDEX_POS_GEN3_V2);
  2847. p_sfft->fft_chn_idx = get_bitfield(p_fft_report->hdr_b,
  2848. FFT_REPORT_HDR_B_CHAIN_INDEX_SIZE_GEN3_V2,
  2849. FFT_REPORT_HDR_B_CHAIN_INDEX_POS_GEN3_V2);
  2850. p_sfft->fft_base_pwr_db = get_bitfield(p_fft_report->hdr_b,
  2851. FFT_REPORT_HDR_B_BASE_PWR_SIZE_GEN3_V2,
  2852. FFT_REPORT_HDR_B_BASE_PWR_POS_GEN3_V2);
  2853. p_sfft->fft_total_gain_db = get_bitfield(p_fft_report->hdr_b,
  2854. FFT_REPORT_HDR_B_TOTAL_GAIN_SIZE_GEN3_V2,
  2855. FFT_REPORT_HDR_B_TOTAL_GAIN_POS_GEN3_V2);
  2856. break;
  2857. default:
  2858. qdf_assert_always(0);
  2859. }
  2860. p_sfft->fft_peak_sidx = unsigned_to_signed(peak_sidx,
  2861. FFT_REPORT_HDR_A_PEAK_INDEX_SIZE_GEN3_V1);
  2862. p_sfft->fft_num_str_bins_ib = get_bitfield(p_fft_report->hdr_c,
  2863. FFT_REPORT_HDR_C_NUM_STRONG_BINS_SIZE_GEN3,
  2864. FFT_REPORT_HDR_C_NUM_STRONG_BINS_POS_GEN3);
  2865. peak_mag = get_bitfield(p_fft_report->hdr_c,
  2866. FFT_REPORT_HDR_C_PEAK_MAGNITUDE_SIZE_GEN3,
  2867. FFT_REPORT_HDR_C_PEAK_MAGNITUDE_POS_GEN3);
  2868. p_sfft->fft_peak_mag = unsigned_to_signed(peak_mag,
  2869. FFT_REPORT_HDR_C_PEAK_MAGNITUDE_SIZE_GEN3);
  2870. p_sfft->fft_avgpwr_db = get_bitfield(p_fft_report->hdr_c,
  2871. FFT_REPORT_HDR_C_AVG_PWR_SIZE_GEN3,
  2872. FFT_REPORT_HDR_C_AVG_PWR_POS_GEN3);
  2873. p_sfft->fft_relpwr_db = get_bitfield(p_fft_report->hdr_c,
  2874. FFT_REPORT_HDR_C_RELATIVE_PWR_SIZE_GEN3,
  2875. FFT_REPORT_HDR_C_RELATIVE_PWR_POS_GEN3);
  2876. p_sfft->fft_bin_count =
  2877. target_if_spectral_get_bin_count_after_len_adj(
  2878. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  2879. spectral->params[spectral_mode].ss_rpt_mode,
  2880. &spectral->len_adj_swar,
  2881. (size_t *)&p_sfft->fft_bin_size);
  2882. p_sfft->bin_pwr_data = (uint8_t *)p_fft_report + SPECTRAL_FFT_BINS_POS;
  2883. /* Apply byte-swap on the FFT bins.
  2884. * NOTE: Until this point, bytes of the FFT bins could be in
  2885. * reverse order on a big-endian machine. If the consumers
  2886. * of FFT bins expects bytes in the correct order,
  2887. * they should use them only after this point.
  2888. */
  2889. if (p_sops->byte_swap_fft_bins) {
  2890. ret = p_sops->byte_swap_fft_bins(&spectral->rparams,
  2891. &p_sfft->bin_pwr_data,
  2892. p_sfft->fft_bin_count);
  2893. if (QDF_IS_STATUS_ERROR(ret)) {
  2894. spectral_err_rl("Byte-swap on the FFT bins failed");
  2895. return QDF_STATUS_E_FAILURE;
  2896. }
  2897. }
  2898. return QDF_STATUS_SUCCESS;
  2899. }
  2900. /**
  2901. * target_if_spectral_populate_samp_params_gen3() - Populate the SAMP params
  2902. * for gen3. SAMP params are to be used for populating SAMP msg.
  2903. * @spectral: Pointer to spectral object
  2904. * @p_sfft: Fields extracted from FFT report
  2905. * @sscan_fields: Fields extracted from Summary report
  2906. * @report: Pointer to spectral report
  2907. * @params: Pointer to Spectral SAMP message fields to be populated
  2908. *
  2909. * Populate the SAMP params for gen3, which will be used to populate SAMP msg.
  2910. *
  2911. * Return: Success/Failure
  2912. */
  2913. static QDF_STATUS
  2914. target_if_spectral_populate_samp_params_gen3(
  2915. struct target_if_spectral *spectral,
  2916. struct spectral_search_fft_info_gen3 *p_sfft,
  2917. struct sscan_report_fields_gen3 *sscan_fields,
  2918. struct spectral_report *report,
  2919. struct target_if_samp_msg_params *params)
  2920. {
  2921. enum spectral_scan_mode spectral_mode;
  2922. uint8_t chn_idx_lowest_enabled;
  2923. struct wlan_objmgr_vdev *vdev;
  2924. uint8_t vdev_rxchainmask;
  2925. if (!p_sfft) {
  2926. spectral_err_rl("Invalid pointer to Search FFT report info");
  2927. return QDF_STATUS_E_NULL_VALUE;
  2928. }
  2929. if (!spectral) {
  2930. spectral_err_rl("Spectral LMAC object is null");
  2931. return QDF_STATUS_E_NULL_VALUE;
  2932. }
  2933. if (!sscan_fields) {
  2934. spectral_err_rl("Invalid pointer to Summary report fields");
  2935. return QDF_STATUS_E_NULL_VALUE;
  2936. }
  2937. if (!report) {
  2938. spectral_err_rl("Spectral report is null");
  2939. return QDF_STATUS_E_NULL_VALUE;
  2940. }
  2941. if (!params) {
  2942. spectral_err_rl("SAMP msg params structure is null");
  2943. return QDF_STATUS_E_NULL_VALUE;
  2944. }
  2945. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  2946. params->rssi = (sscan_fields->inband_pwr_db) >> 1;
  2947. params->hw_detector_id = p_sfft->fft_detector_id;
  2948. params->raw_timestamp = p_sfft->timestamp;
  2949. params->last_raw_timestamp = p_sfft->last_raw_timestamp;
  2950. params->timestamp = p_sfft->adjusted_timestamp;
  2951. params->reset_delay = report->reset_delay;
  2952. params->max_mag = p_sfft->fft_peak_mag;
  2953. spectral_mode = target_if_get_spectral_mode(params->hw_detector_id,
  2954. &spectral->rparams);
  2955. vdev = target_if_spectral_get_vdev(spectral, spectral_mode);
  2956. if (!vdev) {
  2957. spectral_debug("First vdev is NULL");
  2958. return QDF_STATUS_E_FAILURE;
  2959. }
  2960. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  2961. QDF_ASSERT(vdev_rxchainmask != 0);
  2962. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  2963. chn_idx_lowest_enabled =
  2964. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  2965. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  2966. spectral_err("Invalid chain index, detector id = %u",
  2967. params->hw_detector_id);
  2968. return QDF_STATUS_E_FAILURE;
  2969. }
  2970. params->noise_floor = report->noisefloor[chn_idx_lowest_enabled];
  2971. params->agc_total_gain = sscan_fields->sscan_agc_total_gain;
  2972. params->gainchange = sscan_fields->sscan_gainchange;
  2973. params->pri80ind = sscan_fields->sscan_pri80;
  2974. params->bin_pwr_data = p_sfft->bin_pwr_data;
  2975. return QDF_STATUS_SUCCESS;
  2976. }
  2977. int
  2978. target_if_consume_spectral_report_gen3(
  2979. struct target_if_spectral *spectral,
  2980. struct spectral_report *report)
  2981. {
  2982. /*
  2983. * XXX : The classifier do not use all the members of the SAMP
  2984. * message data format.
  2985. * The classifier only depends upon the following parameters
  2986. *
  2987. * 1. Frequency
  2988. * 2. Spectral RSSI
  2989. * 3. Bin Power Count
  2990. * 4. Bin Power values
  2991. * 5. Spectral Timestamp
  2992. * 6. MAC Address
  2993. *
  2994. * This function processes the Spectral summary and FFT reports
  2995. * and passes the processed information
  2996. * target_if_spectral_fill_samp_msg()
  2997. * to prepare fully formatted Spectral SAMP message
  2998. *
  2999. * XXX : Need to verify
  3000. * 1. Order of FFT bin values
  3001. *
  3002. */
  3003. struct target_if_samp_msg_params params = {0};
  3004. struct spectral_search_fft_info_gen3 search_fft_info;
  3005. struct spectral_search_fft_info_gen3 *p_sfft = &search_fft_info;
  3006. struct target_if_spectral_ops *p_sops;
  3007. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  3008. uint8_t *data;
  3009. struct sscan_report_fields_gen3 sscan_report_fields = {0};
  3010. QDF_STATUS ret;
  3011. enum spectral_scan_mode spectral_mode = SPECTRAL_SCAN_MODE_INVALID;
  3012. bool finite_scan = false;
  3013. int det = 0;
  3014. struct sscan_detector_list *det_list;
  3015. struct spectral_data_stats *spectral_dp_stats;
  3016. if (!spectral) {
  3017. spectral_err_rl("Spectral LMAC object is null");
  3018. goto fail_no_print;
  3019. }
  3020. spectral_dp_stats = &spectral->data_stats;
  3021. spectral_dp_stats->consume_spectral_calls++;
  3022. if (!report) {
  3023. spectral_err_rl("Spectral report is null");
  3024. goto fail_no_print;
  3025. }
  3026. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3027. data = report->data;
  3028. /* Apply byte-swap on the headers */
  3029. if (p_sops->byte_swap_headers) {
  3030. ret = p_sops->byte_swap_headers(spectral, data);
  3031. if (QDF_IS_STATUS_ERROR(ret)) {
  3032. spectral_err_rl("Byte-swap on Spectral headers failed");
  3033. goto fail;
  3034. }
  3035. }
  3036. /* Validate and Process Spectral scan summary report */
  3037. ret = target_if_consume_sscan_summary_report_gen3(&data,
  3038. &sscan_report_fields,
  3039. spectral);
  3040. if (QDF_IS_STATUS_ERROR(ret)) {
  3041. spectral_err_rl("Failed to process Spectral summary report");
  3042. goto fail;
  3043. }
  3044. spectral_mode = target_if_get_spectral_mode(
  3045. sscan_report_fields.sscan_detector_id,
  3046. &spectral->rparams);
  3047. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  3048. spectral_err_rl("No valid Spectral mode for detector id %u",
  3049. sscan_report_fields.sscan_detector_id);
  3050. goto fail;
  3051. }
  3052. /* Drop the sample if Spectral is not active for the current mode */
  3053. if (!p_sops->is_spectral_active(spectral, spectral_mode)) {
  3054. spectral_info_rl("Spectral scan is not active");
  3055. goto fail_no_print;
  3056. }
  3057. /* Validate and Process the search FFT report */
  3058. ret = target_if_process_sfft_report_gen3(
  3059. data, p_sfft,
  3060. spectral,
  3061. sscan_report_fields.sscan_detector_id,
  3062. report->reset_delay);
  3063. if (QDF_IS_STATUS_ERROR(ret)) {
  3064. spectral_err_rl("Failed to process search FFT report");
  3065. goto fail;
  3066. }
  3067. qdf_spin_lock_bh(&spectral->detector_list_lock);
  3068. det_list = &spectral->detector_list[spectral_mode]
  3069. [spectral->report_info[spectral_mode].sscan_bw];
  3070. for (det = 0; det < det_list->num_detectors; det++) {
  3071. if (p_sfft->fft_detector_id == det_list->detectors[det])
  3072. break;
  3073. if (det == det_list->num_detectors - 1) {
  3074. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  3075. spectral_info("Incorrect det id %d for given scan mode and channel width",
  3076. p_sfft->fft_detector_id);
  3077. goto fail_no_print;
  3078. }
  3079. }
  3080. qdf_spin_unlock_bh(&spectral->detector_list_lock);
  3081. ret = target_if_update_session_info_from_report_ctx(
  3082. spectral,
  3083. p_sfft->fft_bin_size,
  3084. report->cfreq1, report->cfreq2,
  3085. spectral_mode);
  3086. if (QDF_IS_STATUS_ERROR(ret)) {
  3087. spectral_err_rl("Failed to update per-session info");
  3088. goto fail;
  3089. }
  3090. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  3091. /* Check FFT report are in order for 160 MHz and 80p80 */
  3092. if (is_ch_width_160_or_80p80(
  3093. spectral->report_info[spectral_mode].sscan_bw) &&
  3094. spectral->rparams.fragmentation_160[spectral_mode]) {
  3095. ret = target_if_160mhz_delivery_state_change(
  3096. spectral, spectral_mode,
  3097. p_sfft->fft_detector_id);
  3098. if (ret != QDF_STATUS_SUCCESS) {
  3099. qdf_spin_unlock_bh(
  3100. &spectral->session_report_info_lock);
  3101. goto fail;
  3102. }
  3103. }
  3104. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  3105. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  3106. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  3107. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  3108. p_fft_report, p_sfft);
  3109. target_if_spectral_check_buffer_poisoning(spectral, report,
  3110. p_sfft->fft_bin_count,
  3111. spectral_mode);
  3112. /* Populate SAMP params */
  3113. ret = target_if_spectral_populate_samp_params_gen3(
  3114. spectral, p_sfft,
  3115. &sscan_report_fields,
  3116. report, &params);
  3117. if (QDF_IS_STATUS_ERROR(ret)) {
  3118. spectral_err_rl("Failed to populate SAMP params");
  3119. goto fail;
  3120. }
  3121. /* Fill SAMP message */
  3122. ret = target_if_spectral_fill_samp_msg(spectral, &params);
  3123. if (QDF_IS_STATUS_ERROR(ret)) {
  3124. spectral_err_rl("Failed to fill the SAMP msg");
  3125. goto fail;
  3126. }
  3127. ret = target_if_spectral_is_finite_scan(spectral, spectral_mode,
  3128. &finite_scan);
  3129. if (QDF_IS_STATUS_ERROR(ret)) {
  3130. spectral_err_rl("Failed to check scan is finite");
  3131. goto fail;
  3132. }
  3133. if (finite_scan) {
  3134. ret = target_if_spectral_finite_scan_update(spectral,
  3135. spectral_mode);
  3136. if (QDF_IS_STATUS_ERROR(ret)) {
  3137. spectral_err_rl("Failed to update scan count");
  3138. goto fail;
  3139. }
  3140. }
  3141. return 0;
  3142. fail:
  3143. spectral_err_rl("Error while processing Spectral report");
  3144. fail_no_print:
  3145. if (spectral_mode != SPECTRAL_SCAN_MODE_INVALID)
  3146. reset_160mhz_delivery_state_machine(spectral, spectral_mode);
  3147. return -EPERM;
  3148. }
  3149. #else
  3150. int
  3151. target_if_consume_spectral_report_gen3(
  3152. struct target_if_spectral *spectral,
  3153. struct spectral_report *report)
  3154. {
  3155. /*
  3156. * XXX : The classifier do not use all the members of the SAMP
  3157. * message data format.
  3158. * The classifier only depends upon the following parameters
  3159. *
  3160. * 1. Frequency (freq, msg->freq)
  3161. * 2. Spectral RSSI (spectral_rssi,
  3162. * msg->samp_data.spectral_rssi)
  3163. * 3. Bin Power Count (bin_pwr_count,
  3164. * msg->samp_data.bin_pwr_count)
  3165. * 4. Bin Power values (bin_pwr, msg->samp_data.bin_pwr[0]
  3166. * 5. Spectral Timestamp (spectral_tstamp,
  3167. * msg->samp_data.spectral_tstamp)
  3168. * 6. MAC Address (macaddr, msg->macaddr)
  3169. *
  3170. * This function prepares the params structure and populates it
  3171. * with
  3172. * relevant values, this is in turn passed to
  3173. * spectral_create_samp_msg()
  3174. * to prepare fully formatted Spectral SAMP message
  3175. *
  3176. * XXX : Need to verify
  3177. * 1. Order of FFT bin values
  3178. *
  3179. */
  3180. struct target_if_samp_msg_params params = {0};
  3181. struct spectral_search_fft_info_gen3 search_fft_info;
  3182. struct spectral_search_fft_info_gen3 *p_sfft = &search_fft_info;
  3183. int8_t chn_idx_lowest_enabled = 0;
  3184. int fft_hdr_length = 0;
  3185. int report_len = 0;
  3186. size_t fft_bin_count;
  3187. size_t fft_bin_size;
  3188. struct target_if_spectral_ops *p_sops =
  3189. GET_TARGET_IF_SPECTRAL_OPS(spectral);
  3190. struct spectral_phyerr_fft_report_gen3 *p_fft_report;
  3191. int8_t rssi;
  3192. uint8_t *data = report->data;
  3193. struct wlan_objmgr_vdev *vdev;
  3194. uint8_t vdev_rxchainmask;
  3195. struct sscan_report_fields_gen3 sscan_report_fields = {0};
  3196. enum spectral_detector_id detector_id;
  3197. QDF_STATUS ret;
  3198. enum spectral_scan_mode spectral_mode = SPECTRAL_SCAN_MODE_INVALID;
  3199. uint8_t *temp;
  3200. bool finite_scan = false;
  3201. /* Apply byte-swap on the headers */
  3202. if (p_sops->byte_swap_headers) {
  3203. ret = p_sops->byte_swap_headers(spectral, data);
  3204. if (QDF_IS_STATUS_ERROR(ret)) {
  3205. spectral_err_rl("Byte-swap on Spectral headers failed");
  3206. goto fail;
  3207. }
  3208. }
  3209. /* Process Spectral scan summary report */
  3210. if (target_if_verify_sig_and_tag_gen3(
  3211. spectral, data,
  3212. TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3) != 0) {
  3213. spectral_err_rl("Wrong tag/sig in sscan summary");
  3214. goto fail;
  3215. }
  3216. detector_id = target_if_get_detector_id_sscan_summary_report_gen3(data);
  3217. if (detector_id >= spectral->rparams.num_spectral_detectors) {
  3218. spectral->diag_stats.spectral_invalid_detector_id++;
  3219. spectral_err("Invalid detector id %u, expected is 0/1/2",
  3220. detector_id);
  3221. goto fail;
  3222. }
  3223. spectral_mode = target_if_get_spectral_mode(detector_id,
  3224. &spectral->rparams);
  3225. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  3226. spectral_err_rl("No valid Spectral mode for detector id %u",
  3227. detector_id);
  3228. goto fail;
  3229. }
  3230. /* Drop the sample if Spectral is not active for the current mode */
  3231. if (!p_sops->is_spectral_active(spectral, spectral_mode)) {
  3232. spectral_info_rl("Spectral scan is not active");
  3233. goto fail_no_print;
  3234. }
  3235. ret = target_if_spectral_is_finite_scan(spectral, spectral_mode,
  3236. &finite_scan);
  3237. if (QDF_IS_STATUS_ERROR(ret)) {
  3238. spectral_err_rl("Failed to check scan is finite");
  3239. goto fail;
  3240. }
  3241. if (finite_scan) {
  3242. ret = target_if_spectral_finite_scan_update(spectral,
  3243. spectral_mode);
  3244. if (QDF_IS_STATUS_ERROR(ret)) {
  3245. spectral_err_rl("Failed to update scan count");
  3246. goto fail;
  3247. }
  3248. }
  3249. target_if_consume_sscan_summary_report_gen3(data, &sscan_report_fields,
  3250. &spectral->rparams);
  3251. /* Advance buf pointer to the search fft report */
  3252. data += sizeof(struct spectral_sscan_summary_report_gen3);
  3253. data += spectral->rparams.ssumaary_padding_bytes;
  3254. params.vhtop_ch_freq_seg1 = report->cfreq1;
  3255. params.vhtop_ch_freq_seg2 = report->cfreq2;
  3256. if (is_primaryseg_expected(spectral, spectral_mode)) {
  3257. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  3258. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  3259. params.agc_total_gain =
  3260. sscan_report_fields.sscan_agc_total_gain;
  3261. params.gainchange = sscan_report_fields.sscan_gainchange;
  3262. params.pri80ind = sscan_report_fields.sscan_pri80;
  3263. /* Process Spectral search FFT report */
  3264. if (target_if_verify_sig_and_tag_gen3(
  3265. spectral, data,
  3266. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  3267. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  3268. detector_id);
  3269. goto fail;
  3270. }
  3271. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  3272. fft_hdr_length = get_bitfield(
  3273. p_fft_report->fft_hdr_lts,
  3274. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  3275. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  3276. if (fft_hdr_length < 16) {
  3277. spectral_err("Wrong TLV length %u, detector id = %d",
  3278. fft_hdr_length, detector_id);
  3279. goto fail;
  3280. }
  3281. report_len = (fft_hdr_length + 8);
  3282. target_if_process_sfft_report_gen3(p_fft_report, p_sfft,
  3283. &spectral->rparams);
  3284. /* It is expected to have same detector id for
  3285. * summary and fft report
  3286. */
  3287. if (detector_id != p_sfft->fft_detector_id) {
  3288. spectral_err_rl
  3289. ("Different detid in ssummary(%u) and sfft(%u)",
  3290. detector_id, p_sfft->fft_detector_id);
  3291. goto fail;
  3292. }
  3293. if (detector_id > spectral->rparams.num_spectral_detectors) {
  3294. spectral->diag_stats.spectral_invalid_detector_id++;
  3295. spectral_err("Invalid detector id %u, expected is 0/2",
  3296. detector_id);
  3297. goto fail;
  3298. }
  3299. params.smode = spectral_mode;
  3300. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  3301. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  3302. spectral->params[spectral_mode].ss_rpt_mode,
  3303. &spectral->len_adj_swar, &fft_bin_size);
  3304. params.last_raw_timestamp = spectral->timestamp_war.
  3305. last_fft_timestamp[spectral_mode];
  3306. params.reset_delay = report->reset_delay;
  3307. params.raw_timestamp = p_sfft->timestamp;
  3308. params.tstamp = target_if_spectral_get_adjusted_timestamp(
  3309. &spectral->timestamp_war,
  3310. p_sfft->timestamp, report->reset_delay,
  3311. spectral_mode);
  3312. params.timestamp_war_offset = spectral->timestamp_war.
  3313. timestamp_war_offset[spectral_mode];
  3314. params.target_reset_count = spectral->timestamp_war.
  3315. target_reset_count;
  3316. /* Take care of state transitions for 160 MHz and 80p80 */
  3317. if (is_ch_width_160_or_80p80(spectral->ch_width
  3318. [spectral_mode]) && spectral->rparams.
  3319. fragmentation_160[spectral_mode]) {
  3320. ret = target_if_160mhz_delivery_state_change(
  3321. spectral, spectral_mode,
  3322. detector_id);
  3323. if (ret != QDF_STATUS_SUCCESS)
  3324. goto fail;
  3325. }
  3326. params.rssi = rssi;
  3327. vdev = target_if_spectral_get_vdev(spectral, spectral_mode);
  3328. if (!vdev) {
  3329. spectral_debug("First vdev is NULL");
  3330. reset_160mhz_delivery_state_machine(
  3331. spectral, spectral_mode);
  3332. return -EPERM;
  3333. }
  3334. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  3335. QDF_ASSERT(vdev_rxchainmask != 0);
  3336. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3337. chn_idx_lowest_enabled =
  3338. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  3339. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  3340. spectral_err("Invalid chain index, detector id = %u",
  3341. detector_id);
  3342. goto fail;
  3343. }
  3344. params.max_mag = p_sfft->fft_peak_mag;
  3345. params.freq = p_sops->get_current_channel(spectral,
  3346. spectral_mode);
  3347. params.agile_freq1 = spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  3348. ss_frequency.cfreq1;
  3349. params.agile_freq2 = spectral->params[SPECTRAL_SCAN_MODE_AGILE].
  3350. ss_frequency.cfreq2;
  3351. params.noise_floor =
  3352. report->noisefloor[chn_idx_lowest_enabled];
  3353. temp = (uint8_t *)p_fft_report + SPECTRAL_FFT_BINS_POS;
  3354. if (is_ch_width_160_or_80p80(spectral->ch_width
  3355. [spectral_mode]) && !spectral->rparams.
  3356. fragmentation_160[spectral_mode]) {
  3357. struct wlan_objmgr_psoc *psoc;
  3358. struct spectral_fft_bin_markers_160_165mhz *marker;
  3359. qdf_assert_always(spectral->pdev_obj);
  3360. psoc = wlan_pdev_get_psoc(spectral->pdev_obj);
  3361. qdf_assert_always(psoc);
  3362. params.agc_total_gain_sec80 =
  3363. sscan_report_fields.sscan_agc_total_gain;
  3364. params.gainchange_sec80 =
  3365. sscan_report_fields.sscan_gainchange;
  3366. params.raw_timestamp_sec80 = p_sfft->timestamp;
  3367. params.rssi_sec80 = rssi;
  3368. params.noise_floor_sec80 =
  3369. report->noisefloor[chn_idx_lowest_enabled];
  3370. params.max_mag_sec80 = p_sfft->fft_peak_mag;
  3371. params.datalen = fft_hdr_length * 2;
  3372. params.datalen_sec80 = fft_hdr_length * 2;
  3373. marker = &spectral->rparams.marker[spectral_mode];
  3374. if (!marker->is_valid) {
  3375. /* update stats */
  3376. goto fail_no_print;
  3377. }
  3378. params.bin_pwr_data = temp +
  3379. marker->start_pri80 * fft_bin_size;
  3380. params.pwr_count = marker->num_pri80;
  3381. params.bin_pwr_data_sec80 = temp +
  3382. marker->start_sec80 * fft_bin_size;
  3383. params.pwr_count_sec80 = marker->num_sec80;
  3384. if (spectral->ch_width[spectral_mode] ==
  3385. CH_WIDTH_80P80MHZ && wlan_psoc_nif_fw_ext_cap_get(
  3386. psoc, WLAN_SOC_RESTRICTED_80P80_SUPPORT)) {
  3387. params.bin_pwr_data_5mhz = temp +
  3388. marker->start_5mhz * fft_bin_size;
  3389. params.pwr_count_5mhz = marker->num_5mhz;
  3390. }
  3391. } else {
  3392. params.bin_pwr_data = temp;
  3393. params.pwr_count = fft_bin_count;
  3394. params.datalen = (fft_hdr_length * 4);
  3395. }
  3396. /* Apply byte-swap on the FFT bins.
  3397. * NOTE: Until this point, bytes of the FFT bins could be in
  3398. * reverse order on a big-endian machine. If the consumers
  3399. * of FFT bins expects bytes in the correct order,
  3400. * they should use them only after this point.
  3401. */
  3402. if (p_sops->byte_swap_fft_bins) {
  3403. ret = p_sops->byte_swap_fft_bins(
  3404. &spectral->rparams,
  3405. temp, fft_bin_count);
  3406. if (QDF_IS_STATUS_ERROR(ret)) {
  3407. spectral_err_rl("Byte-swap on the FFT bins failed");
  3408. goto fail;
  3409. }
  3410. }
  3411. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  3412. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  3413. p_fft_report, p_sfft);
  3414. target_if_spectral_verify_ts(spectral, report->data,
  3415. params.tstamp);
  3416. } else if (is_secondaryseg_expected(spectral, spectral_mode)) {
  3417. /* RSSI is in 1/2 dBm steps, Covert it to dBm scale */
  3418. rssi = (sscan_report_fields.inband_pwr_db) >> 1;
  3419. params.agc_total_gain_sec80 =
  3420. sscan_report_fields.sscan_agc_total_gain;
  3421. params.gainchange_sec80 = sscan_report_fields.sscan_gainchange;
  3422. params.pri80ind_sec80 = sscan_report_fields.sscan_pri80;
  3423. /* Process Spectral search FFT report */
  3424. if (target_if_verify_sig_and_tag_gen3(
  3425. spectral, data,
  3426. TLV_TAG_SEARCH_FFT_REPORT_GEN3) != 0) {
  3427. spectral_err_rl("Unexpected tag/sig in sfft, detid= %u",
  3428. detector_id);
  3429. goto fail;
  3430. }
  3431. p_fft_report = (struct spectral_phyerr_fft_report_gen3 *)data;
  3432. fft_hdr_length = get_bitfield(
  3433. p_fft_report->fft_hdr_lts,
  3434. SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3,
  3435. SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3) * 4;
  3436. if (fft_hdr_length < 16) {
  3437. spectral_err("Wrong TLV length %u, detector id = %u",
  3438. fft_hdr_length, detector_id);
  3439. goto fail;
  3440. }
  3441. report_len = (fft_hdr_length + 8);
  3442. target_if_process_sfft_report_gen3(p_fft_report, p_sfft,
  3443. &spectral->rparams);
  3444. /* It is expected to have same detector id for
  3445. * summary and fft report
  3446. */
  3447. if (detector_id != p_sfft->fft_detector_id) {
  3448. spectral_err_rl
  3449. ("Different detid in ssummary(%u) and sfft(%u)",
  3450. detector_id, p_sfft->fft_detector_id);
  3451. goto fail;
  3452. }
  3453. if (detector_id > spectral->rparams.num_spectral_detectors) {
  3454. spectral->diag_stats.spectral_invalid_detector_id++;
  3455. spectral_err("Invalid detector id %u, expected is 1",
  3456. detector_id);
  3457. goto fail;
  3458. }
  3459. params.smode = spectral_mode;
  3460. fft_bin_count = target_if_spectral_get_bin_count_after_len_adj(
  3461. fft_hdr_length - spectral->rparams.fft_report_hdr_len,
  3462. spectral->params[spectral_mode].ss_rpt_mode,
  3463. &spectral->len_adj_swar, &fft_bin_size);
  3464. params.raw_timestamp_sec80 = p_sfft->timestamp;
  3465. /* Take care of state transitions for 160 MHz and 80p80 */
  3466. if (is_ch_width_160_or_80p80(spectral->ch_width
  3467. [spectral_mode]) && spectral->rparams.
  3468. fragmentation_160[spectral_mode]) {
  3469. ret = target_if_160mhz_delivery_state_change(
  3470. spectral, spectral_mode,
  3471. detector_id);
  3472. if (ret != QDF_STATUS_SUCCESS)
  3473. goto fail;
  3474. }
  3475. params.rssi_sec80 = rssi;
  3476. vdev = target_if_spectral_get_vdev(spectral, spectral_mode);
  3477. if (!vdev) {
  3478. spectral_info("First vdev is NULL");
  3479. reset_160mhz_delivery_state_machine
  3480. (spectral, spectral_mode);
  3481. return -EPERM;
  3482. }
  3483. vdev_rxchainmask = wlan_vdev_mlme_get_rxchainmask(vdev);
  3484. QDF_ASSERT(vdev_rxchainmask != 0);
  3485. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  3486. chn_idx_lowest_enabled =
  3487. target_if_spectral_get_lowest_chn_idx(vdev_rxchainmask);
  3488. if (chn_idx_lowest_enabled >= DBR_MAX_CHAINS) {
  3489. spectral_err("Invalid chain index");
  3490. goto fail;
  3491. }
  3492. /* Need to change this as per FW team's inputs */
  3493. params.noise_floor_sec80 =
  3494. report->noisefloor[chn_idx_lowest_enabled];
  3495. params.max_mag_sec80 = p_sfft->fft_peak_mag;
  3496. /* params.max_index_sec80 = p_sfft->peak_inx; */
  3497. /* XXX Does this definition of datalen *still hold? */
  3498. params.datalen_sec80 = fft_hdr_length * 4;
  3499. params.pwr_count_sec80 = fft_bin_count;
  3500. params.bin_pwr_data_sec80 =
  3501. (uint8_t *)((uint8_t *)p_fft_report +
  3502. SPECTRAL_FFT_BINS_POS);
  3503. /* Apply byte-swap on the FFT bins.
  3504. * NOTE: Until this point, bytes of the FFT bins could be in
  3505. * reverse order on a big-endian machine. If the consumers
  3506. * of FFT bins expects bytes in the correct order,
  3507. * they should use them only after this point.
  3508. */
  3509. if (p_sops->byte_swap_fft_bins) {
  3510. ret = p_sops->byte_swap_fft_bins(
  3511. &spectral->rparams,
  3512. params.bin_pwr_data_sec80,
  3513. fft_bin_count);
  3514. if (QDF_IS_STATUS_ERROR(ret)) {
  3515. spectral_err_rl("Byte-swap on the FFT bins failed");
  3516. goto fail;
  3517. }
  3518. }
  3519. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4))
  3520. target_if_dump_fft_report_gen3(spectral, spectral_mode,
  3521. p_fft_report, p_sfft);
  3522. } else {
  3523. spectral_err("Spectral state machine in undefined state");
  3524. goto fail;
  3525. }
  3526. target_if_spectral_check_buffer_poisoning(spectral, report,
  3527. fft_bin_count, spectral_mode);
  3528. qdf_mem_copy(&params.classifier_params,
  3529. &spectral->classifier_params,
  3530. sizeof(struct spectral_classifier_params));
  3531. target_if_spectral_log_SAMP_param(&params);
  3532. target_if_spectral_create_samp_msg(spectral, &params);
  3533. return 0;
  3534. fail:
  3535. spectral_err_rl("Error while processing Spectral report");
  3536. fail_no_print:
  3537. if (spectral_mode != SPECTRAL_SCAN_MODE_INVALID)
  3538. reset_160mhz_delivery_state_machine(spectral, spectral_mode);
  3539. return -EPERM;
  3540. }
  3541. #endif /* OPTIMIZED_SAMP_MESSAGE */
  3542. int target_if_spectral_process_report_gen3(
  3543. struct wlan_objmgr_pdev *pdev,
  3544. void *buf)
  3545. {
  3546. int ret = 0;
  3547. struct direct_buf_rx_data *payload = buf;
  3548. struct target_if_spectral *spectral;
  3549. struct spectral_report report;
  3550. int samp_msg_index;
  3551. struct spectral_data_stats *spectral_dp_stats;
  3552. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  3553. if (!spectral) {
  3554. spectral_err("Spectral target object is null");
  3555. return -EINVAL;
  3556. }
  3557. spectral_dp_stats = &spectral->data_stats;
  3558. spectral_dp_stats->spectral_rx_events++;
  3559. report.data = payload->vaddr;
  3560. if (payload->meta_data_valid) {
  3561. qdf_mem_copy(report.noisefloor, payload->meta_data.noisefloor,
  3562. qdf_min(sizeof(report.noisefloor),
  3563. sizeof(payload->meta_data.noisefloor)));
  3564. report.reset_delay = payload->meta_data.reset_delay;
  3565. report.cfreq1 = payload->meta_data.cfreq1;
  3566. report.cfreq2 = payload->meta_data.cfreq2;
  3567. report.ch_width = payload->meta_data.ch_width;
  3568. }
  3569. if (spectral_debug_level & (DEBUG_SPECTRAL2 | DEBUG_SPECTRAL4)) {
  3570. spectral_debug("Printing the spectral phyerr buffer for debug");
  3571. spectral_debug("Datalength of buffer = 0x%zx(%zd) bufptr = 0x%pK",
  3572. payload->dbr_len,
  3573. payload->dbr_len,
  3574. payload->vaddr);
  3575. target_if_spectral_hexdump((unsigned char *)payload->vaddr,
  3576. 1024);
  3577. }
  3578. samp_msg_index = spectral->spectral_sent_msg;
  3579. ret = target_if_consume_spectral_report_gen3(spectral, &report);
  3580. /* Reset debug level when SAMP msg is sent successfully or on error */
  3581. if ((spectral_debug_level & DEBUG_SPECTRAL4) &&
  3582. (ret != 0 || spectral->spectral_sent_msg == samp_msg_index + 1))
  3583. spectral_debug_level = DEBUG_SPECTRAL;
  3584. return ret;
  3585. }
  3586. #else
  3587. int target_if_spectral_process_report_gen3(
  3588. struct wlan_objmgr_pdev *pdev,
  3589. void *buf)
  3590. {
  3591. spectral_err("Direct dma support is not enabled");
  3592. return -EINVAL;
  3593. }
  3594. #endif
  3595. qdf_export_symbol(target_if_spectral_process_report_gen3);
  3596. /* END of spectral GEN III HW specific functions */
  3597. #endif /* WLAN_CONV_SPECTRAL_ENABLE */