target_if_spectral_phyerr.c 111 KB

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