dp_mon.c 158 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715
  1. /*
  2. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <dp_types.h>
  18. #include "dp_rx.h"
  19. #include "dp_peer.h"
  20. #include <dp_htt.h>
  21. #include <dp_mon_filter.h>
  22. #include <dp_htt.h>
  23. #include <dp_mon.h>
  24. #include <dp_rx_mon.h>
  25. #include <dp_internal.h>
  26. #include "htt_ppdu_stats.h"
  27. #include "dp_cal_client_api.h"
  28. #if defined(DP_CON_MON)
  29. #ifndef REMOVE_PKT_LOG
  30. #include <pktlog_ac_api.h>
  31. #include <pktlog_ac.h>
  32. #endif
  33. #endif
  34. #ifdef FEATURE_PERPKT_INFO
  35. #include "dp_ratetable.h"
  36. #endif
  37. #define DP_INTR_POLL_TIMER_MS 5
  38. #define INVALID_FREE_BUFF 0xffffffff
  39. #ifdef WLAN_RX_PKT_CAPTURE_ENH
  40. #include "dp_rx_mon_feature.h"
  41. #endif /* WLAN_RX_PKT_CAPTURE_ENH */
  42. #ifdef QCA_UNDECODED_METADATA_SUPPORT
  43. #define MAX_STRING_LEN_PER_FIELD 6
  44. #define DP_UNDECODED_ERR_LENGTH (MAX_STRING_LEN_PER_FIELD * CDP_PHYRX_ERR_MAX)
  45. #endif
  46. #ifdef QCA_MCOPY_SUPPORT
  47. static inline void
  48. dp_pdev_disable_mcopy_code(struct dp_pdev *pdev)
  49. {
  50. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  51. mon_pdev->mcopy_mode = M_COPY_DISABLED;
  52. mon_pdev->mvdev = NULL;
  53. }
  54. static inline void
  55. dp_reset_mcopy_mode(struct dp_pdev *pdev)
  56. {
  57. QDF_STATUS status = QDF_STATUS_SUCCESS;
  58. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  59. struct cdp_mon_ops *cdp_ops;
  60. if (mon_pdev->mcopy_mode) {
  61. cdp_ops = dp_mon_cdp_ops_get(pdev->soc);
  62. if (cdp_ops && cdp_ops->config_full_mon_mode)
  63. cdp_ops->soc_config_full_mon_mode((struct cdp_pdev *)pdev,
  64. DP_FULL_MON_ENABLE);
  65. dp_pdev_disable_mcopy_code(pdev);
  66. dp_mon_filter_reset_mcopy_mode(pdev);
  67. status = dp_mon_filter_update(pdev);
  68. if (status != QDF_STATUS_SUCCESS) {
  69. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  70. FL("Failed to reset AM copy mode filters"));
  71. }
  72. mon_pdev->monitor_configured = false;
  73. }
  74. }
  75. static QDF_STATUS
  76. dp_config_mcopy_mode(struct dp_pdev *pdev, int val)
  77. {
  78. QDF_STATUS status = QDF_STATUS_SUCCESS;
  79. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  80. struct dp_mon_ops *mon_ops;
  81. struct cdp_mon_ops *cdp_ops;
  82. if (mon_pdev->mvdev)
  83. return QDF_STATUS_E_RESOURCES;
  84. mon_pdev->mcopy_mode = val;
  85. mon_pdev->tx_sniffer_enable = 0;
  86. mon_pdev->monitor_configured = true;
  87. mon_ops = dp_mon_ops_get(pdev->soc);
  88. if (!wlan_cfg_is_delay_mon_replenish(pdev->soc->wlan_cfg_ctx)) {
  89. if (mon_ops && mon_ops->mon_vdev_set_monitor_mode_rings)
  90. mon_ops->mon_vdev_set_monitor_mode_rings(pdev, true);
  91. }
  92. /*
  93. * Setup the M copy mode filter.
  94. */
  95. cdp_ops = dp_mon_cdp_ops_get(pdev->soc);
  96. if (cdp_ops && cdp_ops->config_full_mon_mode)
  97. cdp_ops->soc_config_full_mon_mode((struct cdp_pdev *)pdev,
  98. DP_FULL_MON_ENABLE);
  99. dp_mon_filter_setup_mcopy_mode(pdev);
  100. status = dp_mon_filter_update(pdev);
  101. if (status != QDF_STATUS_SUCCESS) {
  102. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  103. FL("Failed to set M_copy mode filters"));
  104. dp_mon_filter_reset_mcopy_mode(pdev);
  105. dp_pdev_disable_mcopy_code(pdev);
  106. return status;
  107. }
  108. if (!mon_pdev->pktlog_ppdu_stats)
  109. dp_h2t_cfg_stats_msg_send(pdev,
  110. DP_PPDU_STATS_CFG_SNIFFER,
  111. pdev->pdev_id);
  112. return status;
  113. }
  114. #else
  115. static inline void
  116. dp_reset_mcopy_mode(struct dp_pdev *pdev)
  117. {
  118. }
  119. static inline QDF_STATUS
  120. dp_config_mcopy_mode(struct dp_pdev *pdev, int val)
  121. {
  122. return QDF_STATUS_E_INVAL;
  123. }
  124. #endif /* QCA_MCOPY_SUPPORT */
  125. #ifdef QCA_UNDECODED_METADATA_SUPPORT
  126. static QDF_STATUS
  127. dp_reset_undecoded_metadata_capture(struct dp_pdev *pdev)
  128. {
  129. QDF_STATUS status = QDF_STATUS_SUCCESS;
  130. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  131. if (mon_pdev->undecoded_metadata_capture) {
  132. dp_mon_filter_reset_undecoded_metadata_mode(pdev);
  133. status = dp_mon_filter_update(pdev);
  134. if (status != QDF_STATUS_SUCCESS) {
  135. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  136. FL("Undecoded capture filter reset failed"));
  137. }
  138. }
  139. mon_pdev->undecoded_metadata_capture = 0;
  140. return status;
  141. }
  142. static QDF_STATUS
  143. dp_enable_undecoded_metadata_capture(struct dp_pdev *pdev, int val)
  144. {
  145. QDF_STATUS status = QDF_STATUS_SUCCESS;
  146. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  147. struct dp_mon_ops *mon_ops;
  148. if (!mon_pdev->mvdev) {
  149. qdf_err("monitor_pdev is NULL");
  150. return QDF_STATUS_E_RESOURCES;
  151. }
  152. mon_pdev->undecoded_metadata_capture = val;
  153. mon_pdev->monitor_configured = true;
  154. mon_ops = dp_mon_ops_get(pdev->soc);
  155. /* Setup the undecoded metadata capture mode filter. */
  156. dp_mon_filter_setup_undecoded_metadata_mode(pdev);
  157. status = dp_mon_filter_update(pdev);
  158. if (status != QDF_STATUS_SUCCESS) {
  159. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  160. FL("Failed to set Undecoded capture filters"));
  161. dp_mon_filter_reset_undecoded_metadata_mode(pdev);
  162. return status;
  163. }
  164. return status;
  165. }
  166. #else
  167. static inline QDF_STATUS
  168. dp_reset_undecoded_metadata_capture(struct dp_pdev *pdev)
  169. {
  170. return QDF_STATUS_E_INVAL;
  171. }
  172. static inline QDF_STATUS
  173. dp_enable_undecoded_metadata_capture(struct dp_pdev *pdev, int val)
  174. {
  175. return QDF_STATUS_E_INVAL;
  176. }
  177. #endif /* QCA_UNDECODED_METADATA_SUPPORT */
  178. QDF_STATUS dp_reset_monitor_mode(struct cdp_soc_t *soc_hdl,
  179. uint8_t pdev_id,
  180. uint8_t special_monitor)
  181. {
  182. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  183. struct dp_pdev *pdev =
  184. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  185. pdev_id);
  186. QDF_STATUS status = QDF_STATUS_SUCCESS;
  187. struct dp_mon_pdev *mon_pdev;
  188. struct cdp_mon_ops *cdp_ops;
  189. if (!pdev)
  190. return QDF_STATUS_E_FAILURE;
  191. mon_pdev = pdev->monitor_pdev;
  192. qdf_spin_lock_bh(&mon_pdev->mon_lock);
  193. cdp_ops = dp_mon_cdp_ops_get(soc);
  194. if (cdp_ops && cdp_ops->soc_config_full_mon_mode)
  195. cdp_ops->soc_config_full_mon_mode((struct cdp_pdev *)pdev,
  196. DP_FULL_MON_DISABLE);
  197. mon_pdev->mvdev = NULL;
  198. /*
  199. * Lite monitor mode, smart monitor mode and monitor
  200. * mode uses this APIs to filter reset and mode disable
  201. */
  202. if (mon_pdev->mcopy_mode) {
  203. #if defined(QCA_MCOPY_SUPPORT)
  204. dp_pdev_disable_mcopy_code(pdev);
  205. dp_mon_filter_reset_mcopy_mode(pdev);
  206. #endif /* QCA_MCOPY_SUPPORT */
  207. } else if (special_monitor) {
  208. #if defined(ATH_SUPPORT_NAC)
  209. dp_mon_filter_reset_smart_monitor(pdev);
  210. #endif /* ATH_SUPPORT_NAC */
  211. } else if (mon_pdev->undecoded_metadata_capture) {
  212. #ifdef QCA_UNDECODED_METADATA_SUPPORT
  213. dp_reset_undecoded_metadata_capture(pdev);
  214. #endif
  215. } else {
  216. dp_mon_filter_reset_mon_mode(pdev);
  217. }
  218. status = dp_mon_filter_update(pdev);
  219. if (status != QDF_STATUS_SUCCESS) {
  220. dp_rx_mon_dest_err("%pK: Failed to reset monitor filters",
  221. soc);
  222. }
  223. mon_pdev->monitor_configured = false;
  224. qdf_spin_unlock_bh(&mon_pdev->mon_lock);
  225. return QDF_STATUS_SUCCESS;
  226. }
  227. #ifdef QCA_ADVANCE_MON_FILTER_SUPPORT
  228. QDF_STATUS
  229. dp_pdev_set_advance_monitor_filter(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  230. struct cdp_monitor_filter *filter_val)
  231. {
  232. /* Many monitor VAPs can exists in a system but only one can be up at
  233. * anytime
  234. */
  235. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  236. struct dp_vdev *vdev;
  237. struct dp_pdev *pdev =
  238. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  239. pdev_id);
  240. QDF_STATUS status = QDF_STATUS_SUCCESS;
  241. struct dp_mon_pdev *mon_pdev;
  242. if (!pdev || !pdev->monitor_pdev)
  243. return QDF_STATUS_E_FAILURE;
  244. mon_pdev = pdev->monitor_pdev;
  245. vdev = mon_pdev->mvdev;
  246. if (!vdev)
  247. return QDF_STATUS_E_FAILURE;
  248. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  249. "pdev=%pK, pdev_id=%d, soc=%pK vdev=%pK",
  250. pdev, pdev_id, soc, vdev);
  251. /*Check if current pdev's monitor_vdev exists */
  252. if (!mon_pdev->mvdev) {
  253. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  254. "vdev=%pK", vdev);
  255. qdf_assert(vdev);
  256. }
  257. /* update filter mode, type in pdev structure */
  258. mon_pdev->mon_filter_mode = filter_val->mode;
  259. mon_pdev->fp_mgmt_filter = filter_val->fp_mgmt;
  260. mon_pdev->fp_ctrl_filter = filter_val->fp_ctrl;
  261. mon_pdev->fp_data_filter = filter_val->fp_data;
  262. mon_pdev->mo_mgmt_filter = filter_val->mo_mgmt;
  263. mon_pdev->mo_ctrl_filter = filter_val->mo_ctrl;
  264. mon_pdev->mo_data_filter = filter_val->mo_data;
  265. dp_mon_filter_setup_mon_mode(pdev);
  266. status = dp_mon_filter_update(pdev);
  267. if (status != QDF_STATUS_SUCCESS) {
  268. dp_rx_mon_dest_err("%pK: Failed to set filter for adv mon mode",
  269. soc);
  270. dp_mon_filter_reset_mon_mode(pdev);
  271. }
  272. return status;
  273. }
  274. #endif
  275. QDF_STATUS
  276. dp_deliver_tx_mgmt(struct cdp_soc_t *cdp_soc, uint8_t pdev_id, qdf_nbuf_t nbuf)
  277. {
  278. struct dp_pdev *pdev =
  279. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)cdp_soc,
  280. pdev_id);
  281. if (!pdev)
  282. return QDF_STATUS_E_FAILURE;
  283. dp_deliver_mgmt_frm(pdev, nbuf);
  284. return QDF_STATUS_SUCCESS;
  285. }
  286. #ifdef QCA_SUPPORT_SCAN_SPCL_VAP_STATS
  287. /**
  288. * dp_scan_spcl_vap_stats_attach() - alloc spcl vap stats struct
  289. * @mon_vdev: Datapath mon VDEV handle
  290. *
  291. * Return: 0 on success, not 0 on failure
  292. */
  293. static inline QDF_STATUS
  294. dp_scan_spcl_vap_stats_attach(struct dp_mon_vdev *mon_vdev)
  295. {
  296. mon_vdev->scan_spcl_vap_stats =
  297. qdf_mem_malloc(sizeof(struct cdp_scan_spcl_vap_stats));
  298. if (!mon_vdev->scan_spcl_vap_stats) {
  299. dp_mon_err("scan spcl vap stats attach fail");
  300. return QDF_STATUS_E_NOMEM;
  301. }
  302. return QDF_STATUS_SUCCESS;
  303. }
  304. /**
  305. * dp_scan_spcl_vap_stats_detach() - free spcl vap stats struct
  306. * @mon_vdev: Datapath mon VDEV handle
  307. *
  308. * Return: void
  309. */
  310. static inline void
  311. dp_scan_spcl_vap_stats_detach(struct dp_mon_vdev *mon_vdev)
  312. {
  313. if (mon_vdev->scan_spcl_vap_stats) {
  314. qdf_mem_free(mon_vdev->scan_spcl_vap_stats);
  315. mon_vdev->scan_spcl_vap_stats = NULL;
  316. }
  317. }
  318. /**
  319. * dp_reset_scan_spcl_vap_stats() - reset spcl vap rx stats
  320. * @vdev: Datapath VDEV handle
  321. *
  322. * Return: void
  323. */
  324. static inline void
  325. dp_reset_scan_spcl_vap_stats(struct dp_vdev *vdev)
  326. {
  327. struct dp_mon_vdev *mon_vdev;
  328. struct dp_mon_pdev *mon_pdev;
  329. mon_pdev = vdev->pdev->monitor_pdev;
  330. if (!mon_pdev || !mon_pdev->reset_scan_spcl_vap_stats_enable)
  331. return;
  332. mon_vdev = vdev->monitor_vdev;
  333. if (!mon_vdev || !mon_vdev->scan_spcl_vap_stats)
  334. return;
  335. qdf_mem_zero(mon_vdev->scan_spcl_vap_stats,
  336. sizeof(struct cdp_scan_spcl_vap_stats));
  337. }
  338. /**
  339. * dp_get_scan_spcl_vap_stats() - get spcl vap rx stats
  340. * @soc_hdl: Datapath soc handle
  341. * @vdev_id: vdev id
  342. * @stats: structure to hold spcl vap stats
  343. *
  344. * Return: 0 on success, not 0 on failure
  345. */
  346. static QDF_STATUS
  347. dp_get_scan_spcl_vap_stats(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  348. struct cdp_scan_spcl_vap_stats *stats)
  349. {
  350. struct dp_mon_vdev *mon_vdev = NULL;
  351. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  352. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  353. DP_MOD_ID_CDP);
  354. if (!vdev || !stats) {
  355. if (vdev)
  356. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  357. return QDF_STATUS_E_INVAL;
  358. }
  359. mon_vdev = vdev->monitor_vdev;
  360. if (!mon_vdev || !mon_vdev->scan_spcl_vap_stats) {
  361. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  362. return QDF_STATUS_E_INVAL;
  363. }
  364. qdf_mem_copy(stats, mon_vdev->scan_spcl_vap_stats,
  365. sizeof(struct cdp_scan_spcl_vap_stats));
  366. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  367. return QDF_STATUS_SUCCESS;
  368. }
  369. #else
  370. static inline void
  371. dp_reset_scan_spcl_vap_stats(struct dp_vdev *vdev)
  372. {
  373. }
  374. static inline QDF_STATUS
  375. dp_scan_spcl_vap_stats_attach(struct dp_mon_vdev *mon_vdev)
  376. {
  377. return QDF_STATUS_SUCCESS;
  378. }
  379. static inline void
  380. dp_scan_spcl_vap_stats_detach(struct dp_mon_vdev *mon_vdev)
  381. {
  382. }
  383. #endif
  384. /**
  385. * dp_vdev_set_monitor_mode() - Set DP VDEV to monitor mode
  386. * @vdev_handle: Datapath VDEV handle
  387. * @smart_monitor: Flag to denote if its smart monitor mode
  388. *
  389. * Return: 0 on success, not 0 on failure
  390. */
  391. static QDF_STATUS dp_vdev_set_monitor_mode(struct cdp_soc_t *dp_soc,
  392. uint8_t vdev_id,
  393. uint8_t special_monitor)
  394. {
  395. struct dp_soc *soc = (struct dp_soc *)dp_soc;
  396. struct dp_pdev *pdev;
  397. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  398. DP_MOD_ID_CDP);
  399. QDF_STATUS status = QDF_STATUS_SUCCESS;
  400. struct dp_mon_pdev *mon_pdev;
  401. struct cdp_mon_ops *cdp_ops;
  402. if (!vdev)
  403. return QDF_STATUS_E_FAILURE;
  404. pdev = vdev->pdev;
  405. if (!pdev || !pdev->monitor_pdev)
  406. return QDF_STATUS_E_FAILURE;
  407. mon_pdev = pdev->monitor_pdev;
  408. mon_pdev->mvdev = vdev;
  409. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  410. "pdev=%pK, pdev_id=%d, soc=%pK vdev=%pK\n",
  411. pdev, pdev->pdev_id, pdev->soc, vdev);
  412. /*
  413. * do not configure monitor buf ring and filter for smart and
  414. * lite monitor
  415. * for smart monitor filters are added along with first NAC
  416. * for lite monitor required configuration done through
  417. * dp_set_pdev_param
  418. */
  419. if (special_monitor) {
  420. status = QDF_STATUS_SUCCESS;
  421. goto fail;
  422. }
  423. if (mon_pdev->scan_spcl_vap_configured)
  424. dp_reset_scan_spcl_vap_stats(vdev);
  425. /*Check if current pdev's monitor_vdev exists */
  426. if (mon_pdev->monitor_configured) {
  427. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  428. "monitor vap already created vdev=%pK\n", vdev);
  429. status = QDF_STATUS_E_RESOURCES;
  430. goto fail;
  431. }
  432. mon_pdev->monitor_configured = true;
  433. cdp_ops = dp_mon_cdp_ops_get(soc);
  434. if (cdp_ops && cdp_ops->soc_config_full_mon_mode)
  435. cdp_ops->soc_config_full_mon_mode((struct cdp_pdev *)pdev,
  436. DP_FULL_MON_ENABLE);
  437. dp_mon_filter_setup_mon_mode(pdev);
  438. status = dp_mon_filter_update(pdev);
  439. if (status != QDF_STATUS_SUCCESS) {
  440. dp_cdp_err("%pK: Failed to reset monitor filters", soc);
  441. dp_mon_filter_reset_mon_mode(pdev);
  442. mon_pdev->monitor_configured = false;
  443. mon_pdev->mvdev = NULL;
  444. }
  445. fail:
  446. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  447. return status;
  448. }
  449. #ifdef QCA_TX_CAPTURE_SUPPORT
  450. static QDF_STATUS
  451. dp_config_tx_capture_mode(struct dp_pdev *pdev)
  452. {
  453. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  454. mon_pdev->tx_sniffer_enable = 1;
  455. mon_pdev->monitor_configured = false;
  456. if (!mon_pdev->pktlog_ppdu_stats)
  457. dp_h2t_cfg_stats_msg_send(pdev,
  458. DP_PPDU_STATS_CFG_SNIFFER,
  459. pdev->pdev_id);
  460. return QDF_STATUS_SUCCESS;
  461. }
  462. #else
  463. #ifdef QCA_MCOPY_SUPPORT
  464. static QDF_STATUS
  465. dp_config_tx_capture_mode(struct dp_pdev *pdev)
  466. {
  467. return QDF_STATUS_E_INVAL;
  468. }
  469. #endif
  470. #endif
  471. #if defined(QCA_MCOPY_SUPPORT) || defined(QCA_TX_CAPTURE_SUPPORT)
  472. QDF_STATUS
  473. dp_config_debug_sniffer(struct dp_pdev *pdev, int val)
  474. {
  475. QDF_STATUS status = QDF_STATUS_SUCCESS;
  476. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  477. /*
  478. * Note: The mirror copy mode cannot co-exist with any other
  479. * monitor modes. Hence disabling the filter for this mode will
  480. * reset the monitor destination ring filters.
  481. */
  482. dp_reset_mcopy_mode(pdev);
  483. switch (val) {
  484. case 0:
  485. mon_pdev->tx_sniffer_enable = 0;
  486. mon_pdev->monitor_configured = false;
  487. /*
  488. * We don't need to reset the Rx monitor status ring or call
  489. * the API dp_ppdu_ring_reset() if all debug sniffer mode is
  490. * disabled. The Rx monitor status ring will be disabled when
  491. * the last mode using the monitor status ring get disabled.
  492. */
  493. if (!mon_pdev->pktlog_ppdu_stats &&
  494. !mon_pdev->enhanced_stats_en &&
  495. !mon_pdev->bpr_enable) {
  496. dp_h2t_cfg_stats_msg_send(pdev, 0, pdev->pdev_id);
  497. } else if (mon_pdev->enhanced_stats_en &&
  498. !mon_pdev->bpr_enable) {
  499. dp_h2t_cfg_stats_msg_send(pdev,
  500. DP_PPDU_STATS_CFG_ENH_STATS,
  501. pdev->pdev_id);
  502. } else if (!mon_pdev->enhanced_stats_en &&
  503. mon_pdev->bpr_enable) {
  504. dp_h2t_cfg_stats_msg_send(pdev,
  505. DP_PPDU_STATS_CFG_BPR_ENH,
  506. pdev->pdev_id);
  507. } else {
  508. dp_h2t_cfg_stats_msg_send(pdev,
  509. DP_PPDU_STATS_CFG_BPR,
  510. pdev->pdev_id);
  511. }
  512. break;
  513. case 1:
  514. status = dp_config_tx_capture_mode(pdev);
  515. break;
  516. case 2:
  517. case 4:
  518. status = dp_config_mcopy_mode(pdev, val);
  519. break;
  520. default:
  521. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  522. "Invalid value, mode not supported");
  523. status = QDF_STATUS_E_INVAL;
  524. break;
  525. }
  526. return status;
  527. }
  528. #endif
  529. #ifdef QCA_UNDECODED_METADATA_SUPPORT
  530. QDF_STATUS
  531. dp_mon_config_undecoded_metadata_capture(struct dp_pdev *pdev, int val)
  532. {
  533. QDF_STATUS status = QDF_STATUS_SUCCESS;
  534. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  535. if (!mon_pdev->mvdev && !mon_pdev->scan_spcl_vap_configured) {
  536. qdf_err("No monitor or Special vap, undecoded capture not supported");
  537. return QDF_STATUS_E_RESOURCES;
  538. }
  539. if (val)
  540. status = dp_enable_undecoded_metadata_capture(pdev, val);
  541. else
  542. status = dp_reset_undecoded_metadata_capture(pdev);
  543. return status;
  544. }
  545. #endif
  546. /**
  547. * dp_monitor_mode_ring_config() - Send the tlv config to fw for monitor buffer
  548. * ring based on target
  549. * @soc: soc handle
  550. * @mac_for_pdev: WIN- pdev_id, MCL- mac id
  551. * @pdev: physical device handle
  552. * @ring_num: mac id
  553. * @htt_tlv_filter: tlv filter
  554. *
  555. * Return: zero on success, non-zero on failure
  556. */
  557. static inline QDF_STATUS
  558. dp_monitor_mode_ring_config(struct dp_soc *soc, uint8_t mac_for_pdev,
  559. struct dp_pdev *pdev, uint8_t ring_num,
  560. struct htt_rx_ring_tlv_filter htt_tlv_filter)
  561. {
  562. QDF_STATUS status;
  563. if (soc->wlan_cfg_ctx->rxdma1_enable)
  564. status = htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  565. soc->rxdma_mon_buf_ring[ring_num]
  566. .hal_srng,
  567. RXDMA_MONITOR_BUF,
  568. RX_MONITOR_BUFFER_SIZE,
  569. &htt_tlv_filter);
  570. else
  571. status = htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  572. pdev->rx_mac_buf_ring[ring_num]
  573. .hal_srng,
  574. RXDMA_BUF, RX_DATA_BUFFER_SIZE,
  575. &htt_tlv_filter);
  576. return status;
  577. }
  578. /**
  579. * dp_get_mon_vdev_from_pdev_wifi3() - Get vdev id of monitor mode
  580. * @soc_hdl: datapath soc handle
  581. * @pdev_id: physical device instance id
  582. *
  583. * Return: virtual interface id
  584. */
  585. static uint8_t dp_get_mon_vdev_from_pdev_wifi3(struct cdp_soc_t *soc_hdl,
  586. uint8_t pdev_id)
  587. {
  588. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  589. struct dp_pdev *pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  590. if (qdf_unlikely(!pdev || !pdev->monitor_pdev ||
  591. !pdev->monitor_pdev->mvdev))
  592. return -EINVAL;
  593. return pdev->monitor_pdev->mvdev->vdev_id;
  594. }
  595. #if defined(QCA_TX_CAPTURE_SUPPORT) || defined(QCA_ENHANCED_STATS_SUPPORT)
  596. #ifndef WLAN_TX_PKT_CAPTURE_ENH
  597. void dp_deliver_mgmt_frm(struct dp_pdev *pdev, qdf_nbuf_t nbuf)
  598. {
  599. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  600. if (mon_pdev->tx_sniffer_enable || mon_pdev->mcopy_mode) {
  601. dp_wdi_event_handler(WDI_EVENT_TX_MGMT_CTRL, pdev->soc,
  602. nbuf, HTT_INVALID_PEER,
  603. WDI_NO_VAL, pdev->pdev_id);
  604. } else {
  605. if (!mon_pdev->bpr_enable)
  606. qdf_nbuf_free(nbuf);
  607. }
  608. }
  609. #endif
  610. #endif
  611. QDF_STATUS dp_htt_ppdu_stats_attach(struct dp_pdev *pdev)
  612. {
  613. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  614. mon_pdev->ppdu_tlv_buf = qdf_mem_malloc(HTT_T2H_MAX_MSG_SIZE);
  615. if (!mon_pdev->ppdu_tlv_buf) {
  616. QDF_TRACE_ERROR(QDF_MODULE_ID_DP, "ppdu_tlv_buf alloc fail");
  617. return QDF_STATUS_E_NOMEM;
  618. }
  619. return QDF_STATUS_SUCCESS;
  620. }
  621. void dp_htt_ppdu_stats_detach(struct dp_pdev *pdev)
  622. {
  623. struct ppdu_info *ppdu_info, *ppdu_info_next;
  624. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  625. TAILQ_FOREACH_SAFE(ppdu_info, &mon_pdev->ppdu_info_list,
  626. ppdu_info_list_elem, ppdu_info_next) {
  627. if (!ppdu_info)
  628. break;
  629. TAILQ_REMOVE(&mon_pdev->ppdu_info_list,
  630. ppdu_info, ppdu_info_list_elem);
  631. mon_pdev->list_depth--;
  632. qdf_assert_always(ppdu_info->nbuf);
  633. qdf_nbuf_free(ppdu_info->nbuf);
  634. qdf_mem_free(ppdu_info);
  635. }
  636. TAILQ_FOREACH_SAFE(ppdu_info, &mon_pdev->sched_comp_ppdu_list,
  637. ppdu_info_list_elem, ppdu_info_next) {
  638. if (!ppdu_info)
  639. break;
  640. TAILQ_REMOVE(&mon_pdev->sched_comp_ppdu_list,
  641. ppdu_info, ppdu_info_list_elem);
  642. mon_pdev->sched_comp_list_depth--;
  643. qdf_assert_always(ppdu_info->nbuf);
  644. qdf_nbuf_free(ppdu_info->nbuf);
  645. qdf_mem_free(ppdu_info);
  646. }
  647. if (mon_pdev->ppdu_tlv_buf)
  648. qdf_mem_free(mon_pdev->ppdu_tlv_buf);
  649. }
  650. QDF_STATUS dp_pdev_get_rx_mon_stats(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  651. struct cdp_pdev_mon_stats *stats)
  652. {
  653. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  654. struct dp_pdev *pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  655. struct dp_mon_pdev *mon_pdev;
  656. if (!pdev)
  657. return QDF_STATUS_E_FAILURE;
  658. mon_pdev = pdev->monitor_pdev;
  659. if (!mon_pdev)
  660. return QDF_STATUS_E_FAILURE;
  661. qdf_mem_copy(stats, &mon_pdev->rx_mon_stats,
  662. sizeof(struct cdp_pdev_mon_stats));
  663. return QDF_STATUS_SUCCESS;
  664. }
  665. #ifdef QCA_UNDECODED_METADATA_SUPPORT
  666. /**
  667. * dp_pdev_get_undecoded_capture_stats() - Get undecoded metadata captured
  668. * monitor pdev stats
  669. * @mon_pdev: Monitor PDEV handle
  670. * @rx_mon_stats: Monitor pdev status/destination ring stats
  671. *
  672. * Return: None
  673. */
  674. static inline void
  675. dp_pdev_get_undecoded_capture_stats(struct dp_mon_pdev *mon_pdev,
  676. struct cdp_pdev_mon_stats *rx_mon_stats)
  677. {
  678. char undecoded_error[DP_UNDECODED_ERR_LENGTH];
  679. uint8_t index = 0, i;
  680. DP_PRINT_STATS("Rx Undecoded Frame count:%d",
  681. rx_mon_stats->rx_undecoded_count);
  682. index = 0;
  683. for (i = 0; i < (CDP_PHYRX_ERR_MAX); i++) {
  684. index += qdf_snprint(&undecoded_error[index],
  685. DP_UNDECODED_ERR_LENGTH - index,
  686. " %d", rx_mon_stats->rx_undecoded_error[i]);
  687. }
  688. DP_PRINT_STATS("Undecoded Error (0-63):%s", undecoded_error);
  689. }
  690. #else
  691. static inline void
  692. dp_pdev_get_undecoded_capture_stats(struct dp_mon_pdev *mon_pdev,
  693. struct cdp_pdev_mon_stats *rx_mon_stats)
  694. {
  695. }
  696. #endif
  697. void
  698. dp_print_pdev_rx_mon_stats(struct dp_pdev *pdev)
  699. {
  700. struct cdp_pdev_mon_stats *rx_mon_stats;
  701. uint32_t *stat_ring_ppdu_ids;
  702. uint32_t *dest_ring_ppdu_ids;
  703. int i, idx;
  704. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  705. rx_mon_stats = &mon_pdev->rx_mon_stats;
  706. DP_PRINT_STATS("PDEV Rx Monitor Stats:\n");
  707. DP_PRINT_STATS("status_ppdu_compl_cnt = %d",
  708. rx_mon_stats->status_ppdu_compl);
  709. DP_PRINT_STATS("status_ppdu_start_cnt = %d",
  710. rx_mon_stats->status_ppdu_start);
  711. DP_PRINT_STATS("status_ppdu_end_cnt = %d",
  712. rx_mon_stats->status_ppdu_end);
  713. DP_PRINT_STATS("status_ppdu_start_mis_cnt = %d",
  714. rx_mon_stats->status_ppdu_start_mis);
  715. DP_PRINT_STATS("status_ppdu_end_mis_cnt = %d",
  716. rx_mon_stats->status_ppdu_end_mis);
  717. DP_PRINT_STATS("status_ppdu_done_cnt = %d",
  718. rx_mon_stats->status_ppdu_done);
  719. DP_PRINT_STATS("dest_ppdu_done_cnt = %d",
  720. rx_mon_stats->dest_ppdu_done);
  721. DP_PRINT_STATS("dest_mpdu_done_cnt = %d",
  722. rx_mon_stats->dest_mpdu_done);
  723. DP_PRINT_STATS("tlv_tag_status_err_cnt = %u",
  724. rx_mon_stats->tlv_tag_status_err);
  725. DP_PRINT_STATS("mon status DMA not done WAR count= %u",
  726. rx_mon_stats->status_buf_done_war);
  727. DP_PRINT_STATS("dest_mpdu_drop_cnt = %d",
  728. rx_mon_stats->dest_mpdu_drop);
  729. DP_PRINT_STATS("dup_mon_linkdesc_cnt = %d",
  730. rx_mon_stats->dup_mon_linkdesc_cnt);
  731. DP_PRINT_STATS("dup_mon_buf_cnt = %d",
  732. rx_mon_stats->dup_mon_buf_cnt);
  733. DP_PRINT_STATS("mon_rx_buf_reaped = %u",
  734. rx_mon_stats->mon_rx_bufs_reaped_dest);
  735. DP_PRINT_STATS("mon_rx_buf_replenished = %u",
  736. rx_mon_stats->mon_rx_bufs_replenished_dest);
  737. DP_PRINT_STATS("ppdu_id_mismatch = %u",
  738. rx_mon_stats->ppdu_id_mismatch);
  739. DP_PRINT_STATS("mpdu_ppdu_id_match_cnt = %d",
  740. rx_mon_stats->ppdu_id_match);
  741. DP_PRINT_STATS("ppdus dropped frm status ring = %d",
  742. rx_mon_stats->status_ppdu_drop);
  743. DP_PRINT_STATS("ppdus dropped frm dest ring = %d",
  744. rx_mon_stats->dest_ppdu_drop);
  745. stat_ring_ppdu_ids =
  746. (uint32_t *)qdf_mem_malloc(sizeof(uint32_t) * MAX_PPDU_ID_HIST);
  747. dest_ring_ppdu_ids =
  748. (uint32_t *)qdf_mem_malloc(sizeof(uint32_t) * MAX_PPDU_ID_HIST);
  749. if (!stat_ring_ppdu_ids || !dest_ring_ppdu_ids)
  750. DP_PRINT_STATS("Unable to allocate ppdu id hist mem\n");
  751. qdf_spin_lock_bh(&mon_pdev->mon_lock);
  752. idx = rx_mon_stats->ppdu_id_hist_idx;
  753. qdf_mem_copy(stat_ring_ppdu_ids,
  754. rx_mon_stats->stat_ring_ppdu_id_hist,
  755. sizeof(uint32_t) * MAX_PPDU_ID_HIST);
  756. qdf_mem_copy(dest_ring_ppdu_ids,
  757. rx_mon_stats->dest_ring_ppdu_id_hist,
  758. sizeof(uint32_t) * MAX_PPDU_ID_HIST);
  759. qdf_spin_unlock_bh(&mon_pdev->mon_lock);
  760. DP_PRINT_STATS("PPDU Id history:");
  761. DP_PRINT_STATS("stat_ring_ppdu_ids\t dest_ring_ppdu_ids");
  762. for (i = 0; i < MAX_PPDU_ID_HIST; i++) {
  763. idx = (idx + 1) & (MAX_PPDU_ID_HIST - 1);
  764. DP_PRINT_STATS("%*u\t%*u", 16,
  765. rx_mon_stats->stat_ring_ppdu_id_hist[idx], 16,
  766. rx_mon_stats->dest_ring_ppdu_id_hist[idx]);
  767. }
  768. qdf_mem_free(stat_ring_ppdu_ids);
  769. qdf_mem_free(dest_ring_ppdu_ids);
  770. DP_PRINT_STATS("mon_rx_dest_stuck = %d",
  771. rx_mon_stats->mon_rx_dest_stuck);
  772. dp_pdev_get_undecoded_capture_stats(mon_pdev, rx_mon_stats);
  773. }
  774. #ifdef QCA_SUPPORT_BPR
  775. QDF_STATUS
  776. dp_set_bpr_enable(struct dp_pdev *pdev, int val)
  777. {
  778. struct dp_mon_ops *mon_ops;
  779. mon_ops = dp_mon_ops_get(pdev->soc);
  780. if (mon_ops && mon_ops->mon_set_bpr_enable)
  781. return mon_ops->mon_set_bpr_enable(pdev, val);
  782. return QDF_STATUS_E_FAILURE;
  783. }
  784. #endif
  785. #ifdef WDI_EVENT_ENABLE
  786. #ifdef BE_PKTLOG_SUPPORT
  787. static bool
  788. dp_set_hybrid_pktlog_enable(struct dp_pdev *pdev,
  789. struct dp_mon_pdev *mon_pdev,
  790. struct dp_mon_soc *mon_soc)
  791. {
  792. if (mon_pdev->mvdev) {
  793. /* Nothing needs to be done if monitor mode is
  794. * enabled
  795. */
  796. mon_pdev->pktlog_hybrid_mode = true;
  797. return false;
  798. }
  799. if (!mon_pdev->pktlog_hybrid_mode) {
  800. mon_pdev->pktlog_hybrid_mode = true;
  801. dp_mon_filter_setup_pktlog_hybrid(pdev);
  802. if (dp_mon_filter_update(pdev) !=
  803. QDF_STATUS_SUCCESS) {
  804. dp_cdp_err("Set hybrid filters failed");
  805. dp_mon_filter_reset_pktlog_hybrid(pdev);
  806. mon_pdev->rx_pktlog_mode =
  807. DP_RX_PKTLOG_DISABLED;
  808. return false;
  809. }
  810. if (mon_soc->reap_timer_init &&
  811. !dp_mon_is_enable_reap_timer_non_pkt(pdev))
  812. qdf_timer_mod(&mon_soc->mon_reap_timer,
  813. DP_INTR_POLL_TIMER_MS);
  814. }
  815. return true;
  816. }
  817. static void
  818. dp_set_hybrid_pktlog_disable(struct dp_mon_pdev *mon_pdev)
  819. {
  820. mon_pdev->pktlog_hybrid_mode = false;
  821. }
  822. #else
  823. static void
  824. dp_set_hybrid_pktlog_disable(struct dp_mon_pdev *mon_pdev)
  825. {
  826. }
  827. static bool
  828. dp_set_hybrid_pktlog_enable(struct dp_pdev *pdev,
  829. struct dp_mon_pdev *mon_pdev,
  830. struct dp_mon_soc *mon_soc)
  831. {
  832. dp_cdp_err("Hybrid mode is supported only on beryllium");
  833. return true;
  834. }
  835. #endif
  836. int dp_set_pktlog_wifi3(struct dp_pdev *pdev, uint32_t event,
  837. bool enable)
  838. {
  839. struct dp_soc *soc = NULL;
  840. int max_mac_rings = wlan_cfg_get_num_mac_rings
  841. (pdev->wlan_cfg_ctx);
  842. uint8_t mac_id = 0;
  843. struct dp_mon_soc *mon_soc;
  844. struct dp_mon_ops *mon_ops;
  845. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  846. soc = pdev->soc;
  847. mon_soc = soc->monitor_soc;
  848. mon_ops = dp_mon_ops_get(soc);
  849. if (!mon_ops)
  850. return 0;
  851. dp_update_num_mac_rings_for_dbs(soc, &max_mac_rings);
  852. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  853. FL("Max_mac_rings %d "),
  854. max_mac_rings);
  855. if (enable) {
  856. switch (event) {
  857. case WDI_EVENT_RX_DESC:
  858. if (mon_pdev->mvdev) {
  859. /* Nothing needs to be done if monitor mode is
  860. * enabled
  861. */
  862. mon_pdev->rx_pktlog_mode = DP_RX_PKTLOG_FULL;
  863. return 0;
  864. }
  865. if (mon_pdev->rx_pktlog_mode != DP_RX_PKTLOG_FULL) {
  866. mon_pdev->rx_pktlog_mode = DP_RX_PKTLOG_FULL;
  867. dp_mon_filter_setup_rx_pkt_log_full(pdev);
  868. if (dp_mon_filter_update(pdev) !=
  869. QDF_STATUS_SUCCESS) {
  870. dp_cdp_err("%pK: Pktlog full filters set failed", soc);
  871. dp_mon_filter_reset_rx_pkt_log_full(pdev);
  872. mon_pdev->rx_pktlog_mode =
  873. DP_RX_PKTLOG_DISABLED;
  874. return 0;
  875. }
  876. if (mon_soc->reap_timer_init &&
  877. (!dp_mon_is_enable_reap_timer_non_pkt(pdev)))
  878. qdf_timer_mod(&mon_soc->mon_reap_timer,
  879. DP_INTR_POLL_TIMER_MS);
  880. }
  881. break;
  882. case WDI_EVENT_LITE_RX:
  883. if (mon_pdev->mvdev) {
  884. /* Nothing needs to be done if monitor mode is
  885. * enabled
  886. */
  887. mon_pdev->rx_pktlog_mode = DP_RX_PKTLOG_LITE;
  888. return 0;
  889. }
  890. if (mon_pdev->rx_pktlog_mode != DP_RX_PKTLOG_LITE) {
  891. mon_pdev->rx_pktlog_mode = DP_RX_PKTLOG_LITE;
  892. /*
  893. * Set the packet log lite mode filter.
  894. */
  895. dp_mon_filter_setup_rx_pkt_log_lite(pdev);
  896. if (dp_mon_filter_update(pdev) !=
  897. QDF_STATUS_SUCCESS) {
  898. dp_cdp_err("%pK: Pktlog lite filters set failed", soc);
  899. dp_mon_filter_reset_rx_pkt_log_lite(pdev);
  900. mon_pdev->rx_pktlog_mode =
  901. DP_RX_PKTLOG_DISABLED;
  902. return 0;
  903. }
  904. if (mon_soc->reap_timer_init &&
  905. (!dp_mon_is_enable_reap_timer_non_pkt(pdev)))
  906. qdf_timer_mod(&mon_soc->mon_reap_timer,
  907. DP_INTR_POLL_TIMER_MS);
  908. }
  909. break;
  910. case WDI_EVENT_LITE_T2H:
  911. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  912. int mac_for_pdev = dp_get_mac_id_for_pdev(
  913. mac_id, pdev->pdev_id);
  914. mon_pdev->pktlog_ppdu_stats = true;
  915. dp_h2t_cfg_stats_msg_send(pdev,
  916. DP_PPDU_TXLITE_STATS_BITMASK_CFG,
  917. mac_for_pdev);
  918. }
  919. break;
  920. case WDI_EVENT_RX_CBF:
  921. if (mon_pdev->mvdev) {
  922. /* Nothing needs to be done if monitor mode is
  923. * enabled
  924. */
  925. dp_mon_info("Mon mode, CBF setting filters");
  926. mon_pdev->rx_pktlog_cbf = true;
  927. return 0;
  928. }
  929. if (!mon_pdev->rx_pktlog_cbf) {
  930. mon_pdev->rx_pktlog_cbf = true;
  931. mon_pdev->monitor_configured = true;
  932. if (mon_ops->mon_vdev_set_monitor_mode_buf_rings)
  933. mon_ops->mon_vdev_set_monitor_mode_buf_rings(pdev);
  934. /*
  935. * Set the packet log lite mode filter.
  936. */
  937. qdf_info("Non mon mode: Enable destination ring");
  938. dp_mon_filter_setup_rx_pkt_log_cbf(pdev);
  939. if (dp_mon_filter_update(pdev) !=
  940. QDF_STATUS_SUCCESS) {
  941. dp_mon_err("Pktlog set CBF filters failed");
  942. dp_mon_filter_reset_rx_pktlog_cbf(pdev);
  943. mon_pdev->rx_pktlog_mode =
  944. DP_RX_PKTLOG_DISABLED;
  945. mon_pdev->monitor_configured = false;
  946. return 0;
  947. }
  948. if (mon_soc->reap_timer_init &&
  949. !dp_mon_is_enable_reap_timer_non_pkt(pdev))
  950. qdf_timer_mod(&mon_soc->mon_reap_timer,
  951. DP_INTR_POLL_TIMER_MS);
  952. }
  953. break;
  954. case WDI_EVENT_HYBRID_TX:
  955. if (!dp_set_hybrid_pktlog_enable(pdev,
  956. mon_pdev, mon_soc))
  957. return 0;
  958. break;
  959. default:
  960. /* Nothing needs to be done for other pktlog types */
  961. break;
  962. }
  963. } else {
  964. switch (event) {
  965. case WDI_EVENT_RX_DESC:
  966. case WDI_EVENT_LITE_RX:
  967. if (mon_pdev->mvdev) {
  968. /* Nothing needs to be done if monitor mode is
  969. * enabled
  970. */
  971. mon_pdev->rx_pktlog_mode =
  972. DP_RX_PKTLOG_DISABLED;
  973. return 0;
  974. }
  975. if (mon_pdev->rx_pktlog_mode != DP_RX_PKTLOG_DISABLED) {
  976. mon_pdev->rx_pktlog_mode =
  977. DP_RX_PKTLOG_DISABLED;
  978. dp_mon_filter_reset_rx_pkt_log_full(pdev);
  979. if (dp_mon_filter_update(pdev) !=
  980. QDF_STATUS_SUCCESS) {
  981. dp_cdp_err("%pK: Pktlog filters reset failed", soc);
  982. return 0;
  983. }
  984. dp_mon_filter_reset_rx_pkt_log_lite(pdev);
  985. if (dp_mon_filter_update(pdev) !=
  986. QDF_STATUS_SUCCESS) {
  987. dp_cdp_err("%pK: Pktlog filters reset failed", soc);
  988. return 0;
  989. }
  990. if (mon_soc->reap_timer_init &&
  991. (!dp_mon_is_enable_reap_timer_non_pkt(pdev)))
  992. qdf_timer_stop(&mon_soc->mon_reap_timer);
  993. }
  994. break;
  995. case WDI_EVENT_LITE_T2H:
  996. /*
  997. * To disable HTT_H2T_MSG_TYPE_PPDU_STATS_CFG in FW
  998. * passing value 0. Once these macros will define in htt
  999. * header file will use proper macros
  1000. */
  1001. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  1002. int mac_for_pdev =
  1003. dp_get_mac_id_for_pdev(mac_id,
  1004. pdev->pdev_id);
  1005. mon_pdev->pktlog_ppdu_stats = false;
  1006. if (!mon_pdev->enhanced_stats_en &&
  1007. !mon_pdev->tx_sniffer_enable &&
  1008. !mon_pdev->mcopy_mode) {
  1009. dp_h2t_cfg_stats_msg_send(pdev, 0,
  1010. mac_for_pdev);
  1011. } else if (mon_pdev->tx_sniffer_enable ||
  1012. mon_pdev->mcopy_mode) {
  1013. dp_h2t_cfg_stats_msg_send(pdev,
  1014. DP_PPDU_STATS_CFG_SNIFFER,
  1015. mac_for_pdev);
  1016. } else if (mon_pdev->enhanced_stats_en) {
  1017. dp_h2t_cfg_stats_msg_send(pdev,
  1018. DP_PPDU_STATS_CFG_ENH_STATS,
  1019. mac_for_pdev);
  1020. }
  1021. }
  1022. break;
  1023. case WDI_EVENT_RX_CBF:
  1024. mon_pdev->rx_pktlog_cbf = false;
  1025. break;
  1026. case WDI_EVENT_HYBRID_TX:
  1027. dp_set_hybrid_pktlog_disable(mon_pdev);
  1028. break;
  1029. default:
  1030. /* Nothing needs to be done for other pktlog types */
  1031. break;
  1032. }
  1033. }
  1034. return 0;
  1035. }
  1036. #endif
  1037. /* MCL specific functions */
  1038. #if defined(DP_CON_MON) && !defined(REMOVE_PKT_LOG)
  1039. void dp_pktlogmod_exit(struct dp_pdev *pdev)
  1040. {
  1041. struct dp_soc *soc = pdev->soc;
  1042. struct hif_opaque_softc *scn = soc->hif_handle;
  1043. struct dp_mon_soc *mon_soc = soc->monitor_soc;
  1044. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  1045. if (!scn) {
  1046. dp_mon_err("Invalid hif(scn) handle");
  1047. return;
  1048. }
  1049. /* stop mon_reap_timer if it has been started */
  1050. if (mon_pdev->rx_pktlog_mode != DP_RX_PKTLOG_DISABLED &&
  1051. mon_soc->reap_timer_init &&
  1052. (!dp_mon_is_enable_reap_timer_non_pkt(pdev)))
  1053. qdf_timer_sync_cancel(&mon_soc->mon_reap_timer);
  1054. pktlogmod_exit(scn);
  1055. mon_pdev->pkt_log_init = false;
  1056. }
  1057. #endif /*DP_CON_MON*/
  1058. #if defined(WDI_EVENT_ENABLE) && defined(QCA_ENHANCED_STATS_SUPPORT)
  1059. QDF_STATUS dp_peer_stats_notify(struct dp_pdev *dp_pdev, struct dp_peer *peer)
  1060. {
  1061. struct cdp_interface_peer_stats peer_stats_intf;
  1062. struct dp_mon_peer_stats *mon_peer_stats = NULL;
  1063. struct dp_peer *tgt_peer = NULL;
  1064. struct dp_txrx_peer *txrx_peer = NULL;
  1065. if (!peer || !peer->vdev || !peer->monitor_peer)
  1066. return QDF_STATUS_E_FAULT;
  1067. tgt_peer = dp_get_tgt_peer_from_peer(peer);
  1068. if (!tgt_peer)
  1069. return QDF_STATUS_E_FAULT;
  1070. txrx_peer = tgt_peer->txrx_peer;
  1071. if (!txrx_peer)
  1072. return QDF_STATUS_E_FAULT;
  1073. mon_peer_stats = &peer->monitor_peer->stats;
  1074. qdf_mem_zero(&peer_stats_intf, sizeof(peer_stats_intf));
  1075. if (mon_peer_stats->rx.last_snr != mon_peer_stats->rx.snr)
  1076. peer_stats_intf.rssi_changed = true;
  1077. if ((mon_peer_stats->rx.snr && peer_stats_intf.rssi_changed) ||
  1078. (mon_peer_stats->tx.tx_rate &&
  1079. mon_peer_stats->tx.tx_rate != mon_peer_stats->tx.last_tx_rate)) {
  1080. qdf_mem_copy(peer_stats_intf.peer_mac, peer->mac_addr.raw,
  1081. QDF_MAC_ADDR_SIZE);
  1082. peer_stats_intf.vdev_id = peer->vdev->vdev_id;
  1083. peer_stats_intf.last_peer_tx_rate =
  1084. mon_peer_stats->tx.last_tx_rate;
  1085. peer_stats_intf.peer_tx_rate = mon_peer_stats->tx.tx_rate;
  1086. peer_stats_intf.peer_rssi = mon_peer_stats->rx.snr;
  1087. peer_stats_intf.ack_rssi = mon_peer_stats->tx.last_ack_rssi;
  1088. peer_stats_intf.rx_packet_count = txrx_peer->to_stack.num;
  1089. peer_stats_intf.rx_byte_count = txrx_peer->to_stack.bytes;
  1090. peer_stats_intf.tx_packet_count =
  1091. txrx_peer->stats.per_pkt_stats.tx.ucast.num;
  1092. peer_stats_intf.tx_byte_count =
  1093. txrx_peer->stats.per_pkt_stats.tx.tx_success.bytes;
  1094. peer_stats_intf.per = tgt_peer->stats.tx.last_per;
  1095. peer_stats_intf.free_buff = INVALID_FREE_BUFF;
  1096. dp_wdi_event_handler(WDI_EVENT_PEER_STATS, dp_pdev->soc,
  1097. (void *)&peer_stats_intf, 0,
  1098. WDI_NO_VAL, dp_pdev->pdev_id);
  1099. }
  1100. return QDF_STATUS_SUCCESS;
  1101. }
  1102. #endif
  1103. #ifdef FEATURE_NAC_RSSI
  1104. /**
  1105. * dp_rx_nac_filter(): Function to perform filtering of non-associated
  1106. * clients
  1107. * @pdev: DP pdev handle
  1108. * @rx_pkt_hdr: Rx packet Header
  1109. *
  1110. * return: dp_vdev*
  1111. */
  1112. static
  1113. struct dp_vdev *dp_rx_nac_filter(struct dp_pdev *pdev,
  1114. uint8_t *rx_pkt_hdr)
  1115. {
  1116. struct ieee80211_frame *wh;
  1117. struct dp_neighbour_peer *peer = NULL;
  1118. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  1119. wh = (struct ieee80211_frame *)rx_pkt_hdr;
  1120. if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) != IEEE80211_FC1_DIR_TODS)
  1121. return NULL;
  1122. qdf_spin_lock_bh(&mon_pdev->neighbour_peer_mutex);
  1123. TAILQ_FOREACH(peer, &mon_pdev->neighbour_peers_list,
  1124. neighbour_peer_list_elem) {
  1125. if (qdf_mem_cmp(&peer->neighbour_peers_macaddr.raw[0],
  1126. wh->i_addr2, QDF_MAC_ADDR_SIZE) == 0) {
  1127. dp_rx_debug("%pK: NAC configuration matched for mac-%2x:%2x:%2x:%2x:%2x:%2x",
  1128. pdev->soc,
  1129. peer->neighbour_peers_macaddr.raw[0],
  1130. peer->neighbour_peers_macaddr.raw[1],
  1131. peer->neighbour_peers_macaddr.raw[2],
  1132. peer->neighbour_peers_macaddr.raw[3],
  1133. peer->neighbour_peers_macaddr.raw[4],
  1134. peer->neighbour_peers_macaddr.raw[5]);
  1135. qdf_spin_unlock_bh(&mon_pdev->neighbour_peer_mutex);
  1136. return mon_pdev->mvdev;
  1137. }
  1138. }
  1139. qdf_spin_unlock_bh(&mon_pdev->neighbour_peer_mutex);
  1140. return NULL;
  1141. }
  1142. QDF_STATUS dp_filter_neighbour_peer(struct dp_pdev *pdev,
  1143. uint8_t *rx_pkt_hdr)
  1144. {
  1145. struct dp_vdev *vdev = NULL;
  1146. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  1147. if (mon_pdev->filter_neighbour_peers) {
  1148. /* Next Hop scenario not yet handle */
  1149. vdev = dp_rx_nac_filter(pdev, rx_pkt_hdr);
  1150. if (vdev) {
  1151. dp_rx_mon_deliver(pdev->soc, pdev->pdev_id,
  1152. pdev->invalid_peer_head_msdu,
  1153. pdev->invalid_peer_tail_msdu);
  1154. pdev->invalid_peer_head_msdu = NULL;
  1155. pdev->invalid_peer_tail_msdu = NULL;
  1156. return QDF_STATUS_SUCCESS;
  1157. }
  1158. }
  1159. return QDF_STATUS_E_FAILURE;
  1160. }
  1161. #endif
  1162. #if defined(ATH_SUPPORT_NAC_RSSI) || defined(ATH_SUPPORT_NAC)
  1163. /*
  1164. * dp_update_filter_neighbour_peers() - set neighbour peers(nac clients)
  1165. * address for smart mesh filtering
  1166. * @txrx_soc: cdp soc handle
  1167. * @vdev_id: id of virtual device object
  1168. * @cmd: Add/Del command
  1169. * @macaddr: nac client mac address
  1170. *
  1171. * Return: success/failure
  1172. */
  1173. static int dp_update_filter_neighbour_peers(struct cdp_soc_t *soc_hdl,
  1174. uint8_t vdev_id,
  1175. uint32_t cmd, uint8_t *macaddr)
  1176. {
  1177. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  1178. struct dp_pdev *pdev;
  1179. struct dp_neighbour_peer *peer = NULL;
  1180. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  1181. DP_MOD_ID_CDP);
  1182. struct dp_mon_pdev *mon_pdev;
  1183. if (!vdev || !macaddr)
  1184. goto fail0;
  1185. pdev = vdev->pdev;
  1186. if (!pdev)
  1187. goto fail0;
  1188. mon_pdev = pdev->monitor_pdev;
  1189. /* Store address of NAC (neighbour peer) which will be checked
  1190. * against TA of received packets.
  1191. */
  1192. if (cmd == DP_NAC_PARAM_ADD) {
  1193. peer = (struct dp_neighbour_peer *)qdf_mem_malloc(
  1194. sizeof(*peer));
  1195. if (!peer) {
  1196. dp_cdp_err("%pK: DP neighbour peer node memory allocation failed"
  1197. , soc);
  1198. goto fail0;
  1199. }
  1200. qdf_mem_copy(&peer->neighbour_peers_macaddr.raw[0],
  1201. macaddr, QDF_MAC_ADDR_SIZE);
  1202. peer->vdev = vdev;
  1203. qdf_spin_lock_bh(&mon_pdev->neighbour_peer_mutex);
  1204. /* add this neighbour peer into the list */
  1205. TAILQ_INSERT_TAIL(&mon_pdev->neighbour_peers_list, peer,
  1206. neighbour_peer_list_elem);
  1207. qdf_spin_unlock_bh(&mon_pdev->neighbour_peer_mutex);
  1208. /* first neighbour */
  1209. if (!mon_pdev->neighbour_peers_added) {
  1210. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1211. mon_pdev->neighbour_peers_added = true;
  1212. dp_mon_filter_setup_smart_monitor(pdev);
  1213. status = dp_mon_filter_update(pdev);
  1214. if (status != QDF_STATUS_SUCCESS) {
  1215. dp_cdp_err("%pK: smart mon filter setup failed",
  1216. soc);
  1217. dp_mon_filter_reset_smart_monitor(pdev);
  1218. mon_pdev->neighbour_peers_added = false;
  1219. }
  1220. }
  1221. } else if (cmd == DP_NAC_PARAM_DEL) {
  1222. qdf_spin_lock_bh(&mon_pdev->neighbour_peer_mutex);
  1223. TAILQ_FOREACH(peer, &mon_pdev->neighbour_peers_list,
  1224. neighbour_peer_list_elem) {
  1225. if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr.raw[0],
  1226. macaddr, QDF_MAC_ADDR_SIZE)) {
  1227. /* delete this peer from the list */
  1228. TAILQ_REMOVE(&mon_pdev->neighbour_peers_list,
  1229. peer, neighbour_peer_list_elem);
  1230. qdf_mem_free(peer);
  1231. break;
  1232. }
  1233. }
  1234. /* last neighbour deleted */
  1235. if (TAILQ_EMPTY(&mon_pdev->neighbour_peers_list)) {
  1236. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1237. dp_mon_filter_reset_smart_monitor(pdev);
  1238. status = dp_mon_filter_update(pdev);
  1239. if (status != QDF_STATUS_SUCCESS) {
  1240. dp_cdp_err("%pK: smart mon filter clear failed",
  1241. soc);
  1242. }
  1243. mon_pdev->neighbour_peers_added = false;
  1244. }
  1245. qdf_spin_unlock_bh(&mon_pdev->neighbour_peer_mutex);
  1246. }
  1247. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  1248. return 1;
  1249. fail0:
  1250. if (vdev)
  1251. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  1252. return 0;
  1253. }
  1254. #endif /* ATH_SUPPORT_NAC_RSSI || ATH_SUPPORT_NAC */
  1255. #ifdef ATH_SUPPORT_NAC_RSSI
  1256. /**
  1257. * dp_vdev_get_neighbour_rssi(): Store RSSI for configured NAC
  1258. * @soc_hdl: DP soc handle
  1259. * @vdev_id: id of DP vdev handle
  1260. * @mac_addr: neighbour mac
  1261. * @rssi: rssi value
  1262. *
  1263. * Return: 0 for success. nonzero for failure.
  1264. */
  1265. static QDF_STATUS dp_vdev_get_neighbour_rssi(struct cdp_soc_t *soc_hdl,
  1266. uint8_t vdev_id,
  1267. char *mac_addr,
  1268. uint8_t *rssi)
  1269. {
  1270. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  1271. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  1272. DP_MOD_ID_CDP);
  1273. struct dp_pdev *pdev;
  1274. struct dp_neighbour_peer *peer = NULL;
  1275. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  1276. struct dp_mon_pdev *mon_pdev;
  1277. if (!vdev)
  1278. return status;
  1279. pdev = vdev->pdev;
  1280. mon_pdev = pdev->monitor_pdev;
  1281. *rssi = 0;
  1282. qdf_spin_lock_bh(&mon_pdev->neighbour_peer_mutex);
  1283. TAILQ_FOREACH(peer, &mon_pdev->neighbour_peers_list,
  1284. neighbour_peer_list_elem) {
  1285. if (qdf_mem_cmp(&peer->neighbour_peers_macaddr.raw[0],
  1286. mac_addr, QDF_MAC_ADDR_SIZE) == 0) {
  1287. *rssi = peer->rssi;
  1288. status = QDF_STATUS_SUCCESS;
  1289. break;
  1290. }
  1291. }
  1292. qdf_spin_unlock_bh(&mon_pdev->neighbour_peer_mutex);
  1293. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  1294. return status;
  1295. }
  1296. static QDF_STATUS
  1297. dp_config_for_nac_rssi(struct cdp_soc_t *cdp_soc,
  1298. uint8_t vdev_id,
  1299. enum cdp_nac_param_cmd cmd, char *bssid,
  1300. char *client_macaddr,
  1301. uint8_t chan_num)
  1302. {
  1303. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  1304. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  1305. DP_MOD_ID_CDP);
  1306. struct dp_pdev *pdev;
  1307. struct dp_mon_pdev *mon_pdev;
  1308. if (!vdev)
  1309. return QDF_STATUS_E_FAILURE;
  1310. pdev = (struct dp_pdev *)vdev->pdev;
  1311. mon_pdev = pdev->monitor_pdev;
  1312. mon_pdev->nac_rssi_filtering = 1;
  1313. /* Store address of NAC (neighbour peer) which will be checked
  1314. * against TA of received packets.
  1315. */
  1316. if (cmd == CDP_NAC_PARAM_ADD) {
  1317. dp_update_filter_neighbour_peers(cdp_soc, vdev->vdev_id,
  1318. DP_NAC_PARAM_ADD,
  1319. (uint8_t *)client_macaddr);
  1320. } else if (cmd == CDP_NAC_PARAM_DEL) {
  1321. dp_update_filter_neighbour_peers(cdp_soc, vdev->vdev_id,
  1322. DP_NAC_PARAM_DEL,
  1323. (uint8_t *)client_macaddr);
  1324. }
  1325. if (soc->cdp_soc.ol_ops->config_bssid_in_fw_for_nac_rssi)
  1326. soc->cdp_soc.ol_ops->config_bssid_in_fw_for_nac_rssi
  1327. (soc->ctrl_psoc, pdev->pdev_id,
  1328. vdev->vdev_id, cmd, bssid, client_macaddr);
  1329. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  1330. return QDF_STATUS_SUCCESS;
  1331. }
  1332. #endif
  1333. #if defined(WLAN_CFR_ENABLE) && defined(WLAN_ENH_CFR_ENABLE)
  1334. /*
  1335. * dp_cfr_filter() - Configure HOST RX monitor status ring for CFR
  1336. * @soc_hdl: Datapath soc handle
  1337. * @pdev_id: id of data path pdev handle
  1338. * @enable: Enable/Disable CFR
  1339. * @filter_val: Flag to select Filter for monitor mode
  1340. */
  1341. static void dp_cfr_filter(struct cdp_soc_t *soc_hdl,
  1342. uint8_t pdev_id,
  1343. bool enable,
  1344. struct cdp_monitor_filter *filter_val)
  1345. {
  1346. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  1347. struct dp_pdev *pdev = NULL;
  1348. struct htt_rx_ring_tlv_filter htt_tlv_filter = {0};
  1349. int max_mac_rings;
  1350. uint8_t mac_id = 0;
  1351. struct dp_mon_pdev *mon_pdev;
  1352. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  1353. if (!pdev) {
  1354. dp_mon_err("pdev is NULL");
  1355. return;
  1356. }
  1357. mon_pdev = pdev->monitor_pdev;
  1358. if (mon_pdev->mvdev) {
  1359. dp_mon_info("No action is needed since mon mode is enabled\n");
  1360. return;
  1361. }
  1362. soc = pdev->soc;
  1363. pdev->cfr_rcc_mode = false;
  1364. max_mac_rings = wlan_cfg_get_num_mac_rings(pdev->wlan_cfg_ctx);
  1365. dp_update_num_mac_rings_for_dbs(soc, &max_mac_rings);
  1366. dp_mon_debug("Max_mac_rings %d", max_mac_rings);
  1367. dp_mon_info("enable : %d, mode: 0x%x", enable, filter_val->mode);
  1368. if (enable) {
  1369. pdev->cfr_rcc_mode = true;
  1370. htt_tlv_filter.ppdu_start = 1;
  1371. htt_tlv_filter.ppdu_end = 1;
  1372. htt_tlv_filter.ppdu_end_user_stats = 1;
  1373. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  1374. htt_tlv_filter.ppdu_end_status_done = 1;
  1375. htt_tlv_filter.mpdu_start = 1;
  1376. htt_tlv_filter.offset_valid = false;
  1377. htt_tlv_filter.enable_fp =
  1378. (filter_val->mode & MON_FILTER_PASS) ? 1 : 0;
  1379. htt_tlv_filter.enable_md = 0;
  1380. htt_tlv_filter.enable_mo =
  1381. (filter_val->mode & MON_FILTER_OTHER) ? 1 : 0;
  1382. htt_tlv_filter.fp_mgmt_filter = filter_val->fp_mgmt;
  1383. htt_tlv_filter.fp_ctrl_filter = filter_val->fp_ctrl;
  1384. htt_tlv_filter.fp_data_filter = filter_val->fp_data;
  1385. htt_tlv_filter.mo_mgmt_filter = filter_val->mo_mgmt;
  1386. htt_tlv_filter.mo_ctrl_filter = filter_val->mo_ctrl;
  1387. htt_tlv_filter.mo_data_filter = filter_val->mo_data;
  1388. }
  1389. for (mac_id = 0;
  1390. mac_id < soc->wlan_cfg_ctx->num_rxdma_status_rings_per_pdev;
  1391. mac_id++) {
  1392. int mac_for_pdev =
  1393. dp_get_mac_id_for_pdev(mac_id,
  1394. pdev->pdev_id);
  1395. htt_h2t_rx_ring_cfg(soc->htt_handle,
  1396. mac_for_pdev,
  1397. soc->rxdma_mon_status_ring[mac_id]
  1398. .hal_srng,
  1399. RXDMA_MONITOR_STATUS,
  1400. RX_MON_STATUS_BUF_SIZE,
  1401. &htt_tlv_filter);
  1402. }
  1403. }
  1404. /*
  1405. * dp_enable_mon_reap_timer() - enable/disable reap timer
  1406. * @soc_hdl: Datapath soc handle
  1407. * @pdev_id: id of objmgr pdev
  1408. * @enable: Enable/Disable reap timer of monitor status ring
  1409. *
  1410. * Return: none
  1411. */
  1412. static void
  1413. dp_enable_mon_reap_timer(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  1414. bool enable)
  1415. {
  1416. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  1417. struct dp_pdev *pdev = NULL;
  1418. struct dp_mon_soc *mon_soc = soc->monitor_soc;
  1419. struct dp_mon_pdev *mon_pdev;
  1420. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  1421. if (!pdev) {
  1422. dp_mon_err("pdev is NULL");
  1423. return;
  1424. }
  1425. mon_pdev = pdev->monitor_pdev;
  1426. mon_pdev->enable_reap_timer_non_pkt = enable;
  1427. if (mon_pdev->rx_pktlog_mode != DP_RX_PKTLOG_DISABLED) {
  1428. dp_mon_debug("pktlog enabled %d", mon_pdev->rx_pktlog_mode);
  1429. return;
  1430. }
  1431. if (!mon_soc->reap_timer_init) {
  1432. dp_mon_err("reap timer not init");
  1433. return;
  1434. }
  1435. if (enable)
  1436. qdf_timer_mod(&mon_soc->mon_reap_timer,
  1437. DP_INTR_POLL_TIMER_MS);
  1438. else
  1439. qdf_timer_sync_cancel(&mon_soc->mon_reap_timer);
  1440. }
  1441. #endif
  1442. #if defined(DP_CON_MON)
  1443. #ifndef REMOVE_PKT_LOG
  1444. /**
  1445. * dp_pkt_log_init() - API to initialize packet log
  1446. * @soc_hdl: Datapath soc handle
  1447. * @pdev_id: id of data path pdev handle
  1448. * @scn: HIF context
  1449. *
  1450. * Return: none
  1451. */
  1452. void dp_pkt_log_init(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, void *scn)
  1453. {
  1454. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  1455. struct dp_pdev *handle =
  1456. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  1457. struct dp_mon_pdev *mon_pdev;
  1458. if (!handle) {
  1459. dp_mon_err("pdev handle is NULL");
  1460. return;
  1461. }
  1462. mon_pdev = handle->monitor_pdev;
  1463. if (mon_pdev->pkt_log_init) {
  1464. dp_mon_err("%pK: Packet log not initialized", soc);
  1465. return;
  1466. }
  1467. pktlog_sethandle(&mon_pdev->pl_dev, scn);
  1468. pktlog_set_pdev_id(mon_pdev->pl_dev, pdev_id);
  1469. pktlog_set_callback_regtype(PKTLOG_DEFAULT_CALLBACK_REGISTRATION);
  1470. if (pktlogmod_init(scn)) {
  1471. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1472. "%s: pktlogmod_init failed", __func__);
  1473. mon_pdev->pkt_log_init = false;
  1474. } else {
  1475. mon_pdev->pkt_log_init = true;
  1476. }
  1477. }
  1478. /**
  1479. * dp_pkt_log_con_service() - connect packet log service
  1480. * @soc_hdl: Datapath soc handle
  1481. * @pdev_id: id of data path pdev handle
  1482. * @scn: device context
  1483. *
  1484. * Return: none
  1485. */
  1486. static void dp_pkt_log_con_service(struct cdp_soc_t *soc_hdl,
  1487. uint8_t pdev_id, void *scn)
  1488. {
  1489. dp_pkt_log_init(soc_hdl, pdev_id, scn);
  1490. pktlog_htc_attach();
  1491. }
  1492. /**
  1493. * dp_pkt_log_exit() - Wrapper API to cleanup pktlog info
  1494. * @soc_hdl: Datapath soc handle
  1495. * @pdev_id: id of data path pdev handle
  1496. *
  1497. * Return: none
  1498. */
  1499. static void dp_pkt_log_exit(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  1500. {
  1501. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  1502. struct dp_pdev *pdev =
  1503. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  1504. if (!pdev) {
  1505. dp_err("pdev handle is NULL");
  1506. return;
  1507. }
  1508. dp_pktlogmod_exit(pdev);
  1509. }
  1510. #else
  1511. static void dp_pkt_log_con_service(struct cdp_soc_t *soc_hdl,
  1512. uint8_t pdev_id, void *scn)
  1513. {
  1514. }
  1515. static void dp_pkt_log_exit(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  1516. {
  1517. }
  1518. #endif
  1519. #endif
  1520. void dp_neighbour_peers_detach(struct dp_pdev *pdev)
  1521. {
  1522. struct dp_neighbour_peer *peer = NULL;
  1523. struct dp_neighbour_peer *temp_peer = NULL;
  1524. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  1525. TAILQ_FOREACH_SAFE(peer, &mon_pdev->neighbour_peers_list,
  1526. neighbour_peer_list_elem, temp_peer) {
  1527. /* delete this peer from the list */
  1528. TAILQ_REMOVE(&mon_pdev->neighbour_peers_list,
  1529. peer, neighbour_peer_list_elem);
  1530. qdf_mem_free(peer);
  1531. }
  1532. qdf_spinlock_destroy(&mon_pdev->neighbour_peer_mutex);
  1533. }
  1534. #ifdef QCA_ENHANCED_STATS_SUPPORT
  1535. /*
  1536. * dp_mon_tx_enable_enhanced_stats() - Enable enhanced Tx stats
  1537. * @pdev: Datapath pdev handle
  1538. *
  1539. * Return: void
  1540. */
  1541. static void dp_mon_tx_enable_enhanced_stats(struct dp_pdev *pdev)
  1542. {
  1543. struct dp_soc *soc = pdev->soc;
  1544. struct dp_mon_ops *mon_ops = NULL;
  1545. mon_ops = dp_mon_ops_get(soc);
  1546. if (mon_ops && mon_ops->mon_tx_enable_enhanced_stats)
  1547. mon_ops->mon_tx_enable_enhanced_stats(pdev);
  1548. }
  1549. /*
  1550. * dp_enable_enhanced_stats()- API to enable enhanced statistcs
  1551. * @soc_handle: DP_SOC handle
  1552. * @pdev_id: id of DP_PDEV handle
  1553. *
  1554. * Return: QDF_STATUS
  1555. */
  1556. static QDF_STATUS
  1557. dp_enable_enhanced_stats(struct cdp_soc_t *soc, uint8_t pdev_id)
  1558. {
  1559. struct dp_pdev *pdev = NULL;
  1560. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1561. struct dp_mon_pdev *mon_pdev;
  1562. pdev = dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  1563. pdev_id);
  1564. if (!pdev)
  1565. return QDF_STATUS_E_FAILURE;
  1566. mon_pdev = pdev->monitor_pdev;
  1567. if (!mon_pdev)
  1568. return QDF_STATUS_E_FAILURE;
  1569. if (mon_pdev->enhanced_stats_en == 0)
  1570. dp_cal_client_timer_start(mon_pdev->cal_client_ctx);
  1571. mon_pdev->enhanced_stats_en = 1;
  1572. pdev->enhanced_stats_en = true;
  1573. dp_mon_filter_setup_enhanced_stats(pdev);
  1574. status = dp_mon_filter_update(pdev);
  1575. if (status != QDF_STATUS_SUCCESS) {
  1576. dp_cdp_err("%pK: Failed to set enhanced mode filters", soc);
  1577. dp_mon_filter_reset_enhanced_stats(pdev);
  1578. dp_cal_client_timer_stop(mon_pdev->cal_client_ctx);
  1579. mon_pdev->enhanced_stats_en = 0;
  1580. pdev->enhanced_stats_en = false;
  1581. return QDF_STATUS_E_FAILURE;
  1582. }
  1583. dp_mon_tx_enable_enhanced_stats(pdev);
  1584. return QDF_STATUS_SUCCESS;
  1585. }
  1586. /*
  1587. * dp_mon_tx_disable_enhanced_stats() - Disable enhanced Tx stats
  1588. * @pdev: Datapath pdev handle
  1589. *
  1590. * Return: void
  1591. */
  1592. static void dp_mon_tx_disable_enhanced_stats(struct dp_pdev *pdev)
  1593. {
  1594. struct dp_soc *soc = pdev->soc;
  1595. struct dp_mon_ops *mon_ops = NULL;
  1596. mon_ops = dp_mon_ops_get(soc);
  1597. if (mon_ops && mon_ops->mon_tx_disable_enhanced_stats)
  1598. mon_ops->mon_tx_disable_enhanced_stats(pdev);
  1599. }
  1600. /*
  1601. * dp_disable_enhanced_stats()- API to disable enhanced statistcs
  1602. *
  1603. * @param soc - the soc handle
  1604. * @param pdev_id - pdev_id of pdev
  1605. * @return - QDF_STATUS
  1606. */
  1607. static QDF_STATUS
  1608. dp_disable_enhanced_stats(struct cdp_soc_t *soc, uint8_t pdev_id)
  1609. {
  1610. struct dp_pdev *pdev =
  1611. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  1612. pdev_id);
  1613. struct dp_mon_pdev *mon_pdev;
  1614. if (!pdev || !pdev->monitor_pdev)
  1615. return QDF_STATUS_E_FAILURE;
  1616. mon_pdev = pdev->monitor_pdev;
  1617. if (mon_pdev->enhanced_stats_en == 1)
  1618. dp_cal_client_timer_stop(mon_pdev->cal_client_ctx);
  1619. mon_pdev->enhanced_stats_en = 0;
  1620. pdev->enhanced_stats_en = false;
  1621. dp_mon_tx_disable_enhanced_stats(pdev);
  1622. dp_mon_filter_reset_enhanced_stats(pdev);
  1623. if (dp_mon_filter_update(pdev) != QDF_STATUS_SUCCESS) {
  1624. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1625. FL("Failed to reset enhanced mode filters"));
  1626. }
  1627. return QDF_STATUS_SUCCESS;
  1628. }
  1629. #ifdef WDI_EVENT_ENABLE
  1630. QDF_STATUS dp_peer_qos_stats_notify(struct dp_pdev *dp_pdev,
  1631. struct cdp_rx_stats_ppdu_user *ppdu_user)
  1632. {
  1633. struct cdp_interface_peer_qos_stats qos_stats_intf;
  1634. if (ppdu_user->peer_id == HTT_INVALID_PEER) {
  1635. dp_mon_warn("Invalid peer id");
  1636. return QDF_STATUS_E_FAILURE;
  1637. }
  1638. qdf_mem_zero(&qos_stats_intf, sizeof(qos_stats_intf));
  1639. qdf_mem_copy(qos_stats_intf.peer_mac, ppdu_user->mac_addr,
  1640. QDF_MAC_ADDR_SIZE);
  1641. qos_stats_intf.frame_control = ppdu_user->frame_control;
  1642. qos_stats_intf.frame_control_info_valid =
  1643. ppdu_user->frame_control_info_valid;
  1644. qos_stats_intf.qos_control = ppdu_user->qos_control;
  1645. qos_stats_intf.qos_control_info_valid =
  1646. ppdu_user->qos_control_info_valid;
  1647. qos_stats_intf.vdev_id = ppdu_user->vdev_id;
  1648. dp_wdi_event_handler(WDI_EVENT_PEER_QOS_STATS, dp_pdev->soc,
  1649. (void *)&qos_stats_intf, 0,
  1650. WDI_NO_VAL, dp_pdev->pdev_id);
  1651. return QDF_STATUS_SUCCESS;
  1652. }
  1653. #else
  1654. static inline QDF_STATUS
  1655. dp_peer_qos_stats_notify(struct dp_pdev *dp_pdev,
  1656. struct cdp_rx_stats_ppdu_user *ppdu_user)
  1657. {
  1658. return QDF_STATUS_SUCCESS;
  1659. }
  1660. #endif
  1661. #endif /* QCA_ENHANCED_STATS_SUPPORT */
  1662. /**
  1663. * dp_enable_peer_based_pktlog() - Set Flag for peer based filtering
  1664. * for pktlog
  1665. * @soc: cdp_soc handle
  1666. * @pdev_id: id of dp pdev handle
  1667. * @mac_addr: Peer mac address
  1668. * @enb_dsb: Enable or disable peer based filtering
  1669. *
  1670. * Return: QDF_STATUS
  1671. */
  1672. static int
  1673. dp_enable_peer_based_pktlog(struct cdp_soc_t *soc, uint8_t pdev_id,
  1674. uint8_t *mac_addr, uint8_t enb_dsb)
  1675. {
  1676. struct dp_peer *peer;
  1677. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  1678. struct dp_pdev *pdev =
  1679. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  1680. pdev_id);
  1681. struct dp_mon_pdev *mon_pdev;
  1682. if (!pdev)
  1683. return QDF_STATUS_E_FAILURE;
  1684. mon_pdev = pdev->monitor_pdev;
  1685. peer = dp_peer_find_hash_find((struct dp_soc *)soc, mac_addr,
  1686. 0, DP_VDEV_ALL, DP_MOD_ID_CDP);
  1687. if (!peer) {
  1688. dp_mon_err("Invalid Peer");
  1689. return QDF_STATUS_E_FAILURE;
  1690. }
  1691. if (!IS_MLO_DP_MLD_PEER(peer) && peer->monitor_peer) {
  1692. peer->monitor_peer->peer_based_pktlog_filter = enb_dsb;
  1693. mon_pdev->dp_peer_based_pktlog = enb_dsb;
  1694. status = QDF_STATUS_SUCCESS;
  1695. }
  1696. dp_peer_unref_delete(peer, DP_MOD_ID_CDP);
  1697. return status;
  1698. }
  1699. /**
  1700. * dp_peer_update_pkt_capture_params: Set Rx & Tx Capture flags for a peer
  1701. * @soc: DP_SOC handle
  1702. * @pdev_id: id of DP_PDEV handle
  1703. * @is_rx_pkt_cap_enable: enable/disable Rx packet capture in monitor mode
  1704. * @is_tx_pkt_cap_enable: enable/disable/delete/print
  1705. * Tx packet capture in monitor mode
  1706. * @peer_mac: MAC address for which the above need to be enabled/disabled
  1707. *
  1708. * Return: Success if Rx & Tx capture is enabled for peer, false otherwise
  1709. */
  1710. #if defined(WLAN_TX_PKT_CAPTURE_ENH) || defined(WLAN_RX_PKT_CAPTURE_ENH)
  1711. static QDF_STATUS
  1712. dp_peer_update_pkt_capture_params(ol_txrx_soc_handle soc,
  1713. uint8_t pdev_id,
  1714. bool is_rx_pkt_cap_enable,
  1715. uint8_t is_tx_pkt_cap_enable,
  1716. uint8_t *peer_mac)
  1717. {
  1718. struct dp_peer *peer;
  1719. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  1720. struct dp_pdev *pdev =
  1721. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  1722. pdev_id);
  1723. if (!pdev)
  1724. return QDF_STATUS_E_FAILURE;
  1725. peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  1726. peer_mac, 0, DP_VDEV_ALL,
  1727. DP_MOD_ID_CDP);
  1728. if (!peer)
  1729. return QDF_STATUS_E_FAILURE;
  1730. /* we need to set tx pkt capture for non associated peer */
  1731. if (!IS_MLO_DP_MLD_PEER(peer)) {
  1732. status = dp_monitor_tx_peer_filter(pdev, peer,
  1733. is_tx_pkt_cap_enable,
  1734. peer_mac);
  1735. status = dp_peer_set_rx_capture_enabled(pdev, peer,
  1736. is_rx_pkt_cap_enable,
  1737. peer_mac);
  1738. }
  1739. dp_peer_unref_delete(peer, DP_MOD_ID_CDP);
  1740. return status;
  1741. }
  1742. #endif
  1743. #ifdef QCA_MCOPY_SUPPORT
  1744. QDF_STATUS dp_mcopy_check_deliver(struct dp_pdev *pdev,
  1745. uint16_t peer_id,
  1746. uint32_t ppdu_id,
  1747. uint8_t first_msdu)
  1748. {
  1749. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  1750. if (mon_pdev->mcopy_mode) {
  1751. if (mon_pdev->mcopy_mode == M_COPY) {
  1752. if ((mon_pdev->m_copy_id.tx_ppdu_id == ppdu_id) &&
  1753. (mon_pdev->m_copy_id.tx_peer_id == peer_id)) {
  1754. return QDF_STATUS_E_INVAL;
  1755. }
  1756. }
  1757. if (!first_msdu)
  1758. return QDF_STATUS_E_INVAL;
  1759. mon_pdev->m_copy_id.tx_ppdu_id = ppdu_id;
  1760. mon_pdev->m_copy_id.tx_peer_id = peer_id;
  1761. }
  1762. return QDF_STATUS_SUCCESS;
  1763. }
  1764. #endif
  1765. #ifdef WDI_EVENT_ENABLE
  1766. #ifndef REMOVE_PKT_LOG
  1767. static void *dp_get_pldev(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  1768. {
  1769. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  1770. struct dp_pdev *pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  1771. if (!pdev || !pdev->monitor_pdev)
  1772. return NULL;
  1773. return pdev->monitor_pdev->pl_dev;
  1774. }
  1775. #else
  1776. static void *dp_get_pldev(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  1777. {
  1778. return NULL;
  1779. }
  1780. #endif
  1781. #endif
  1782. QDF_STATUS dp_rx_populate_cbf_hdr(struct dp_soc *soc,
  1783. uint32_t mac_id,
  1784. uint32_t event,
  1785. qdf_nbuf_t mpdu,
  1786. uint32_t msdu_timestamp)
  1787. {
  1788. uint32_t data_size, hdr_size, ppdu_id, align4byte;
  1789. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1790. uint32_t *msg_word;
  1791. if (!pdev)
  1792. return QDF_STATUS_E_INVAL;
  1793. ppdu_id = pdev->monitor_pdev->ppdu_info.com_info.ppdu_id;
  1794. hdr_size = HTT_T2H_PPDU_STATS_IND_HDR_SIZE
  1795. + qdf_offsetof(htt_ppdu_stats_rx_mgmtctrl_payload_tlv, payload);
  1796. data_size = qdf_nbuf_len(mpdu);
  1797. qdf_nbuf_push_head(mpdu, hdr_size);
  1798. msg_word = (uint32_t *)qdf_nbuf_data(mpdu);
  1799. /*
  1800. * Populate the PPDU Stats Indication header
  1801. */
  1802. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_T2H_MSG_TYPE_PPDU_STATS_IND);
  1803. HTT_T2H_PPDU_STATS_MAC_ID_SET(*msg_word, mac_id);
  1804. HTT_T2H_PPDU_STATS_PDEV_ID_SET(*msg_word, pdev->pdev_id);
  1805. align4byte = ((data_size +
  1806. qdf_offsetof(htt_ppdu_stats_rx_mgmtctrl_payload_tlv, payload)
  1807. + 3) >> 2) << 2;
  1808. HTT_T2H_PPDU_STATS_PAYLOAD_SIZE_SET(*msg_word, align4byte);
  1809. msg_word++;
  1810. HTT_T2H_PPDU_STATS_PPDU_ID_SET(*msg_word, ppdu_id);
  1811. msg_word++;
  1812. *msg_word = msdu_timestamp;
  1813. msg_word++;
  1814. /* Skip reserved field */
  1815. msg_word++;
  1816. /*
  1817. * Populate MGMT_CTRL Payload TLV first
  1818. */
  1819. HTT_STATS_TLV_TAG_SET(*msg_word,
  1820. HTT_PPDU_STATS_RX_MGMTCTRL_PAYLOAD_TLV);
  1821. align4byte = ((data_size - sizeof(htt_tlv_hdr_t) +
  1822. qdf_offsetof(htt_ppdu_stats_rx_mgmtctrl_payload_tlv, payload)
  1823. + 3) >> 2) << 2;
  1824. HTT_STATS_TLV_LENGTH_SET(*msg_word, align4byte);
  1825. msg_word++;
  1826. HTT_PPDU_STATS_RX_MGMTCTRL_TLV_FRAME_LENGTH_SET(
  1827. *msg_word, data_size);
  1828. msg_word++;
  1829. dp_wdi_event_handler(event, soc, (void *)mpdu,
  1830. HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
  1831. qdf_nbuf_pull_head(mpdu, hdr_size);
  1832. return QDF_STATUS_SUCCESS;
  1833. }
  1834. #ifdef ATH_SUPPORT_EXT_STAT
  1835. /*dp_peer_cal_clients_stats_update - update peer stats on cal client timer
  1836. * @soc : Datapath SOC
  1837. * @peer : Datapath peer
  1838. * @arg : argument to iter function
  1839. */
  1840. static void
  1841. dp_peer_cal_clients_stats_update(struct dp_soc *soc,
  1842. struct dp_peer *peer,
  1843. void *arg)
  1844. {
  1845. struct cdp_calibr_stats_intf peer_stats_intf = {0};
  1846. struct dp_peer *tgt_peer = NULL;
  1847. struct dp_txrx_peer *txrx_peer = NULL;
  1848. if (!dp_peer_is_primary_link_peer(peer))
  1849. return;
  1850. tgt_peer = dp_get_tgt_peer_from_peer(peer);
  1851. if (!tgt_peer || !(tgt_peer->txrx_peer))
  1852. return;
  1853. txrx_peer = tgt_peer->txrx_peer;
  1854. peer_stats_intf.to_stack = txrx_peer->to_stack;
  1855. peer_stats_intf.tx_success =
  1856. txrx_peer->stats.per_pkt_stats.tx.tx_success;
  1857. peer_stats_intf.tx_ucast =
  1858. txrx_peer->stats.per_pkt_stats.tx.ucast;
  1859. dp_cal_client_update_peer_stats_wifi3(&peer_stats_intf,
  1860. &tgt_peer->stats);
  1861. }
  1862. /*dp_iterate_update_peer_list - update peer stats on cal client timer
  1863. * @pdev_hdl: pdev handle
  1864. */
  1865. static void dp_iterate_update_peer_list(struct cdp_pdev *pdev_hdl)
  1866. {
  1867. struct dp_pdev *pdev = (struct dp_pdev *)pdev_hdl;
  1868. dp_pdev_iterate_peer(pdev, dp_peer_cal_clients_stats_update, NULL,
  1869. DP_MOD_ID_CDP);
  1870. }
  1871. #else
  1872. static void dp_iterate_update_peer_list(struct cdp_pdev *pdev_hdl)
  1873. {
  1874. }
  1875. #endif
  1876. #ifdef ATH_SUPPORT_NAC
  1877. int dp_set_filter_neigh_peers(struct dp_pdev *pdev,
  1878. bool val)
  1879. {
  1880. /* Enable/Disable smart mesh filtering. This flag will be checked
  1881. * during rx processing to check if packets are from NAC clients.
  1882. */
  1883. pdev->monitor_pdev->filter_neighbour_peers = val;
  1884. return 0;
  1885. }
  1886. #endif /* ATH_SUPPORT_NAC */
  1887. #ifdef WLAN_ATF_ENABLE
  1888. void dp_set_atf_stats_enable(struct dp_pdev *pdev, bool value)
  1889. {
  1890. if (!pdev) {
  1891. dp_cdp_err("Invalid pdev");
  1892. return;
  1893. }
  1894. pdev->monitor_pdev->dp_atf_stats_enable = value;
  1895. }
  1896. #endif
  1897. #ifdef QCA_ENHANCED_STATS_SUPPORT
  1898. /*
  1899. * dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv: Process
  1900. * htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  1901. * @pdev: DP PDEV handle
  1902. * @tag_buf: buffer containing the htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  1903. * @length: tlv_length
  1904. *
  1905. * return:QDF_STATUS_SUCCESS if nbuf has to be freed in caller
  1906. */
  1907. QDF_STATUS
  1908. dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv(struct dp_pdev *pdev,
  1909. qdf_nbuf_t tag_buf,
  1910. uint32_t ppdu_id)
  1911. {
  1912. uint32_t *nbuf_ptr;
  1913. uint8_t trim_size;
  1914. size_t head_size;
  1915. struct cdp_tx_mgmt_comp_info *ptr_mgmt_comp_info;
  1916. uint32_t *msg_word;
  1917. uint32_t tsf_hdr;
  1918. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  1919. if ((!mon_pdev->tx_sniffer_enable) && (!mon_pdev->mcopy_mode) &&
  1920. (!mon_pdev->bpr_enable) && (!mon_pdev->tx_capture_enabled))
  1921. return QDF_STATUS_SUCCESS;
  1922. /*
  1923. * get timestamp from htt_t2h_ppdu_stats_ind_hdr_t
  1924. */
  1925. msg_word = (uint32_t *)qdf_nbuf_data(tag_buf);
  1926. msg_word = msg_word + 2;
  1927. tsf_hdr = *msg_word;
  1928. trim_size = ((mon_pdev->mgmtctrl_frm_info.mgmt_buf +
  1929. HTT_MGMT_CTRL_TLV_HDR_RESERVERD_LEN) -
  1930. qdf_nbuf_data(tag_buf));
  1931. if (!qdf_nbuf_pull_head(tag_buf, trim_size))
  1932. return QDF_STATUS_SUCCESS;
  1933. qdf_nbuf_trim_tail(tag_buf, qdf_nbuf_len(tag_buf) -
  1934. mon_pdev->mgmtctrl_frm_info.mgmt_buf_len);
  1935. if (mon_pdev->tx_capture_enabled) {
  1936. head_size = sizeof(struct cdp_tx_mgmt_comp_info);
  1937. if (qdf_unlikely(qdf_nbuf_headroom(tag_buf) < head_size)) {
  1938. qdf_err("Fail to get headroom h_sz %zu h_avail %d\n",
  1939. head_size, qdf_nbuf_headroom(tag_buf));
  1940. qdf_assert_always(0);
  1941. return QDF_STATUS_E_NOMEM;
  1942. }
  1943. ptr_mgmt_comp_info = (struct cdp_tx_mgmt_comp_info *)
  1944. qdf_nbuf_push_head(tag_buf, head_size);
  1945. qdf_assert_always(ptr_mgmt_comp_info);
  1946. ptr_mgmt_comp_info->ppdu_id = ppdu_id;
  1947. ptr_mgmt_comp_info->is_sgen_pkt = true;
  1948. ptr_mgmt_comp_info->tx_tsf = tsf_hdr;
  1949. } else {
  1950. head_size = sizeof(ppdu_id);
  1951. nbuf_ptr = (uint32_t *)qdf_nbuf_push_head(tag_buf, head_size);
  1952. *nbuf_ptr = ppdu_id;
  1953. }
  1954. if (mon_pdev->bpr_enable) {
  1955. dp_wdi_event_handler(WDI_EVENT_TX_BEACON, pdev->soc,
  1956. tag_buf, HTT_INVALID_PEER,
  1957. WDI_NO_VAL, pdev->pdev_id);
  1958. }
  1959. dp_deliver_mgmt_frm(pdev, tag_buf);
  1960. return QDF_STATUS_E_ALREADY;
  1961. }
  1962. /*
  1963. * dp_htt_get_ppdu_sniffer_ampdu_tlv_bitmap() - Get ppdu stats tlv
  1964. * bitmap for sniffer mode
  1965. * @bitmap: received bitmap
  1966. *
  1967. * Return: expected bitmap value, returns zero if doesn't match with
  1968. * either 64-bit Tx window or 256-bit window tlv bitmap
  1969. */
  1970. int
  1971. dp_htt_get_ppdu_sniffer_ampdu_tlv_bitmap(uint32_t bitmap)
  1972. {
  1973. if (bitmap == (HTT_PPDU_SNIFFER_AMPDU_TLV_BITMAP_64))
  1974. return HTT_PPDU_SNIFFER_AMPDU_TLV_BITMAP_64;
  1975. else if (bitmap == (HTT_PPDU_SNIFFER_AMPDU_TLV_BITMAP_256))
  1976. return HTT_PPDU_SNIFFER_AMPDU_TLV_BITMAP_256;
  1977. return 0;
  1978. }
  1979. /*
  1980. * dp_peer_copy_delay_stats() - copy ppdu stats to peer delayed stats.
  1981. * @peer: Datapath peer handle
  1982. * @ppdu: User PPDU Descriptor
  1983. * @cur_ppdu_id: PPDU_ID
  1984. *
  1985. * Return: None
  1986. *
  1987. * on Tx data frame, we may get delayed ba set
  1988. * in htt_ppdu_stats_user_common_tlv. which mean we get Block Ack(BA) after we
  1989. * request Block Ack Request(BAR). Successful msdu is received only after Block
  1990. * Ack. To populate peer stats we need successful msdu(data frame).
  1991. * So we hold the Tx data stats on delayed_ba for stats update.
  1992. */
  1993. static void
  1994. dp_peer_copy_delay_stats(struct dp_peer *peer,
  1995. struct cdp_tx_completion_ppdu_user *ppdu,
  1996. uint32_t cur_ppdu_id)
  1997. {
  1998. struct dp_pdev *pdev;
  1999. struct dp_vdev *vdev;
  2000. struct dp_mon_peer *mon_peer = peer->monitor_peer;
  2001. if (mon_peer->last_delayed_ba) {
  2002. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  2003. "BA not yet recv for prev delayed ppdu[%d] - cur ppdu[%d]",
  2004. mon_peer->last_delayed_ba_ppduid, cur_ppdu_id);
  2005. vdev = peer->vdev;
  2006. if (vdev) {
  2007. pdev = vdev->pdev;
  2008. pdev->stats.cdp_delayed_ba_not_recev++;
  2009. }
  2010. }
  2011. mon_peer->delayed_ba_ppdu_stats.ltf_size = ppdu->ltf_size;
  2012. mon_peer->delayed_ba_ppdu_stats.stbc = ppdu->stbc;
  2013. mon_peer->delayed_ba_ppdu_stats.he_re = ppdu->he_re;
  2014. mon_peer->delayed_ba_ppdu_stats.txbf = ppdu->txbf;
  2015. mon_peer->delayed_ba_ppdu_stats.bw = ppdu->bw;
  2016. mon_peer->delayed_ba_ppdu_stats.nss = ppdu->nss;
  2017. mon_peer->delayed_ba_ppdu_stats.gi = ppdu->gi;
  2018. mon_peer->delayed_ba_ppdu_stats.dcm = ppdu->dcm;
  2019. mon_peer->delayed_ba_ppdu_stats.ldpc = ppdu->ldpc;
  2020. mon_peer->delayed_ba_ppdu_stats.dcm = ppdu->dcm;
  2021. mon_peer->delayed_ba_ppdu_stats.mpdu_tried_ucast =
  2022. ppdu->mpdu_tried_ucast;
  2023. mon_peer->delayed_ba_ppdu_stats.mpdu_tried_mcast =
  2024. ppdu->mpdu_tried_mcast;
  2025. mon_peer->delayed_ba_ppdu_stats.frame_ctrl = ppdu->frame_ctrl;
  2026. mon_peer->delayed_ba_ppdu_stats.qos_ctrl = ppdu->qos_ctrl;
  2027. mon_peer->delayed_ba_ppdu_stats.dcm = ppdu->dcm;
  2028. mon_peer->delayed_ba_ppdu_stats.ru_start = ppdu->ru_start;
  2029. mon_peer->delayed_ba_ppdu_stats.ru_tones = ppdu->ru_tones;
  2030. mon_peer->delayed_ba_ppdu_stats.is_mcast = ppdu->is_mcast;
  2031. mon_peer->delayed_ba_ppdu_stats.user_pos = ppdu->user_pos;
  2032. mon_peer->delayed_ba_ppdu_stats.mu_group_id = ppdu->mu_group_id;
  2033. mon_peer->last_delayed_ba = true;
  2034. ppdu->debug_copied = true;
  2035. }
  2036. /*
  2037. * dp_peer_copy_stats_to_bar() - copy delayed stats to ppdu stats.
  2038. * @peer: Datapath peer handle
  2039. * @ppdu: PPDU Descriptor
  2040. *
  2041. * Return: None
  2042. *
  2043. * For Tx BAR, PPDU stats TLV include Block Ack info. PPDU info
  2044. * from Tx BAR frame not required to populate peer stats.
  2045. * But we need successful MPDU and MSDU to update previous
  2046. * transmitted Tx data frame. Overwrite ppdu stats with the previous
  2047. * stored ppdu stats.
  2048. */
  2049. static void
  2050. dp_peer_copy_stats_to_bar(struct dp_peer *peer,
  2051. struct cdp_tx_completion_ppdu_user *ppdu)
  2052. {
  2053. struct dp_mon_peer *mon_peer = peer->monitor_peer;
  2054. ppdu->ltf_size = mon_peer->delayed_ba_ppdu_stats.ltf_size;
  2055. ppdu->stbc = mon_peer->delayed_ba_ppdu_stats.stbc;
  2056. ppdu->he_re = mon_peer->delayed_ba_ppdu_stats.he_re;
  2057. ppdu->txbf = mon_peer->delayed_ba_ppdu_stats.txbf;
  2058. ppdu->bw = mon_peer->delayed_ba_ppdu_stats.bw;
  2059. ppdu->nss = mon_peer->delayed_ba_ppdu_stats.nss;
  2060. ppdu->gi = mon_peer->delayed_ba_ppdu_stats.gi;
  2061. ppdu->dcm = mon_peer->delayed_ba_ppdu_stats.dcm;
  2062. ppdu->ldpc = mon_peer->delayed_ba_ppdu_stats.ldpc;
  2063. ppdu->dcm = mon_peer->delayed_ba_ppdu_stats.dcm;
  2064. ppdu->mpdu_tried_ucast =
  2065. mon_peer->delayed_ba_ppdu_stats.mpdu_tried_ucast;
  2066. ppdu->mpdu_tried_mcast =
  2067. mon_peer->delayed_ba_ppdu_stats.mpdu_tried_mcast;
  2068. ppdu->frame_ctrl = mon_peer->delayed_ba_ppdu_stats.frame_ctrl;
  2069. ppdu->qos_ctrl = mon_peer->delayed_ba_ppdu_stats.qos_ctrl;
  2070. ppdu->dcm = mon_peer->delayed_ba_ppdu_stats.dcm;
  2071. ppdu->ru_start = mon_peer->delayed_ba_ppdu_stats.ru_start;
  2072. ppdu->ru_tones = mon_peer->delayed_ba_ppdu_stats.ru_tones;
  2073. ppdu->is_mcast = mon_peer->delayed_ba_ppdu_stats.is_mcast;
  2074. ppdu->user_pos = mon_peer->delayed_ba_ppdu_stats.user_pos;
  2075. ppdu->mu_group_id = mon_peer->delayed_ba_ppdu_stats.mu_group_id;
  2076. mon_peer->last_delayed_ba = false;
  2077. ppdu->debug_copied = true;
  2078. }
  2079. /*
  2080. * dp_tx_rate_stats_update() - Update rate per-peer statistics
  2081. * @peer: Datapath peer handle
  2082. * @ppdu: PPDU Descriptor
  2083. *
  2084. * Return: None
  2085. */
  2086. static void
  2087. dp_tx_rate_stats_update(struct dp_peer *peer,
  2088. struct cdp_tx_completion_ppdu_user *ppdu)
  2089. {
  2090. uint32_t ratekbps = 0;
  2091. uint64_t ppdu_tx_rate = 0;
  2092. uint32_t rix;
  2093. uint16_t ratecode = 0;
  2094. enum PUNCTURED_MODES punc_mode = NO_PUNCTURE;
  2095. struct dp_mon_peer *mon_peer = NULL;
  2096. if (!peer || !ppdu)
  2097. return;
  2098. if (ppdu->completion_status != HTT_PPDU_STATS_USER_STATUS_OK)
  2099. return;
  2100. mon_peer = peer->monitor_peer;
  2101. if (!mon_peer)
  2102. return;
  2103. ratekbps = dp_getrateindex(ppdu->gi,
  2104. ppdu->mcs,
  2105. ppdu->nss,
  2106. ppdu->preamble,
  2107. ppdu->bw,
  2108. punc_mode,
  2109. &rix,
  2110. &ratecode);
  2111. DP_STATS_UPD(mon_peer, tx.last_tx_rate, ratekbps);
  2112. if (!ratekbps)
  2113. return;
  2114. /* Calculate goodput in non-training period
  2115. * In training period, don't do anything as
  2116. * pending pkt is send as goodput.
  2117. */
  2118. if ((!peer->bss_peer) && (!ppdu->sa_is_training)) {
  2119. ppdu->sa_goodput = ((ratekbps / CDP_NUM_KB_IN_MB) *
  2120. (CDP_PERCENT_MACRO - ppdu->current_rate_per));
  2121. }
  2122. ppdu->rix = rix;
  2123. ppdu->tx_ratekbps = ratekbps;
  2124. ppdu->tx_ratecode = ratecode;
  2125. mon_peer->stats.tx.avg_tx_rate =
  2126. dp_ath_rate_lpf(mon_peer->stats.tx.avg_tx_rate, ratekbps);
  2127. ppdu_tx_rate = dp_ath_rate_out(mon_peer->stats.tx.avg_tx_rate);
  2128. DP_STATS_UPD(mon_peer, tx.rnd_avg_tx_rate, ppdu_tx_rate);
  2129. mon_peer->stats.tx.bw_info = ppdu->bw;
  2130. mon_peer->stats.tx.gi_info = ppdu->gi;
  2131. mon_peer->stats.tx.nss_info = ppdu->nss;
  2132. mon_peer->stats.tx.mcs_info = ppdu->mcs;
  2133. mon_peer->stats.tx.preamble_info = ppdu->preamble;
  2134. if (peer->vdev) {
  2135. /*
  2136. * In STA mode:
  2137. * We get ucast stats as BSS peer stats.
  2138. *
  2139. * In AP mode:
  2140. * We get mcast stats as BSS peer stats.
  2141. * We get ucast stats as assoc peer stats.
  2142. */
  2143. if (peer->vdev->opmode == wlan_op_mode_ap && peer->bss_peer) {
  2144. peer->vdev->stats.tx.mcast_last_tx_rate = ratekbps;
  2145. peer->vdev->stats.tx.mcast_last_tx_rate_mcs = ppdu->mcs;
  2146. } else {
  2147. peer->vdev->stats.tx.last_tx_rate = ratekbps;
  2148. peer->vdev->stats.tx.last_tx_rate_mcs = ppdu->mcs;
  2149. }
  2150. }
  2151. }
  2152. #if defined(FEATURE_PERPKT_INFO) && defined(WDI_EVENT_ENABLE)
  2153. void dp_send_stats_event(struct dp_pdev *pdev, struct dp_peer *peer,
  2154. uint16_t peer_id)
  2155. {
  2156. struct cdp_interface_peer_stats peer_stats_intf;
  2157. struct dp_mon_peer *mon_peer = peer->monitor_peer;
  2158. struct dp_txrx_peer *txrx_peer = NULL;
  2159. if (!mon_peer)
  2160. return;
  2161. qdf_mem_zero(&peer_stats_intf,
  2162. sizeof(struct cdp_interface_peer_stats));
  2163. mon_peer->stats.rx.rx_snr_measured_time = qdf_system_ticks();
  2164. peer_stats_intf.rx_avg_snr = mon_peer->stats.rx.avg_snr;
  2165. txrx_peer = dp_get_txrx_peer(peer);
  2166. if (txrx_peer) {
  2167. peer_stats_intf.rx_byte_count = txrx_peer->to_stack.bytes;
  2168. peer_stats_intf.tx_byte_count =
  2169. txrx_peer->stats.per_pkt_stats.tx.tx_success.bytes;
  2170. }
  2171. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
  2172. &peer_stats_intf, peer_id,
  2173. UPDATE_PEER_STATS, pdev->pdev_id);
  2174. }
  2175. #endif
  2176. /*
  2177. * dp_get_ru_index_frm_ru_tones() - get ru index
  2178. * @ru_tones: ru tones
  2179. *
  2180. * Return: ru index
  2181. */
  2182. #ifdef WLAN_FEATURE_11BE
  2183. static inline enum cdp_ru_index dp_get_ru_index_frm_ru_tones(uint16_t ru_tones)
  2184. {
  2185. enum cdp_ru_index ru_index;
  2186. switch (ru_tones) {
  2187. case RU_26:
  2188. ru_index = RU_26_INDEX;
  2189. break;
  2190. case RU_52:
  2191. ru_index = RU_52_INDEX;
  2192. break;
  2193. case RU_52_26:
  2194. ru_index = RU_52_26_INDEX;
  2195. break;
  2196. case RU_106:
  2197. ru_index = RU_106_INDEX;
  2198. break;
  2199. case RU_106_26:
  2200. ru_index = RU_106_26_INDEX;
  2201. break;
  2202. case RU_242:
  2203. ru_index = RU_242_INDEX;
  2204. break;
  2205. case RU_484:
  2206. ru_index = RU_484_INDEX;
  2207. break;
  2208. case RU_484_242:
  2209. ru_index = RU_484_242_INDEX;
  2210. break;
  2211. case RU_996:
  2212. ru_index = RU_996_INDEX;
  2213. break;
  2214. case RU_996_484:
  2215. ru_index = RU_996_484_INDEX;
  2216. break;
  2217. case RU_996_484_242:
  2218. ru_index = RU_996_484_242_INDEX;
  2219. break;
  2220. case RU_2X996:
  2221. ru_index = RU_2X996_INDEX;
  2222. break;
  2223. case RU_2X996_484:
  2224. ru_index = RU_2X996_484_INDEX;
  2225. break;
  2226. case RU_3X996:
  2227. ru_index = RU_3X996_INDEX;
  2228. break;
  2229. case RU_3X996_484:
  2230. ru_index = RU_2X996_484_INDEX;
  2231. break;
  2232. case RU_4X996:
  2233. ru_index = RU_4X996_INDEX;
  2234. break;
  2235. default:
  2236. ru_index = RU_INDEX_MAX;
  2237. break;
  2238. }
  2239. return ru_index;
  2240. }
  2241. #else
  2242. static inline enum cdp_ru_index dp_get_ru_index_frm_ru_tones(uint16_t ru_tones)
  2243. {
  2244. enum cdp_ru_index ru_index;
  2245. switch (ru_tones) {
  2246. case RU_26:
  2247. ru_index = RU_26_INDEX;
  2248. break;
  2249. case RU_52:
  2250. ru_index = RU_52_INDEX;
  2251. break;
  2252. case RU_106:
  2253. ru_index = RU_106_INDEX;
  2254. break;
  2255. case RU_242:
  2256. ru_index = RU_242_INDEX;
  2257. break;
  2258. case RU_484:
  2259. ru_index = RU_484_INDEX;
  2260. break;
  2261. case RU_996:
  2262. ru_index = RU_996_INDEX;
  2263. break;
  2264. default:
  2265. ru_index = RU_INDEX_MAX;
  2266. break;
  2267. }
  2268. return ru_index;
  2269. }
  2270. #endif
  2271. /*
  2272. * dp_tx_stats_update() - Update per-peer statistics
  2273. * @pdev: Datapath pdev handle
  2274. * @peer: Datapath peer handle
  2275. * @ppdu: PPDU Descriptor
  2276. * @ack_rssi: RSSI of last ack received
  2277. *
  2278. * Return: None
  2279. */
  2280. static void
  2281. dp_tx_stats_update(struct dp_pdev *pdev, struct dp_peer *peer,
  2282. struct cdp_tx_completion_ppdu_user *ppdu,
  2283. uint32_t ack_rssi)
  2284. {
  2285. uint8_t preamble, mcs;
  2286. uint16_t num_msdu;
  2287. uint16_t num_mpdu;
  2288. uint16_t mpdu_tried;
  2289. uint16_t mpdu_failed;
  2290. struct dp_mon_ops *mon_ops;
  2291. enum cdp_ru_index ru_index;
  2292. struct dp_mon_peer *mon_peer = NULL;
  2293. preamble = ppdu->preamble;
  2294. mcs = ppdu->mcs;
  2295. num_msdu = ppdu->num_msdu;
  2296. num_mpdu = ppdu->mpdu_success;
  2297. mpdu_tried = ppdu->mpdu_tried_ucast + ppdu->mpdu_tried_mcast;
  2298. mpdu_failed = mpdu_tried - num_mpdu;
  2299. /* If the peer statistics are already processed as part of
  2300. * per-MSDU completion handler, do not process these again in per-PPDU
  2301. * indications
  2302. */
  2303. if (pdev->soc->process_tx_status)
  2304. return;
  2305. mon_peer = peer->monitor_peer;
  2306. if (!mon_peer)
  2307. return;
  2308. if (ppdu->completion_status != HTT_PPDU_STATS_USER_STATUS_OK) {
  2309. /*
  2310. * All failed mpdu will be retried, so incrementing
  2311. * retries mpdu based on mpdu failed. Even for
  2312. * ack failure i.e for long retries we get
  2313. * mpdu failed equal mpdu tried.
  2314. */
  2315. DP_STATS_INC(mon_peer, tx.retries, mpdu_failed);
  2316. return;
  2317. }
  2318. if (ppdu->is_ppdu_cookie_valid)
  2319. DP_STATS_INC(mon_peer, tx.num_ppdu_cookie_valid, 1);
  2320. if (ppdu->mu_group_id <= MAX_MU_GROUP_ID &&
  2321. ppdu->ppdu_type != HTT_PPDU_STATS_PPDU_TYPE_SU) {
  2322. if (unlikely(!(ppdu->mu_group_id & (MAX_MU_GROUP_ID - 1))))
  2323. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  2324. "mu_group_id out of bound!!\n");
  2325. else
  2326. DP_STATS_UPD(mon_peer, tx.mu_group_id[ppdu->mu_group_id],
  2327. (ppdu->user_pos + 1));
  2328. }
  2329. if (ppdu->ppdu_type == HTT_PPDU_STATS_PPDU_TYPE_MU_OFDMA ||
  2330. ppdu->ppdu_type == HTT_PPDU_STATS_PPDU_TYPE_MU_MIMO_OFDMA) {
  2331. DP_STATS_UPD(mon_peer, tx.ru_tones, ppdu->ru_tones);
  2332. DP_STATS_UPD(mon_peer, tx.ru_start, ppdu->ru_start);
  2333. ru_index = dp_get_ru_index_frm_ru_tones(ppdu->ru_tones);
  2334. if (ru_index != RU_INDEX_MAX) {
  2335. DP_STATS_INC(mon_peer, tx.ru_loc[ru_index].num_msdu,
  2336. num_msdu);
  2337. DP_STATS_INC(mon_peer, tx.ru_loc[ru_index].num_mpdu,
  2338. num_mpdu);
  2339. DP_STATS_INC(mon_peer, tx.ru_loc[ru_index].mpdu_tried,
  2340. mpdu_tried);
  2341. }
  2342. }
  2343. /*
  2344. * All failed mpdu will be retried, so incrementing
  2345. * retries mpdu based on mpdu failed. Even for
  2346. * ack failure i.e for long retries we get
  2347. * mpdu failed equal mpdu tried.
  2348. */
  2349. DP_STATS_INC(mon_peer, tx.retries, mpdu_failed);
  2350. DP_STATS_INC(mon_peer, tx.transmit_type[ppdu->ppdu_type].num_msdu,
  2351. num_msdu);
  2352. DP_STATS_INC(mon_peer, tx.transmit_type[ppdu->ppdu_type].num_mpdu,
  2353. num_mpdu);
  2354. DP_STATS_INC(mon_peer, tx.transmit_type[ppdu->ppdu_type].mpdu_tried,
  2355. mpdu_tried);
  2356. DP_STATS_UPD(mon_peer, tx.tx_rate, ppdu->tx_rate);
  2357. DP_STATS_INC(mon_peer, tx.sgi_count[ppdu->gi], num_msdu);
  2358. DP_STATS_INC(mon_peer, tx.bw[ppdu->bw], num_msdu);
  2359. DP_STATS_INC(mon_peer, tx.nss[ppdu->nss], num_msdu);
  2360. if (ppdu->tid < CDP_DATA_TID_MAX)
  2361. DP_STATS_INC(mon_peer, tx.wme_ac_type[TID_TO_WME_AC(ppdu->tid)],
  2362. num_msdu);
  2363. DP_STATS_INCC(mon_peer, tx.stbc, num_msdu, ppdu->stbc);
  2364. DP_STATS_INCC(mon_peer, tx.ldpc, num_msdu, ppdu->ldpc);
  2365. if (!(ppdu->is_mcast) && ppdu->ack_rssi_valid)
  2366. DP_STATS_UPD(mon_peer, tx.last_ack_rssi, ack_rssi);
  2367. DP_STATS_INCC(mon_peer,
  2368. tx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  2369. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
  2370. DP_STATS_INCC(mon_peer,
  2371. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  2372. ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
  2373. DP_STATS_INCC(mon_peer,
  2374. tx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  2375. ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
  2376. DP_STATS_INCC(mon_peer,
  2377. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  2378. ((mcs < (MAX_MCS_11B)) && (preamble == DOT11_B)));
  2379. DP_STATS_INCC(mon_peer,
  2380. tx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  2381. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
  2382. DP_STATS_INCC(mon_peer,
  2383. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  2384. ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
  2385. DP_STATS_INCC(mon_peer,
  2386. tx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  2387. ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
  2388. DP_STATS_INCC(mon_peer,
  2389. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  2390. ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
  2391. DP_STATS_INCC(mon_peer,
  2392. tx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  2393. ((mcs >= MAX_MCS_11AX) && (preamble == DOT11_AX)));
  2394. DP_STATS_INCC(mon_peer,
  2395. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  2396. ((mcs < MAX_MCS_11AX) && (preamble == DOT11_AX)));
  2397. DP_STATS_INCC(mon_peer, tx.ampdu_cnt, num_mpdu, ppdu->is_ampdu);
  2398. DP_STATS_INCC(mon_peer, tx.non_ampdu_cnt, num_mpdu, !(ppdu->is_ampdu));
  2399. DP_STATS_INCC(mon_peer, tx.pream_punct_cnt, 1, ppdu->pream_punct);
  2400. DP_STATS_INC(mon_peer, tx.tx_ppdus, 1);
  2401. DP_STATS_INC(mon_peer, tx.tx_mpdus_success, num_mpdu);
  2402. DP_STATS_INC(mon_peer, tx.tx_mpdus_tried, mpdu_tried);
  2403. mon_ops = dp_mon_ops_get(pdev->soc);
  2404. if (mon_ops && mon_ops->mon_tx_stats_update)
  2405. mon_ops->mon_tx_stats_update(mon_peer, ppdu);
  2406. dp_peer_stats_notify(pdev, peer);
  2407. dp_send_stats_event(pdev, peer, ppdu->peer_id);
  2408. }
  2409. /*
  2410. * dp_get_ppdu_info_user_index: Find and allocate a per-user descriptor for a PPDU,
  2411. * if a new peer id arrives in a PPDU
  2412. * pdev: DP pdev handle
  2413. * @peer_id : peer unique identifier
  2414. * @ppdu_info: per ppdu tlv structure
  2415. *
  2416. * return:user index to be populated
  2417. */
  2418. static uint8_t dp_get_ppdu_info_user_index(struct dp_pdev *pdev,
  2419. uint16_t peer_id,
  2420. struct ppdu_info *ppdu_info)
  2421. {
  2422. uint8_t user_index = 0;
  2423. struct cdp_tx_completion_ppdu *ppdu_desc;
  2424. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2425. ppdu_desc =
  2426. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2427. while ((user_index + 1) <= ppdu_info->last_user) {
  2428. ppdu_user_desc = &ppdu_desc->user[user_index];
  2429. if (ppdu_user_desc->peer_id != peer_id) {
  2430. user_index++;
  2431. continue;
  2432. } else {
  2433. /* Max users possible is 8 so user array index should
  2434. * not exceed 7
  2435. */
  2436. qdf_assert_always(user_index <= (ppdu_desc->max_users - 1));
  2437. return user_index;
  2438. }
  2439. }
  2440. ppdu_info->last_user++;
  2441. /* Max users possible is 8 so last user should not exceed 8 */
  2442. qdf_assert_always(ppdu_info->last_user <= ppdu_desc->max_users);
  2443. return ppdu_info->last_user - 1;
  2444. }
  2445. /*
  2446. * dp_process_ppdu_stats_common_tlv: Process htt_ppdu_stats_common_tlv
  2447. * pdev: DP pdev handle
  2448. * @tag_buf: buffer containing the tlv htt_ppdu_stats_common_tlv
  2449. * @ppdu_info: per ppdu tlv structure
  2450. *
  2451. * return:void
  2452. */
  2453. static void
  2454. dp_process_ppdu_stats_common_tlv(struct dp_pdev *pdev,
  2455. uint32_t *tag_buf,
  2456. struct ppdu_info *ppdu_info)
  2457. {
  2458. uint16_t frame_type;
  2459. uint16_t frame_ctrl;
  2460. uint16_t freq;
  2461. struct dp_soc *soc = NULL;
  2462. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  2463. uint64_t ppdu_start_timestamp;
  2464. uint32_t *start_tag_buf;
  2465. start_tag_buf = tag_buf;
  2466. ppdu_desc =
  2467. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2468. ppdu_desc->ppdu_id = ppdu_info->ppdu_id;
  2469. tag_buf = start_tag_buf + HTT_GET_STATS_CMN_INDEX(RING_ID_SCH_CMD_ID);
  2470. ppdu_info->sched_cmdid =
  2471. HTT_PPDU_STATS_COMMON_TLV_SCH_CMDID_GET(*tag_buf);
  2472. ppdu_desc->num_users =
  2473. HTT_PPDU_STATS_COMMON_TLV_NUM_USERS_GET(*tag_buf);
  2474. qdf_assert_always(ppdu_desc->num_users <= ppdu_desc->max_users);
  2475. tag_buf = start_tag_buf + HTT_GET_STATS_CMN_INDEX(QTYPE_FRM_TYPE);
  2476. frame_type = HTT_PPDU_STATS_COMMON_TLV_FRM_TYPE_GET(*tag_buf);
  2477. ppdu_desc->htt_frame_type = frame_type;
  2478. frame_ctrl = ppdu_desc->frame_ctrl;
  2479. ppdu_desc->bar_ppdu_id = ppdu_info->ppdu_id;
  2480. switch (frame_type) {
  2481. case HTT_STATS_FTYPE_TIDQ_DATA_SU:
  2482. case HTT_STATS_FTYPE_TIDQ_DATA_MU:
  2483. case HTT_STATS_FTYPE_SGEN_QOS_NULL:
  2484. /*
  2485. * for management packet, frame type come as DATA_SU
  2486. * need to check frame_ctrl before setting frame_type
  2487. */
  2488. if (HTT_GET_FRAME_CTRL_TYPE(frame_ctrl) <= FRAME_CTRL_TYPE_CTRL)
  2489. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  2490. else
  2491. ppdu_desc->frame_type = CDP_PPDU_FTYPE_DATA;
  2492. break;
  2493. case HTT_STATS_FTYPE_SGEN_MU_BAR:
  2494. case HTT_STATS_FTYPE_SGEN_BAR:
  2495. ppdu_desc->frame_type = CDP_PPDU_FTYPE_BAR;
  2496. break;
  2497. default:
  2498. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  2499. break;
  2500. }
  2501. tag_buf = start_tag_buf + HTT_GET_STATS_CMN_INDEX(FES_DUR_US);
  2502. ppdu_desc->tx_duration = *tag_buf;
  2503. tag_buf = start_tag_buf + HTT_GET_STATS_CMN_INDEX(START_TSTMP_L32_US);
  2504. ppdu_desc->ppdu_start_timestamp = *tag_buf;
  2505. tag_buf = start_tag_buf + HTT_GET_STATS_CMN_INDEX(CHAN_MHZ_PHY_MODE);
  2506. freq = HTT_PPDU_STATS_COMMON_TLV_CHAN_MHZ_GET(*tag_buf);
  2507. if (freq != ppdu_desc->channel) {
  2508. soc = pdev->soc;
  2509. ppdu_desc->channel = freq;
  2510. pdev->operating_channel.freq = freq;
  2511. if (soc && soc->cdp_soc.ol_ops->freq_to_channel)
  2512. pdev->operating_channel.num =
  2513. soc->cdp_soc.ol_ops->freq_to_channel(soc->ctrl_psoc,
  2514. pdev->pdev_id,
  2515. freq);
  2516. if (soc && soc->cdp_soc.ol_ops->freq_to_band)
  2517. pdev->operating_channel.band =
  2518. soc->cdp_soc.ol_ops->freq_to_band(soc->ctrl_psoc,
  2519. pdev->pdev_id,
  2520. freq);
  2521. }
  2522. ppdu_desc->phy_mode = HTT_PPDU_STATS_COMMON_TLV_PHY_MODE_GET(*tag_buf);
  2523. tag_buf = start_tag_buf + HTT_GET_STATS_CMN_INDEX(RESV_NUM_UL_BEAM);
  2524. ppdu_desc->phy_ppdu_tx_time_us =
  2525. HTT_PPDU_STATS_COMMON_TLV_PHY_PPDU_TX_TIME_US_GET(*tag_buf);
  2526. ppdu_desc->beam_change =
  2527. HTT_PPDU_STATS_COMMON_TLV_BEAM_CHANGE_GET(*tag_buf);
  2528. ppdu_desc->doppler =
  2529. HTT_PPDU_STATS_COMMON_TLV_DOPPLER_INDICATION_GET(*tag_buf);
  2530. ppdu_desc->spatial_reuse =
  2531. HTT_PPDU_STATS_COMMON_TLV_SPATIAL_REUSE_GET(*tag_buf);
  2532. dp_tx_capture_htt_frame_counter(pdev, frame_type);
  2533. tag_buf = start_tag_buf + HTT_GET_STATS_CMN_INDEX(START_TSTMP_U32_US);
  2534. ppdu_start_timestamp = *tag_buf;
  2535. ppdu_desc->ppdu_start_timestamp |= ((ppdu_start_timestamp <<
  2536. HTT_SHIFT_UPPER_TIMESTAMP) &
  2537. HTT_MASK_UPPER_TIMESTAMP);
  2538. ppdu_desc->ppdu_end_timestamp = ppdu_desc->ppdu_start_timestamp +
  2539. ppdu_desc->tx_duration;
  2540. /* Ack time stamp is same as end time stamp*/
  2541. ppdu_desc->ack_timestamp = ppdu_desc->ppdu_end_timestamp;
  2542. ppdu_desc->ppdu_end_timestamp = ppdu_desc->ppdu_start_timestamp +
  2543. ppdu_desc->tx_duration;
  2544. ppdu_desc->bar_ppdu_start_timestamp = ppdu_desc->ppdu_start_timestamp;
  2545. ppdu_desc->bar_ppdu_end_timestamp = ppdu_desc->ppdu_end_timestamp;
  2546. ppdu_desc->bar_tx_duration = ppdu_desc->tx_duration;
  2547. /* Ack time stamp is same as end time stamp*/
  2548. ppdu_desc->ack_timestamp = ppdu_desc->ppdu_end_timestamp;
  2549. tag_buf = start_tag_buf + HTT_GET_STATS_CMN_INDEX(BSSCOLOR_OBSS_PSR);
  2550. ppdu_desc->bss_color =
  2551. HTT_PPDU_STATS_COMMON_TLV_BSS_COLOR_ID_GET(*tag_buf);
  2552. }
  2553. /*
  2554. * dp_process_ppdu_stats_user_common_tlv: Process ppdu_stats_user_common
  2555. * @tag_buf: buffer containing the tlv htt_ppdu_stats_user_common_tlv
  2556. * @ppdu_info: per ppdu tlv structure
  2557. *
  2558. * return:void
  2559. */
  2560. static void dp_process_ppdu_stats_user_common_tlv(
  2561. struct dp_pdev *pdev, uint32_t *tag_buf,
  2562. struct ppdu_info *ppdu_info)
  2563. {
  2564. uint16_t peer_id;
  2565. struct cdp_tx_completion_ppdu *ppdu_desc;
  2566. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2567. uint8_t curr_user_index = 0;
  2568. struct dp_peer *peer;
  2569. struct dp_vdev *vdev;
  2570. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  2571. ppdu_desc =
  2572. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2573. tag_buf++;
  2574. peer_id = HTT_PPDU_STATS_USER_RATE_TLV_SW_PEER_ID_GET(*tag_buf);
  2575. curr_user_index =
  2576. dp_get_ppdu_info_user_index(pdev,
  2577. peer_id, ppdu_info);
  2578. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  2579. ppdu_user_desc->tlv_bitmap |= (1 << tlv_type);
  2580. ppdu_desc->vdev_id =
  2581. HTT_PPDU_STATS_USER_COMMON_TLV_VAP_ID_GET(*tag_buf);
  2582. ppdu_user_desc->peer_id = peer_id;
  2583. tag_buf++;
  2584. if (HTT_PPDU_STATS_USER_COMMON_TLV_DELAYED_BA_GET(*tag_buf)) {
  2585. ppdu_user_desc->delayed_ba = 1;
  2586. ppdu_desc->delayed_ba = 1;
  2587. }
  2588. if (HTT_PPDU_STATS_USER_COMMON_TLV_MCAST_GET(*tag_buf)) {
  2589. ppdu_user_desc->is_mcast = true;
  2590. ppdu_user_desc->mpdu_tried_mcast =
  2591. HTT_PPDU_STATS_USER_COMMON_TLV_MPDUS_TRIED_GET(*tag_buf);
  2592. ppdu_user_desc->num_mpdu = ppdu_user_desc->mpdu_tried_mcast;
  2593. } else {
  2594. ppdu_user_desc->mpdu_tried_ucast =
  2595. HTT_PPDU_STATS_USER_COMMON_TLV_MPDUS_TRIED_GET(*tag_buf);
  2596. }
  2597. ppdu_user_desc->is_seq_num_valid =
  2598. HTT_PPDU_STATS_USER_COMMON_TLV_IS_SQNUM_VALID_IN_BUFFER_GET(*tag_buf);
  2599. tag_buf++;
  2600. ppdu_user_desc->qos_ctrl =
  2601. HTT_PPDU_STATS_USER_COMMON_TLV_QOS_CTRL_GET(*tag_buf);
  2602. ppdu_user_desc->frame_ctrl =
  2603. HTT_PPDU_STATS_USER_COMMON_TLV_FRAME_CTRL_GET(*tag_buf);
  2604. ppdu_desc->frame_ctrl = ppdu_user_desc->frame_ctrl;
  2605. if (ppdu_user_desc->delayed_ba)
  2606. ppdu_user_desc->mpdu_success = 0;
  2607. tag_buf += 3;
  2608. if (HTT_PPDU_STATS_IS_OPAQUE_VALID_GET(*tag_buf)) {
  2609. ppdu_user_desc->ppdu_cookie =
  2610. HTT_PPDU_STATS_HOST_OPAQUE_COOKIE_GET(*tag_buf);
  2611. ppdu_user_desc->is_ppdu_cookie_valid = 1;
  2612. }
  2613. /* returning earlier causes other feilds unpopulated */
  2614. if (peer_id == DP_SCAN_PEER_ID) {
  2615. vdev = dp_vdev_get_ref_by_id(pdev->soc, ppdu_desc->vdev_id,
  2616. DP_MOD_ID_TX_PPDU_STATS);
  2617. if (!vdev)
  2618. return;
  2619. qdf_mem_copy(ppdu_user_desc->mac_addr, vdev->mac_addr.raw,
  2620. QDF_MAC_ADDR_SIZE);
  2621. dp_vdev_unref_delete(pdev->soc, vdev, DP_MOD_ID_TX_PPDU_STATS);
  2622. } else {
  2623. peer = dp_peer_get_ref_by_id(pdev->soc, peer_id,
  2624. DP_MOD_ID_TX_PPDU_STATS);
  2625. if (!peer) {
  2626. /*
  2627. * fw sends peer_id which is about to removed but
  2628. * it was already removed in host.
  2629. * eg: for disassoc, fw send ppdu stats
  2630. * with peer id equal to previously associated
  2631. * peer's peer_id but it was removed
  2632. */
  2633. vdev = dp_vdev_get_ref_by_id(pdev->soc,
  2634. ppdu_desc->vdev_id,
  2635. DP_MOD_ID_TX_PPDU_STATS);
  2636. if (!vdev)
  2637. return;
  2638. qdf_mem_copy(ppdu_user_desc->mac_addr,
  2639. vdev->mac_addr.raw, QDF_MAC_ADDR_SIZE);
  2640. dp_vdev_unref_delete(pdev->soc, vdev,
  2641. DP_MOD_ID_TX_PPDU_STATS);
  2642. return;
  2643. }
  2644. qdf_mem_copy(ppdu_user_desc->mac_addr,
  2645. peer->mac_addr.raw, QDF_MAC_ADDR_SIZE);
  2646. dp_peer_unref_delete(peer, DP_MOD_ID_TX_PPDU_STATS);
  2647. }
  2648. }
  2649. /**
  2650. * dp_process_ppdu_stats_user_rate_tlv() - Process htt_ppdu_stats_user_rate_tlv
  2651. * @pdev: DP pdev handle
  2652. * @tag_buf: T2H message buffer carrying the user rate TLV
  2653. * @ppdu_info: per ppdu tlv structure
  2654. *
  2655. * return:void
  2656. */
  2657. static void
  2658. dp_process_ppdu_stats_user_rate_tlv(struct dp_pdev *pdev,
  2659. uint32_t *tag_buf,
  2660. struct ppdu_info *ppdu_info)
  2661. {
  2662. uint16_t peer_id;
  2663. struct cdp_tx_completion_ppdu *ppdu_desc;
  2664. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2665. uint8_t curr_user_index = 0;
  2666. struct dp_vdev *vdev;
  2667. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  2668. uint8_t bw;
  2669. ppdu_desc =
  2670. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2671. tag_buf++;
  2672. peer_id = HTT_PPDU_STATS_USER_RATE_TLV_SW_PEER_ID_GET(*tag_buf);
  2673. curr_user_index =
  2674. dp_get_ppdu_info_user_index(pdev,
  2675. peer_id, ppdu_info);
  2676. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  2677. ppdu_user_desc->tlv_bitmap |= (1 << tlv_type);
  2678. if (peer_id == DP_SCAN_PEER_ID) {
  2679. vdev = dp_vdev_get_ref_by_id(pdev->soc, ppdu_desc->vdev_id,
  2680. DP_MOD_ID_TX_PPDU_STATS);
  2681. if (!vdev)
  2682. return;
  2683. dp_vdev_unref_delete(pdev->soc, vdev,
  2684. DP_MOD_ID_TX_PPDU_STATS);
  2685. }
  2686. ppdu_user_desc->peer_id = peer_id;
  2687. ppdu_user_desc->tid =
  2688. HTT_PPDU_STATS_USER_RATE_TLV_TID_NUM_GET(*tag_buf);
  2689. tag_buf += 1;
  2690. ppdu_user_desc->user_pos =
  2691. HTT_PPDU_STATS_USER_RATE_TLV_USER_POS_GET(*tag_buf);
  2692. ppdu_user_desc->mu_group_id =
  2693. HTT_PPDU_STATS_USER_RATE_TLV_MU_GROUPID_GET(*tag_buf);
  2694. tag_buf += 1;
  2695. ppdu_user_desc->ru_start =
  2696. HTT_PPDU_STATS_USER_RATE_TLV_RU_START_GET(*tag_buf);
  2697. ppdu_user_desc->ru_tones =
  2698. (HTT_PPDU_STATS_USER_RATE_TLV_RU_END_GET(*tag_buf) -
  2699. HTT_PPDU_STATS_USER_RATE_TLV_RU_START_GET(*tag_buf)) + 1;
  2700. ppdu_desc->usr_ru_tones_sum += ppdu_user_desc->ru_tones;
  2701. tag_buf += 2;
  2702. ppdu_user_desc->ppdu_type =
  2703. HTT_PPDU_STATS_USER_RATE_TLV_PPDU_TYPE_GET(*tag_buf);
  2704. tag_buf++;
  2705. ppdu_user_desc->tx_rate = *tag_buf;
  2706. ppdu_user_desc->ltf_size =
  2707. HTT_PPDU_STATS_USER_RATE_TLV_LTF_SIZE_GET(*tag_buf);
  2708. ppdu_user_desc->stbc =
  2709. HTT_PPDU_STATS_USER_RATE_TLV_STBC_GET(*tag_buf);
  2710. ppdu_user_desc->he_re =
  2711. HTT_PPDU_STATS_USER_RATE_TLV_HE_RE_GET(*tag_buf);
  2712. ppdu_user_desc->txbf =
  2713. HTT_PPDU_STATS_USER_RATE_TLV_TXBF_GET(*tag_buf);
  2714. bw = HTT_PPDU_STATS_USER_RATE_TLV_BW_GET(*tag_buf);
  2715. /* Align bw value as per host data structures */
  2716. if (bw == HTT_PPDU_STATS_BANDWIDTH_320MHZ)
  2717. ppdu_user_desc->bw = bw - 3;
  2718. else
  2719. ppdu_user_desc->bw = bw - 2;
  2720. ppdu_user_desc->nss = HTT_PPDU_STATS_USER_RATE_TLV_NSS_GET(*tag_buf);
  2721. ppdu_desc->usr_nss_sum += ppdu_user_desc->nss;
  2722. ppdu_user_desc->mcs = HTT_PPDU_STATS_USER_RATE_TLV_MCS_GET(*tag_buf);
  2723. ppdu_user_desc->preamble =
  2724. HTT_PPDU_STATS_USER_RATE_TLV_PREAMBLE_GET(*tag_buf);
  2725. ppdu_user_desc->gi = HTT_PPDU_STATS_USER_RATE_TLV_GI_GET(*tag_buf);
  2726. ppdu_user_desc->dcm = HTT_PPDU_STATS_USER_RATE_TLV_DCM_GET(*tag_buf);
  2727. ppdu_user_desc->ldpc = HTT_PPDU_STATS_USER_RATE_TLV_LDPC_GET(*tag_buf);
  2728. }
  2729. /*
  2730. * dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv: Process
  2731. * htt_ppdu_stats_enq_mpdu_bitmap_64_tlv
  2732. * pdev: DP PDEV handle
  2733. * @tag_buf: buffer containing the tlv htt_ppdu_stats_enq_mpdu_bitmap_64_tlv
  2734. * @ppdu_info: per ppdu tlv structure
  2735. *
  2736. * return:void
  2737. */
  2738. static void dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv(
  2739. struct dp_pdev *pdev, uint32_t *tag_buf,
  2740. struct ppdu_info *ppdu_info)
  2741. {
  2742. htt_ppdu_stats_enq_mpdu_bitmap_64_tlv *dp_stats_buf =
  2743. (htt_ppdu_stats_enq_mpdu_bitmap_64_tlv *)tag_buf;
  2744. struct cdp_tx_completion_ppdu *ppdu_desc;
  2745. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2746. uint8_t curr_user_index = 0;
  2747. uint16_t peer_id;
  2748. uint32_t size = CDP_BA_64_BIT_MAP_SIZE_DWORDS;
  2749. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  2750. ppdu_desc =
  2751. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2752. tag_buf++;
  2753. peer_id =
  2754. HTT_PPDU_STATS_ENQ_MPDU_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  2755. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  2756. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  2757. ppdu_user_desc->tlv_bitmap |= (1 << tlv_type);
  2758. ppdu_user_desc->peer_id = peer_id;
  2759. ppdu_user_desc->start_seq = dp_stats_buf->start_seq;
  2760. qdf_mem_copy(&ppdu_user_desc->enq_bitmap, &dp_stats_buf->enq_bitmap,
  2761. sizeof(uint32_t) * CDP_BA_64_BIT_MAP_SIZE_DWORDS);
  2762. dp_process_ppdu_stats_update_failed_bitmap(pdev,
  2763. (void *)ppdu_user_desc,
  2764. ppdu_info->ppdu_id,
  2765. size);
  2766. }
  2767. /*
  2768. * dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv: Process
  2769. * htt_ppdu_stats_enq_mpdu_bitmap_256_tlv
  2770. * soc: DP SOC handle
  2771. * @tag_buf: buffer containing the tlv htt_ppdu_stats_enq_mpdu_bitmap_256_tlv
  2772. * @ppdu_info: per ppdu tlv structure
  2773. *
  2774. * return:void
  2775. */
  2776. static void dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv(
  2777. struct dp_pdev *pdev, uint32_t *tag_buf,
  2778. struct ppdu_info *ppdu_info)
  2779. {
  2780. htt_ppdu_stats_enq_mpdu_bitmap_256_tlv *dp_stats_buf =
  2781. (htt_ppdu_stats_enq_mpdu_bitmap_256_tlv *)tag_buf;
  2782. struct cdp_tx_completion_ppdu *ppdu_desc;
  2783. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2784. uint8_t curr_user_index = 0;
  2785. uint16_t peer_id;
  2786. uint32_t size = CDP_BA_256_BIT_MAP_SIZE_DWORDS;
  2787. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  2788. ppdu_desc =
  2789. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2790. tag_buf++;
  2791. peer_id =
  2792. HTT_PPDU_STATS_ENQ_MPDU_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  2793. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  2794. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  2795. ppdu_user_desc->tlv_bitmap |= (1 << tlv_type);
  2796. ppdu_user_desc->peer_id = peer_id;
  2797. ppdu_user_desc->start_seq = dp_stats_buf->start_seq;
  2798. qdf_mem_copy(&ppdu_user_desc->enq_bitmap, &dp_stats_buf->enq_bitmap,
  2799. sizeof(uint32_t) * CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  2800. dp_process_ppdu_stats_update_failed_bitmap(pdev,
  2801. (void *)ppdu_user_desc,
  2802. ppdu_info->ppdu_id,
  2803. size);
  2804. }
  2805. /*
  2806. * dp_process_ppdu_stats_user_cmpltn_common_tlv: Process
  2807. * htt_ppdu_stats_user_cmpltn_common_tlv
  2808. * soc: DP SOC handle
  2809. * @tag_buf: buffer containing the tlv htt_ppdu_stats_user_cmpltn_common_tlv
  2810. * @ppdu_info: per ppdu tlv structure
  2811. *
  2812. * return:void
  2813. */
  2814. static void dp_process_ppdu_stats_user_cmpltn_common_tlv(
  2815. struct dp_pdev *pdev, uint32_t *tag_buf,
  2816. struct ppdu_info *ppdu_info)
  2817. {
  2818. uint16_t peer_id;
  2819. struct cdp_tx_completion_ppdu *ppdu_desc;
  2820. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2821. uint8_t curr_user_index = 0;
  2822. uint8_t bw_iter;
  2823. htt_ppdu_stats_user_cmpltn_common_tlv *dp_stats_buf =
  2824. (htt_ppdu_stats_user_cmpltn_common_tlv *)tag_buf;
  2825. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  2826. ppdu_desc =
  2827. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2828. tag_buf++;
  2829. peer_id =
  2830. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_SW_PEER_ID_GET(*tag_buf);
  2831. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  2832. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  2833. ppdu_user_desc->tlv_bitmap |= (1 << tlv_type);
  2834. ppdu_user_desc->peer_id = peer_id;
  2835. ppdu_user_desc->completion_status =
  2836. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_COMPLETION_STATUS_GET(
  2837. *tag_buf);
  2838. ppdu_user_desc->tid =
  2839. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_TID_NUM_GET(*tag_buf);
  2840. tag_buf++;
  2841. if (qdf_likely(ppdu_user_desc->completion_status ==
  2842. HTT_PPDU_STATS_USER_STATUS_OK)) {
  2843. ppdu_desc->ack_rssi = dp_stats_buf->ack_rssi;
  2844. ppdu_user_desc->usr_ack_rssi = dp_stats_buf->ack_rssi;
  2845. ppdu_user_desc->ack_rssi_valid = 1;
  2846. } else {
  2847. ppdu_user_desc->ack_rssi_valid = 0;
  2848. }
  2849. tag_buf++;
  2850. ppdu_user_desc->mpdu_success =
  2851. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_MPDU_SUCCESS_GET(*tag_buf);
  2852. ppdu_user_desc->mpdu_failed =
  2853. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_MPDU_TRIED_GET(*tag_buf) -
  2854. ppdu_user_desc->mpdu_success;
  2855. tag_buf++;
  2856. ppdu_user_desc->long_retries =
  2857. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_LONG_RETRY_GET(*tag_buf);
  2858. ppdu_user_desc->short_retries =
  2859. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_SHORT_RETRY_GET(*tag_buf);
  2860. ppdu_user_desc->retry_mpdus =
  2861. ppdu_user_desc->long_retries + ppdu_user_desc->short_retries;
  2862. ppdu_user_desc->is_ampdu =
  2863. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_IS_AMPDU_GET(*tag_buf);
  2864. ppdu_info->is_ampdu = ppdu_user_desc->is_ampdu;
  2865. ppdu_desc->resp_type =
  2866. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_RESP_TYPE_GET(*tag_buf);
  2867. ppdu_desc->mprot_type =
  2868. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_MPROT_TYPE_GET(*tag_buf);
  2869. ppdu_desc->rts_success =
  2870. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_RTS_SUCCESS_GET(*tag_buf);
  2871. ppdu_desc->rts_failure =
  2872. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_RTS_FAILURE_GET(*tag_buf);
  2873. ppdu_user_desc->pream_punct =
  2874. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_PREAM_PUNC_TX_GET(*tag_buf);
  2875. ppdu_info->compltn_common_tlv++;
  2876. /*
  2877. * MU BAR may send request to n users but we may received ack only from
  2878. * m users. To have count of number of users respond back, we have a
  2879. * separate counter bar_num_users per PPDU that get increment for every
  2880. * htt_ppdu_stats_user_cmpltn_common_tlv
  2881. */
  2882. ppdu_desc->bar_num_users++;
  2883. tag_buf++;
  2884. for (bw_iter = 0; bw_iter < CDP_RSSI_CHAIN_LEN; bw_iter++) {
  2885. ppdu_user_desc->rssi_chain[bw_iter] =
  2886. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_CHAIN_RSSI_GET(*tag_buf);
  2887. tag_buf++;
  2888. }
  2889. ppdu_user_desc->sa_tx_antenna =
  2890. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_TX_ANTENNA_MASK_GET(*tag_buf);
  2891. tag_buf++;
  2892. ppdu_user_desc->sa_is_training =
  2893. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_IS_TRAINING_GET(*tag_buf);
  2894. if (ppdu_user_desc->sa_is_training) {
  2895. ppdu_user_desc->sa_goodput =
  2896. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_PENDING_TRAINING_PKTS_GET(*tag_buf);
  2897. }
  2898. tag_buf++;
  2899. for (bw_iter = 0; bw_iter < CDP_NUM_SA_BW; bw_iter++) {
  2900. ppdu_user_desc->sa_max_rates[bw_iter] =
  2901. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_MAX_RATES_GET(tag_buf[bw_iter]);
  2902. }
  2903. tag_buf += CDP_NUM_SA_BW;
  2904. ppdu_user_desc->current_rate_per =
  2905. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_CURRENT_RATE_PER_GET(*tag_buf);
  2906. }
  2907. /*
  2908. * dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv: Process
  2909. * htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv
  2910. * pdev: DP PDEV handle
  2911. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv
  2912. * @ppdu_info: per ppdu tlv structure
  2913. *
  2914. * return:void
  2915. */
  2916. static void dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv(
  2917. struct dp_pdev *pdev, uint32_t *tag_buf,
  2918. struct ppdu_info *ppdu_info)
  2919. {
  2920. htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv *dp_stats_buf =
  2921. (htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv *)tag_buf;
  2922. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2923. struct cdp_tx_completion_ppdu *ppdu_desc;
  2924. uint8_t curr_user_index = 0;
  2925. uint16_t peer_id;
  2926. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  2927. ppdu_desc =
  2928. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2929. tag_buf++;
  2930. peer_id =
  2931. HTT_PPDU_STATS_USER_CMPLTN_BA_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  2932. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  2933. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  2934. ppdu_user_desc->tlv_bitmap |= (1 << tlv_type);
  2935. ppdu_user_desc->peer_id = peer_id;
  2936. ppdu_user_desc->ba_seq_no = dp_stats_buf->ba_seq_no;
  2937. qdf_mem_copy(&ppdu_user_desc->ba_bitmap, &dp_stats_buf->ba_bitmap,
  2938. sizeof(uint32_t) * CDP_BA_64_BIT_MAP_SIZE_DWORDS);
  2939. ppdu_user_desc->ba_size = CDP_BA_64_BIT_MAP_SIZE_DWORDS * 32;
  2940. }
  2941. /*
  2942. * dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv: Process
  2943. * htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv
  2944. * pdev: DP PDEV handle
  2945. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv
  2946. * @ppdu_info: per ppdu tlv structure
  2947. *
  2948. * return:void
  2949. */
  2950. static void dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv(
  2951. struct dp_pdev *pdev, uint32_t *tag_buf,
  2952. struct ppdu_info *ppdu_info)
  2953. {
  2954. htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv *dp_stats_buf =
  2955. (htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv *)tag_buf;
  2956. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2957. struct cdp_tx_completion_ppdu *ppdu_desc;
  2958. uint8_t curr_user_index = 0;
  2959. uint16_t peer_id;
  2960. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  2961. ppdu_desc =
  2962. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2963. tag_buf++;
  2964. peer_id =
  2965. HTT_PPDU_STATS_USER_CMPLTN_BA_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  2966. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  2967. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  2968. ppdu_user_desc->tlv_bitmap |= (1 << tlv_type);
  2969. ppdu_user_desc->peer_id = peer_id;
  2970. ppdu_user_desc->ba_seq_no = dp_stats_buf->ba_seq_no;
  2971. qdf_mem_copy(&ppdu_user_desc->ba_bitmap, &dp_stats_buf->ba_bitmap,
  2972. sizeof(uint32_t) * CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  2973. ppdu_user_desc->ba_size = CDP_BA_256_BIT_MAP_SIZE_DWORDS * 32;
  2974. }
  2975. /*
  2976. * dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv: Process
  2977. * htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  2978. * pdev: DP PDE handle
  2979. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  2980. * @ppdu_info: per ppdu tlv structure
  2981. *
  2982. * return:void
  2983. */
  2984. static void dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv(
  2985. struct dp_pdev *pdev, uint32_t *tag_buf,
  2986. struct ppdu_info *ppdu_info)
  2987. {
  2988. uint16_t peer_id;
  2989. struct cdp_tx_completion_ppdu *ppdu_desc;
  2990. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2991. uint8_t curr_user_index = 0;
  2992. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  2993. ppdu_desc =
  2994. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2995. tag_buf += 2;
  2996. peer_id =
  2997. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_SW_PEER_ID_GET(*tag_buf);
  2998. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  2999. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  3000. ppdu_user_desc->tlv_bitmap |= (1 << tlv_type);
  3001. if (!ppdu_user_desc->ack_ba_tlv) {
  3002. ppdu_user_desc->ack_ba_tlv = 1;
  3003. } else {
  3004. pdev->stats.ack_ba_comes_twice++;
  3005. return;
  3006. }
  3007. ppdu_user_desc->peer_id = peer_id;
  3008. tag_buf++;
  3009. /* not to update ppdu_desc->tid from this TLV */
  3010. ppdu_user_desc->num_mpdu =
  3011. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_NUM_MPDU_GET(*tag_buf);
  3012. ppdu_user_desc->num_msdu =
  3013. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_NUM_MSDU_GET(*tag_buf);
  3014. ppdu_user_desc->success_msdus = ppdu_user_desc->num_msdu;
  3015. tag_buf++;
  3016. ppdu_user_desc->start_seq =
  3017. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_START_SEQ_GET(
  3018. *tag_buf);
  3019. tag_buf++;
  3020. ppdu_user_desc->success_bytes = *tag_buf;
  3021. /* increase ack ba tlv counter on successful mpdu */
  3022. if (ppdu_user_desc->num_mpdu)
  3023. ppdu_info->ack_ba_tlv++;
  3024. if (ppdu_user_desc->ba_size == 0) {
  3025. ppdu_user_desc->ba_seq_no = ppdu_user_desc->start_seq;
  3026. ppdu_user_desc->ba_bitmap[0] = 1;
  3027. ppdu_user_desc->ba_size = 1;
  3028. }
  3029. }
  3030. /*
  3031. * dp_process_ppdu_stats_user_common_array_tlv: Process
  3032. * htt_ppdu_stats_user_common_array_tlv
  3033. * pdev: DP PDEV handle
  3034. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  3035. * @ppdu_info: per ppdu tlv structure
  3036. *
  3037. * return:void
  3038. */
  3039. static void dp_process_ppdu_stats_user_common_array_tlv(
  3040. struct dp_pdev *pdev, uint32_t *tag_buf,
  3041. struct ppdu_info *ppdu_info)
  3042. {
  3043. uint32_t peer_id;
  3044. struct cdp_tx_completion_ppdu *ppdu_desc;
  3045. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  3046. uint8_t curr_user_index = 0;
  3047. struct htt_tx_ppdu_stats_info *dp_stats_buf;
  3048. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  3049. ppdu_desc =
  3050. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  3051. tag_buf++;
  3052. dp_stats_buf = (struct htt_tx_ppdu_stats_info *)tag_buf;
  3053. tag_buf += 3;
  3054. peer_id =
  3055. HTT_PPDU_STATS_ARRAY_ITEM_TLV_PEERID_GET(*tag_buf);
  3056. if (!dp_peer_find_by_id_valid(pdev->soc, peer_id)) {
  3057. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  3058. "Invalid peer");
  3059. return;
  3060. }
  3061. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  3062. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  3063. ppdu_user_desc->tlv_bitmap |= (1 << tlv_type);
  3064. ppdu_user_desc->retry_bytes = dp_stats_buf->tx_retry_bytes;
  3065. ppdu_user_desc->failed_bytes = dp_stats_buf->tx_failed_bytes;
  3066. tag_buf++;
  3067. ppdu_user_desc->success_msdus =
  3068. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_SUCC_MSDUS_GET(*tag_buf);
  3069. ppdu_user_desc->retry_bytes =
  3070. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_RETRY_MSDUS_GET(*tag_buf);
  3071. tag_buf++;
  3072. ppdu_user_desc->failed_msdus =
  3073. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_FAILED_MSDUS_GET(*tag_buf);
  3074. }
  3075. /*
  3076. * dp_process_ppdu_stats_flush_tlv: Process
  3077. * htt_ppdu_stats_flush_tlv
  3078. * @pdev: DP PDEV handle
  3079. * @tag_buf: buffer containing the htt_ppdu_stats_flush_tlv
  3080. * @ppdu_info: per ppdu tlv structure
  3081. *
  3082. * return:void
  3083. */
  3084. static void
  3085. dp_process_ppdu_stats_user_compltn_flush_tlv(struct dp_pdev *pdev,
  3086. uint32_t *tag_buf,
  3087. struct ppdu_info *ppdu_info)
  3088. {
  3089. struct cdp_tx_completion_ppdu *ppdu_desc;
  3090. uint32_t peer_id;
  3091. uint8_t tid;
  3092. struct dp_peer *peer;
  3093. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  3094. struct dp_mon_peer *mon_peer = NULL;
  3095. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3096. qdf_nbuf_data(ppdu_info->nbuf);
  3097. ppdu_desc->is_flush = 1;
  3098. tag_buf++;
  3099. ppdu_desc->drop_reason = *tag_buf;
  3100. tag_buf++;
  3101. ppdu_desc->num_msdu = HTT_PPDU_STATS_FLUSH_TLV_NUM_MSDU_GET(*tag_buf);
  3102. ppdu_desc->num_mpdu = HTT_PPDU_STATS_FLUSH_TLV_NUM_MPDU_GET(*tag_buf);
  3103. ppdu_desc->flow_type = HTT_PPDU_STATS_FLUSH_TLV_FLOW_TYPE_GET(*tag_buf);
  3104. tag_buf++;
  3105. peer_id = HTT_PPDU_STATS_FLUSH_TLV_SW_PEER_ID_GET(*tag_buf);
  3106. tid = HTT_PPDU_STATS_FLUSH_TLV_TID_NUM_GET(*tag_buf);
  3107. ppdu_desc->num_users = 1;
  3108. ppdu_desc->user[0].peer_id = peer_id;
  3109. ppdu_desc->user[0].tid = tid;
  3110. ppdu_desc->queue_type =
  3111. HTT_PPDU_STATS_FLUSH_TLV_QUEUE_TYPE_GET(*tag_buf);
  3112. peer = dp_peer_get_ref_by_id(pdev->soc, peer_id,
  3113. DP_MOD_ID_TX_PPDU_STATS);
  3114. if (!peer)
  3115. goto add_ppdu_to_sched_list;
  3116. if (ppdu_desc->drop_reason == HTT_FLUSH_EXCESS_RETRIES) {
  3117. mon_peer = peer->monitor_peer;
  3118. DP_STATS_INC(mon_peer,
  3119. tx.excess_retries_per_ac[TID_TO_WME_AC(tid)],
  3120. ppdu_desc->num_msdu);
  3121. }
  3122. dp_peer_unref_delete(peer, DP_MOD_ID_TX_PPDU_STATS);
  3123. add_ppdu_to_sched_list:
  3124. ppdu_info->done = 1;
  3125. TAILQ_REMOVE(&mon_pdev->ppdu_info_list, ppdu_info, ppdu_info_list_elem);
  3126. mon_pdev->list_depth--;
  3127. TAILQ_INSERT_TAIL(&mon_pdev->sched_comp_ppdu_list, ppdu_info,
  3128. ppdu_info_list_elem);
  3129. mon_pdev->sched_comp_list_depth++;
  3130. }
  3131. /**
  3132. * dp_process_ppdu_stats_sch_cmd_status_tlv: Process schedule command status tlv
  3133. * Here we are not going to process the buffer.
  3134. * @pdev: DP PDEV handle
  3135. * @ppdu_info: per ppdu tlv structure
  3136. *
  3137. * return:void
  3138. */
  3139. static void
  3140. dp_process_ppdu_stats_sch_cmd_status_tlv(struct dp_pdev *pdev,
  3141. struct ppdu_info *ppdu_info)
  3142. {
  3143. struct cdp_tx_completion_ppdu *ppdu_desc;
  3144. struct dp_peer *peer;
  3145. uint8_t num_users;
  3146. uint8_t i;
  3147. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  3148. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3149. qdf_nbuf_data(ppdu_info->nbuf);
  3150. num_users = ppdu_desc->bar_num_users;
  3151. for (i = 0; i < num_users; i++) {
  3152. if (ppdu_desc->user[i].user_pos == 0) {
  3153. if (ppdu_desc->frame_type == CDP_PPDU_FTYPE_BAR) {
  3154. /* update phy mode for bar frame */
  3155. ppdu_desc->phy_mode =
  3156. ppdu_desc->user[i].preamble;
  3157. ppdu_desc->user[0].mcs = ppdu_desc->user[i].mcs;
  3158. break;
  3159. }
  3160. if (ppdu_desc->frame_type == CDP_PPDU_FTYPE_CTRL) {
  3161. ppdu_desc->frame_ctrl =
  3162. ppdu_desc->user[i].frame_ctrl;
  3163. break;
  3164. }
  3165. }
  3166. }
  3167. if (ppdu_desc->frame_type == CDP_PPDU_FTYPE_DATA &&
  3168. ppdu_desc->delayed_ba) {
  3169. qdf_assert_always(ppdu_desc->num_users <= ppdu_desc->max_users);
  3170. for (i = 0; i < ppdu_desc->num_users; i++) {
  3171. struct cdp_delayed_tx_completion_ppdu_user *delay_ppdu;
  3172. uint64_t start_tsf;
  3173. uint64_t end_tsf;
  3174. uint32_t ppdu_id;
  3175. struct dp_mon_peer *mon_peer;
  3176. ppdu_id = ppdu_desc->ppdu_id;
  3177. peer = dp_peer_get_ref_by_id
  3178. (pdev->soc, ppdu_desc->user[i].peer_id,
  3179. DP_MOD_ID_TX_PPDU_STATS);
  3180. /**
  3181. * This check is to make sure peer is not deleted
  3182. * after processing the TLVs.
  3183. */
  3184. if (!peer)
  3185. continue;
  3186. mon_peer = peer->monitor_peer;
  3187. delay_ppdu = &mon_peer->delayed_ba_ppdu_stats;
  3188. start_tsf = ppdu_desc->ppdu_start_timestamp;
  3189. end_tsf = ppdu_desc->ppdu_end_timestamp;
  3190. /**
  3191. * save delayed ba user info
  3192. */
  3193. if (ppdu_desc->user[i].delayed_ba) {
  3194. dp_peer_copy_delay_stats(peer,
  3195. &ppdu_desc->user[i],
  3196. ppdu_id);
  3197. mon_peer->last_delayed_ba_ppduid = ppdu_id;
  3198. delay_ppdu->ppdu_start_timestamp = start_tsf;
  3199. delay_ppdu->ppdu_end_timestamp = end_tsf;
  3200. }
  3201. ppdu_desc->user[i].peer_last_delayed_ba =
  3202. mon_peer->last_delayed_ba;
  3203. dp_peer_unref_delete(peer, DP_MOD_ID_TX_PPDU_STATS);
  3204. if (ppdu_desc->user[i].delayed_ba &&
  3205. !ppdu_desc->user[i].debug_copied) {
  3206. QDF_TRACE(QDF_MODULE_ID_TXRX,
  3207. QDF_TRACE_LEVEL_INFO_MED,
  3208. "%s: %d ppdu_id[%d] bar_ppdu_id[%d] num_users[%d] usr[%d] htt_frame_type[%d]\n",
  3209. __func__, __LINE__,
  3210. ppdu_desc->ppdu_id,
  3211. ppdu_desc->bar_ppdu_id,
  3212. ppdu_desc->num_users,
  3213. i,
  3214. ppdu_desc->htt_frame_type);
  3215. }
  3216. }
  3217. }
  3218. /*
  3219. * when frame type is BAR and STATS_COMMON_TLV is set
  3220. * copy the store peer delayed info to BAR status
  3221. */
  3222. if (ppdu_desc->frame_type == CDP_PPDU_FTYPE_BAR) {
  3223. for (i = 0; i < ppdu_desc->bar_num_users; i++) {
  3224. struct cdp_delayed_tx_completion_ppdu_user *delay_ppdu;
  3225. uint64_t start_tsf;
  3226. uint64_t end_tsf;
  3227. struct dp_mon_peer *mon_peer;
  3228. peer = dp_peer_get_ref_by_id
  3229. (pdev->soc,
  3230. ppdu_desc->user[i].peer_id,
  3231. DP_MOD_ID_TX_PPDU_STATS);
  3232. /**
  3233. * This check is to make sure peer is not deleted
  3234. * after processing the TLVs.
  3235. */
  3236. if (!peer)
  3237. continue;
  3238. mon_peer = peer->monitor_peer;
  3239. if (ppdu_desc->user[i].completion_status !=
  3240. HTT_PPDU_STATS_USER_STATUS_OK) {
  3241. dp_peer_unref_delete(peer,
  3242. DP_MOD_ID_TX_PPDU_STATS);
  3243. continue;
  3244. }
  3245. delay_ppdu = &mon_peer->delayed_ba_ppdu_stats;
  3246. start_tsf = delay_ppdu->ppdu_start_timestamp;
  3247. end_tsf = delay_ppdu->ppdu_end_timestamp;
  3248. if (mon_peer->last_delayed_ba) {
  3249. dp_peer_copy_stats_to_bar(peer,
  3250. &ppdu_desc->user[i]);
  3251. ppdu_desc->ppdu_id =
  3252. mon_peer->last_delayed_ba_ppduid;
  3253. ppdu_desc->ppdu_start_timestamp = start_tsf;
  3254. ppdu_desc->ppdu_end_timestamp = end_tsf;
  3255. }
  3256. ppdu_desc->user[i].peer_last_delayed_ba =
  3257. mon_peer->last_delayed_ba;
  3258. dp_peer_unref_delete(peer, DP_MOD_ID_TX_PPDU_STATS);
  3259. }
  3260. }
  3261. TAILQ_REMOVE(&mon_pdev->ppdu_info_list, ppdu_info, ppdu_info_list_elem);
  3262. mon_pdev->list_depth--;
  3263. TAILQ_INSERT_TAIL(&mon_pdev->sched_comp_ppdu_list, ppdu_info,
  3264. ppdu_info_list_elem);
  3265. mon_pdev->sched_comp_list_depth++;
  3266. }
  3267. /**
  3268. * dp_validate_fix_ppdu_tlv(): Function to validate the length of PPDU
  3269. *
  3270. * If the TLV length sent as part of PPDU TLV is less that expected size i.e
  3271. * size of corresponding data structure, pad the remaining bytes with zeros
  3272. * and continue processing the TLVs
  3273. *
  3274. * @pdev: DP pdev handle
  3275. * @tag_buf: TLV buffer
  3276. * @tlv_expected_size: Expected size of Tag
  3277. * @tlv_len: TLV length received from FW
  3278. *
  3279. * Return: Pointer to updated TLV
  3280. */
  3281. static inline uint32_t *dp_validate_fix_ppdu_tlv(struct dp_pdev *pdev,
  3282. uint32_t *tag_buf,
  3283. uint16_t tlv_expected_size,
  3284. uint16_t tlv_len)
  3285. {
  3286. uint32_t *tlv_desc = tag_buf;
  3287. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  3288. qdf_assert_always(tlv_len != 0);
  3289. if (tlv_len < tlv_expected_size) {
  3290. qdf_mem_zero(mon_pdev->ppdu_tlv_buf, tlv_expected_size);
  3291. qdf_mem_copy(mon_pdev->ppdu_tlv_buf, tag_buf, tlv_len);
  3292. tlv_desc = mon_pdev->ppdu_tlv_buf;
  3293. }
  3294. return tlv_desc;
  3295. }
  3296. /**
  3297. * dp_process_ppdu_tag(): Function to process the PPDU TLVs
  3298. * @pdev: DP pdev handle
  3299. * @tag_buf: TLV buffer
  3300. * @tlv_len: length of tlv
  3301. * @ppdu_info: per ppdu tlv structure
  3302. *
  3303. * return: void
  3304. */
  3305. static void dp_process_ppdu_tag(struct dp_pdev *pdev,
  3306. uint32_t *tag_buf,
  3307. uint32_t tlv_len,
  3308. struct ppdu_info *ppdu_info)
  3309. {
  3310. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  3311. uint16_t tlv_expected_size;
  3312. uint32_t *tlv_desc;
  3313. switch (tlv_type) {
  3314. case HTT_PPDU_STATS_COMMON_TLV:
  3315. tlv_expected_size = sizeof(htt_ppdu_stats_common_tlv);
  3316. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  3317. tlv_expected_size, tlv_len);
  3318. dp_process_ppdu_stats_common_tlv(pdev, tlv_desc, ppdu_info);
  3319. break;
  3320. case HTT_PPDU_STATS_USR_COMMON_TLV:
  3321. tlv_expected_size = sizeof(htt_ppdu_stats_user_common_tlv);
  3322. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  3323. tlv_expected_size, tlv_len);
  3324. dp_process_ppdu_stats_user_common_tlv(pdev, tlv_desc,
  3325. ppdu_info);
  3326. break;
  3327. case HTT_PPDU_STATS_USR_RATE_TLV:
  3328. tlv_expected_size = sizeof(htt_ppdu_stats_user_rate_tlv);
  3329. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  3330. tlv_expected_size, tlv_len);
  3331. dp_process_ppdu_stats_user_rate_tlv(pdev, tlv_desc,
  3332. ppdu_info);
  3333. break;
  3334. case HTT_PPDU_STATS_USR_MPDU_ENQ_BITMAP_64_TLV:
  3335. tlv_expected_size =
  3336. sizeof(htt_ppdu_stats_enq_mpdu_bitmap_64_tlv);
  3337. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  3338. tlv_expected_size, tlv_len);
  3339. dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv(
  3340. pdev, tlv_desc, ppdu_info);
  3341. break;
  3342. case HTT_PPDU_STATS_USR_MPDU_ENQ_BITMAP_256_TLV:
  3343. tlv_expected_size =
  3344. sizeof(htt_ppdu_stats_enq_mpdu_bitmap_256_tlv);
  3345. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  3346. tlv_expected_size, tlv_len);
  3347. dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv(
  3348. pdev, tlv_desc, ppdu_info);
  3349. break;
  3350. case HTT_PPDU_STATS_USR_COMPLTN_COMMON_TLV:
  3351. tlv_expected_size =
  3352. sizeof(htt_ppdu_stats_user_cmpltn_common_tlv);
  3353. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  3354. tlv_expected_size, tlv_len);
  3355. dp_process_ppdu_stats_user_cmpltn_common_tlv(
  3356. pdev, tlv_desc, ppdu_info);
  3357. break;
  3358. case HTT_PPDU_STATS_USR_COMPLTN_BA_BITMAP_64_TLV:
  3359. tlv_expected_size =
  3360. sizeof(htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv);
  3361. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  3362. tlv_expected_size, tlv_len);
  3363. dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv(
  3364. pdev, tlv_desc, ppdu_info);
  3365. break;
  3366. case HTT_PPDU_STATS_USR_COMPLTN_BA_BITMAP_256_TLV:
  3367. tlv_expected_size =
  3368. sizeof(htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv);
  3369. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  3370. tlv_expected_size, tlv_len);
  3371. dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv(
  3372. pdev, tlv_desc, ppdu_info);
  3373. break;
  3374. case HTT_PPDU_STATS_USR_COMPLTN_ACK_BA_STATUS_TLV:
  3375. tlv_expected_size =
  3376. sizeof(htt_ppdu_stats_user_compltn_ack_ba_status_tlv);
  3377. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  3378. tlv_expected_size, tlv_len);
  3379. dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv(
  3380. pdev, tlv_desc, ppdu_info);
  3381. break;
  3382. case HTT_PPDU_STATS_USR_COMMON_ARRAY_TLV:
  3383. tlv_expected_size =
  3384. sizeof(htt_ppdu_stats_usr_common_array_tlv_v);
  3385. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  3386. tlv_expected_size, tlv_len);
  3387. dp_process_ppdu_stats_user_common_array_tlv(
  3388. pdev, tlv_desc, ppdu_info);
  3389. break;
  3390. case HTT_PPDU_STATS_USR_COMPLTN_FLUSH_TLV:
  3391. tlv_expected_size = sizeof(htt_ppdu_stats_flush_tlv);
  3392. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  3393. tlv_expected_size, tlv_len);
  3394. dp_process_ppdu_stats_user_compltn_flush_tlv(pdev, tlv_desc,
  3395. ppdu_info);
  3396. break;
  3397. case HTT_PPDU_STATS_SCH_CMD_STATUS_TLV:
  3398. dp_process_ppdu_stats_sch_cmd_status_tlv(pdev, ppdu_info);
  3399. break;
  3400. default:
  3401. break;
  3402. }
  3403. }
  3404. #ifdef WLAN_ATF_ENABLE
  3405. static void
  3406. dp_ppdu_desc_user_phy_tx_time_update(struct dp_pdev *pdev,
  3407. struct cdp_tx_completion_ppdu *ppdu_desc,
  3408. struct cdp_tx_completion_ppdu_user *user)
  3409. {
  3410. uint32_t nss_ru_width_sum = 0;
  3411. struct dp_mon_pdev *mon_pdev = NULL;
  3412. if (!pdev || !ppdu_desc || !user)
  3413. return;
  3414. mon_pdev = pdev->monitor_pdev;
  3415. if (!mon_pdev || !mon_pdev->dp_atf_stats_enable)
  3416. return;
  3417. if (ppdu_desc->frame_type != CDP_PPDU_FTYPE_DATA)
  3418. return;
  3419. nss_ru_width_sum = ppdu_desc->usr_nss_sum * ppdu_desc->usr_ru_tones_sum;
  3420. if (!nss_ru_width_sum)
  3421. nss_ru_width_sum = 1;
  3422. /**
  3423. * For SU-MIMO PPDU phy Tx time is same for the single user.
  3424. * For MU-MIMO phy Tx time is calculated per user as below
  3425. * user phy tx time =
  3426. * Entire PPDU duration * MU Ratio * OFDMA Ratio
  3427. * MU Ratio = usr_nss / Sum_of_nss_of_all_users
  3428. * OFDMA_ratio = usr_ru_width / Sum_of_ru_width_of_all_users
  3429. * usr_ru_widt = ru_end – ru_start + 1
  3430. */
  3431. if (ppdu_desc->htt_frame_type == HTT_STATS_FTYPE_TIDQ_DATA_SU) {
  3432. user->phy_tx_time_us = ppdu_desc->phy_ppdu_tx_time_us;
  3433. } else {
  3434. user->phy_tx_time_us = (ppdu_desc->phy_ppdu_tx_time_us *
  3435. user->nss * user->ru_tones) / nss_ru_width_sum;
  3436. }
  3437. }
  3438. #else
  3439. static void
  3440. dp_ppdu_desc_user_phy_tx_time_update(struct dp_pdev *pdev,
  3441. struct cdp_tx_completion_ppdu *ppdu_desc,
  3442. struct cdp_tx_completion_ppdu_user *user)
  3443. {
  3444. }
  3445. #endif
  3446. /**
  3447. * dp_ppdu_desc_user_stats_update(): Function to update TX user stats
  3448. * @pdev: DP pdev handle
  3449. * @ppdu_info: per PPDU TLV descriptor
  3450. *
  3451. * return: void
  3452. */
  3453. void
  3454. dp_ppdu_desc_user_stats_update(struct dp_pdev *pdev,
  3455. struct ppdu_info *ppdu_info)
  3456. {
  3457. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  3458. struct dp_peer *peer = NULL;
  3459. uint32_t tlv_bitmap_expected;
  3460. uint32_t tlv_bitmap_default;
  3461. uint16_t i;
  3462. uint32_t num_users;
  3463. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  3464. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3465. qdf_nbuf_data(ppdu_info->nbuf);
  3466. if (ppdu_desc->frame_type != CDP_PPDU_FTYPE_BAR)
  3467. ppdu_desc->ppdu_id = ppdu_info->ppdu_id;
  3468. tlv_bitmap_expected = HTT_PPDU_DEFAULT_TLV_BITMAP;
  3469. if (mon_pdev->tx_sniffer_enable || mon_pdev->mcopy_mode ||
  3470. mon_pdev->tx_capture_enabled) {
  3471. if (ppdu_info->is_ampdu)
  3472. tlv_bitmap_expected =
  3473. dp_htt_get_ppdu_sniffer_ampdu_tlv_bitmap(
  3474. ppdu_info->tlv_bitmap);
  3475. }
  3476. tlv_bitmap_default = tlv_bitmap_expected;
  3477. if (ppdu_desc->frame_type == CDP_PPDU_FTYPE_BAR) {
  3478. num_users = ppdu_desc->bar_num_users;
  3479. ppdu_desc->num_users = ppdu_desc->bar_num_users;
  3480. } else {
  3481. num_users = ppdu_desc->num_users;
  3482. }
  3483. qdf_assert_always(ppdu_desc->num_users <= ppdu_desc->max_users);
  3484. for (i = 0; i < num_users; i++) {
  3485. ppdu_desc->num_mpdu += ppdu_desc->user[i].num_mpdu;
  3486. ppdu_desc->num_msdu += ppdu_desc->user[i].num_msdu;
  3487. peer = dp_peer_get_ref_by_id(pdev->soc,
  3488. ppdu_desc->user[i].peer_id,
  3489. DP_MOD_ID_TX_PPDU_STATS);
  3490. /**
  3491. * This check is to make sure peer is not deleted
  3492. * after processing the TLVs.
  3493. */
  3494. if (!peer)
  3495. continue;
  3496. ppdu_desc->user[i].is_bss_peer = peer->bss_peer;
  3497. /*
  3498. * different frame like DATA, BAR or CTRL has different
  3499. * tlv bitmap expected. Apart from ACK_BA_STATUS TLV, we
  3500. * receive other tlv in-order/sequential from fw.
  3501. * Since ACK_BA_STATUS TLV come from Hardware it is
  3502. * asynchronous So we need to depend on some tlv to confirm
  3503. * all tlv is received for a ppdu.
  3504. * So we depend on both SCHED_CMD_STATUS_TLV and
  3505. * ACK_BA_STATUS_TLV. for failure packet we won't get
  3506. * ACK_BA_STATUS_TLV.
  3507. */
  3508. if (!(ppdu_info->tlv_bitmap &
  3509. (1 << HTT_PPDU_STATS_SCH_CMD_STATUS_TLV)) ||
  3510. (!(ppdu_info->tlv_bitmap &
  3511. (1 << HTT_PPDU_STATS_USR_COMPLTN_ACK_BA_STATUS_TLV)) &&
  3512. (ppdu_desc->user[i].completion_status ==
  3513. HTT_PPDU_STATS_USER_STATUS_OK))) {
  3514. dp_peer_unref_delete(peer, DP_MOD_ID_TX_PPDU_STATS);
  3515. continue;
  3516. }
  3517. /**
  3518. * Update tx stats for data frames having Qos as well as
  3519. * non-Qos data tid
  3520. */
  3521. if ((ppdu_desc->user[i].tid < CDP_DATA_TID_MAX ||
  3522. (ppdu_desc->user[i].tid == CDP_DATA_NON_QOS_TID) ||
  3523. (ppdu_desc->htt_frame_type ==
  3524. HTT_STATS_FTYPE_SGEN_QOS_NULL) ||
  3525. ((ppdu_desc->frame_type == CDP_PPDU_FTYPE_BAR) &&
  3526. (ppdu_desc->num_mpdu > 1))) &&
  3527. (ppdu_desc->frame_type != CDP_PPDU_FTYPE_CTRL)) {
  3528. dp_tx_stats_update(pdev, peer,
  3529. &ppdu_desc->user[i],
  3530. ppdu_desc->ack_rssi);
  3531. dp_tx_rate_stats_update(peer, &ppdu_desc->user[i]);
  3532. }
  3533. dp_ppdu_desc_user_phy_tx_time_update(pdev, ppdu_desc,
  3534. &ppdu_desc->user[i]);
  3535. dp_peer_unref_delete(peer, DP_MOD_ID_TX_PPDU_STATS);
  3536. tlv_bitmap_expected = tlv_bitmap_default;
  3537. }
  3538. }
  3539. #if !defined(WLAN_TX_PKT_CAPTURE_ENH) || defined(QCA_MONITOR_2_0_SUPPORT)
  3540. /*
  3541. * dp_tx_ppdu_desc_notify() - Notify to upper layer about PPDU via WDI
  3542. *
  3543. * @pdev: Datapath pdev handle
  3544. * @nbuf: Buffer to be delivered to upper layer
  3545. *
  3546. * Return: void
  3547. */
  3548. static void dp_tx_ppdu_desc_notify(struct dp_pdev *pdev, qdf_nbuf_t nbuf)
  3549. {
  3550. struct dp_soc *soc = pdev->soc;
  3551. struct dp_mon_ops *mon_ops = NULL;
  3552. mon_ops = dp_mon_ops_get(soc);
  3553. if (mon_ops && mon_ops->mon_ppdu_desc_notify)
  3554. mon_ops->mon_ppdu_desc_notify(pdev, nbuf);
  3555. else
  3556. qdf_nbuf_free(nbuf);
  3557. }
  3558. void dp_ppdu_desc_deliver(struct dp_pdev *pdev,
  3559. struct ppdu_info *ppdu_info)
  3560. {
  3561. struct ppdu_info *s_ppdu_info = NULL;
  3562. struct ppdu_info *ppdu_info_next = NULL;
  3563. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  3564. qdf_nbuf_t nbuf;
  3565. uint32_t time_delta = 0;
  3566. bool starved = 0;
  3567. bool matched = 0;
  3568. bool recv_ack_ba_done = 0;
  3569. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  3570. if (ppdu_info->tlv_bitmap &
  3571. (1 << HTT_PPDU_STATS_USR_COMPLTN_ACK_BA_STATUS_TLV) &&
  3572. ppdu_info->done)
  3573. recv_ack_ba_done = 1;
  3574. mon_pdev->last_sched_cmdid = ppdu_info->sched_cmdid;
  3575. s_ppdu_info = TAILQ_FIRST(&mon_pdev->sched_comp_ppdu_list);
  3576. TAILQ_FOREACH_SAFE(s_ppdu_info, &mon_pdev->sched_comp_ppdu_list,
  3577. ppdu_info_list_elem, ppdu_info_next) {
  3578. if (s_ppdu_info->tsf_l32 > ppdu_info->tsf_l32)
  3579. time_delta = (MAX_TSF_32 - s_ppdu_info->tsf_l32) +
  3580. ppdu_info->tsf_l32;
  3581. else
  3582. time_delta = ppdu_info->tsf_l32 - s_ppdu_info->tsf_l32;
  3583. if (!s_ppdu_info->done && !recv_ack_ba_done) {
  3584. if (time_delta < MAX_SCHED_STARVE) {
  3585. dp_mon_info("pdev[%d] ppdu_id[%d] sched_cmdid[%d] TLV_B[0x%x] TSF[%u] D[%d]",
  3586. pdev->pdev_id,
  3587. s_ppdu_info->ppdu_id,
  3588. s_ppdu_info->sched_cmdid,
  3589. s_ppdu_info->tlv_bitmap,
  3590. s_ppdu_info->tsf_l32,
  3591. s_ppdu_info->done);
  3592. break;
  3593. }
  3594. starved = 1;
  3595. }
  3596. mon_pdev->delivered_sched_cmdid = s_ppdu_info->sched_cmdid;
  3597. TAILQ_REMOVE(&mon_pdev->sched_comp_ppdu_list, s_ppdu_info,
  3598. ppdu_info_list_elem);
  3599. mon_pdev->sched_comp_list_depth--;
  3600. nbuf = s_ppdu_info->nbuf;
  3601. qdf_assert_always(nbuf);
  3602. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3603. qdf_nbuf_data(nbuf);
  3604. ppdu_desc->tlv_bitmap = s_ppdu_info->tlv_bitmap;
  3605. if (starved) {
  3606. dp_mon_err("ppdu starved fc[0x%x] h_ftype[%d] tlv_bitmap[0x%x] cs[%d]\n",
  3607. ppdu_desc->frame_ctrl,
  3608. ppdu_desc->htt_frame_type,
  3609. ppdu_desc->tlv_bitmap,
  3610. ppdu_desc->user[0].completion_status);
  3611. starved = 0;
  3612. }
  3613. if (ppdu_info->ppdu_id == s_ppdu_info->ppdu_id &&
  3614. ppdu_info->sched_cmdid == s_ppdu_info->sched_cmdid)
  3615. matched = 1;
  3616. dp_ppdu_desc_user_stats_update(pdev, s_ppdu_info);
  3617. qdf_mem_free(s_ppdu_info);
  3618. dp_tx_ppdu_desc_notify(pdev, nbuf);
  3619. if (matched)
  3620. break;
  3621. }
  3622. }
  3623. #endif
  3624. /*
  3625. * dp_tx_ppdu_desc_deliver() - Deliver PPDU desc to upper layer
  3626. *
  3627. * @pdev: Datapath pdev handle
  3628. * @ppdu_info: per PPDU TLV descriptor
  3629. *
  3630. * Return: void
  3631. */
  3632. static void dp_tx_ppdu_desc_deliver(struct dp_pdev *pdev,
  3633. struct ppdu_info *ppdu_info)
  3634. {
  3635. struct dp_soc *soc = pdev->soc;
  3636. struct dp_mon_ops *mon_ops = NULL;
  3637. mon_ops = dp_mon_ops_get(soc);
  3638. if (mon_ops && mon_ops->mon_ppdu_desc_deliver) {
  3639. mon_ops->mon_ppdu_desc_deliver(pdev, ppdu_info);
  3640. } else {
  3641. qdf_nbuf_free(ppdu_info->nbuf);
  3642. ppdu_info->nbuf = NULL;
  3643. qdf_mem_free(ppdu_info);
  3644. }
  3645. }
  3646. /**
  3647. * dp_get_ppdu_desc(): Function to allocate new PPDU status
  3648. * desc for new ppdu id
  3649. * @pdev: DP pdev handle
  3650. * @ppdu_id: PPDU unique identifier
  3651. * @tlv_type: TLV type received
  3652. * @tsf_l32: timestamp received along with ppdu stats indication header
  3653. * @max_users: Maximum user for that particular ppdu
  3654. *
  3655. * return: ppdu_info per ppdu tlv structure
  3656. */
  3657. static
  3658. struct ppdu_info *dp_get_ppdu_desc(struct dp_pdev *pdev, uint32_t ppdu_id,
  3659. uint8_t tlv_type, uint32_t tsf_l32,
  3660. uint8_t max_users)
  3661. {
  3662. struct ppdu_info *ppdu_info = NULL;
  3663. struct ppdu_info *s_ppdu_info = NULL;
  3664. struct ppdu_info *ppdu_info_next = NULL;
  3665. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  3666. uint32_t size = 0;
  3667. struct cdp_tx_completion_ppdu *tmp_ppdu_desc = NULL;
  3668. struct cdp_tx_completion_ppdu_user *tmp_user;
  3669. uint32_t time_delta;
  3670. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  3671. /*
  3672. * Find ppdu_id node exists or not
  3673. */
  3674. TAILQ_FOREACH_SAFE(ppdu_info, &mon_pdev->ppdu_info_list,
  3675. ppdu_info_list_elem, ppdu_info_next) {
  3676. if (ppdu_info && (ppdu_info->ppdu_id == ppdu_id)) {
  3677. if (ppdu_info->tsf_l32 > tsf_l32)
  3678. time_delta = (MAX_TSF_32 -
  3679. ppdu_info->tsf_l32) + tsf_l32;
  3680. else
  3681. time_delta = tsf_l32 - ppdu_info->tsf_l32;
  3682. if (time_delta > WRAP_DROP_TSF_DELTA) {
  3683. TAILQ_REMOVE(&mon_pdev->ppdu_info_list,
  3684. ppdu_info, ppdu_info_list_elem);
  3685. mon_pdev->list_depth--;
  3686. pdev->stats.ppdu_wrap_drop++;
  3687. tmp_ppdu_desc =
  3688. (struct cdp_tx_completion_ppdu *)
  3689. qdf_nbuf_data(ppdu_info->nbuf);
  3690. tmp_user = &tmp_ppdu_desc->user[0];
  3691. dp_htt_tx_stats_info("S_PID [%d] S_TSF[%u] TLV_BITMAP[0x%x] [CMPLTN - %d ACK_BA - %d] CS[%d] - R_PID[%d] R_TSF[%u] R_TLV_TAG[0x%x]\n",
  3692. ppdu_info->ppdu_id,
  3693. ppdu_info->tsf_l32,
  3694. ppdu_info->tlv_bitmap,
  3695. tmp_user->completion_status,
  3696. ppdu_info->compltn_common_tlv,
  3697. ppdu_info->ack_ba_tlv,
  3698. ppdu_id, tsf_l32,
  3699. tlv_type);
  3700. qdf_nbuf_free(ppdu_info->nbuf);
  3701. ppdu_info->nbuf = NULL;
  3702. qdf_mem_free(ppdu_info);
  3703. } else {
  3704. break;
  3705. }
  3706. }
  3707. }
  3708. /*
  3709. * check if it is ack ba tlv and if it is not there in ppdu info
  3710. * list then check it in sched completion ppdu list
  3711. */
  3712. if (!ppdu_info &&
  3713. tlv_type == HTT_PPDU_STATS_USR_COMPLTN_ACK_BA_STATUS_TLV) {
  3714. TAILQ_FOREACH(s_ppdu_info,
  3715. &mon_pdev->sched_comp_ppdu_list,
  3716. ppdu_info_list_elem) {
  3717. if (s_ppdu_info && (s_ppdu_info->ppdu_id == ppdu_id)) {
  3718. if (s_ppdu_info->tsf_l32 > tsf_l32)
  3719. time_delta = (MAX_TSF_32 -
  3720. s_ppdu_info->tsf_l32) +
  3721. tsf_l32;
  3722. else
  3723. time_delta = tsf_l32 -
  3724. s_ppdu_info->tsf_l32;
  3725. if (time_delta < WRAP_DROP_TSF_DELTA) {
  3726. ppdu_info = s_ppdu_info;
  3727. break;
  3728. }
  3729. } else {
  3730. /*
  3731. * ACK BA STATUS TLV comes sequential order
  3732. * if we received ack ba status tlv for second
  3733. * ppdu and first ppdu is still waiting for
  3734. * ACK BA STATUS TLV. Based on fw comment
  3735. * we won't receive it tlv later. So we can
  3736. * set ppdu info done.
  3737. */
  3738. if (s_ppdu_info)
  3739. s_ppdu_info->done = 1;
  3740. }
  3741. }
  3742. }
  3743. if (ppdu_info) {
  3744. if (ppdu_info->tlv_bitmap & (1 << tlv_type)) {
  3745. /**
  3746. * if we get tlv_type that is already been processed
  3747. * for ppdu, that means we got a new ppdu with same
  3748. * ppdu id. Hence Flush the older ppdu
  3749. * for MUMIMO and OFDMA, In a PPDU we have
  3750. * multiple user with same tlv types. tlv bitmap is
  3751. * used to check whether SU or MU_MIMO/OFDMA
  3752. */
  3753. if (!(ppdu_info->tlv_bitmap &
  3754. (1 << HTT_PPDU_STATS_SCH_CMD_STATUS_TLV)))
  3755. return ppdu_info;
  3756. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3757. qdf_nbuf_data(ppdu_info->nbuf);
  3758. /**
  3759. * apart from ACK BA STATUS TLV rest all comes in order
  3760. * so if tlv type not ACK BA STATUS TLV we can deliver
  3761. * ppdu_info
  3762. */
  3763. if ((tlv_type ==
  3764. HTT_PPDU_STATS_USR_COMPLTN_ACK_BA_STATUS_TLV) &&
  3765. (ppdu_desc->htt_frame_type ==
  3766. HTT_STATS_FTYPE_SGEN_MU_BAR))
  3767. return ppdu_info;
  3768. dp_tx_ppdu_desc_deliver(pdev, ppdu_info);
  3769. } else {
  3770. return ppdu_info;
  3771. }
  3772. }
  3773. /**
  3774. * Flush the head ppdu descriptor if ppdu desc list reaches max
  3775. * threshold
  3776. */
  3777. if (mon_pdev->list_depth > HTT_PPDU_DESC_MAX_DEPTH) {
  3778. ppdu_info = TAILQ_FIRST(&mon_pdev->ppdu_info_list);
  3779. TAILQ_REMOVE(&mon_pdev->ppdu_info_list,
  3780. ppdu_info, ppdu_info_list_elem);
  3781. mon_pdev->list_depth--;
  3782. pdev->stats.ppdu_drop++;
  3783. qdf_nbuf_free(ppdu_info->nbuf);
  3784. ppdu_info->nbuf = NULL;
  3785. qdf_mem_free(ppdu_info);
  3786. }
  3787. size = sizeof(struct cdp_tx_completion_ppdu) +
  3788. (max_users * sizeof(struct cdp_tx_completion_ppdu_user));
  3789. /*
  3790. * Allocate new ppdu_info node
  3791. */
  3792. ppdu_info = qdf_mem_malloc(sizeof(struct ppdu_info));
  3793. if (!ppdu_info)
  3794. return NULL;
  3795. ppdu_info->nbuf = qdf_nbuf_alloc(pdev->soc->osdev, size,
  3796. 0, 4, TRUE);
  3797. if (!ppdu_info->nbuf) {
  3798. qdf_mem_free(ppdu_info);
  3799. return NULL;
  3800. }
  3801. ppdu_info->ppdu_desc =
  3802. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  3803. qdf_mem_zero(qdf_nbuf_data(ppdu_info->nbuf), size);
  3804. if (!qdf_nbuf_put_tail(ppdu_info->nbuf, size)) {
  3805. dp_mon_err("No tailroom for HTT PPDU");
  3806. qdf_nbuf_free(ppdu_info->nbuf);
  3807. ppdu_info->nbuf = NULL;
  3808. ppdu_info->last_user = 0;
  3809. qdf_mem_free(ppdu_info);
  3810. return NULL;
  3811. }
  3812. ppdu_info->ppdu_desc->max_users = max_users;
  3813. ppdu_info->tsf_l32 = tsf_l32;
  3814. /**
  3815. * No lock is needed because all PPDU TLVs are processed in
  3816. * same context and this list is updated in same context
  3817. */
  3818. TAILQ_INSERT_TAIL(&mon_pdev->ppdu_info_list, ppdu_info,
  3819. ppdu_info_list_elem);
  3820. mon_pdev->list_depth++;
  3821. return ppdu_info;
  3822. }
  3823. /**
  3824. * dp_htt_process_tlv(): Function to process each PPDU TLVs
  3825. * @pdev: DP pdev handle
  3826. * @htt_t2h_msg: HTT target to host message
  3827. *
  3828. * return: ppdu_info per ppdu tlv structure
  3829. */
  3830. static struct ppdu_info *dp_htt_process_tlv(struct dp_pdev *pdev,
  3831. qdf_nbuf_t htt_t2h_msg)
  3832. {
  3833. uint32_t length;
  3834. uint32_t ppdu_id;
  3835. uint8_t tlv_type;
  3836. uint32_t tlv_length, tlv_bitmap_expected;
  3837. uint8_t *tlv_buf;
  3838. struct ppdu_info *ppdu_info = NULL;
  3839. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  3840. uint8_t max_users = CDP_MU_MAX_USERS;
  3841. uint32_t tsf_l32;
  3842. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  3843. uint32_t *msg_word = (uint32_t *)qdf_nbuf_data(htt_t2h_msg);
  3844. length = HTT_T2H_PPDU_STATS_PAYLOAD_SIZE_GET(*msg_word);
  3845. msg_word = msg_word + 1;
  3846. ppdu_id = HTT_T2H_PPDU_STATS_PPDU_ID_GET(*msg_word);
  3847. msg_word = msg_word + 1;
  3848. tsf_l32 = (uint32_t)(*msg_word);
  3849. msg_word = msg_word + 2;
  3850. while (length > 0) {
  3851. tlv_buf = (uint8_t *)msg_word;
  3852. tlv_type = HTT_STATS_TLV_TAG_GET(*msg_word);
  3853. tlv_length = HTT_STATS_TLV_LENGTH_GET(*msg_word);
  3854. if (qdf_likely(tlv_type < CDP_PPDU_STATS_MAX_TAG))
  3855. pdev->stats.ppdu_stats_counter[tlv_type]++;
  3856. if (tlv_length == 0)
  3857. break;
  3858. tlv_length += HTT_TLV_HDR_LEN;
  3859. /**
  3860. * Not allocating separate ppdu descriptor for MGMT Payload
  3861. * TLV as this is sent as separate WDI indication and it
  3862. * doesn't contain any ppdu information
  3863. */
  3864. if (tlv_type == HTT_PPDU_STATS_TX_MGMTCTRL_PAYLOAD_TLV) {
  3865. mon_pdev->mgmtctrl_frm_info.mgmt_buf = tlv_buf;
  3866. mon_pdev->mgmtctrl_frm_info.ppdu_id = ppdu_id;
  3867. mon_pdev->mgmtctrl_frm_info.mgmt_buf_len =
  3868. HTT_PPDU_STATS_TX_MGMTCTRL_TLV_FRAME_LENGTH_GET
  3869. (*(msg_word + 1));
  3870. msg_word =
  3871. (uint32_t *)((uint8_t *)tlv_buf + tlv_length);
  3872. length -= (tlv_length);
  3873. continue;
  3874. }
  3875. /*
  3876. * retrieve max_users if it's USERS_INFO,
  3877. * else, it's 1 for COMPLTN_FLUSH,
  3878. * else, use CDP_MU_MAX_USERS
  3879. */
  3880. if (tlv_type == HTT_PPDU_STATS_USERS_INFO_TLV) {
  3881. max_users =
  3882. HTT_PPDU_STATS_USERS_INFO_TLV_MAX_USERS_GET(*(msg_word + 1));
  3883. } else if (tlv_type == HTT_PPDU_STATS_USR_COMPLTN_FLUSH_TLV) {
  3884. max_users = 1;
  3885. }
  3886. ppdu_info = dp_get_ppdu_desc(pdev, ppdu_id, tlv_type,
  3887. tsf_l32, max_users);
  3888. if (!ppdu_info)
  3889. return NULL;
  3890. ppdu_info->ppdu_id = ppdu_id;
  3891. ppdu_info->tlv_bitmap |= (1 << tlv_type);
  3892. dp_process_ppdu_tag(pdev, msg_word, tlv_length, ppdu_info);
  3893. /**
  3894. * Increment pdev level tlv count to monitor
  3895. * missing TLVs
  3896. */
  3897. mon_pdev->tlv_count++;
  3898. ppdu_info->last_tlv_cnt = mon_pdev->tlv_count;
  3899. msg_word = (uint32_t *)((uint8_t *)tlv_buf + tlv_length);
  3900. length -= (tlv_length);
  3901. }
  3902. if (!ppdu_info)
  3903. return NULL;
  3904. mon_pdev->last_ppdu_id = ppdu_id;
  3905. tlv_bitmap_expected = HTT_PPDU_DEFAULT_TLV_BITMAP;
  3906. if (mon_pdev->tx_sniffer_enable || mon_pdev->mcopy_mode ||
  3907. mon_pdev->tx_capture_enabled) {
  3908. if (ppdu_info->is_ampdu)
  3909. tlv_bitmap_expected =
  3910. dp_htt_get_ppdu_sniffer_ampdu_tlv_bitmap(
  3911. ppdu_info->tlv_bitmap);
  3912. }
  3913. ppdu_desc = ppdu_info->ppdu_desc;
  3914. if (!ppdu_desc)
  3915. return NULL;
  3916. if (ppdu_desc->user[ppdu_desc->last_usr_index].completion_status !=
  3917. HTT_PPDU_STATS_USER_STATUS_OK) {
  3918. tlv_bitmap_expected = tlv_bitmap_expected & 0xFF;
  3919. }
  3920. /*
  3921. * for frame type DATA and BAR, we update stats based on MSDU,
  3922. * successful msdu and mpdu are populate from ACK BA STATUS TLV
  3923. * which comes out of order. successful mpdu also populated from
  3924. * COMPLTN COMMON TLV which comes in order. for every ppdu_info
  3925. * we store successful mpdu from both tlv and compare before delivering
  3926. * to make sure we received ACK BA STATUS TLV. For some self generated
  3927. * frame we won't get ack ba status tlv so no need to wait for
  3928. * ack ba status tlv.
  3929. */
  3930. if (ppdu_desc->frame_type != CDP_PPDU_FTYPE_CTRL &&
  3931. ppdu_desc->htt_frame_type != HTT_STATS_FTYPE_SGEN_QOS_NULL) {
  3932. /*
  3933. * most of the time bar frame will have duplicate ack ba
  3934. * status tlv
  3935. */
  3936. if (ppdu_desc->frame_type == CDP_PPDU_FTYPE_BAR &&
  3937. (ppdu_info->compltn_common_tlv != ppdu_info->ack_ba_tlv))
  3938. return NULL;
  3939. /*
  3940. * For data frame, compltn common tlv should match ack ba status
  3941. * tlv and completion status. Reason we are checking first user
  3942. * for ofdma, completion seen at next MU BAR frm, for mimo
  3943. * only for first user completion will be immediate.
  3944. */
  3945. if (ppdu_desc->frame_type == CDP_PPDU_FTYPE_DATA &&
  3946. (ppdu_desc->user[0].completion_status == 0 &&
  3947. (ppdu_info->compltn_common_tlv != ppdu_info->ack_ba_tlv)))
  3948. return NULL;
  3949. }
  3950. /**
  3951. * Once all the TLVs for a given PPDU has been processed,
  3952. * return PPDU status to be delivered to higher layer.
  3953. * tlv_bitmap_expected can't be available for different frame type.
  3954. * But SCHED CMD STATS TLV is the last TLV from the FW for a ppdu.
  3955. * apart from ACK BA TLV, FW sends other TLV in sequential order.
  3956. * flush tlv comes separate.
  3957. */
  3958. if ((ppdu_info->tlv_bitmap != 0 &&
  3959. (ppdu_info->tlv_bitmap &
  3960. (1 << HTT_PPDU_STATS_SCH_CMD_STATUS_TLV))) ||
  3961. (ppdu_info->tlv_bitmap &
  3962. (1 << HTT_PPDU_STATS_USR_COMPLTN_FLUSH_TLV))) {
  3963. ppdu_info->done = 1;
  3964. return ppdu_info;
  3965. }
  3966. return NULL;
  3967. }
  3968. #endif /* QCA_ENHANCED_STATS_SUPPORT */
  3969. #if defined(WDI_EVENT_ENABLE)
  3970. #ifdef QCA_ENHANCED_STATS_SUPPORT
  3971. /**
  3972. * dp_tx_ppdu_stats_feat_enable_check() - Check if feature(s) is enabled to
  3973. * consume stats received from FW via HTT
  3974. * @pdev: Datapath pdev handle
  3975. *
  3976. * Return: void
  3977. */
  3978. static bool dp_tx_ppdu_stats_feat_enable_check(struct dp_pdev *pdev)
  3979. {
  3980. struct dp_soc *soc = pdev->soc;
  3981. struct dp_mon_ops *mon_ops = NULL;
  3982. mon_ops = dp_mon_ops_get(soc);
  3983. if (mon_ops && mon_ops->mon_ppdu_stats_feat_enable_check)
  3984. return mon_ops->mon_ppdu_stats_feat_enable_check(pdev);
  3985. else
  3986. return false;
  3987. }
  3988. /**
  3989. * dp_txrx_ppdu_stats_handler() - Function to process HTT PPDU stats from FW
  3990. * @soc: DP SOC handle
  3991. * @pdev_id: pdev id
  3992. * @htt_t2h_msg: HTT message nbuf
  3993. *
  3994. * return:void
  3995. */
  3996. static bool dp_txrx_ppdu_stats_handler(struct dp_soc *soc,
  3997. uint8_t pdev_id, qdf_nbuf_t htt_t2h_msg)
  3998. {
  3999. struct dp_pdev *pdev;
  4000. struct ppdu_info *ppdu_info = NULL;
  4001. bool free_buf = true;
  4002. struct dp_mon_pdev *mon_pdev;
  4003. if (pdev_id >= MAX_PDEV_CNT)
  4004. return true;
  4005. pdev = soc->pdev_list[pdev_id];
  4006. if (!pdev)
  4007. return true;
  4008. mon_pdev = pdev->monitor_pdev;
  4009. if (!mon_pdev)
  4010. return true;
  4011. if (!dp_tx_ppdu_stats_feat_enable_check(pdev))
  4012. return free_buf;
  4013. qdf_spin_lock_bh(&mon_pdev->ppdu_stats_lock);
  4014. ppdu_info = dp_htt_process_tlv(pdev, htt_t2h_msg);
  4015. if (mon_pdev->mgmtctrl_frm_info.mgmt_buf) {
  4016. if (dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv
  4017. (pdev, htt_t2h_msg, mon_pdev->mgmtctrl_frm_info.ppdu_id) !=
  4018. QDF_STATUS_SUCCESS)
  4019. free_buf = false;
  4020. }
  4021. if (ppdu_info)
  4022. dp_tx_ppdu_desc_deliver(pdev, ppdu_info);
  4023. mon_pdev->mgmtctrl_frm_info.mgmt_buf = NULL;
  4024. mon_pdev->mgmtctrl_frm_info.mgmt_buf_len = 0;
  4025. mon_pdev->mgmtctrl_frm_info.ppdu_id = 0;
  4026. qdf_spin_unlock_bh(&mon_pdev->ppdu_stats_lock);
  4027. return free_buf;
  4028. }
  4029. #else
  4030. static bool dp_txrx_ppdu_stats_handler(struct dp_soc *soc,
  4031. uint8_t pdev_id, qdf_nbuf_t htt_t2h_msg)
  4032. {
  4033. return true;
  4034. }
  4035. #endif/* QCA_ENHANCED_STATS_SUPPORT */
  4036. #endif
  4037. #if defined(WDI_EVENT_ENABLE) &&\
  4038. (defined(QCA_ENHANCED_STATS_SUPPORT) || !defined(REMOVE_PKT_LOG))
  4039. /*
  4040. * dp_ppdu_stats_ind_handler() - PPDU stats msg handler
  4041. * @htt_soc: HTT SOC handle
  4042. * @msg_word: Pointer to payload
  4043. * @htt_t2h_msg: HTT msg nbuf
  4044. *
  4045. * Return: True if buffer should be freed by caller.
  4046. */
  4047. bool
  4048. dp_ppdu_stats_ind_handler(struct htt_soc *soc,
  4049. uint32_t *msg_word,
  4050. qdf_nbuf_t htt_t2h_msg)
  4051. {
  4052. u_int8_t pdev_id;
  4053. u_int8_t target_pdev_id;
  4054. bool free_buf;
  4055. target_pdev_id = HTT_T2H_PPDU_STATS_PDEV_ID_GET(*msg_word);
  4056. pdev_id = dp_get_host_pdev_id_for_target_pdev_id(soc->dp_soc,
  4057. target_pdev_id);
  4058. dp_wdi_event_handler(WDI_EVENT_LITE_T2H, soc->dp_soc,
  4059. htt_t2h_msg, HTT_INVALID_PEER, WDI_NO_VAL,
  4060. pdev_id);
  4061. free_buf = dp_txrx_ppdu_stats_handler(soc->dp_soc, pdev_id,
  4062. htt_t2h_msg);
  4063. return free_buf;
  4064. }
  4065. #endif
  4066. void
  4067. dp_mon_set_bsscolor(struct dp_pdev *pdev, uint8_t bsscolor)
  4068. {
  4069. pdev->monitor_pdev->rx_mon_recv_status.bsscolor = bsscolor;
  4070. }
  4071. bool dp_pdev_get_filter_ucast_data(struct cdp_pdev *pdev_handle)
  4072. {
  4073. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  4074. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  4075. if ((mon_pdev->fp_data_filter & FILTER_DATA_UCAST) ||
  4076. (mon_pdev->mo_data_filter & FILTER_DATA_UCAST))
  4077. return true;
  4078. return false;
  4079. }
  4080. bool dp_pdev_get_filter_mcast_data(struct cdp_pdev *pdev_handle)
  4081. {
  4082. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  4083. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  4084. if ((mon_pdev->fp_data_filter & FILTER_DATA_MCAST) ||
  4085. (mon_pdev->mo_data_filter & FILTER_DATA_MCAST))
  4086. return true;
  4087. return false;
  4088. }
  4089. bool dp_pdev_get_filter_non_data(struct cdp_pdev *pdev_handle)
  4090. {
  4091. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  4092. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  4093. if ((mon_pdev->fp_mgmt_filter & FILTER_MGMT_ALL) ||
  4094. (mon_pdev->mo_mgmt_filter & FILTER_MGMT_ALL)) {
  4095. if ((mon_pdev->fp_ctrl_filter & FILTER_CTRL_ALL) ||
  4096. (mon_pdev->mo_ctrl_filter & FILTER_CTRL_ALL)) {
  4097. return true;
  4098. }
  4099. }
  4100. return false;
  4101. }
  4102. QDF_STATUS dp_mon_soc_cfg_init(struct dp_soc *soc)
  4103. {
  4104. int target_type;
  4105. struct dp_mon_soc *mon_soc = soc->monitor_soc;
  4106. struct cdp_mon_ops *cdp_ops;
  4107. cdp_ops = dp_mon_cdp_ops_get(soc);
  4108. target_type = hal_get_target_type(soc->hal_soc);
  4109. switch (target_type) {
  4110. case TARGET_TYPE_QCA6290:
  4111. case TARGET_TYPE_QCA6390:
  4112. case TARGET_TYPE_QCA6490:
  4113. case TARGET_TYPE_QCA6750:
  4114. case TARGET_TYPE_KIWI:
  4115. /* do nothing */
  4116. break;
  4117. case TARGET_TYPE_QCA8074:
  4118. wlan_cfg_set_mon_delayed_replenish_entries(soc->wlan_cfg_ctx,
  4119. MON_BUF_MIN_ENTRIES);
  4120. break;
  4121. case TARGET_TYPE_QCA8074V2:
  4122. case TARGET_TYPE_QCA6018:
  4123. case TARGET_TYPE_QCA9574:
  4124. wlan_cfg_set_mon_delayed_replenish_entries(soc->wlan_cfg_ctx,
  4125. MON_BUF_MIN_ENTRIES);
  4126. mon_soc->hw_nac_monitor_support = 1;
  4127. break;
  4128. case TARGET_TYPE_QCN9000:
  4129. wlan_cfg_set_mon_delayed_replenish_entries(soc->wlan_cfg_ctx,
  4130. MON_BUF_MIN_ENTRIES);
  4131. mon_soc->hw_nac_monitor_support = 1;
  4132. if (cfg_get(soc->ctrl_psoc, CFG_DP_FULL_MON_MODE)) {
  4133. if (cdp_ops && cdp_ops->config_full_mon_mode)
  4134. cdp_ops->config_full_mon_mode((struct cdp_soc_t *)soc, 1);
  4135. }
  4136. break;
  4137. case TARGET_TYPE_QCA5018:
  4138. case TARGET_TYPE_QCN6122:
  4139. wlan_cfg_set_mon_delayed_replenish_entries(soc->wlan_cfg_ctx,
  4140. MON_BUF_MIN_ENTRIES);
  4141. mon_soc->hw_nac_monitor_support = 1;
  4142. break;
  4143. case TARGET_TYPE_QCN9224:
  4144. wlan_cfg_set_mon_delayed_replenish_entries(soc->wlan_cfg_ctx,
  4145. MON_BUF_MIN_ENTRIES);
  4146. mon_soc->hw_nac_monitor_support = 1;
  4147. mon_soc->monitor_mode_v2 = 1;
  4148. break;
  4149. default:
  4150. dp_mon_info("%s: Unknown tgt type %d\n", __func__, target_type);
  4151. qdf_assert_always(0);
  4152. break;
  4153. }
  4154. dp_mon_info("hw_nac_monitor_support = %d",
  4155. mon_soc->hw_nac_monitor_support);
  4156. return QDF_STATUS_SUCCESS;
  4157. }
  4158. /**
  4159. * dp_mon_pdev_per_target_config() - Target specific monitor pdev configuration
  4160. * @pdev: PDEV handle [Should be valid]
  4161. *
  4162. * Return: None
  4163. */
  4164. static void dp_mon_pdev_per_target_config(struct dp_pdev *pdev)
  4165. {
  4166. struct dp_soc *soc = pdev->soc;
  4167. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  4168. int target_type;
  4169. target_type = hal_get_target_type(soc->hal_soc);
  4170. switch (target_type) {
  4171. case TARGET_TYPE_KIWI:
  4172. mon_pdev->is_tlv_hdr_64_bit = true;
  4173. break;
  4174. default:
  4175. mon_pdev->is_tlv_hdr_64_bit = false;
  4176. break;
  4177. }
  4178. }
  4179. QDF_STATUS dp_mon_pdev_attach(struct dp_pdev *pdev)
  4180. {
  4181. struct dp_soc *soc;
  4182. struct dp_mon_pdev *mon_pdev;
  4183. struct dp_mon_ops *mon_ops;
  4184. qdf_size_t mon_pdev_context_size;
  4185. if (!pdev) {
  4186. dp_mon_err("pdev is NULL");
  4187. goto fail0;
  4188. }
  4189. soc = pdev->soc;
  4190. mon_pdev_context_size = soc->arch_ops.txrx_get_mon_context_size(DP_CONTEXT_TYPE_MON_PDEV);
  4191. mon_pdev = dp_context_alloc_mem(soc, DP_MON_PDEV_TYPE, mon_pdev_context_size);
  4192. if (!mon_pdev) {
  4193. dp_mon_err("%pK: MONITOR pdev allocation failed", pdev);
  4194. goto fail0;
  4195. }
  4196. pdev->monitor_pdev = mon_pdev;
  4197. mon_ops = dp_mon_ops_get(pdev->soc);
  4198. if (!mon_ops) {
  4199. dp_mon_err("%pK: Invalid monitor ops", pdev);
  4200. goto fail1;
  4201. }
  4202. if (mon_ops->mon_pdev_alloc) {
  4203. if (mon_ops->mon_pdev_alloc(pdev)) {
  4204. dp_mon_err("%pK: MONITOR pdev alloc failed", pdev);
  4205. goto fail1;
  4206. }
  4207. }
  4208. if (mon_ops->mon_rings_alloc) {
  4209. if (mon_ops->mon_rings_alloc(pdev)) {
  4210. dp_mon_err("%pK: MONITOR rings setup failed", pdev);
  4211. goto fail2;
  4212. }
  4213. }
  4214. /* Rx monitor mode specific init */
  4215. if (mon_ops->rx_mon_desc_pool_alloc) {
  4216. if (mon_ops->rx_mon_desc_pool_alloc(pdev)) {
  4217. dp_mon_err("%pK: dp_rx_pdev_mon_attach failed", pdev);
  4218. goto fail3;
  4219. }
  4220. }
  4221. pdev->monitor_pdev = mon_pdev;
  4222. dp_mon_pdev_per_target_config(pdev);
  4223. return QDF_STATUS_SUCCESS;
  4224. fail3:
  4225. if (mon_ops->mon_rings_free)
  4226. mon_ops->mon_rings_free(pdev);
  4227. fail2:
  4228. if (mon_ops->mon_pdev_free)
  4229. mon_ops->mon_pdev_free(pdev);
  4230. fail1:
  4231. pdev->monitor_pdev = NULL;
  4232. qdf_mem_free(mon_pdev);
  4233. fail0:
  4234. return QDF_STATUS_E_NOMEM;
  4235. }
  4236. QDF_STATUS dp_mon_pdev_detach(struct dp_pdev *pdev)
  4237. {
  4238. struct dp_mon_pdev *mon_pdev;
  4239. struct dp_mon_ops *mon_ops = NULL;
  4240. if (!pdev) {
  4241. dp_mon_err("pdev is NULL");
  4242. return QDF_STATUS_E_FAILURE;
  4243. }
  4244. mon_pdev = pdev->monitor_pdev;
  4245. if (!mon_pdev) {
  4246. dp_mon_err("Monitor pdev is NULL");
  4247. return QDF_STATUS_E_FAILURE;
  4248. }
  4249. mon_ops = dp_mon_ops_get(pdev->soc);
  4250. if (!mon_ops) {
  4251. dp_mon_err("Monitor ops is NULL");
  4252. return QDF_STATUS_E_FAILURE;
  4253. }
  4254. if (mon_ops->rx_mon_desc_pool_free)
  4255. mon_ops->rx_mon_desc_pool_free(pdev);
  4256. if (mon_ops->mon_rings_free)
  4257. mon_ops->mon_rings_free(pdev);
  4258. if (mon_ops->mon_pdev_free)
  4259. mon_ops->mon_pdev_free(pdev);
  4260. qdf_mem_free(mon_pdev);
  4261. pdev->monitor_pdev = NULL;
  4262. return QDF_STATUS_SUCCESS;
  4263. }
  4264. QDF_STATUS dp_mon_pdev_init(struct dp_pdev *pdev)
  4265. {
  4266. struct dp_soc *soc;
  4267. struct dp_mon_pdev *mon_pdev;
  4268. struct dp_mon_ops *mon_ops = NULL;
  4269. if (!pdev) {
  4270. dp_mon_err("pdev is NULL");
  4271. return QDF_STATUS_E_FAILURE;
  4272. }
  4273. soc = pdev->soc;
  4274. mon_pdev = pdev->monitor_pdev;
  4275. mon_pdev->invalid_mon_peer = qdf_mem_malloc(sizeof(struct dp_mon_peer));
  4276. if (!mon_pdev->invalid_mon_peer) {
  4277. dp_mon_err("%pK: Memory allocation failed for invalid "
  4278. "monitor peer", pdev);
  4279. return QDF_STATUS_E_NOMEM;
  4280. }
  4281. mon_ops = dp_mon_ops_get(pdev->soc);
  4282. if (!mon_ops) {
  4283. dp_mon_err("Monitor ops is NULL");
  4284. goto fail0;
  4285. }
  4286. mon_pdev->filter = dp_mon_filter_alloc(mon_pdev);
  4287. if (!mon_pdev->filter) {
  4288. dp_mon_err("%pK: Memory allocation failed for monitor filter",
  4289. pdev);
  4290. goto fail0;
  4291. }
  4292. if (mon_ops->tx_mon_filter_alloc) {
  4293. if (mon_ops->tx_mon_filter_alloc(pdev)) {
  4294. dp_mon_err("%pK: Memory allocation failed for tx monitor "
  4295. "filter", pdev);
  4296. goto fail1;
  4297. }
  4298. }
  4299. qdf_spinlock_create(&mon_pdev->ppdu_stats_lock);
  4300. qdf_spinlock_create(&mon_pdev->neighbour_peer_mutex);
  4301. mon_pdev->monitor_configured = false;
  4302. mon_pdev->mon_chan_band = REG_BAND_UNKNOWN;
  4303. TAILQ_INIT(&mon_pdev->neighbour_peers_list);
  4304. mon_pdev->neighbour_peers_added = false;
  4305. mon_pdev->monitor_configured = false;
  4306. /* Monitor filter init */
  4307. mon_pdev->mon_filter_mode = MON_FILTER_ALL;
  4308. mon_pdev->fp_mgmt_filter = FILTER_MGMT_ALL;
  4309. mon_pdev->fp_ctrl_filter = FILTER_CTRL_ALL;
  4310. mon_pdev->fp_data_filter = FILTER_DATA_ALL;
  4311. mon_pdev->mo_mgmt_filter = FILTER_MGMT_ALL;
  4312. mon_pdev->mo_ctrl_filter = FILTER_CTRL_ALL;
  4313. mon_pdev->mo_data_filter = FILTER_DATA_ALL;
  4314. /*
  4315. * initialize ppdu tlv list
  4316. */
  4317. TAILQ_INIT(&mon_pdev->ppdu_info_list);
  4318. TAILQ_INIT(&mon_pdev->sched_comp_ppdu_list);
  4319. mon_pdev->list_depth = 0;
  4320. mon_pdev->tlv_count = 0;
  4321. /* initlialize cal client timer */
  4322. dp_cal_client_attach(&mon_pdev->cal_client_ctx,
  4323. dp_pdev_to_cdp_pdev(pdev),
  4324. pdev->soc->osdev,
  4325. &dp_iterate_update_peer_list);
  4326. if (dp_htt_ppdu_stats_attach(pdev) != QDF_STATUS_SUCCESS)
  4327. goto fail2;
  4328. if (mon_ops->mon_rings_init) {
  4329. if (mon_ops->mon_rings_init(pdev)) {
  4330. dp_mon_err("%pK: MONITOR rings setup failed", pdev);
  4331. goto fail3;
  4332. }
  4333. }
  4334. /* initialize sw monitor rx descriptors */
  4335. if (mon_ops->rx_mon_desc_pool_init)
  4336. mon_ops->rx_mon_desc_pool_init(pdev);
  4337. /* allocate buffers and replenish the monitor RxDMA ring */
  4338. if (mon_ops->rx_mon_buffers_alloc) {
  4339. if (mon_ops->rx_mon_buffers_alloc(pdev)) {
  4340. dp_mon_err("%pK: rx mon buffers alloc failed", pdev);
  4341. goto fail4;
  4342. }
  4343. }
  4344. /* attach monitor function */
  4345. dp_monitor_tx_ppdu_stats_attach(pdev);
  4346. mon_pdev->is_dp_mon_pdev_initialized = true;
  4347. return QDF_STATUS_SUCCESS;
  4348. fail4:
  4349. if (mon_ops->rx_mon_desc_pool_deinit)
  4350. mon_ops->rx_mon_desc_pool_deinit(pdev);
  4351. if (mon_ops->mon_rings_deinit)
  4352. mon_ops->mon_rings_deinit(pdev);
  4353. fail3:
  4354. dp_htt_ppdu_stats_detach(pdev);
  4355. fail2:
  4356. qdf_spinlock_destroy(&mon_pdev->neighbour_peer_mutex);
  4357. qdf_spinlock_destroy(&mon_pdev->ppdu_stats_lock);
  4358. if (mon_ops->tx_mon_filter_dealloc)
  4359. mon_ops->tx_mon_filter_dealloc(pdev);
  4360. fail1:
  4361. dp_mon_filter_dealloc(mon_pdev);
  4362. fail0:
  4363. qdf_mem_free(mon_pdev->invalid_mon_peer);
  4364. return QDF_STATUS_E_FAILURE;
  4365. }
  4366. QDF_STATUS dp_mon_pdev_deinit(struct dp_pdev *pdev)
  4367. {
  4368. struct dp_mon_pdev *mon_pdev = pdev->monitor_pdev;
  4369. struct dp_mon_ops *mon_ops = NULL;
  4370. mon_ops = dp_mon_ops_get(pdev->soc);
  4371. if (!mon_ops) {
  4372. dp_mon_err("Monitor ops is NULL");
  4373. return QDF_STATUS_E_FAILURE;
  4374. }
  4375. if (!mon_pdev->is_dp_mon_pdev_initialized)
  4376. return QDF_STATUS_SUCCESS;
  4377. dp_mon_filters_reset(pdev);
  4378. /* detach monitor function */
  4379. dp_monitor_tx_ppdu_stats_detach(pdev);
  4380. if (mon_ops->rx_mon_buffers_free)
  4381. mon_ops->rx_mon_buffers_free(pdev);
  4382. if (mon_ops->rx_mon_desc_pool_deinit)
  4383. mon_ops->rx_mon_desc_pool_deinit(pdev);
  4384. if (mon_ops->mon_rings_deinit)
  4385. mon_ops->mon_rings_deinit(pdev);
  4386. dp_cal_client_detach(&mon_pdev->cal_client_ctx);
  4387. dp_htt_ppdu_stats_detach(pdev);
  4388. qdf_spinlock_destroy(&mon_pdev->ppdu_stats_lock);
  4389. dp_neighbour_peers_detach(pdev);
  4390. dp_pktlogmod_exit(pdev);
  4391. if (mon_ops->tx_mon_filter_dealloc)
  4392. mon_ops->tx_mon_filter_dealloc(pdev);
  4393. if (mon_pdev->filter)
  4394. dp_mon_filter_dealloc(mon_pdev);
  4395. if (mon_ops->mon_rings_deinit)
  4396. mon_ops->mon_rings_deinit(pdev);
  4397. if (mon_pdev->invalid_mon_peer)
  4398. qdf_mem_free(mon_pdev->invalid_mon_peer);
  4399. mon_pdev->is_dp_mon_pdev_initialized = false;
  4400. return QDF_STATUS_SUCCESS;
  4401. }
  4402. QDF_STATUS dp_mon_vdev_attach(struct dp_vdev *vdev)
  4403. {
  4404. struct dp_mon_vdev *mon_vdev;
  4405. struct dp_pdev *pdev = vdev->pdev;
  4406. mon_vdev = (struct dp_mon_vdev *)qdf_mem_malloc(sizeof(*mon_vdev));
  4407. if (!mon_vdev) {
  4408. dp_mon_err("%pK: Monitor vdev allocation failed", vdev);
  4409. return QDF_STATUS_E_NOMEM;
  4410. }
  4411. if (pdev->monitor_pdev->scan_spcl_vap_configured)
  4412. dp_scan_spcl_vap_stats_attach(mon_vdev);
  4413. vdev->monitor_vdev = mon_vdev;
  4414. return QDF_STATUS_SUCCESS;
  4415. }
  4416. QDF_STATUS dp_mon_vdev_detach(struct dp_vdev *vdev)
  4417. {
  4418. struct dp_mon_vdev *mon_vdev = vdev->monitor_vdev;
  4419. struct dp_pdev *pdev = vdev->pdev;
  4420. if (!mon_vdev)
  4421. return QDF_STATUS_E_FAILURE;
  4422. if (pdev->monitor_pdev->scan_spcl_vap_configured)
  4423. dp_scan_spcl_vap_stats_detach(mon_vdev);
  4424. qdf_mem_free(mon_vdev);
  4425. vdev->monitor_vdev = NULL;
  4426. /* set mvdev to NULL only if detach is called for monitor/special vap
  4427. */
  4428. if (pdev->monitor_pdev->mvdev == vdev)
  4429. pdev->monitor_pdev->mvdev = NULL;
  4430. return QDF_STATUS_SUCCESS;
  4431. }
  4432. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  4433. /**
  4434. * dp_mon_peer_attach_notify() - Raise WDI event for peer create
  4435. * @peer: DP Peer handle
  4436. *
  4437. * Return: none
  4438. */
  4439. static inline
  4440. void dp_mon_peer_attach_notify(struct dp_peer *peer)
  4441. {
  4442. struct dp_mon_peer *mon_peer = peer->monitor_peer;
  4443. struct dp_pdev *pdev;
  4444. struct dp_soc *soc;
  4445. struct cdp_peer_cookie peer_cookie;
  4446. pdev = peer->vdev->pdev;
  4447. soc = pdev->soc;
  4448. qdf_mem_copy(peer_cookie.mac_addr, peer->mac_addr.raw,
  4449. QDF_MAC_ADDR_SIZE);
  4450. peer_cookie.ctx = NULL;
  4451. peer_cookie.pdev_id = pdev->pdev_id;
  4452. peer_cookie.cookie = pdev->next_peer_cookie++;
  4453. dp_wdi_event_handler(WDI_EVENT_PEER_CREATE, soc,
  4454. (void *)&peer_cookie,
  4455. peer->peer_id, WDI_NO_VAL, pdev->pdev_id);
  4456. if (soc->rdkstats_enabled) {
  4457. if (!peer_cookie.ctx) {
  4458. pdev->next_peer_cookie--;
  4459. qdf_err("Failed to initialize peer rate stats");
  4460. mon_peer->rdkstats_ctx = NULL;
  4461. } else {
  4462. mon_peer->rdkstats_ctx = (struct cdp_peer_rate_stats_ctx *)
  4463. peer_cookie.ctx;
  4464. }
  4465. }
  4466. }
  4467. /**
  4468. * dp_mon_peer_detach_notify() - Raise WDI event for peer destroy
  4469. * @peer: DP Peer handle
  4470. *
  4471. * Return: none
  4472. */
  4473. static inline
  4474. void dp_mon_peer_detach_notify(struct dp_peer *peer)
  4475. {
  4476. struct dp_mon_peer *mon_peer = peer->monitor_peer;
  4477. struct dp_pdev *pdev;
  4478. struct dp_soc *soc;
  4479. struct cdp_peer_cookie peer_cookie;
  4480. pdev = peer->vdev->pdev;
  4481. soc = pdev->soc;
  4482. /* send peer destroy event to upper layer */
  4483. qdf_mem_copy(peer_cookie.mac_addr, peer->mac_addr.raw,
  4484. QDF_MAC_ADDR_SIZE);
  4485. peer_cookie.ctx = NULL;
  4486. peer_cookie.ctx = (struct cdp_stats_cookie *)mon_peer->rdkstats_ctx;
  4487. dp_wdi_event_handler(WDI_EVENT_PEER_DESTROY,
  4488. soc,
  4489. (void *)&peer_cookie,
  4490. peer->peer_id,
  4491. WDI_NO_VAL,
  4492. pdev->pdev_id);
  4493. mon_peer->rdkstats_ctx = NULL;
  4494. }
  4495. #else
  4496. static inline
  4497. void dp_mon_peer_attach_notify(struct dp_peer *peer)
  4498. {
  4499. peer->monitor_peer->rdkstats_ctx = NULL;
  4500. }
  4501. static inline
  4502. void dp_mon_peer_detach_notify(struct dp_peer *peer)
  4503. {
  4504. peer->monitor_peer->rdkstats_ctx = NULL;
  4505. }
  4506. #endif
  4507. #if defined(WLAN_TX_PKT_CAPTURE_ENH) || defined(FEATURE_PERPKT_INFO)
  4508. QDF_STATUS dp_mon_peer_attach(struct dp_peer *peer)
  4509. {
  4510. struct dp_mon_peer *mon_peer;
  4511. struct dp_pdev *pdev;
  4512. mon_peer = (struct dp_mon_peer *)qdf_mem_malloc(sizeof(*mon_peer));
  4513. if (!mon_peer) {
  4514. dp_mon_err("%pK: MONITOR peer allocation failed", peer);
  4515. return QDF_STATUS_E_NOMEM;
  4516. }
  4517. peer->monitor_peer = mon_peer;
  4518. pdev = peer->vdev->pdev;
  4519. /*
  4520. * In tx_monitor mode, filter may be set for unassociated peer
  4521. * when unassociated peer get associated peer need to
  4522. * update tx_cap_enabled flag to support peer filter.
  4523. */
  4524. dp_monitor_peer_tx_capture_filter_check(pdev, peer);
  4525. DP_STATS_INIT(mon_peer);
  4526. DP_STATS_UPD(mon_peer, rx.avg_snr, CDP_INVALID_SNR);
  4527. dp_mon_peer_attach_notify(peer);
  4528. return QDF_STATUS_SUCCESS;
  4529. }
  4530. #endif
  4531. QDF_STATUS dp_mon_peer_detach(struct dp_peer *peer)
  4532. {
  4533. struct dp_mon_peer *mon_peer = peer->monitor_peer;
  4534. if (!mon_peer)
  4535. return QDF_STATUS_SUCCESS;
  4536. dp_mon_peer_detach_notify(peer);
  4537. qdf_mem_free(mon_peer);
  4538. peer->monitor_peer = NULL;
  4539. return QDF_STATUS_SUCCESS;
  4540. }
  4541. #ifndef DISABLE_MON_CONFIG
  4542. void dp_mon_register_intr_ops(struct dp_soc *soc)
  4543. {
  4544. struct dp_mon_ops *mon_ops = NULL;
  4545. mon_ops = dp_mon_ops_get(soc);
  4546. if (!mon_ops) {
  4547. dp_mon_err("Monitor ops is NULL");
  4548. return;
  4549. }
  4550. if (mon_ops->mon_register_intr_ops)
  4551. mon_ops->mon_register_intr_ops(soc);
  4552. }
  4553. #endif
  4554. struct cdp_peer_rate_stats_ctx *dp_mon_peer_get_rdkstats_ctx(struct dp_peer *peer)
  4555. {
  4556. struct dp_mon_peer *mon_peer = peer->monitor_peer;
  4557. if (mon_peer)
  4558. return mon_peer->rdkstats_ctx;
  4559. else
  4560. return NULL;
  4561. }
  4562. #ifdef QCA_ENHANCED_STATS_SUPPORT
  4563. void dp_mon_peer_reset_stats(struct dp_peer *peer)
  4564. {
  4565. struct dp_mon_peer *mon_peer = NULL;
  4566. mon_peer = peer->monitor_peer;
  4567. if (!mon_peer)
  4568. return;
  4569. DP_STATS_CLR(mon_peer);
  4570. DP_STATS_UPD(mon_peer, rx.avg_snr, CDP_INVALID_SNR);
  4571. }
  4572. void dp_mon_peer_get_stats(struct dp_peer *peer, void *arg,
  4573. enum cdp_stat_update_type type)
  4574. {
  4575. struct dp_mon_peer *mon_peer = peer->monitor_peer;
  4576. struct dp_mon_peer_stats *mon_peer_stats;
  4577. if (!mon_peer || !arg)
  4578. return;
  4579. mon_peer_stats = &mon_peer->stats;
  4580. switch (type) {
  4581. case UPDATE_PEER_STATS:
  4582. {
  4583. struct cdp_peer_stats *peer_stats =
  4584. (struct cdp_peer_stats *)arg;
  4585. DP_UPDATE_MON_STATS(peer_stats, mon_peer_stats);
  4586. break;
  4587. }
  4588. case UPDATE_VDEV_STATS:
  4589. {
  4590. struct cdp_vdev_stats *vdev_stats =
  4591. (struct cdp_vdev_stats *)arg;
  4592. DP_UPDATE_MON_STATS(vdev_stats, mon_peer_stats);
  4593. break;
  4594. }
  4595. default:
  4596. dp_mon_err("Invalid stats_update_type");
  4597. }
  4598. }
  4599. void dp_mon_invalid_peer_update_pdev_stats(struct dp_pdev *pdev)
  4600. {
  4601. struct dp_mon_peer *mon_peer;
  4602. struct dp_mon_peer_stats *mon_peer_stats;
  4603. struct cdp_pdev_stats *pdev_stats;
  4604. if (!pdev || !pdev->monitor_pdev)
  4605. return;
  4606. mon_peer = pdev->monitor_pdev->invalid_mon_peer;
  4607. if (!mon_peer)
  4608. return;
  4609. mon_peer_stats = &mon_peer->stats;
  4610. pdev_stats = &pdev->stats;
  4611. DP_UPDATE_MON_STATS(pdev_stats, mon_peer_stats);
  4612. }
  4613. QDF_STATUS
  4614. dp_mon_peer_get_stats_param(struct dp_peer *peer, enum cdp_peer_stats_type type,
  4615. cdp_peer_stats_param_t *buf)
  4616. {
  4617. QDF_STATUS ret = QDF_STATUS_SUCCESS;
  4618. struct dp_mon_peer *mon_peer;
  4619. mon_peer = peer->monitor_peer;
  4620. if (!mon_peer)
  4621. return QDF_STATUS_E_FAILURE;
  4622. switch (type) {
  4623. case cdp_peer_tx_rate:
  4624. buf->tx_rate = mon_peer->stats.tx.tx_rate;
  4625. break;
  4626. case cdp_peer_tx_last_tx_rate:
  4627. buf->last_tx_rate = mon_peer->stats.tx.last_tx_rate;
  4628. break;
  4629. case cdp_peer_tx_ratecode:
  4630. buf->tx_ratecode = mon_peer->stats.tx.tx_ratecode;
  4631. break;
  4632. case cdp_peer_rx_rate:
  4633. buf->rx_rate = mon_peer->stats.rx.rx_rate;
  4634. break;
  4635. case cdp_peer_rx_last_rx_rate:
  4636. buf->last_rx_rate = mon_peer->stats.rx.last_rx_rate;
  4637. break;
  4638. case cdp_peer_rx_ratecode:
  4639. buf->rx_ratecode = mon_peer->stats.rx.rx_ratecode;
  4640. break;
  4641. case cdp_peer_rx_avg_snr:
  4642. buf->rx_avg_snr = mon_peer->stats.rx.avg_snr;
  4643. break;
  4644. case cdp_peer_rx_snr:
  4645. buf->rx_snr = mon_peer->stats.rx.snr;
  4646. break;
  4647. default:
  4648. dp_err("Invalid stats type requested");
  4649. ret = QDF_STATUS_E_FAILURE;
  4650. }
  4651. return ret;
  4652. }
  4653. #endif
  4654. void dp_mon_ops_register(struct dp_soc *soc)
  4655. {
  4656. struct dp_mon_soc *mon_soc = soc->monitor_soc;
  4657. uint32_t target_type;
  4658. target_type = hal_get_target_type(soc->hal_soc);
  4659. switch (target_type) {
  4660. case TARGET_TYPE_QCA6290:
  4661. case TARGET_TYPE_QCA6390:
  4662. case TARGET_TYPE_QCA6490:
  4663. case TARGET_TYPE_QCA6750:
  4664. case TARGET_TYPE_KIWI:
  4665. case TARGET_TYPE_QCA8074:
  4666. case TARGET_TYPE_QCA8074V2:
  4667. case TARGET_TYPE_QCA6018:
  4668. case TARGET_TYPE_QCA9574:
  4669. case TARGET_TYPE_QCN9000:
  4670. case TARGET_TYPE_QCA5018:
  4671. case TARGET_TYPE_QCN6122:
  4672. dp_mon_ops_register_1_0(mon_soc);
  4673. break;
  4674. case TARGET_TYPE_QCN9224:
  4675. #ifdef QCA_MONITOR_2_0_SUPPORT
  4676. dp_mon_ops_register_2_0(mon_soc);
  4677. #endif
  4678. break;
  4679. default:
  4680. dp_mon_err("%s: Unknown tgt type %d", __func__, target_type);
  4681. qdf_assert_always(0);
  4682. break;
  4683. }
  4684. }
  4685. #ifdef QCA_MONITOR_OPS_PER_SOC_SUPPORT
  4686. void dp_mon_ops_free(struct dp_soc *soc)
  4687. {
  4688. struct cdp_ops *ops = soc->cdp_soc.ops;
  4689. struct cdp_mon_ops *cdp_mon_ops = ops->mon_ops;
  4690. struct dp_mon_soc *mon_soc = soc->monitor_soc;
  4691. struct dp_mon_ops *mon_ops = mon_soc->mon_ops;
  4692. if (cdp_mon_ops)
  4693. qdf_mem_free(cdp_mon_ops);
  4694. if (mon_ops)
  4695. qdf_mem_free(mon_ops);
  4696. }
  4697. #else
  4698. void dp_mon_ops_free(struct dp_soc *soc)
  4699. {
  4700. }
  4701. #endif
  4702. void dp_mon_cdp_ops_register(struct dp_soc *soc)
  4703. {
  4704. struct cdp_ops *ops = soc->cdp_soc.ops;
  4705. uint32_t target_type;
  4706. if (!ops) {
  4707. dp_mon_err("cdp_ops is NULL");
  4708. return;
  4709. }
  4710. target_type = hal_get_target_type(soc->hal_soc);
  4711. switch (target_type) {
  4712. case TARGET_TYPE_QCA6290:
  4713. case TARGET_TYPE_QCA6390:
  4714. case TARGET_TYPE_QCA6490:
  4715. case TARGET_TYPE_QCA6750:
  4716. case TARGET_TYPE_KIWI:
  4717. case TARGET_TYPE_QCA8074:
  4718. case TARGET_TYPE_QCA8074V2:
  4719. case TARGET_TYPE_QCA6018:
  4720. case TARGET_TYPE_QCA9574:
  4721. case TARGET_TYPE_QCN9000:
  4722. case TARGET_TYPE_QCA5018:
  4723. case TARGET_TYPE_QCN6122:
  4724. dp_mon_cdp_ops_register_1_0(ops);
  4725. break;
  4726. case TARGET_TYPE_QCN9224:
  4727. #ifdef QCA_MONITOR_2_0_SUPPORT
  4728. dp_mon_cdp_ops_register_2_0(ops);
  4729. #endif
  4730. break;
  4731. default:
  4732. dp_mon_err("%s: Unknown tgt type %d", __func__, target_type);
  4733. qdf_assert_always(0);
  4734. break;
  4735. }
  4736. #if defined(WLAN_CFR_ENABLE) && defined(WLAN_ENH_CFR_ENABLE)
  4737. ops->cfr_ops->txrx_cfr_filter = dp_cfr_filter;
  4738. ops->cfr_ops->txrx_enable_mon_reap_timer = dp_enable_mon_reap_timer;
  4739. #endif
  4740. ops->cmn_drv_ops->txrx_set_monitor_mode = dp_vdev_set_monitor_mode;
  4741. ops->cmn_drv_ops->txrx_get_mon_vdev_from_pdev =
  4742. dp_get_mon_vdev_from_pdev_wifi3;
  4743. #ifdef DP_PEER_EXTENDED_API
  4744. ops->misc_ops->pkt_log_init = dp_pkt_log_init;
  4745. ops->misc_ops->pkt_log_con_service = dp_pkt_log_con_service;
  4746. ops->misc_ops->pkt_log_exit = dp_pkt_log_exit;
  4747. #endif
  4748. #ifdef ATH_SUPPORT_NAC_RSSI
  4749. ops->ctrl_ops->txrx_vdev_config_for_nac_rssi = dp_config_for_nac_rssi;
  4750. ops->ctrl_ops->txrx_vdev_get_neighbour_rssi =
  4751. dp_vdev_get_neighbour_rssi;
  4752. #endif
  4753. #if defined(ATH_SUPPORT_NAC_RSSI) || defined(ATH_SUPPORT_NAC)
  4754. ops->ctrl_ops->txrx_update_filter_neighbour_peers =
  4755. dp_update_filter_neighbour_peers;
  4756. #endif /* ATH_SUPPORT_NAC_RSSI || ATH_SUPPORT_NAC */
  4757. ops->ctrl_ops->enable_peer_based_pktlog =
  4758. dp_enable_peer_based_pktlog;
  4759. #if defined(WLAN_TX_PKT_CAPTURE_ENH) || defined(WLAN_RX_PKT_CAPTURE_ENH)
  4760. ops->ctrl_ops->txrx_update_peer_pkt_capture_params =
  4761. dp_peer_update_pkt_capture_params;
  4762. #endif /* WLAN_TX_PKT_CAPTURE_ENH || WLAN_RX_PKT_CAPTURE_ENH */
  4763. #ifdef QCA_ENHANCED_STATS_SUPPORT
  4764. ops->host_stats_ops->txrx_enable_enhanced_stats =
  4765. dp_enable_enhanced_stats;
  4766. ops->host_stats_ops->txrx_disable_enhanced_stats =
  4767. dp_disable_enhanced_stats;
  4768. #endif /* QCA_ENHANCED_STATS_SUPPORT */
  4769. #ifdef WDI_EVENT_ENABLE
  4770. ops->ctrl_ops->txrx_get_pldev = dp_get_pldev;
  4771. #endif
  4772. #ifdef QCA_SUPPORT_SCAN_SPCL_VAP_STATS
  4773. ops->host_stats_ops->txrx_get_scan_spcl_vap_stats =
  4774. dp_get_scan_spcl_vap_stats;
  4775. #endif
  4776. return;
  4777. }
  4778. #ifdef QCA_MONITOR_OPS_PER_SOC_SUPPORT
  4779. static inline void
  4780. dp_mon_cdp_mon_ops_deregister(struct cdp_ops *ops)
  4781. {
  4782. if (ops->mon_ops) {
  4783. qdf_mem_free(ops->mon_ops);
  4784. ops->mon_ops = NULL;
  4785. }
  4786. }
  4787. #else
  4788. static inline void
  4789. dp_mon_cdp_mon_ops_deregister(struct cdp_ops *ops)
  4790. {
  4791. ops->mon_ops = NULL;
  4792. }
  4793. #endif
  4794. void dp_mon_cdp_ops_deregister(struct dp_soc *soc)
  4795. {
  4796. struct cdp_ops *ops = soc->cdp_soc.ops;
  4797. if (!ops) {
  4798. dp_mon_err("cdp_ops is NULL");
  4799. return;
  4800. }
  4801. dp_mon_cdp_mon_ops_deregister(ops);
  4802. #if defined(WLAN_CFR_ENABLE) && defined(WLAN_ENH_CFR_ENABLE)
  4803. ops->cfr_ops->txrx_cfr_filter = NULL;
  4804. ops->cfr_ops->txrx_enable_mon_reap_timer = NULL;
  4805. #endif
  4806. ops->cmn_drv_ops->txrx_set_monitor_mode = NULL;
  4807. ops->cmn_drv_ops->txrx_get_mon_vdev_from_pdev = NULL;
  4808. #ifdef DP_PEER_EXTENDED_API
  4809. ops->misc_ops->pkt_log_init = NULL;
  4810. ops->misc_ops->pkt_log_con_service = NULL;
  4811. ops->misc_ops->pkt_log_exit = NULL;
  4812. #endif
  4813. #ifdef ATH_SUPPORT_NAC_RSSI
  4814. ops->ctrl_ops->txrx_vdev_config_for_nac_rssi = NULL;
  4815. ops->ctrl_ops->txrx_vdev_get_neighbour_rssi = NULL;
  4816. #endif
  4817. #if defined(ATH_SUPPORT_NAC_RSSI) || defined(ATH_SUPPORT_NAC)
  4818. ops->ctrl_ops->txrx_update_filter_neighbour_peers = NULL;
  4819. #endif /* ATH_SUPPORT_NAC_RSSI || ATH_SUPPORT_NAC */
  4820. ops->ctrl_ops->enable_peer_based_pktlog = NULL;
  4821. #if defined(WLAN_TX_PKT_CAPTURE_ENH) || defined(WLAN_RX_PKT_CAPTURE_ENH)
  4822. ops->ctrl_ops->txrx_update_peer_pkt_capture_params = NULL;
  4823. #endif /* WLAN_TX_PKT_CAPTURE_ENH || WLAN_RX_PKT_CAPTURE_ENH */
  4824. #ifdef FEATURE_PERPKT_INFO
  4825. ops->host_stats_ops->txrx_enable_enhanced_stats = NULL;
  4826. ops->host_stats_ops->txrx_disable_enhanced_stats = NULL;
  4827. #endif /* FEATURE_PERPKT_INFO */
  4828. #ifdef WDI_EVENT_ENABLE
  4829. ops->ctrl_ops->txrx_get_pldev = NULL;
  4830. #endif
  4831. return;
  4832. }
  4833. void dp_mon_intr_ops_deregister(struct dp_soc *soc)
  4834. {
  4835. struct dp_mon_soc *mon_soc = soc->monitor_soc;
  4836. mon_soc->mon_rx_process = NULL;
  4837. }
  4838. void dp_mon_feature_ops_deregister(struct dp_soc *soc)
  4839. {
  4840. struct dp_mon_ops *mon_ops = dp_mon_ops_get(soc);
  4841. if (!mon_ops) {
  4842. dp_err("mon_ops is NULL");
  4843. return;
  4844. }
  4845. mon_ops->mon_config_debug_sniffer = NULL;
  4846. mon_ops->mon_peer_tx_init = NULL;
  4847. mon_ops->mon_peer_tx_cleanup = NULL;
  4848. mon_ops->mon_htt_ppdu_stats_attach = NULL;
  4849. mon_ops->mon_htt_ppdu_stats_detach = NULL;
  4850. mon_ops->mon_print_pdev_rx_mon_stats = NULL;
  4851. mon_ops->mon_set_bsscolor = NULL;
  4852. mon_ops->mon_pdev_get_filter_ucast_data = NULL;
  4853. mon_ops->mon_pdev_get_filter_mcast_data = NULL;
  4854. mon_ops->mon_pdev_get_filter_non_data = NULL;
  4855. mon_ops->mon_neighbour_peer_add_ast = NULL;
  4856. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  4857. mon_ops->mon_peer_tid_peer_id_update = NULL;
  4858. mon_ops->mon_tx_ppdu_stats_attach = NULL;
  4859. mon_ops->mon_tx_ppdu_stats_detach = NULL;
  4860. mon_ops->mon_tx_capture_debugfs_init = NULL;
  4861. mon_ops->mon_tx_add_to_comp_queue = NULL;
  4862. mon_ops->mon_peer_tx_capture_filter_check = NULL;
  4863. mon_ops->mon_print_pdev_tx_capture_stats = NULL;
  4864. mon_ops->mon_config_enh_tx_capture = NULL;
  4865. #endif
  4866. #if defined(WDI_EVENT_ENABLE) &&\
  4867. (defined(QCA_ENHANCED_STATS_SUPPORT) || !defined(REMOVE_PKT_LOG))
  4868. mon_ops->mon_ppdu_stats_ind_handler = NULL;
  4869. mon_ops->mon_ppdu_desc_deliver = NULL;
  4870. mon_ops->mon_ppdu_desc_notify = NULL;
  4871. mon_ops->mon_ppdu_stats_feat_enable_check = NULL;
  4872. #endif
  4873. #ifdef WLAN_RX_PKT_CAPTURE_ENH
  4874. mon_ops->mon_config_enh_rx_capture = NULL;
  4875. #endif
  4876. #ifdef QCA_SUPPORT_BPR
  4877. mon_ops->mon_set_bpr_enable = NULL;
  4878. #endif
  4879. #ifdef ATH_SUPPORT_NAC
  4880. mon_ops->mon_set_filter_neigh_peers = NULL;
  4881. #endif
  4882. #ifdef WLAN_ATF_ENABLE
  4883. mon_ops->mon_set_atf_stats_enable = NULL;
  4884. #endif
  4885. #ifdef FEATURE_NAC_RSSI
  4886. mon_ops->mon_filter_neighbour_peer = NULL;
  4887. #endif
  4888. #ifdef QCA_MCOPY_SUPPORT
  4889. mon_ops->mon_filter_setup_mcopy_mode = NULL;
  4890. mon_ops->mon_filter_reset_mcopy_mode = NULL;
  4891. mon_ops->mon_mcopy_check_deliver = NULL;
  4892. #endif
  4893. #ifdef QCA_ENHANCED_STATS_SUPPORT
  4894. mon_ops->mon_filter_setup_enhanced_stats = NULL;
  4895. mon_ops->mon_tx_enable_enhanced_stats = NULL;
  4896. mon_ops->mon_tx_disable_enhanced_stats = NULL;
  4897. #ifdef WLAN_FEATURE_11BE
  4898. mon_ops->mon_tx_stats_update = NULL;
  4899. #endif
  4900. #endif
  4901. #if defined(ATH_SUPPORT_NAC_RSSI) || defined(ATH_SUPPORT_NAC)
  4902. mon_ops->mon_filter_setup_smart_monitor = NULL;
  4903. #endif
  4904. #ifdef WLAN_RX_PKT_CAPTURE_ENH
  4905. mon_ops->mon_filter_setup_rx_enh_capture = NULL;
  4906. #endif
  4907. #ifdef WDI_EVENT_ENABLE
  4908. mon_ops->mon_set_pktlog_wifi3 = NULL;
  4909. mon_ops->mon_filter_setup_rx_pkt_log_full = NULL;
  4910. mon_ops->mon_filter_reset_rx_pkt_log_full = NULL;
  4911. mon_ops->mon_filter_setup_rx_pkt_log_lite = NULL;
  4912. mon_ops->mon_filter_reset_rx_pkt_log_lite = NULL;
  4913. mon_ops->mon_filter_setup_rx_pkt_log_cbf = NULL;
  4914. mon_ops->mon_filter_reset_rx_pkt_log_cbf = NULL;
  4915. #ifdef BE_PKTLOG_SUPPORT
  4916. mon_ops->mon_filter_setup_pktlog_hybrid = NULL;
  4917. mon_ops->mon_filter_reset_pktlog_hybrid = NULL;
  4918. #endif
  4919. #endif
  4920. #if defined(DP_CON_MON) && !defined(REMOVE_PKT_LOG)
  4921. mon_ops->mon_pktlogmod_exit = NULL;
  4922. #endif
  4923. mon_ops->rx_packet_length_set = NULL;
  4924. mon_ops->rx_wmask_subscribe = NULL;
  4925. mon_ops->rx_enable_mpdu_logging = NULL;
  4926. mon_ops->mon_neighbour_peers_detach = NULL;
  4927. mon_ops->mon_vdev_set_monitor_mode_buf_rings = NULL;
  4928. mon_ops->mon_vdev_set_monitor_mode_rings = NULL;
  4929. #ifdef QCA_ENHANCED_STATS_SUPPORT
  4930. mon_ops->mon_rx_stats_update = NULL;
  4931. mon_ops->mon_rx_populate_ppdu_usr_info = NULL;
  4932. mon_ops->mon_rx_populate_ppdu_info = NULL;
  4933. #endif
  4934. }
  4935. QDF_STATUS dp_mon_soc_attach(struct dp_soc *soc)
  4936. {
  4937. struct dp_mon_soc *mon_soc;
  4938. if (!soc) {
  4939. dp_mon_err("dp_soc is NULL");
  4940. return QDF_STATUS_E_FAILURE;
  4941. }
  4942. mon_soc = (struct dp_mon_soc *)qdf_mem_malloc(sizeof(*mon_soc));
  4943. if (!mon_soc) {
  4944. dp_mon_err("%pK: mem allocation failed", soc);
  4945. return QDF_STATUS_E_NOMEM;
  4946. }
  4947. /* register monitor ops */
  4948. soc->monitor_soc = mon_soc;
  4949. dp_mon_ops_register(soc);
  4950. dp_mon_register_intr_ops(soc);
  4951. dp_mon_cdp_ops_register(soc);
  4952. dp_mon_register_feature_ops(soc);
  4953. return QDF_STATUS_SUCCESS;
  4954. }
  4955. QDF_STATUS dp_mon_soc_detach(struct dp_soc *soc)
  4956. {
  4957. struct dp_mon_soc *mon_soc;
  4958. if (!soc) {
  4959. dp_mon_err("dp_soc is NULL");
  4960. return QDF_STATUS_E_FAILURE;
  4961. }
  4962. mon_soc = soc->monitor_soc;
  4963. dp_monitor_vdev_timer_deinit(soc);
  4964. dp_mon_cdp_ops_deregister(soc);
  4965. soc->monitor_soc = NULL;
  4966. qdf_mem_free(mon_soc);
  4967. return QDF_STATUS_SUCCESS;
  4968. }