target_if_spectral_phyerr.c 118 KB

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