target_if_spectral_phyerr.c 121 KB

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