target_if_spectral_phyerr.c 125 KB

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